Initial commit
This commit is contained in:
15
.gitignore
vendored
Normal file
15
.gitignore
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
node_modules/
|
||||
dist/
|
||||
frontend/dist/
|
||||
|
||||
*.exe
|
||||
*.test
|
||||
backend/arma3-web-server
|
||||
|
||||
data/
|
||||
serverfiles/
|
||||
|
||||
.env
|
||||
.DS_Store
|
||||
*.log
|
||||
*.rpt
|
||||
29
ARMA3.md
Normal file
29
ARMA3.md
Normal file
@@ -0,0 +1,29 @@
|
||||
Description of ArmA3 structure
|
||||
|
||||
# Directory Structure
|
||||
|
||||
## GameDir
|
||||
```dir
|
||||
<serverdir>/
|
||||
|- mpmissions/
|
||||
|- userconfig/ #cba, ai difficulty, ecc
|
||||
```
|
||||
## Cfg & Mods
|
||||
Parameter based, can be everywhere
|
||||
# Parameters
|
||||
```
|
||||
aram3server_x64[.exe]
|
||||
-server
|
||||
-world=empty
|
||||
-loadMissionToMemory
|
||||
-maxMem=13107
|
||||
-cpuCount=16
|
||||
-hugepages
|
||||
-enableHT
|
||||
-setThreadCharacteristics
|
||||
-noPause
|
||||
-profiles="<path to profile directory>" # path to the profiles directory (misison save dir) and in general the logs directory
|
||||
-config="<cfg-path>/file.cfg" # server related config, name, password, autostart missions )
|
||||
-mods="<path-to-mod1>;<path-to-mod2>" # list of paths to mods separated by ';'
|
||||
-filePatching
|
||||
```
|
||||
156
CODEBASE.md
Normal file
156
CODEBASE.md
Normal file
@@ -0,0 +1,156 @@
|
||||
# Codebase Analysis: arma3-web-server
|
||||
|
||||
## Identity
|
||||
- **Language / runtime**: Go 1.25 (backend), TypeScript 6 + React 19 (frontend)
|
||||
- **Framework(s)**: Gin v1.12 (HTTP router), gorilla/websocket (WS), TanStack Query v5 (data fetching), Tailwind CSS 4 (styling), Vite 8 (bundler)
|
||||
- **Build system**: Go toolchain (`go build`), Vite/Rollup for frontend, multi-stage Docker build
|
||||
- **Test framework**: None detected
|
||||
|
||||
## Directory map
|
||||
|
||||
```
|
||||
arma3-web-server/
|
||||
├── backend/ # Go backend
|
||||
│ ├── cmd/server/main.go # Entry point, env parsing, dir creation, wiring
|
||||
│ ├── internal/
|
||||
│ │ ├── api/ # Gin HTTP handlers + WebSocket endpoints
|
||||
│ │ │ ├── router.go # Route registration, Handler struct + New()
|
||||
│ │ │ ├── settings.go # Settings CRUD + server start/stop/restart + steamcmd
|
||||
│ │ │ ├── configs.go # .cfg file CRUD handlers
|
||||
│ │ │ ├── modlists.go # Modlist CRUD + import + check/download-missing/update-all
|
||||
│ │ │ └── logs.go # WS streaming (server, steamcmd, rpt) + log file listing
|
||||
│ │ ├── models/ # Data structs
|
||||
│ │ │ ├── settings.go # ServerSettings (singleton)
|
||||
│ │ │ └── modlist.go # Modlist + ModEntry + ModlistListItem
|
||||
│ │ └── services/ # Business logic layer
|
||||
│ │ ├── settings.go # JSON load/save from data/settings.json
|
||||
│ │ ├── config_manager.go # .cfg file I/O in $CFG_DIR
|
||||
│ │ ├── modlist_manager.go # Modlist CRUD against data/modlists/*.json
|
||||
│ │ ├── modlist_parser.go # HTML Arma Launcher preset parser
|
||||
│ │ ├── server_process.go # Process lifecycle, arg builder, mod path resolver
|
||||
│ │ ├── steamcmd.go # SteamCMD manager (UpdateGame, DownloadMod, DownloadMods)
|
||||
│ │ └── log_streamer.go # Pub/sub fan-out for stdout/stderr via channels
|
||||
│ ├── go.mod / go.sum
|
||||
│ └── serverfiles/ # Default SERVERFILE_DIR (created at startup)
|
||||
├── frontend/ # React SPA
|
||||
│ ├── src/
|
||||
│ │ ├── App.tsx # Router setup (React Router v7)
|
||||
│ │ ├── main.tsx # Entry point (QueryClient + BrowserRouter)
|
||||
│ │ ├── index.css # Tailwind v4 imports
|
||||
│ │ ├── api/client.ts # Typed fetch wrappers + WS URL builders
|
||||
│ │ ├── types/index.ts # ServerSettings, Modlist, ModEntry, ConfigInfo, ServerPaths
|
||||
│ │ ├── pages/ # 7 route-level page components
|
||||
│ │ │ ├── Dashboard.tsx # Overview cards (status, configs, modlists)
|
||||
│ │ │ ├── Settings.tsx # Main settings tab + userconfig tabs + SteamCMD section
|
||||
│ │ │ ├── Configs.tsx # List/create/duplicate/delete configs
|
||||
│ │ │ ├── ConfigEditor.tsx # Full-page Monaco editor for a single config
|
||||
│ │ │ ├── Modlists.tsx # List/create/duplicate/delete + HTML import
|
||||
│ │ │ ├── ModlistEditor.tsx # Mod list reorder + enable/disable + check/download-missing/update-all
|
||||
│ │ │ └── Logs.tsx # Tabbed LiveTerminal (Server Console / RPT / SteamCMD) + file browser
|
||||
│ │ └── components/
|
||||
│ │ ├── ConfigEditor.tsx # Monaco editor wrapper
|
||||
│ │ ├── LiveTerminal.tsx # xterm.js + auto-reconnect WebSocket
|
||||
│ │ ├── Layout.tsx # Sidebar navigation shell
|
||||
│ │ └── ui/ # Empty
|
||||
│ ├── package.json
|
||||
│ ├── vite.config.ts # Proxy /api + /ws to :8080
|
||||
│ └── tsconfig*.json
|
||||
├── data/ # Runtime data (mounted volume in Docker)
|
||||
│ ├── presets/ # (unused)
|
||||
│ └── servers/ # (unused)
|
||||
├── Dockerfile # Multi-stage: Go build -> npm build -> alpine runtime
|
||||
├── docker-compose.yml # Single service with volume mounts + env vars
|
||||
└── Makefile # Convenience targets: backend, frontend, build, run, dev, clean
|
||||
```
|
||||
|
||||
## Dependencies
|
||||
|
||||
### Backend (Go)
|
||||
|
||||
| Module | Type | Version | Purpose |
|
||||
|---|---|---|---|
|
||||
| `github.com/gin-gonic/gin` | framework | v1.12.0 | HTTP routing, middleware, request binding |
|
||||
| `github.com/gorilla/websocket` | library | v1.5.3 | WebSocket upgrade + message I/O |
|
||||
| `github.com/google/uuid` | utility | v1.6.0 | UUID generation for modlists |
|
||||
| `modernc.org/sqlite` | database | v1.53.0 | Declared but **not used** (file-based chosen) |
|
||||
| `golang.org/x/net` | stdlib | v0.51.0 | HTML parser for modlist import |
|
||||
|
||||
### Frontend (npm)
|
||||
|
||||
| Package | Type | Version | Purpose |
|
||||
|---|---|---|---|
|
||||
| `react` / `react-dom` | framework | ^19.2.7 | UI rendering |
|
||||
| `react-router-dom` | routing | ^7.18.1 | Client-side routing (7 pages) |
|
||||
| `@tanstack/react-query` | data fetching | ^5.101.2 | Server state, caching, polling, mutations |
|
||||
| `tailwindcss` | styling | ^4.3.2 | Utility-first CSS |
|
||||
| `@monaco-editor/react` | editor | ^4.7.0 | Monaco code editor for .cfg files |
|
||||
| `@xterm/xterm` / `@xterm/addon-fit` | terminal | ^6.0.0 / ^0.11.0 | In-browser xterm.js terminal |
|
||||
| `zustand` | state | ^5.0.14 | Declared but **unused** (no stores exist) |
|
||||
| `vite` | bundler | ^8.1.1 | Dev server + production build |
|
||||
| `@vitejs/plugin-react` | tooling | ^6.0.3 | React fast-refresh / JSX transform |
|
||||
| `typescript` | language | ~6.0.2 | Type checking |
|
||||
| `oxlint` | linter | ^1.71.0 | Linting |
|
||||
|
||||
## Architecture
|
||||
|
||||
### Pattern: Layered (API -> Service -> Model), file-based persistence
|
||||
|
||||
```
|
||||
HTTP/WS Gin Router Services Filesystem
|
||||
--------- ---------- -------- ----------
|
||||
Browser -- REST/WS --> api.Handler --> SettingsManager --> data/settings.json
|
||||
| ConfigManager --> $CFG_DIR/*.cfg
|
||||
| ModlistManager --> data/modlists/*.json
|
||||
| ProcessManager --> spawn arma3server_x64
|
||||
| SteamCmdManager --> spawn steamcmd
|
||||
| LogStreamer --> pub/sub (channels)
|
||||
+---> WebSocket clients (xterm.js)
|
||||
```
|
||||
|
||||
### Key abstractions
|
||||
- **Handler** (api package) -- stateless; receives service pointers via constructor injection. All handlers are methods on Handler.
|
||||
- ***Manager** (services package) -- stateful structs for each concern. Hold their own `sync.Mutex` for thread safety.
|
||||
- **LogStreamer** -- pub/sub per named stream (`"server"`, `"steamcmd"`). Subscribe returns a `chan string`; Stream reads from an `io.Reader` (process stdout/stderr) and broadcasts to all subscribers of that key.
|
||||
- **ProcessManager** -- manages the Arma 3 server child process lifecycle. Builds the command line from settings, resolves mod paths, monitors process exit.
|
||||
|
||||
### Notable design decisions
|
||||
1. **No database** -- everything is files: `settings.json`, `*.cfg` in `$CFG_DIR`, modlist JSON files. Backup means copying directories.
|
||||
2. **Single server instance** -- ProcessManager allows only one running process at a time.
|
||||
3. **`%command%` substitution** -- if ServerParameters contains `%command%`, the entire textarea is treated as a shell template, with `%command%` replaced by the binary path and auto-args (`-config=`, `-mod=`, `-profiles=`, `-port=`) appended. Enables Wine wrappers.
|
||||
4. **Two-tier mod resolution** -- resolveModPath checks `$MODS_DIR/@name` first (manual/symlinked), then falls back to `$SERVERFILE_DIR/steamapps/workshop/content/107410/<id>` for workshop downloads.
|
||||
5. **SteamCMD async with live streaming** -- all steamcmd operations run in background goroutines, output broadcast to `"steamcmd"` key.
|
||||
6. **Env-defined paths** -- all dirs set via env vars with hardcoded defaults, resolved to absolute paths at startup.
|
||||
|
||||
## Data flow (example: Start server)
|
||||
|
||||
```
|
||||
User clicks "Start" (Settings.tsx)
|
||||
--> handleSaveThen() -- auto-saves if dirty
|
||||
--> POST /api/server/start
|
||||
--> Handler.StartServer() (settings.go)
|
||||
--> process.Start() (server_process.go)
|
||||
--> Load settings.json
|
||||
--> If %command% in ServerParameters:
|
||||
--> Replace %command% with binPath
|
||||
--> Split into command + args
|
||||
--> Append buildAutoArgs(s): -config=, -mod=, -profiles=, -port=
|
||||
--> exec.CommandContext(ctx, parts[0], append(parts[1:], autoArgs...)...)
|
||||
Else:
|
||||
--> buildArgs(s): split parameters + append auto-args
|
||||
--> exec.CommandContext(ctx, binPath, args...)
|
||||
--> cmd.Dir = serverfileDir
|
||||
--> Pipe stdout/stderr
|
||||
--> cmd.Start()
|
||||
--> Stream stdout/stderr to LogStreamer("server")
|
||||
--> Monitor exit, broadcast [SERVER_PROCESS_EXITED]
|
||||
--> Returns {"status": "starting"}
|
||||
--> Frontend polls GET /api/server/status every 3s
|
||||
--> Shows "Running" badge
|
||||
```
|
||||
|
||||
## CI/CD
|
||||
- **No CI pipeline** -- no `.github/` or `.gitlab-ci.yml` found
|
||||
- **No tests** -- zero test files anywhere in the codebase
|
||||
- **Docker build**: multi-stage Dockerfile at root -- builds Go binary, builds frontend dist, assembles Alpine image with steamcmd, exposes `:8080`, mounts `/data` and `/servers` volumes
|
||||
- **Deployment**: single docker-compose.yml with one service, volume mounts for persistence
|
||||
- **Local dev**: Makefile targets -- `make run` starts backend, `make dev` starts both backend + Vite dev server with hot reload
|
||||
40
Dockerfile
Normal file
40
Dockerfile
Normal file
@@ -0,0 +1,40 @@
|
||||
FROM golang:1.25-alpine AS backend
|
||||
WORKDIR /src
|
||||
COPY backend/go.mod backend/go.sum ./
|
||||
RUN go mod download
|
||||
COPY backend/ .
|
||||
RUN CGO_ENABLED=0 go build -o /server ./cmd/server/
|
||||
|
||||
FROM node:22-alpine AS frontend
|
||||
WORKDIR /src
|
||||
COPY frontend/package.json frontend/package-lock.json ./
|
||||
RUN npm ci
|
||||
COPY frontend/ .
|
||||
RUN npm run build
|
||||
|
||||
FROM alpine:3.21
|
||||
RUN apk add --no-cache ca-certificates tzdata
|
||||
RUN apk add --no-cache steamcmd libstdc++ libgcc || true
|
||||
|
||||
COPY --from=backend /server /usr/local/bin/arma3-web-server
|
||||
COPY --from=frontend /src/dist /usr/share/arma3-web-server/frontend
|
||||
|
||||
EXPOSE 8080
|
||||
VOLUME ["/data", "/servers"]
|
||||
|
||||
# Expected mount structure under /servers:
|
||||
# /servers/ ← SERVERFILE_DIR (arma3server_x64 binary, userconfig/)
|
||||
# /servers/steamapps/workshop/content/107410/ ← workshop mods (downloaded via SteamCMD)
|
||||
# /servers/mods/ ← MODS_DIR (@modname mod folders)
|
||||
# /servers/cfg/ ← CFG_DIR (.cfg files)
|
||||
# /servers/profiles/ ← PROFILES_DIR (logs, .rpt, server profile)
|
||||
ENV DATA_DIR=/data
|
||||
ENV SERVERFILE_DIR=/servers
|
||||
ENV MODS_DIR=/servers/mods
|
||||
ENV CFG_DIR=/servers/cfg
|
||||
ENV PROFILES_DIR=/servers/profiles
|
||||
ENV LISTEN=:8080
|
||||
ENV FRONTEND_DIR=/usr/share/arma3-web-server/frontend
|
||||
ENV GIN_MODE=release
|
||||
|
||||
ENTRYPOINT ["arma3-web-server"]
|
||||
27
Makefile
Normal file
27
Makefile
Normal file
@@ -0,0 +1,27 @@
|
||||
.PHONY: backend frontend build run clean dev
|
||||
|
||||
# Default paths — override via env or copy .env.example
|
||||
SERVERFILE_DIR ?= ./serverfiles
|
||||
MODS_DIR ?= ./serverfiles/mods
|
||||
CFG_DIR ?= ./serverfiles/cfg
|
||||
PROFILES_DIR ?= ./serverfiles/profiles
|
||||
DATA_DIR ?= ../../data
|
||||
|
||||
backend:
|
||||
cd backend && go build -o arma3-web-server ./cmd/server/
|
||||
|
||||
frontend:
|
||||
cd frontend && npm run build
|
||||
|
||||
build: backend frontend
|
||||
|
||||
run:
|
||||
cd backend && SERVERFILE_DIR=$(SERVERFILE_DIR) MODS_DIR=$(MODS_DIR) CFG_DIR=$(CFG_DIR) PROFILES_DIR=$(PROFILES_DIR) DATA_DIR=$(DATA_DIR) GIN_MODE=debug go run ./cmd/server/
|
||||
|
||||
dev:
|
||||
cd backend && SERVERFILE_DIR=$(SERVERFILE_DIR) MODS_DIR=$(MODS_DIR) CFG_DIR=$(CFG_DIR) PROFILES_DIR=$(PROFILES_DIR) DATA_DIR=$(DATA_DIR) GIN_MODE=debug go run ./cmd/server/ &
|
||||
cd frontend && npm run dev
|
||||
|
||||
clean:
|
||||
rm -f backend/arma3-web-server
|
||||
rm -rf frontend/dist
|
||||
213
PLAN.md
Normal file
213
PLAN.md
Normal file
@@ -0,0 +1,213 @@
|
||||
# Arma 3 Web Server — Architecture Plan
|
||||
|
||||
## Overview
|
||||
|
||||
A web-based control panel to configure, update, install, and execute a **single** Arma 3 dedicated server instance. Supports both Windows and Linux server binaries via SteamCMD.
|
||||
|
||||
---
|
||||
|
||||
## Tech Stack
|
||||
|
||||
| Layer | Choice | Rationale |
|
||||
|-------|--------|-----------|
|
||||
| **Backend** | Go 1.24+ (`gin`, `gorilla/websocket`) | Single binary, cross-compiles, goroutines for process streaming |
|
||||
| **Storage** | File-based (JSON on disk) | No database dependency; settings, configs, and modlists are files |
|
||||
| **Frontend** | React 19 + TypeScript + Vite | Fast iteration, rich ecosystem |
|
||||
| **UI Kit** | Tailwind CSS 4 | Dark-theme UI, utility-first styling |
|
||||
| **Code Editor** | Monaco (VS Code) | Syntax-highlighted config editing |
|
||||
| **Terminal** | xterm.js | Live log display from server stdout |
|
||||
|
||||
---
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
arma3-web-server/
|
||||
├── backend/
|
||||
│ ├── cmd/server/main.go # Entry point
|
||||
│ ├── internal/
|
||||
│ │ ├── api/ # HTTP handlers (Gin routes)
|
||||
│ │ │ ├── router.go # Route registration
|
||||
│ │ │ ├── settings.go # Server settings + start/stop/restart
|
||||
│ │ │ ├── configs.go # .cfg file CRUD
|
||||
│ │ │ ├── modlists.go # Modlist CRUD
|
||||
│ │ │ └── logs.go # WebSocket handler for live logs
|
||||
│ │ ├── models/ # Data structs
|
||||
│ │ │ ├── settings.go # ServerSettings (singleton)
|
||||
│ │ │ └── modlist.go # Modlist + ModEntry
|
||||
│ │ └── services/ # Business logic
|
||||
│ │ ├── settings.go # Singleton settings load/save
|
||||
│ │ ├── config_manager.go # .cfg file I/O in $CFG_DIR
|
||||
│ │ ├── modlist_manager.go # Modlist CRUD (JSON files)
|
||||
│ │ ├── server_process.go # Process lifecycle (start/stop/restart)
|
||||
│ │ └── log_streamer.go # stdout/stderr → WebSocket fan-out
|
||||
│ ├── go.mod
|
||||
│ └── go.sum
|
||||
├── frontend/
|
||||
│ ├── src/
|
||||
│ │ ├── pages/
|
||||
│ │ │ ├── Dashboard.tsx
|
||||
│ │ │ ├── Settings.tsx
|
||||
│ │ │ ├── Configs.tsx
|
||||
│ │ │ ├── ConfigEditor.tsx
|
||||
│ │ │ ├── Modlists.tsx
|
||||
│ │ │ ├── ModlistEditor.tsx
|
||||
│ │ │ └── Logs.tsx
|
||||
│ │ ├── components/
|
||||
│ │ │ ├── ConfigEditor.tsx # Monaco wrapper
|
||||
│ │ │ ├── LiveTerminal.tsx # xterm.js wrapper
|
||||
│ │ │ └── Layout.tsx # Sidebar nav shell
|
||||
│ │ ├── api/client.ts # Typed fetch wrapper
|
||||
│ │ └── types/index.ts # TypeScript types
|
||||
│ ├── package.json
|
||||
│ └── vite.config.ts
|
||||
├── data/ # Runtime data
|
||||
│ ├── settings.json # Singleton server settings
|
||||
│ └── modlists/ # Modlist JSON files (*.json)
|
||||
├── docker-compose.yml
|
||||
├── Dockerfile
|
||||
└── Makefile
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Environment Variables
|
||||
|
||||
| Env | Purpose | Default |
|
||||
|-----|---------|---------|
|
||||
| `SERVERFILE_DIR` | Base dir where `arma3server_x64` binary + `userconfig/` live | `""` (must be set) |
|
||||
| `MODS_DIR` | Base dir where `@modname` folders are stored | `""` (must be set) |
|
||||
| `CFG_DIR` | Base dir where `.cfg` config files are stored | `""` (must be set) |
|
||||
| `PROFILES_DIR` | Server profile/save path (ignored in UI) | `$SERVERFILE_DIR/Profiles` |
|
||||
| `DATA_DIR` | Internal data (settings.json, modlists/) | `./data` |
|
||||
| `LISTEN` | HTTP listen address | `:8080` |
|
||||
| `FRONTEND_DIR` | Path to built frontend files | `../frontend/dist` |
|
||||
|
||||
---
|
||||
|
||||
## Data Model
|
||||
|
||||
### Server Settings (singleton) — `data/settings.json`
|
||||
|
||||
```json
|
||||
{
|
||||
"ip_port": "0.0.0.0:2302",
|
||||
"server_parameters": "-server -world=empty -loadMissionToMemory -noPause",
|
||||
"steam_branch": "stable",
|
||||
"steam_user": "anonymous",
|
||||
"platform": "linux",
|
||||
"cba_settings": "",
|
||||
"ai_level_presets": "",
|
||||
"difficulty_presets": "",
|
||||
"active_config": "server",
|
||||
"active_modlist": "uuid-of-modlist",
|
||||
"updated_at": "2026-01-01T00:00:00Z"
|
||||
}
|
||||
```
|
||||
|
||||
### Configs — `$CFG_DIR/*.cfg`
|
||||
|
||||
Each config is a plain `.cfg` file stored in the env-defined `CFG_DIR`.
|
||||
CRUD operations create/rename/delete these files directly on disk.
|
||||
|
||||
### Modlists — `data/modlists/{uuid}.json`
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "uuid",
|
||||
"name": "My Modlist",
|
||||
"mods": [
|
||||
{ "id": "450814997", "name": "CBA_A3", "enabled": true },
|
||||
{ "id": "463939057", "name": "ACE", "enabled": false }
|
||||
],
|
||||
"created_at": "...",
|
||||
"updated_at": "..."
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Server Configuration
|
||||
|
||||
The three userconfig files are **singletons** — only one version can exist on disk at a time:
|
||||
|
||||
| File | Disk location | Managed in |
|
||||
|------|--------------|------------|
|
||||
| `cba_settings.sqf` | `$SERVERFILE_DIR/userconfig/cba_settings.sqf` | Settings page (textarea) |
|
||||
| `CfgAILevelPresets.sqf` | `$SERVERFILE_DIR/userconfig/CfgAILevelPresets.sqf` | Settings page (textarea) |
|
||||
| `CfgDifficultyPresets.sqf` | `$SERVERFILE_DIR/userconfig/CfgDifficultyPresets.sqf` | Settings page (textarea) |
|
||||
|
||||
These are written to disk immediately when settings are saved.
|
||||
|
||||
---
|
||||
|
||||
## API Routes
|
||||
|
||||
```
|
||||
# Server Settings (singleton)
|
||||
GET /api/server/settings
|
||||
PUT /api/server/settings # also writes userconfig files to disk
|
||||
POST /api/server/start
|
||||
POST /api/server/stop
|
||||
POST /api/server/restart
|
||||
GET /api/server/status
|
||||
GET /api/server/steamcmd # returns current branch/user/platform
|
||||
POST /api/server/steamcmd/update-game
|
||||
POST /api/server/steamcmd/download-mod
|
||||
GET /api/server/steamcmd/status
|
||||
|
||||
# Configs (.cfg files in $CFG_DIR)
|
||||
GET /api/configs
|
||||
POST /api/configs
|
||||
GET /api/configs/:name
|
||||
PUT /api/configs/:name
|
||||
DELETE /api/configs/:name
|
||||
POST /api/configs/:name/duplicate
|
||||
|
||||
# Modlists
|
||||
GET /api/modlists
|
||||
POST /api/modlists
|
||||
GET /api/modlists/:id
|
||||
PUT /api/modlists/:id
|
||||
DELETE /api/modlists/:id
|
||||
POST /api/modlists/:id/duplicate
|
||||
POST /api/modlists/import (multipart form: file=*.html — parses Arma Launcher HTML preset)
|
||||
GET /api/modlists/:id/check (returns mod entries with downloaded: bool)
|
||||
POST /api/modlists/:id/download-missing
|
||||
POST /api/modlists/:id/update-all
|
||||
|
||||
# Logs
|
||||
GET /ws/server/logs (WebSocket — live server stream)
|
||||
GET /ws/steamcmd/logs (WebSocket — live steamcmd stream)
|
||||
GET /api/server/logs (list log files)
|
||||
GET /api/server/logs/:file (read log file)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Process Start Flow
|
||||
|
||||
```
|
||||
User clicks Start
|
||||
→ Settings loaded from data/settings.json
|
||||
→ Args built from server_parameters + -config=<active_config>.cfg
|
||||
→ -profiles=$PROFILES_DIR auto-appended (unless already in server_parameters)
|
||||
→ -port= derived from ip_port field (unless -port= already in server_parameters)
|
||||
→ Mod path built from active modlist (enabled mods → @modname paths)
|
||||
→ arma3server_x64 spawned via exec.CommandContext
|
||||
→ stdout/stderr piped to LogStreamer fan-out
|
||||
→ WebSocket clients receive live output
|
||||
→ On exit, process reference cleaned up
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Key Design Decisions
|
||||
|
||||
1. **File-based storage** — No database. Settings, configs, and modlists are files on disk. Portable, backup-able with simple file copy.
|
||||
2. **Env-defined paths** — `SERVERFILE_DIR`, `MODS_DIR`, `CFG_DIR`, `PROFILES_DIR` are environment variables, not stored in the UI.
|
||||
3. **Configs are real .cfg files** — Stored in `$CFG_DIR`, directly usable by the Arma 3 server's `-config=` parameter.
|
||||
4. **Modlist = mod references + enabled state** — The `-mod=` parameter is built at start time by resolving enabled mods. For each mod, `$MODS_DIR/@name` is tried first (manually placed or symlinked); if not found and a Steam Workshop `id` exists, `$SERVERFILE_DIR/steamapps/workshop/content/107410/<id>` is used as fallback.
|
||||
5. **Single server instance** — Only one server at a time. No multi-instance support.
|
||||
6. **No auth for v1** — JWT auth can be added later without breaking the API design.
|
||||
7. **Docker-first deployment** — Single docker-compose.yml bundles SteamCMD, backend, and frontend serving.
|
||||
104
README.md
Normal file
104
README.md
Normal file
@@ -0,0 +1,104 @@
|
||||
# Arma 3 Web Server
|
||||
|
||||
Web-based management panel for Arma 3 dedicated servers. Start, stop, configure, and monitor your server from a browser.
|
||||
|
||||
## Features
|
||||
|
||||
- **Server control** — Start, stop, restart, and view status
|
||||
- **Live console** — WebSocket terminal showing server stdout/stderr and RPT log tailing
|
||||
- **Config management** — Create, edit, duplicate, and delete `.cfg` configuration files with a Monaco editor
|
||||
- **Modlist management** — Create modlists with reorderable entries, enable/disable per mod, import from HTML (e.g. ArmA 3 Steam Workshop collections), check download status
|
||||
- **SteamCMD integration** — Update the server binary, download individual workshop mods, bulk download missing or outdated mods, all streamed live to the UI
|
||||
- **Settings UI** — Edit server parameters, IP:port, platform, Steam branch/user, CBA/AI/difficulty presets, and select active config/modlist
|
||||
- **Log viewer** — Browse and read server log files
|
||||
|
||||
## Quick Start
|
||||
|
||||
### Docker
|
||||
|
||||
```bash
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
The web UI is served on `http://localhost:8080`.
|
||||
|
||||
### Manual
|
||||
|
||||
```bash
|
||||
# Backend
|
||||
cd backend
|
||||
go build -o arma3-web-server ./cmd/server
|
||||
./arma3-web-server
|
||||
|
||||
# Frontend (development)
|
||||
cd frontend
|
||||
npm install
|
||||
npm run dev
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
All paths are configurable via environment variables:
|
||||
|
||||
| Variable | Default | Description |
|
||||
|----------|---------|-------------|
|
||||
| `DATA_DIR` | `data` | Server metadata (settings, modlist JSON files) |
|
||||
| `SERVERFILE_DIR` | `serverfiles` | Arma 3 server installation |
|
||||
| `MODS_DIR` | `serverfiles/mods` | Local mod symlinks/copies |
|
||||
| `CFG_DIR` | `serverfiles/cfg` | Server configuration `.cfg` files |
|
||||
| `PROFILES_DIR` | `serverfiles/profiles` | Arma 3 profile and log directory |
|
||||
| `FRONTEND_DIR` | `../frontend/dist` | Built frontend assets |
|
||||
| `LISTEN` | `:8080` | HTTP listen address |
|
||||
|
||||
## API
|
||||
|
||||
REST API at `/api/*` and WebSocket endpoints at `/ws/*`. Key routes:
|
||||
|
||||
| Method | Path | Description |
|
||||
|--------|------|-------------|
|
||||
| `GET/PUT` | `/api/server/settings` | Read/update server settings |
|
||||
| `POST` | `/api/server/start\|stop\|restart` | Server lifecycle |
|
||||
| `GET` | `/api/server/status` | Running state |
|
||||
| `GET/POST/PUT/DELETE` | `/api/configs` | CRUD for `.cfg` files |
|
||||
| `GET/POST/PUT/DELETE` | `/api/modlists` | CRUD for modlists |
|
||||
| `POST` | `/api/modlists/import` | Import HTML workshop list |
|
||||
| `GET` | `/api/modlists/:id/check` | Check mod download status |
|
||||
| `POST` | `/api/modlists/:id/download-missing\|update-all` | Bulk workshop operations |
|
||||
| `POST` | `/api/server/steamcmd/update-game\|download-mod` | SteamCMD operations |
|
||||
| `GET` | `/api/server/logs` | List log files |
|
||||
| `GET` | `/api/server/paths` | Show server file paths |
|
||||
| `WS` | `/ws/server/logs\|rpt\|steamcmd/logs` | Live log streaming |
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
backend/
|
||||
cmd/server/ Entry point
|
||||
internal/
|
||||
api/ HTTP handlers and routes
|
||||
models/ Data types
|
||||
services/ Business logic
|
||||
frontend/
|
||||
src/
|
||||
api/ HTTP and WebSocket client
|
||||
components/ Shared UI components
|
||||
pages/ Route-level views
|
||||
types/ TypeScript interfaces
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
```bash
|
||||
# Backend
|
||||
cd backend && go run ./cmd/server
|
||||
|
||||
# Frontend (hot reload)
|
||||
cd frontend && npm run dev
|
||||
|
||||
# Lint
|
||||
cd frontend && npm run lint
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
105
backend/cmd/server/main.go
Normal file
105
backend/cmd/server/main.go
Normal file
@@ -0,0 +1,105 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"arma3-web-server/internal/api"
|
||||
"arma3-web-server/internal/services"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func main() {
|
||||
dataDir := mustAbs(getEnv("DATA_DIR", filepath.Join("data")))
|
||||
serverfileDir := mustAbs(getEnv("SERVERFILE_DIR", "serverfiles"))
|
||||
modsDir := mustAbs(getEnv("MODS_DIR", "serverfiles/mods"))
|
||||
cfgDir := mustAbs(getEnv("CFG_DIR", "serverfiles/cfg"))
|
||||
profilesDir := mustAbs(getEnv("PROFILES_DIR", "serverfiles/profiles"))
|
||||
listen := getEnv("LISTEN", ":8080")
|
||||
frontendDir := mustAbs(getEnv("FRONTEND_DIR", filepath.Join("..", "frontend", "dist")))
|
||||
|
||||
log.Printf("data dir: %s", dataDir)
|
||||
log.Printf("serverfile dir: %s", serverfileDir)
|
||||
log.Printf("mods dir: %s", modsDir)
|
||||
log.Printf("cfg dir: %s", cfgDir)
|
||||
log.Printf("profiles dir: %s", profilesDir)
|
||||
log.Printf("listening on %s", listen)
|
||||
|
||||
dirs := []string{
|
||||
dataDir, filepath.Join(dataDir, "modlists"),
|
||||
serverfileDir, modsDir, cfgDir, profilesDir,
|
||||
filepath.Join(serverfileDir, "steamapps", "workshop", "content", "107410"),
|
||||
}
|
||||
for _, dir := range dirs {
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
log.Fatalf("mkdir %s: %v", dir, err)
|
||||
}
|
||||
}
|
||||
|
||||
settings := services.NewSettingsManager(dataDir)
|
||||
|
||||
streamer := services.NewLogStreamer()
|
||||
configMgr := services.NewConfigManager(cfgDir)
|
||||
modlistMgr := services.NewModlistManager(dataDir)
|
||||
process := services.NewProcessManager(serverfileDir, modsDir, cfgDir, profilesDir, settings, modlistMgr, configMgr, streamer)
|
||||
steamcmd := services.NewSteamCmdManager(serverfileDir, streamer)
|
||||
|
||||
r := gin.Default()
|
||||
|
||||
if fi, err := os.Stat(frontendDir); err == nil && fi.IsDir() {
|
||||
r.Static("/assets", filepath.Join(frontendDir, "assets"))
|
||||
r.StaticFile("/favicon.ico", filepath.Join(frontendDir, "favicon.ico"))
|
||||
r.NoRoute(func(c *gin.Context) {
|
||||
c.File(filepath.Join(frontendDir, "index.html"))
|
||||
})
|
||||
log.Printf("serving frontend from %s", frontendDir)
|
||||
}
|
||||
|
||||
handler := api.New(settings, configMgr, modlistMgr, process, steamcmd, streamer, serverfileDir, modsDir, cfgDir, profilesDir)
|
||||
handler.SetupRoutes(r)
|
||||
|
||||
log.Printf("starting server on %s", listen)
|
||||
|
||||
srv := &http.Server{Addr: listen, Handler: r}
|
||||
|
||||
go func() {
|
||||
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
||||
log.Fatalf("server: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
quit := make(chan os.Signal, 1)
|
||||
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
|
||||
<-quit
|
||||
|
||||
log.Print("shutting down server...")
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
if err := srv.Shutdown(ctx); err != nil {
|
||||
log.Fatalf("server forced shutdown: %v", err)
|
||||
}
|
||||
log.Print("server exited")
|
||||
}
|
||||
|
||||
func mustAbs(p string) string {
|
||||
a, err := filepath.Abs(p)
|
||||
if err != nil {
|
||||
log.Fatalf("abs %s: %v", p, err)
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
func getEnv(key, fallback string) string {
|
||||
if v := os.Getenv(key); v != "" {
|
||||
return v
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
48
backend/go.mod
Normal file
48
backend/go.mod
Normal file
@@ -0,0 +1,48 @@
|
||||
module arma3-web-server
|
||||
|
||||
go 1.25.0
|
||||
|
||||
require (
|
||||
github.com/gin-gonic/gin v1.12.0
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/gorilla/websocket v1.5.3
|
||||
modernc.org/sqlite v1.53.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/bytedance/gopkg v0.1.3 // indirect
|
||||
github.com/bytedance/sonic v1.15.0 // indirect
|
||||
github.com/bytedance/sonic/loader v0.5.0 // indirect
|
||||
github.com/cloudwego/base64x v0.1.6 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.12 // indirect
|
||||
github.com/gin-contrib/sse v1.1.0 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/go-playground/validator/v10 v10.30.1 // indirect
|
||||
github.com/goccy/go-json v0.10.5 // indirect
|
||||
github.com/goccy/go-yaml v1.19.2 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
|
||||
github.com/leodido/go-urn v1.4.0 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/ncruces/go-strftime v1.0.0 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
|
||||
github.com/quic-go/qpack v0.6.0 // indirect
|
||||
github.com/quic-go/quic-go v0.59.0 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.3.1 // indirect
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0 // indirect
|
||||
golang.org/x/arch v0.22.0 // indirect
|
||||
golang.org/x/crypto v0.48.0 // indirect
|
||||
golang.org/x/net v0.51.0 // indirect
|
||||
golang.org/x/sys v0.44.0 // indirect
|
||||
golang.org/x/text v0.34.0 // indirect
|
||||
google.golang.org/protobuf v1.36.10 // indirect
|
||||
modernc.org/libc v1.73.4 // indirect
|
||||
modernc.org/mathutil v1.7.1 // indirect
|
||||
modernc.org/memory v1.11.0 // indirect
|
||||
)
|
||||
137
backend/go.sum
Normal file
137
backend/go.sum
Normal file
@@ -0,0 +1,137 @@
|
||||
github.com/bytedance/gopkg v0.1.3 h1:TPBSwH8RsouGCBcMBktLt1AymVo2TVsBVCY4b6TnZ/M=
|
||||
github.com/bytedance/gopkg v0.1.3/go.mod h1:576VvJ+eJgyCzdjS+c4+77QF3p7ubbtiKARP3TxducM=
|
||||
github.com/bytedance/sonic v1.15.0 h1:/PXeWFaR5ElNcVE84U0dOHjiMHQOwNIx3K4ymzh/uSE=
|
||||
github.com/bytedance/sonic v1.15.0/go.mod h1:tFkWrPz0/CUCLEF4ri4UkHekCIcdnkqXw9VduqpJh0k=
|
||||
github.com/bytedance/sonic/loader v0.5.0 h1:gXH3KVnatgY7loH5/TkeVyXPfESoqSBSBEiDd5VjlgE=
|
||||
github.com/bytedance/sonic/loader v0.5.0/go.mod h1:AR4NYCk5DdzZizZ5djGqQ92eEhCCcdf5x77udYiSJRo=
|
||||
github.com/cloudwego/base64x v0.1.6 h1:t11wG9AECkCDk5fMSoxmufanudBtJ+/HemLstXDLI2M=
|
||||
github.com/cloudwego/base64x v0.1.6/go.mod h1:OFcloc187FXDaYHvrNIjxSe8ncn0OOM8gEHfghB2IPU=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||
github.com/gabriel-vasile/mimetype v1.4.12 h1:e9hWvmLYvtp846tLHam2o++qitpguFiYCKbn0w9jyqw=
|
||||
github.com/gabriel-vasile/mimetype v1.4.12/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s=
|
||||
github.com/gin-contrib/sse v1.1.0 h1:n0w2GMuUpWDVp7qSpvze6fAu9iRxJY4Hmj6AmBOU05w=
|
||||
github.com/gin-contrib/sse v1.1.0/go.mod h1:hxRZ5gVpWMT7Z0B0gSNYqqsSCNIJMjzvm6fqCz9vjwM=
|
||||
github.com/gin-gonic/gin v1.12.0 h1:b3YAbrZtnf8N//yjKeU2+MQsh2mY5htkZidOM7O0wG8=
|
||||
github.com/gin-gonic/gin v1.12.0/go.mod h1:VxccKfsSllpKshkBWgVgRniFFAzFb9csfngsqANjnLc=
|
||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
||||
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
||||
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
||||
github.com/go-playground/validator/v10 v10.30.1 h1:f3zDSN/zOma+w6+1Wswgd9fLkdwy06ntQJp0BBvFG0w=
|
||||
github.com/go-playground/validator/v10 v10.30.1/go.mod h1:oSuBIQzuJxL//3MelwSLD5hc2Tu889bF0Idm9Dg26cM=
|
||||
github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
|
||||
github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
|
||||
github.com/goccy/go-yaml v1.19.2 h1:PmFC1S6h8ljIz6gMRBopkjP1TVT7xuwrButHID66PoM=
|
||||
github.com/goccy/go-yaml v1.19.2/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs=
|
||||
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
||||
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
|
||||
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
|
||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
|
||||
github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
|
||||
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
|
||||
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/quic-go/qpack v0.6.0 h1:g7W+BMYynC1LbYLSqRt8PBg5Tgwxn214ZZR34VIOjz8=
|
||||
github.com/quic-go/qpack v0.6.0/go.mod h1:lUpLKChi8njB4ty2bFLX2x4gzDqXwUpaO1DP9qMDZII=
|
||||
github.com/quic-go/quic-go v0.59.0 h1:OLJkp1Mlm/aS7dpKgTc6cnpynnD2Xg7C1pwL6vy/SAw=
|
||||
github.com/quic-go/quic-go v0.59.0/go.mod h1:upnsH4Ju1YkqpLXC305eW3yDZ4NfnNbmQRCMWS58IKU=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
||||
github.com/ugorji/go/codec v1.3.1 h1:waO7eEiFDwidsBN6agj1vJQ4AG7lh2yqXyOXqhgQuyY=
|
||||
github.com/ugorji/go/codec v1.3.1/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4=
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE=
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0=
|
||||
go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y=
|
||||
go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU=
|
||||
golang.org/x/arch v0.22.0 h1:c/Zle32i5ttqRXjdLyyHZESLD/bB90DCU1g9l/0YBDI=
|
||||
golang.org/x/arch v0.22.0/go.mod h1:dNHoOeKiyja7GTvF9NJS1l3Z2yntpQNzgrjh1cU103A=
|
||||
golang.org/x/crypto v0.48.0 h1:/VRzVqiRSggnhY7gNRxPauEQ5Drw9haKdM0jqfcCFts=
|
||||
golang.org/x/crypto v0.48.0/go.mod h1:r0kV5h3qnFPlQnBSrULhlsRfryS2pmewsg+XfMgkVos=
|
||||
golang.org/x/mod v0.36.0 h1:JJjpVx6myfUsUdAzZuOSTTmRE0PfZeNWzzvKrP7amb4=
|
||||
golang.org/x/mod v0.36.0/go.mod h1:moc6ELqsWcOw5Ef3xVprK5ul/MvtVvkIXLziUOICjUQ=
|
||||
golang.org/x/net v0.51.0 h1:94R/GTO7mt3/4wIKpcR5gkGmRLOuE/2hNGeWq/GBIFo=
|
||||
golang.org/x/net v0.51.0/go.mod h1:aamm+2QF5ogm02fjy5Bb7CQ0WMt1/WVM7FtyaTLlA9Y=
|
||||
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
|
||||
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.44.0 h1:ildZl3J4uzeKP07r2F++Op7E9B29JRUy+a27EibtBTQ=
|
||||
golang.org/x/sys v0.44.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||
golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk=
|
||||
golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA=
|
||||
golang.org/x/tools v0.45.0 h1:18qN3FAooORvApf5XjCXgsuayZOEtXf6JK18I3+ONa8=
|
||||
golang.org/x/tools v0.45.0/go.mod h1:LuUGqqaXcXMEFEruIVJVm5mgDD8vww/z/SR1gQ4uE/0=
|
||||
google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE=
|
||||
google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
modernc.org/cc/v4 v4.28.4 h1:Hd/4Es+MBj+/7hSdZaisNyu6bv3V0Dp2MdllyfqaH+c=
|
||||
modernc.org/cc/v4 v4.28.4/go.mod h1:OnovgIhbbMXMu1aISnJ0wvVD1KnW+cAUJkIrAWh+kVI=
|
||||
modernc.org/ccgo/v4 v4.34.4 h1:OVnSOWQjVKOYkFxoHYB+qQmSHK5gqMqARM+K9DpR/Ws=
|
||||
modernc.org/ccgo/v4 v4.34.4/go.mod h1:qdKqE8FNIYyysougB1RX9MxCzp5oJOcQXSobANJ4TuE=
|
||||
modernc.org/fileutil v1.4.0 h1:j6ZzNTftVS054gi281TyLjHPp6CPHr2KCxEXjEbD6SM=
|
||||
modernc.org/fileutil v1.4.0/go.mod h1:EqdKFDxiByqxLk8ozOxObDSfcVOv/54xDs/DUHdvCUU=
|
||||
modernc.org/gc/v2 v2.6.5 h1:nyqdV8q46KvTpZlsw66kWqwXRHdjIlJOhG6kxiV/9xI=
|
||||
modernc.org/gc/v2 v2.6.5/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito=
|
||||
modernc.org/gc/v3 v3.1.3 h1:6QAplYyVO+KdPW3pGnqmJDUxtkec8ooEWvks/hhU3lc=
|
||||
modernc.org/gc/v3 v3.1.3/go.mod h1:HFK/6AGESC7Ex+EZJhJ2Gni6cTaYpSMmU/cT9RmlfYY=
|
||||
modernc.org/goabi0 v0.2.0 h1:HvEowk7LxcPd0eq6mVOAEMai46V+i7Jrj13t4AzuNks=
|
||||
modernc.org/goabi0 v0.2.0/go.mod h1:CEFRnnJhKvWT1c1JTI3Avm+tgOWbkOu5oPA8eH8LnMI=
|
||||
modernc.org/libc v1.73.4 h1:+ra4Ui8ngyt8HDcO1FTDPWlkAh6yOdaO2yAoh8MddQA=
|
||||
modernc.org/libc v1.73.4/go.mod h1:DXZ3eO8qMCNn2SnmTNCiC71nJ9Rcq3PsnpU6Vc4rWK8=
|
||||
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
|
||||
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
|
||||
modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI=
|
||||
modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
|
||||
modernc.org/opt v0.2.0 h1:tGyef5ApycA7FSEOMraay9SaTk5zmbx7Tu+cJs4QKZg=
|
||||
modernc.org/opt v0.2.0/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns=
|
||||
modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=
|
||||
modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
|
||||
modernc.org/sqlite v1.53.0 h1:20WG8N9q4ji/dEqGk4uiI0c6OPjSeLTNYGFCc3+7c1M=
|
||||
modernc.org/sqlite v1.53.0/go.mod h1:xoEpOIpGrgT48H5iiyt/YXPCZPEzlfmfFwtk8Lklw8s=
|
||||
modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
|
||||
modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
|
||||
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
|
||||
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
|
||||
114
backend/internal/api/configs.go
Normal file
114
backend/internal/api/configs.go
Normal file
@@ -0,0 +1,114 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type createConfigInput struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
type updateConfigInput struct {
|
||||
Content string `json:"content" binding:"required"`
|
||||
}
|
||||
|
||||
type duplicateConfigInput struct {
|
||||
NewName string `json:"new_name" binding:"required"`
|
||||
}
|
||||
|
||||
func (h *Handler) ListConfigs(c *gin.Context) {
|
||||
configs, err := h.configs.List()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, configs)
|
||||
}
|
||||
|
||||
func validateConfigName(name string) bool {
|
||||
return name != "" && !strings.ContainsAny(name, "/\\")
|
||||
}
|
||||
|
||||
func (h *Handler) CreateConfig(c *gin.Context) {
|
||||
var input createConfigInput
|
||||
if err := c.ShouldBindJSON(&input); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
if !validateConfigName(input.Name) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid config name"})
|
||||
return
|
||||
}
|
||||
if err := h.configs.Create(input.Name, input.Content); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusCreated, gin.H{"name": input.Name})
|
||||
}
|
||||
|
||||
func (h *Handler) GetConfig(c *gin.Context) {
|
||||
name := c.Param("name")
|
||||
if !validateConfigName(name) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid config name"})
|
||||
return
|
||||
}
|
||||
content, err := h.configs.Get(name)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.String(http.StatusOK, content)
|
||||
}
|
||||
|
||||
func (h *Handler) UpdateConfig(c *gin.Context) {
|
||||
var input updateConfigInput
|
||||
if err := c.ShouldBindJSON(&input); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
name := c.Param("name")
|
||||
if !validateConfigName(name) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid config name"})
|
||||
return
|
||||
}
|
||||
if err := h.configs.Update(name, input.Content); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"status": "ok"})
|
||||
}
|
||||
|
||||
func (h *Handler) DeleteConfig(c *gin.Context) {
|
||||
name := c.Param("name")
|
||||
if !validateConfigName(name) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid config name"})
|
||||
return
|
||||
}
|
||||
if err := h.configs.Delete(name); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusNoContent, nil)
|
||||
}
|
||||
|
||||
func (h *Handler) DuplicateConfig(c *gin.Context) {
|
||||
var input duplicateConfigInput
|
||||
if err := c.ShouldBindJSON(&input); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
name := c.Param("name")
|
||||
if !validateConfigName(name) || !validateConfigName(input.NewName) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid config name"})
|
||||
return
|
||||
}
|
||||
if err := h.configs.Duplicate(name, input.NewName); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusCreated, gin.H{"name": input.NewName})
|
||||
}
|
||||
196
backend/internal/api/logs.go
Normal file
196
backend/internal/api/logs.go
Normal file
@@ -0,0 +1,196 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
var upgrader = websocket.Upgrader{
|
||||
CheckOrigin: func(r *http.Request) bool { return true },
|
||||
}
|
||||
|
||||
func (h *Handler) StreamLogs(c *gin.Context) {
|
||||
conn, err := upgrader.Upgrade(c.Writer, c.Request, nil)
|
||||
if err != nil {
|
||||
log.Printf("websocket upgrade error: %v", err)
|
||||
return
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
clientID := conn.RemoteAddr().String()
|
||||
ch := h.streamer.Subscribe("server", clientID)
|
||||
defer h.streamer.Unsubscribe("server", clientID)
|
||||
|
||||
for line := range ch {
|
||||
if err := conn.WriteMessage(websocket.TextMessage, []byte(line)); err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) ListLogs(c *gin.Context) {
|
||||
profilesDir := h.process.ProfilesDir()
|
||||
files := h.collectLogFiles(profilesDir, "")
|
||||
|
||||
logsDir := filepath.Join(profilesDir, "logs")
|
||||
if fi, err := os.Stat(logsDir); err == nil && fi.IsDir() {
|
||||
files = append(files, h.collectLogFiles(logsDir, "logs")...)
|
||||
}
|
||||
|
||||
slices.Sort(files)
|
||||
if files == nil {
|
||||
files = []string{}
|
||||
}
|
||||
c.JSON(http.StatusOK, files)
|
||||
}
|
||||
|
||||
func (h *Handler) collectLogFiles(dir, prefix string) []string {
|
||||
entries, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
var files []string
|
||||
for _, e := range entries {
|
||||
if !e.IsDir() {
|
||||
ext := filepath.Ext(e.Name())
|
||||
if ext == ".log" || ext == ".rpt" || e.Name() == "script.log" {
|
||||
if prefix != "" {
|
||||
files = append(files, prefix+"/"+e.Name())
|
||||
} else {
|
||||
files = append(files, e.Name())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
||||
func (h *Handler) StreamSteamCMDLogs(c *gin.Context) {
|
||||
conn, err := upgrader.Upgrade(c.Writer, c.Request, nil)
|
||||
if err != nil {
|
||||
log.Printf("websocket upgrade error: %v", err)
|
||||
return
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
clientID := conn.RemoteAddr().String()
|
||||
ch := h.streamer.Subscribe("steamcmd", clientID)
|
||||
defer h.streamer.Unsubscribe("steamcmd", clientID)
|
||||
|
||||
for line := range ch {
|
||||
if err := conn.WriteMessage(websocket.TextMessage, []byte(line)); err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) StreamRPTLogs(c *gin.Context) {
|
||||
conn, err := upgrader.Upgrade(c.Writer, c.Request, nil)
|
||||
if err != nil {
|
||||
log.Printf("websocket upgrade error: %v", err)
|
||||
return
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
profilesDir := h.process.ProfilesDir()
|
||||
var currentPath string
|
||||
var currentOffset int64
|
||||
ticker := time.NewTicker(250 * time.Millisecond)
|
||||
defer ticker.Stop()
|
||||
|
||||
for range ticker.C {
|
||||
path := findLatestRPT(profilesDir)
|
||||
|
||||
if path != currentPath {
|
||||
currentPath = path
|
||||
currentOffset = 0
|
||||
if currentPath == "" {
|
||||
continue
|
||||
}
|
||||
conn.WriteMessage(websocket.TextMessage, []byte("--- tailing: "+filepath.Base(currentPath)+" ---"))
|
||||
}
|
||||
if currentPath == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
fi, err := os.Stat(currentPath)
|
||||
if err != nil {
|
||||
currentPath = ""
|
||||
continue
|
||||
}
|
||||
if fi.Size() <= currentOffset {
|
||||
continue
|
||||
}
|
||||
|
||||
f, err := os.Open(currentPath)
|
||||
if err != nil {
|
||||
currentPath = ""
|
||||
continue
|
||||
}
|
||||
f.Seek(currentOffset, io.SeekStart)
|
||||
buf := make([]byte, fi.Size()-currentOffset)
|
||||
n, _ := io.ReadFull(f, buf)
|
||||
f.Close()
|
||||
|
||||
currentOffset += int64(n)
|
||||
for _, line := range strings.Split(string(buf[:n]), "\n") {
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
if err := conn.WriteMessage(websocket.TextMessage, []byte(line)); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func findLatestRPT(dir string) string {
|
||||
pattern := filepath.Join(dir, "arma3server_x64_*.rpt")
|
||||
matches, err := filepath.Glob(pattern)
|
||||
if err != nil || len(matches) == 0 {
|
||||
return ""
|
||||
}
|
||||
sort.Slice(matches, func(i, j int) bool {
|
||||
fi, _ := os.Stat(matches[i])
|
||||
fj, _ := os.Stat(matches[j])
|
||||
return fi.ModTime().After(fj.ModTime())
|
||||
})
|
||||
return matches[0]
|
||||
}
|
||||
|
||||
func (h *Handler) GetLog(c *gin.Context) {
|
||||
filename := filepath.Base(c.Param("file"))
|
||||
if filename == "" || strings.ContainsRune(c.Param("file"), os.PathSeparator) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid filename"})
|
||||
return
|
||||
}
|
||||
profilesDir := h.process.ProfilesDir()
|
||||
path := filepath.Join(profilesDir, filename)
|
||||
|
||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||
logsPath := filepath.Join(profilesDir, "logs", filename)
|
||||
if _, err2 := os.Stat(logsPath); err2 == nil {
|
||||
path = logsPath
|
||||
} else {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "file not found"})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.String(http.StatusOK, string(data))
|
||||
}
|
||||
202
backend/internal/api/modlists.go
Normal file
202
backend/internal/api/modlists.go
Normal file
@@ -0,0 +1,202 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"arma3-web-server/internal/models"
|
||||
"arma3-web-server/internal/services"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type createModlistInput struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
}
|
||||
|
||||
type updateModlistInput struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
Mods []models.ModEntry `json:"mods"`
|
||||
}
|
||||
|
||||
type duplicateModlistInput struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
}
|
||||
|
||||
func (h *Handler) ListModlists(c *gin.Context) {
|
||||
items, err := h.modlists.List()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, items)
|
||||
}
|
||||
|
||||
func (h *Handler) CreateModlist(c *gin.Context) {
|
||||
var input createModlistInput
|
||||
if err := c.ShouldBindJSON(&input); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
ml, err := h.modlists.Create(input.Name)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusCreated, ml)
|
||||
}
|
||||
|
||||
func (h *Handler) GetModlist(c *gin.Context) {
|
||||
ml, err := h.modlists.Get(c.Param("id"))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, ml)
|
||||
}
|
||||
|
||||
func (h *Handler) UpdateModlist(c *gin.Context) {
|
||||
var input updateModlistInput
|
||||
if err := c.ShouldBindJSON(&input); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
ml, err := h.modlists.Update(c.Param("id"), input.Name, input.Mods)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, ml)
|
||||
}
|
||||
|
||||
func (h *Handler) DeleteModlist(c *gin.Context) {
|
||||
if err := h.modlists.Delete(c.Param("id")); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusNoContent, nil)
|
||||
}
|
||||
|
||||
func (h *Handler) DuplicateModlist(c *gin.Context) {
|
||||
var input duplicateModlistInput
|
||||
if err := c.ShouldBindJSON(&input); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
ml, err := h.modlists.Duplicate(c.Param("id"), input.Name)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusCreated, ml)
|
||||
}
|
||||
|
||||
func (h *Handler) ImportModlist(c *gin.Context) {
|
||||
file, header, err := c.Request.FormFile("file")
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "file field required"})
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
_, mods, err := services.ParseModlistHTML(file)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "parse html: " + err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
listName := services.FileNameToModlistName(header.Filename)
|
||||
|
||||
ml, err := h.modlists.Create(listName)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
ml, err = h.modlists.Update(ml.ID, ml.Name, mods)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusCreated, ml)
|
||||
}
|
||||
|
||||
type modStatus struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Downloaded bool `json:"downloaded"`
|
||||
}
|
||||
|
||||
func (h *Handler) CheckModlistMods(c *gin.Context) {
|
||||
ml, err := h.modlists.Get(c.Param("id"))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
dir := h.process.ServerfileDir()
|
||||
var result []modStatus
|
||||
for _, m := range ml.Mods {
|
||||
result = append(result, modStatus{
|
||||
ID: m.ID,
|
||||
Name: m.Name,
|
||||
Enabled: m.Enabled,
|
||||
Downloaded: services.CheckWorkshopMod(dir, m.ID),
|
||||
})
|
||||
}
|
||||
c.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
func (h *Handler) DownloadMissingMods(c *gin.Context) {
|
||||
ml, err := h.modlists.Get(c.Param("id"))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
dir := h.process.ServerfileDir()
|
||||
var missing []string
|
||||
for _, m := range ml.Mods {
|
||||
if m.ID != "" && !services.CheckWorkshopMod(dir, m.ID) {
|
||||
missing = append(missing, m.ID)
|
||||
}
|
||||
}
|
||||
|
||||
if len(missing) == 0 {
|
||||
c.JSON(http.StatusOK, gin.H{"status": "all mods present"})
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.steamcmd.DownloadMods(missing); err != nil {
|
||||
c.JSON(http.StatusConflict, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"status": "downloading", "count": len(missing)})
|
||||
}
|
||||
|
||||
func (h *Handler) UpdateAllMods(c *gin.Context) {
|
||||
ml, err := h.modlists.Get(c.Param("id"))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
var ids []string
|
||||
for _, m := range ml.Mods {
|
||||
if m.ID != "" {
|
||||
ids = append(ids, m.ID)
|
||||
}
|
||||
}
|
||||
|
||||
if len(ids) == 0 {
|
||||
c.JSON(http.StatusOK, gin.H{"status": "no mods with workshop ids"})
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.steamcmd.DownloadMods(ids); err != nil {
|
||||
c.JSON(http.StatusConflict, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"status": "updating", "count": len(ids)})
|
||||
}
|
||||
85
backend/internal/api/router.go
Normal file
85
backend/internal/api/router.go
Normal file
@@ -0,0 +1,85 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"arma3-web-server/internal/services"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
settings *services.SettingsManager
|
||||
configs *services.ConfigManager
|
||||
modlists *services.ModlistManager
|
||||
process *services.ProcessManager
|
||||
steamcmd *services.SteamCmdManager
|
||||
streamer *services.LogStreamer
|
||||
serverfileDir string
|
||||
modsDir string
|
||||
cfgDir string
|
||||
profilesDir string
|
||||
}
|
||||
|
||||
func New(
|
||||
settings *services.SettingsManager,
|
||||
configs *services.ConfigManager,
|
||||
modlists *services.ModlistManager,
|
||||
process *services.ProcessManager,
|
||||
steamcmd *services.SteamCmdManager,
|
||||
streamer *services.LogStreamer,
|
||||
serverfileDir, modsDir, cfgDir, profilesDir string,
|
||||
) *Handler {
|
||||
return &Handler{
|
||||
settings: settings,
|
||||
configs: configs,
|
||||
modlists: modlists,
|
||||
process: process,
|
||||
steamcmd: steamcmd,
|
||||
streamer: streamer,
|
||||
serverfileDir: serverfileDir,
|
||||
modsDir: modsDir,
|
||||
cfgDir: cfgDir,
|
||||
profilesDir: profilesDir,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) SetupRoutes(r *gin.Engine) {
|
||||
api := r.Group("/api")
|
||||
{
|
||||
api.GET("/server/settings", h.GetSettings)
|
||||
api.PUT("/server/settings", h.UpdateSettings)
|
||||
api.POST("/server/start", h.StartServer)
|
||||
api.POST("/server/stop", h.StopServer)
|
||||
api.POST("/server/restart", h.RestartServer)
|
||||
api.GET("/server/status", h.ServerStatus)
|
||||
api.GET("/server/steamcmd", h.SteamCMDSettings)
|
||||
api.POST("/server/steamcmd/update-game", h.SteamCMDUpdateGame)
|
||||
api.POST("/server/steamcmd/download-mod", h.SteamCMDDownloadMod)
|
||||
api.GET("/server/steamcmd/status", h.SteamCMDStatus)
|
||||
api.GET("/server/paths", h.ServerPaths)
|
||||
|
||||
api.GET("/server/logs", h.ListLogs)
|
||||
api.GET("/server/logs/:file", h.GetLog)
|
||||
|
||||
api.GET("/configs", h.ListConfigs)
|
||||
api.POST("/configs", h.CreateConfig)
|
||||
api.GET("/configs/:name", h.GetConfig)
|
||||
api.PUT("/configs/:name", h.UpdateConfig)
|
||||
api.DELETE("/configs/:name", h.DeleteConfig)
|
||||
api.POST("/configs/:name/duplicate", h.DuplicateConfig)
|
||||
|
||||
api.GET("/modlists", h.ListModlists)
|
||||
api.POST("/modlists", h.CreateModlist)
|
||||
api.GET("/modlists/:id", h.GetModlist)
|
||||
api.PUT("/modlists/:id", h.UpdateModlist)
|
||||
api.DELETE("/modlists/:id", h.DeleteModlist)
|
||||
api.POST("/modlists/:id/duplicate", h.DuplicateModlist)
|
||||
api.POST("/modlists/import", h.ImportModlist)
|
||||
api.GET("/modlists/:id/check", h.CheckModlistMods)
|
||||
api.POST("/modlists/:id/download-missing", h.DownloadMissingMods)
|
||||
api.POST("/modlists/:id/update-all", h.UpdateAllMods)
|
||||
}
|
||||
|
||||
r.GET("/ws/server/logs", h.StreamLogs)
|
||||
r.GET("/ws/steamcmd/logs", h.StreamSteamCMDLogs)
|
||||
r.GET("/ws/server/rpt", h.StreamRPTLogs)
|
||||
}
|
||||
173
backend/internal/api/settings.go
Normal file
173
backend/internal/api/settings.go
Normal file
@@ -0,0 +1,173 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type updateSettingsInput struct {
|
||||
IPPort *string `json:"ip_port"`
|
||||
ServerParameters *string `json:"server_parameters"`
|
||||
SteamBranch *string `json:"steam_branch"`
|
||||
SteamUser *string `json:"steam_user"`
|
||||
Platform *string `json:"platform"`
|
||||
CBASettings *string `json:"cba_settings"`
|
||||
AILevelPresets *string `json:"ai_level_presets"`
|
||||
DifficultyPresets *string `json:"difficulty_presets"`
|
||||
ActiveConfig *string `json:"active_config"`
|
||||
ActiveModlist *string `json:"active_modlist"`
|
||||
}
|
||||
|
||||
func (h *Handler) GetSettings(c *gin.Context) {
|
||||
s, err := h.settings.Load()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, s)
|
||||
}
|
||||
|
||||
func (h *Handler) UpdateSettings(c *gin.Context) {
|
||||
var input updateSettingsInput
|
||||
if err := c.ShouldBindJSON(&input); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
s, err := h.settings.Load()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
if input.IPPort != nil { s.IPPort = *input.IPPort }
|
||||
if input.ServerParameters != nil { s.ServerParameters = *input.ServerParameters }
|
||||
if input.SteamBranch != nil { s.SteamBranch = *input.SteamBranch }
|
||||
if input.SteamUser != nil { s.SteamUser = *input.SteamUser }
|
||||
if input.Platform != nil { s.Platform = *input.Platform }
|
||||
if input.CBASettings != nil { s.CBASettings = *input.CBASettings }
|
||||
if input.AILevelPresets != nil { s.AILevelPresets = *input.AILevelPresets }
|
||||
if input.DifficultyPresets != nil { s.DifficultyPresets = *input.DifficultyPresets }
|
||||
if input.ActiveConfig != nil { s.ActiveConfig = *input.ActiveConfig }
|
||||
if input.ActiveModlist != nil { s.ActiveModlist = *input.ActiveModlist }
|
||||
|
||||
if err := h.process.WriteUserconfigFiles(s); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "write userconfig: " + err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.settings.Save(s); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, s)
|
||||
}
|
||||
|
||||
func (h *Handler) StartServer(c *gin.Context) {
|
||||
if err := h.process.Start(); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"status": "starting"})
|
||||
}
|
||||
|
||||
func (h *Handler) StopServer(c *gin.Context) {
|
||||
if err := h.process.Stop(); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"status": "stopping"})
|
||||
}
|
||||
|
||||
func (h *Handler) RestartServer(c *gin.Context) {
|
||||
if err := h.process.Restart(); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"status": "restarting"})
|
||||
}
|
||||
|
||||
func (h *Handler) ServerStatus(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"running": h.process.IsRunning(),
|
||||
})
|
||||
}
|
||||
|
||||
func (h *Handler) SteamCMDSettings(c *gin.Context) {
|
||||
s, err := h.settings.Load()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"branch": s.SteamBranch,
|
||||
"user": s.SteamUser,
|
||||
"platform": s.Platform,
|
||||
})
|
||||
}
|
||||
|
||||
type steamcmdUpdateGameInput struct {
|
||||
Branch string `json:"branch"`
|
||||
User string `json:"user"`
|
||||
}
|
||||
|
||||
func (h *Handler) SteamCMDUpdateGame(c *gin.Context) {
|
||||
var input steamcmdUpdateGameInput
|
||||
if err := c.ShouldBindJSON(&input); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
user := input.User
|
||||
if user == "" {
|
||||
user = "anonymous"
|
||||
}
|
||||
branch := input.Branch
|
||||
if branch == "" {
|
||||
branch = "stable"
|
||||
}
|
||||
|
||||
if err := h.steamcmd.UpdateGame(branch, user); err != nil {
|
||||
c.JSON(http.StatusConflict, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"status": "started"})
|
||||
}
|
||||
|
||||
type steamcmdDownloadModInput struct {
|
||||
ModID string `json:"mod_id"`
|
||||
}
|
||||
|
||||
func (h *Handler) SteamCMDDownloadMod(c *gin.Context) {
|
||||
var input steamcmdDownloadModInput
|
||||
if err := c.ShouldBindJSON(&input); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
if input.ModID == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "mod_id is required"})
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.steamcmd.DownloadMod(input.ModID); err != nil {
|
||||
c.JSON(http.StatusConflict, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"status": "started"})
|
||||
}
|
||||
|
||||
func (h *Handler) SteamCMDStatus(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"running": h.steamcmd.IsRunning(),
|
||||
})
|
||||
}
|
||||
|
||||
func (h *Handler) ServerPaths(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"serverfile_dir": h.serverfileDir,
|
||||
"mods_dir": h.modsDir,
|
||||
"cfg_dir": h.cfgDir,
|
||||
"profiles_dir": h.profilesDir,
|
||||
})
|
||||
}
|
||||
25
backend/internal/models/modlist.go
Normal file
25
backend/internal/models/modlist.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
type ModEntry struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Enabled bool `json:"enabled"`
|
||||
}
|
||||
|
||||
type Modlist struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Mods []ModEntry `json:"mods"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type ModlistListItem struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
ModCount int `json:"mod_count"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
17
backend/internal/models/settings.go
Normal file
17
backend/internal/models/settings.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
type ServerSettings struct {
|
||||
IPPort string `json:"ip_port"`
|
||||
ServerParameters string `json:"server_parameters"`
|
||||
SteamBranch string `json:"steam_branch"`
|
||||
SteamUser string `json:"steam_user"`
|
||||
Platform string `json:"platform"`
|
||||
CBASettings string `json:"cba_settings"`
|
||||
AILevelPresets string `json:"ai_level_presets"`
|
||||
DifficultyPresets string `json:"difficulty_presets"`
|
||||
ActiveConfig string `json:"active_config"`
|
||||
ActiveModlist string `json:"active_modlist"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
89
backend/internal/services/config_manager.go
Normal file
89
backend/internal/services/config_manager.go
Normal file
@@ -0,0 +1,89 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ConfigManager struct {
|
||||
cfgDir string
|
||||
}
|
||||
|
||||
func NewConfigManager(cfgDir string) *ConfigManager {
|
||||
return &ConfigManager{cfgDir: cfgDir}
|
||||
}
|
||||
|
||||
type ConfigInfo struct {
|
||||
Name string `json:"name"`
|
||||
Size int64 `json:"size"`
|
||||
}
|
||||
|
||||
func (cm *ConfigManager) List() ([]ConfigInfo, error) {
|
||||
entries, err := os.ReadDir(cm.cfgDir)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return []ConfigInfo{}, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var configs []ConfigInfo
|
||||
for _, e := range entries {
|
||||
if !e.IsDir() && strings.HasSuffix(e.Name(), ".cfg") {
|
||||
info, _ := e.Info()
|
||||
configs = append(configs, ConfigInfo{
|
||||
Name: strings.TrimSuffix(e.Name(), ".cfg"),
|
||||
Size: info.Size(),
|
||||
})
|
||||
}
|
||||
}
|
||||
return configs, nil
|
||||
}
|
||||
|
||||
func (cm *ConfigManager) Get(name string) (string, error) {
|
||||
path := cm.path(name)
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return "", fmt.Errorf("config not found")
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
return string(data), nil
|
||||
}
|
||||
|
||||
func (cm *ConfigManager) Create(name, content string) error {
|
||||
path := cm.path(name)
|
||||
if _, err := os.Stat(path); err == nil {
|
||||
return fmt.Errorf("config already exists")
|
||||
}
|
||||
return os.WriteFile(path, []byte(content), 0644)
|
||||
}
|
||||
|
||||
func (cm *ConfigManager) Update(name, content string) error {
|
||||
return os.WriteFile(cm.path(name), []byte(content), 0644)
|
||||
}
|
||||
|
||||
func (cm *ConfigManager) Delete(name string) error {
|
||||
return os.Remove(cm.path(name))
|
||||
}
|
||||
|
||||
func (cm *ConfigManager) Duplicate(name, newName string) error {
|
||||
content, err := cm.Get(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return cm.Create(newName, content)
|
||||
}
|
||||
|
||||
func (cm *ConfigManager) path(name string) string {
|
||||
return filepath.Join(cm.cfgDir, sanitizeConfigName(name)+".cfg")
|
||||
}
|
||||
|
||||
func sanitizeConfigName(name string) string {
|
||||
name = filepath.Base(name)
|
||||
name = strings.TrimSuffix(name, ".cfg")
|
||||
return name
|
||||
}
|
||||
81
backend/internal/services/log_streamer.go
Normal file
81
backend/internal/services/log_streamer.go
Normal file
@@ -0,0 +1,81 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"log"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type LogStreamer struct {
|
||||
mu sync.RWMutex
|
||||
subs map[string]map[string]chan string
|
||||
}
|
||||
|
||||
func NewLogStreamer() *LogStreamer {
|
||||
return &LogStreamer{
|
||||
subs: make(map[string]map[string]chan string),
|
||||
}
|
||||
}
|
||||
|
||||
func (ls *LogStreamer) Subscribe(serverID, clientID string) chan string {
|
||||
ls.mu.Lock()
|
||||
defer ls.mu.Unlock()
|
||||
|
||||
if ls.subs[serverID] == nil {
|
||||
ls.subs[serverID] = make(map[string]chan string)
|
||||
}
|
||||
|
||||
ch := make(chan string, 256)
|
||||
ls.subs[serverID][clientID] = ch
|
||||
return ch
|
||||
}
|
||||
|
||||
func (ls *LogStreamer) Unsubscribe(serverID, clientID string) {
|
||||
ls.mu.Lock()
|
||||
defer ls.mu.Unlock()
|
||||
|
||||
if ls.subs[serverID] != nil {
|
||||
if ch, ok := ls.subs[serverID][clientID]; ok {
|
||||
close(ch)
|
||||
delete(ls.subs[serverID], clientID)
|
||||
}
|
||||
if len(ls.subs[serverID]) == 0 {
|
||||
delete(ls.subs, serverID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (ls *LogStreamer) Stream(serverID string, reader io.Reader, closeMsg string) {
|
||||
scanner := bufio.NewScanner(reader)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
ls.broadcast(serverID, line)
|
||||
}
|
||||
if err := scanner.Err(); err != nil {
|
||||
log.Printf("log stream error for server %s: %v", serverID, err)
|
||||
}
|
||||
if closeMsg != "" {
|
||||
ls.broadcast(serverID, closeMsg)
|
||||
}
|
||||
}
|
||||
|
||||
func (ls *LogStreamer) Broadcast(serverID, line string) {
|
||||
ls.broadcast(serverID, line)
|
||||
}
|
||||
|
||||
func (ls *LogStreamer) broadcast(serverID, line string) {
|
||||
ls.mu.RLock()
|
||||
defer ls.mu.RUnlock()
|
||||
|
||||
if ls.subs[serverID] == nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, ch := range ls.subs[serverID] {
|
||||
select {
|
||||
case ch <- line:
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
182
backend/internal/services/modlist_manager.go
Normal file
182
backend/internal/services/modlist_manager.go
Normal file
@@ -0,0 +1,182 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"arma3-web-server/internal/models"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type ModlistManager struct {
|
||||
dir string
|
||||
mu sync.RWMutex
|
||||
}
|
||||
|
||||
func NewModlistManager(dataDir string) *ModlistManager {
|
||||
return &ModlistManager{
|
||||
dir: filepath.Join(dataDir, "modlists"),
|
||||
}
|
||||
}
|
||||
|
||||
func (mm *ModlistManager) path(id string) string {
|
||||
return filepath.Join(mm.dir, id+".json")
|
||||
}
|
||||
|
||||
func (mm *ModlistManager) List() ([]models.ModlistListItem, error) {
|
||||
mm.mu.RLock()
|
||||
defer mm.mu.RUnlock()
|
||||
|
||||
entries, err := os.ReadDir(mm.dir)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return []models.ModlistListItem{}, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var items []models.ModlistListItem
|
||||
for _, e := range entries {
|
||||
if e.IsDir() || !strings.HasSuffix(e.Name(), ".json") {
|
||||
continue
|
||||
}
|
||||
data, err := os.ReadFile(filepath.Join(mm.dir, e.Name()))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
var m models.Modlist
|
||||
if err := json.Unmarshal(data, &m); err != nil {
|
||||
continue
|
||||
}
|
||||
items = append(items, models.ModlistListItem{
|
||||
ID: m.ID,
|
||||
Name: m.Name,
|
||||
ModCount: len(m.Mods),
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
})
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
func (mm *ModlistManager) Get(id string) (*models.Modlist, error) {
|
||||
mm.mu.RLock()
|
||||
defer mm.mu.RUnlock()
|
||||
|
||||
data, err := os.ReadFile(mm.path(id))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil, fmt.Errorf("modlist not found")
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
var m models.Modlist
|
||||
if err := json.Unmarshal(data, &m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &m, nil
|
||||
}
|
||||
|
||||
func (mm *ModlistManager) Create(name string) (*models.Modlist, error) {
|
||||
mm.mu.Lock()
|
||||
defer mm.mu.Unlock()
|
||||
|
||||
now := time.Now().UTC()
|
||||
m := &models.Modlist{
|
||||
ID: uuid.New().String(),
|
||||
Name: name,
|
||||
Mods: []models.ModEntry{},
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
|
||||
data, err := json.MarshalIndent(m, "", " ")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := os.MkdirAll(mm.dir, 0755); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := os.WriteFile(mm.path(m.ID), data, 0644); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (mm *ModlistManager) Update(id, name string, mods []models.ModEntry) (*models.Modlist, error) {
|
||||
mm.mu.Lock()
|
||||
defer mm.mu.Unlock()
|
||||
|
||||
m, err := mm.getLocked(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m.Name = name
|
||||
m.Mods = mods
|
||||
m.UpdatedAt = time.Now().UTC()
|
||||
|
||||
data, err := json.MarshalIndent(m, "", " ")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := os.WriteFile(mm.path(id), data, 0644); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (mm *ModlistManager) Delete(id string) error {
|
||||
mm.mu.Lock()
|
||||
defer mm.mu.Unlock()
|
||||
return os.Remove(mm.path(id))
|
||||
}
|
||||
|
||||
func (mm *ModlistManager) Duplicate(id, newName string) (*models.Modlist, error) {
|
||||
mm.mu.Lock()
|
||||
defer mm.mu.Unlock()
|
||||
|
||||
orig, err := mm.getLocked(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
now := time.Now().UTC()
|
||||
dup := &models.Modlist{
|
||||
ID: uuid.New().String(),
|
||||
Name: newName,
|
||||
Mods: orig.Mods,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
|
||||
data, err := json.MarshalIndent(dup, "", " ")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := os.WriteFile(mm.path(dup.ID), data, 0644); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dup, nil
|
||||
}
|
||||
|
||||
func (mm *ModlistManager) getLocked(id string) (*models.Modlist, error) {
|
||||
data, err := os.ReadFile(mm.path(id))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil, fmt.Errorf("modlist not found")
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
var m models.Modlist
|
||||
if err := json.Unmarshal(data, &m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &m, nil
|
||||
}
|
||||
116
backend/internal/services/modlist_parser.go
Normal file
116
backend/internal/services/modlist_parser.go
Normal file
@@ -0,0 +1,116 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"arma3-web-server/internal/models"
|
||||
"golang.org/x/net/html"
|
||||
)
|
||||
|
||||
func ParseModlistHTML(r io.Reader) (string, []models.ModEntry, error) {
|
||||
doc, err := html.Parse(r)
|
||||
if err != nil {
|
||||
return "", nil, fmt.Errorf("parse html: %w", err)
|
||||
}
|
||||
|
||||
var mods []models.ModEntry
|
||||
seen := map[string]bool{}
|
||||
|
||||
var walk func(*html.Node)
|
||||
walk = func(n *html.Node) {
|
||||
if n.Type == html.ElementNode && n.Data == "tr" {
|
||||
if name, id, ok := extractModRow(n); ok && id != "" {
|
||||
if !seen[id] {
|
||||
seen[id] = true
|
||||
mods = append(mods, models.ModEntry{
|
||||
ID: id,
|
||||
Name: cleanModName(name),
|
||||
Enabled: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
for c := n.FirstChild; c != nil; c = c.NextSibling {
|
||||
walk(c)
|
||||
}
|
||||
}
|
||||
walk(doc)
|
||||
|
||||
if mods == nil {
|
||||
mods = []models.ModEntry{}
|
||||
}
|
||||
return "", mods, nil
|
||||
}
|
||||
|
||||
func extractModRow(tr *html.Node) (name, id string, ok bool) {
|
||||
var cells []*html.Node
|
||||
for c := tr.FirstChild; c != nil; c = c.NextSibling {
|
||||
if c.Type == html.ElementNode && c.Data == "td" {
|
||||
cells = append(cells, c)
|
||||
}
|
||||
}
|
||||
if len(cells) < 3 {
|
||||
return "", "", false
|
||||
}
|
||||
|
||||
name = extractText(cells[0])
|
||||
|
||||
for c := cells[2].FirstChild; c != nil; c = c.NextSibling {
|
||||
if c.Type == html.ElementNode && c.Data == "a" {
|
||||
id = extractWorkshopID(c)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if name == "" {
|
||||
return "", "", false
|
||||
}
|
||||
return name, id, true
|
||||
}
|
||||
|
||||
func extractText(n *html.Node) string {
|
||||
var b strings.Builder
|
||||
var walk func(*html.Node)
|
||||
walk = func(n *html.Node) {
|
||||
if n.Type == html.TextNode {
|
||||
b.WriteString(n.Data)
|
||||
}
|
||||
for c := n.FirstChild; c != nil; c = c.NextSibling {
|
||||
walk(c)
|
||||
}
|
||||
}
|
||||
walk(n)
|
||||
return strings.TrimSpace(b.String())
|
||||
}
|
||||
|
||||
func extractWorkshopID(a *html.Node) string {
|
||||
for _, attr := range a.Attr {
|
||||
if attr.Key == "href" {
|
||||
u, err := url.Parse(attr.Val)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
return u.Query().Get("id")
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func cleanModName(name string) string {
|
||||
name = strings.TrimSpace(name)
|
||||
name = strings.ReplaceAll(name, "/", "_")
|
||||
name = strings.ReplaceAll(name, "\\", "_")
|
||||
return name
|
||||
}
|
||||
|
||||
func FileNameToModlistName(filename string) string {
|
||||
ext := path.Ext(filename)
|
||||
name := strings.TrimSuffix(filename, ext)
|
||||
name = strings.ReplaceAll(name, "_", " ")
|
||||
name = strings.ReplaceAll(name, "-", " ")
|
||||
return name
|
||||
}
|
||||
267
backend/internal/services/server_process.go
Normal file
267
backend/internal/services/server_process.go
Normal file
@@ -0,0 +1,267 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"arma3-web-server/internal/models"
|
||||
)
|
||||
|
||||
type ProcessManager struct {
|
||||
serverfileDir string
|
||||
modsDir string
|
||||
cfgDir string
|
||||
profilesDir string
|
||||
settings *SettingsManager
|
||||
modlists *ModlistManager
|
||||
configs *ConfigManager
|
||||
streamer *LogStreamer
|
||||
proc *runningProcess
|
||||
mu sync.RWMutex
|
||||
}
|
||||
|
||||
type runningProcess struct {
|
||||
cmd *exec.Cmd
|
||||
cancel context.CancelFunc
|
||||
exited chan struct{}
|
||||
}
|
||||
|
||||
func NewProcessManager(serverfileDir, modsDir, cfgDir, profilesDir string, settings *SettingsManager, modlists *ModlistManager, configs *ConfigManager, streamer *LogStreamer) *ProcessManager {
|
||||
return &ProcessManager{
|
||||
serverfileDir: serverfileDir,
|
||||
modsDir: modsDir,
|
||||
cfgDir: cfgDir,
|
||||
profilesDir: profilesDir,
|
||||
settings: settings,
|
||||
modlists: modlists,
|
||||
configs: configs,
|
||||
streamer: streamer,
|
||||
}
|
||||
}
|
||||
|
||||
func (pm *ProcessManager) ServerfileDir() string {
|
||||
return pm.serverfileDir
|
||||
}
|
||||
|
||||
func (pm *ProcessManager) ProfilesDir() string {
|
||||
return pm.profilesDir
|
||||
}
|
||||
|
||||
func (pm *ProcessManager) IsRunning() bool {
|
||||
pm.mu.RLock()
|
||||
defer pm.mu.RUnlock()
|
||||
return pm.proc != nil
|
||||
}
|
||||
|
||||
func (pm *ProcessManager) Start() error {
|
||||
pm.mu.Lock()
|
||||
if pm.proc != nil {
|
||||
pm.mu.Unlock()
|
||||
return fmt.Errorf("server already running")
|
||||
}
|
||||
pm.mu.Unlock()
|
||||
|
||||
s, err := pm.settings.Load()
|
||||
if err != nil {
|
||||
return fmt.Errorf("load settings: %w", err)
|
||||
}
|
||||
|
||||
binName := "arma3server_x64"
|
||||
if s.Platform == "windows" {
|
||||
binName = "arma3server_x64.exe"
|
||||
}
|
||||
binPath := filepath.Join(pm.serverfileDir, binName)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
var cmd *exec.Cmd
|
||||
if strings.Contains(s.ServerParameters, "%command%") {
|
||||
full := strings.ReplaceAll(s.ServerParameters, "%command%", binPath)
|
||||
parts := splitArgs(full)
|
||||
if len(parts) == 0 {
|
||||
cancel()
|
||||
return fmt.Errorf("empty command after %%command%% substitution")
|
||||
}
|
||||
autoArgs := pm.buildAutoArgs(s)
|
||||
cmd = exec.CommandContext(ctx, parts[0], append(parts[1:], autoArgs...)...)
|
||||
} else {
|
||||
cmd = exec.CommandContext(ctx, binPath, pm.buildArgs(s)...)
|
||||
}
|
||||
cmd.Dir = pm.serverfileDir
|
||||
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
cancel()
|
||||
return fmt.Errorf("stdout pipe: %w", err)
|
||||
}
|
||||
stderr, err := cmd.StderrPipe()
|
||||
if err != nil {
|
||||
cancel()
|
||||
return fmt.Errorf("stderr pipe: %w", err)
|
||||
}
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
cancel()
|
||||
return fmt.Errorf("start: %w", err)
|
||||
}
|
||||
|
||||
exited := make(chan struct{})
|
||||
pm.mu.Lock()
|
||||
pm.proc = &runningProcess{cmd: cmd, cancel: cancel, exited: exited}
|
||||
pm.mu.Unlock()
|
||||
|
||||
go pm.streamer.Stream("server", stdout, "")
|
||||
go pm.streamer.Stream("server", stderr, "")
|
||||
|
||||
go func() {
|
||||
cmd.Wait()
|
||||
pm.mu.Lock()
|
||||
pm.proc = nil
|
||||
pm.mu.Unlock()
|
||||
close(exited)
|
||||
pm.streamer.Broadcast("server", "[SERVER_PROCESS_EXITED]")
|
||||
}()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (pm *ProcessManager) Stop() error {
|
||||
pm.mu.Lock()
|
||||
rp := pm.proc
|
||||
pm.mu.Unlock()
|
||||
|
||||
if rp == nil {
|
||||
return fmt.Errorf("server not running")
|
||||
}
|
||||
|
||||
rp.cancel()
|
||||
<-rp.exited
|
||||
return nil
|
||||
}
|
||||
|
||||
func (pm *ProcessManager) Restart() error {
|
||||
_ = pm.Stop()
|
||||
return pm.Start()
|
||||
}
|
||||
|
||||
func splitArgs(raw string) []string {
|
||||
var args []string
|
||||
for _, part := range strings.Fields(raw) {
|
||||
part = strings.TrimSpace(part)
|
||||
if part != "" {
|
||||
args = append(args, part)
|
||||
}
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
||||
func (pm *ProcessManager) buildAutoArgs(s *models.ServerSettings) []string {
|
||||
var args []string
|
||||
|
||||
if s.ActiveConfig != "" {
|
||||
cfgPath := filepath.Join(pm.cfgDir, s.ActiveConfig+".cfg")
|
||||
args = append(args, "-config="+cfgPath)
|
||||
}
|
||||
|
||||
if s.ActiveModlist != "" {
|
||||
modPath := pm.buildModPath(s.ActiveModlist)
|
||||
if modPath != "" {
|
||||
args = append(args, modPath)
|
||||
}
|
||||
}
|
||||
|
||||
if pm.profilesDir != "" && !hasArgPrefix(args, "-profiles=") {
|
||||
args = append(args, "-profiles="+pm.profilesDir)
|
||||
}
|
||||
|
||||
if s.IPPort != "" && !hasArgPrefix(args, "-port=") {
|
||||
if _, portStr, err := net.SplitHostPort(s.IPPort); err == nil && portStr != "" {
|
||||
args = append(args, "-port="+portStr)
|
||||
}
|
||||
}
|
||||
|
||||
return args
|
||||
}
|
||||
|
||||
func (pm *ProcessManager) buildArgs(s *models.ServerSettings) []string {
|
||||
args := splitArgs(s.ServerParameters)
|
||||
args = append(args, pm.buildAutoArgs(s)...)
|
||||
return args
|
||||
}
|
||||
|
||||
func hasArgPrefix(args []string, prefix string) bool {
|
||||
for _, a := range args {
|
||||
if strings.HasPrefix(a, prefix) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
const workshopAppID = "107410"
|
||||
|
||||
func (pm *ProcessManager) buildModPath(modlistID string) string {
|
||||
ml, err := pm.modlists.Get(modlistID)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
var parts []string
|
||||
for _, mod := range ml.Mods {
|
||||
if !mod.Enabled {
|
||||
continue
|
||||
}
|
||||
parts = append(parts, pm.resolveModPath(mod))
|
||||
}
|
||||
|
||||
if len(parts) == 0 {
|
||||
return ""
|
||||
}
|
||||
return "-mod=" + strings.Join(parts, ";")
|
||||
}
|
||||
|
||||
func (pm *ProcessManager) resolveModPath(mod models.ModEntry) string {
|
||||
if mod.Name != "" {
|
||||
p := filepath.Join(pm.modsDir, "@"+mod.Name)
|
||||
if _, err := os.Stat(p); err == nil {
|
||||
return p
|
||||
}
|
||||
}
|
||||
|
||||
if mod.ID != "" {
|
||||
p := filepath.Join(pm.serverfileDir, "steamapps", "workshop", "content", workshopAppID, mod.ID)
|
||||
if _, err := os.Stat(p); err == nil {
|
||||
return p
|
||||
}
|
||||
}
|
||||
|
||||
if mod.Name != "" {
|
||||
return filepath.Join(pm.modsDir, "@"+mod.Name)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (pm *ProcessManager) WriteUserconfigFiles(s *models.ServerSettings) error {
|
||||
userconfigDir := filepath.Join(pm.serverfileDir, "userconfig")
|
||||
if err := os.MkdirAll(userconfigDir, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
files := map[string]string{
|
||||
"cba_settings.sqf": s.CBASettings,
|
||||
"CfgAILevelPresets.sqf": s.AILevelPresets,
|
||||
"CfgDifficultyPresets.sqf": s.DifficultyPresets,
|
||||
}
|
||||
for name, content := range files {
|
||||
path := filepath.Join(userconfigDir, name)
|
||||
if err := os.WriteFile(path, []byte(content), 0644); err != nil {
|
||||
return fmt.Errorf("write %s: %w", name, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
66
backend/internal/services/settings.go
Normal file
66
backend/internal/services/settings.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"arma3-web-server/internal/models"
|
||||
)
|
||||
|
||||
type SettingsManager struct {
|
||||
path string
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
func NewSettingsManager(dataDir string) *SettingsManager {
|
||||
return &SettingsManager{
|
||||
path: filepath.Join(dataDir, "settings.json"),
|
||||
}
|
||||
}
|
||||
|
||||
func (sm *SettingsManager) Load() (*models.ServerSettings, error) {
|
||||
sm.mu.Lock()
|
||||
defer sm.mu.Unlock()
|
||||
|
||||
data, err := os.ReadFile(sm.path)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return sm.defaults(), nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var s models.ServerSettings
|
||||
if err := json.Unmarshal(data, &s); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &s, nil
|
||||
}
|
||||
|
||||
func (sm *SettingsManager) Save(s *models.ServerSettings) error {
|
||||
sm.mu.Lock()
|
||||
defer sm.mu.Unlock()
|
||||
|
||||
s.UpdatedAt = time.Now().UTC()
|
||||
data, err := json.MarshalIndent(s, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(sm.path, data, 0644)
|
||||
}
|
||||
|
||||
func (sm *SettingsManager) defaults() *models.ServerSettings {
|
||||
return &models.ServerSettings{
|
||||
IPPort: "0.0.0.0:2302",
|
||||
ServerParameters: "-server -world=empty -loadMissionToMemory -noPause",
|
||||
SteamBranch: "stable",
|
||||
SteamUser: "anonymous",
|
||||
Platform: "linux",
|
||||
ActiveConfig: "",
|
||||
ActiveModlist: "",
|
||||
UpdatedAt: time.Now().UTC(),
|
||||
}
|
||||
}
|
||||
142
backend/internal/services/steamcmd.go
Normal file
142
backend/internal/services/steamcmd.go
Normal file
@@ -0,0 +1,142 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
func CheckWorkshopMod(serverfileDir, modID string) bool {
|
||||
if modID == "" {
|
||||
return false
|
||||
}
|
||||
p := filepath.Join(serverfileDir, "steamapps", "workshop", "content", "107410", modID)
|
||||
fi, err := os.Stat(p)
|
||||
return err == nil && fi.IsDir()
|
||||
}
|
||||
|
||||
const arma3AppID = "233780"
|
||||
|
||||
type SteamCmdManager struct {
|
||||
serverfileDir string
|
||||
streamer *LogStreamer
|
||||
mu sync.Mutex
|
||||
cancel context.CancelFunc
|
||||
running bool
|
||||
}
|
||||
|
||||
func NewSteamCmdManager(serverfileDir string, streamer *LogStreamer) *SteamCmdManager {
|
||||
return &SteamCmdManager{
|
||||
serverfileDir: serverfileDir,
|
||||
streamer: streamer,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SteamCmdManager) IsRunning() bool {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
return s.running
|
||||
}
|
||||
|
||||
func (s *SteamCmdManager) UpdateGame(branch, user string) error {
|
||||
s.mu.Lock()
|
||||
if s.running {
|
||||
s.mu.Unlock()
|
||||
return fmt.Errorf("steamcmd already running")
|
||||
}
|
||||
s.mu.Unlock()
|
||||
|
||||
args := []string{
|
||||
"+force_install_dir", s.serverfileDir,
|
||||
"+login", user,
|
||||
"+app_update", arma3AppID,
|
||||
}
|
||||
if branch != "" && branch != "stable" {
|
||||
args = append(args, "-beta", branch)
|
||||
}
|
||||
args = append(args, "validate", "+quit")
|
||||
|
||||
return s.run("Game update", args)
|
||||
}
|
||||
|
||||
func (s *SteamCmdManager) DownloadMod(modID string) error {
|
||||
return s.DownloadMods([]string{modID})
|
||||
}
|
||||
|
||||
func (s *SteamCmdManager) DownloadMods(modIDs []string) error {
|
||||
s.mu.Lock()
|
||||
if s.running {
|
||||
s.mu.Unlock()
|
||||
return fmt.Errorf("steamcmd already running")
|
||||
}
|
||||
s.mu.Unlock()
|
||||
|
||||
if len(modIDs) == 0 {
|
||||
return fmt.Errorf("no mod ids provided")
|
||||
}
|
||||
|
||||
args := []string{
|
||||
"+force_install_dir", s.serverfileDir,
|
||||
"+login", "anonymous",
|
||||
}
|
||||
for _, id := range modIDs {
|
||||
args = append(args, "+workshop_download_item", "107410", id)
|
||||
}
|
||||
args = append(args, "+quit")
|
||||
|
||||
label := fmt.Sprintf("Download %d mod(s)", len(modIDs))
|
||||
return s.run(label, args)
|
||||
}
|
||||
|
||||
const steamcmdTimeout = 10 * time.Minute
|
||||
|
||||
func (s *SteamCmdManager) run(label string, args []string) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), steamcmdTimeout)
|
||||
|
||||
s.streamer.Broadcast("steamcmd", "[STEAMCMD] "+label+" starting...")
|
||||
|
||||
cmd := exec.CommandContext(ctx, "steamcmd", args...)
|
||||
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
cancel()
|
||||
return fmt.Errorf("stdout pipe: %w", err)
|
||||
}
|
||||
stderr, err := cmd.StderrPipe()
|
||||
if err != nil {
|
||||
cancel()
|
||||
return fmt.Errorf("stderr pipe: %w", err)
|
||||
}
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
cancel()
|
||||
return fmt.Errorf("start steamcmd: %w", err)
|
||||
}
|
||||
|
||||
s.mu.Lock()
|
||||
s.running = true
|
||||
s.cancel = cancel
|
||||
s.mu.Unlock()
|
||||
|
||||
go s.streamer.Stream("steamcmd", stdout, "")
|
||||
go s.streamer.Stream("steamcmd", stderr, "")
|
||||
|
||||
go func() {
|
||||
err := cmd.Wait()
|
||||
s.mu.Lock()
|
||||
s.running = false
|
||||
s.cancel = nil
|
||||
s.mu.Unlock()
|
||||
if err == nil {
|
||||
s.streamer.Broadcast("steamcmd", "[STEAMCMD] SUCCESS: "+label+" finished")
|
||||
} else {
|
||||
s.streamer.Broadcast("steamcmd", "[STEAMCMD] ERROR: "+label+" failed: "+err.Error())
|
||||
}
|
||||
}()
|
||||
|
||||
return nil
|
||||
}
|
||||
20
docker-compose.yml
Normal file
20
docker-compose.yml
Normal file
@@ -0,0 +1,20 @@
|
||||
services:
|
||||
arma3-web-server:
|
||||
build: .
|
||||
container_name: arma3-web
|
||||
ports:
|
||||
- "8080:8080"
|
||||
volumes:
|
||||
- ./data:/data
|
||||
# /servers should contain the Arma 3 server install (binary + steamapps/workshop for mods)
|
||||
- /path/to/your/servers:/servers
|
||||
environment:
|
||||
- DATA_DIR=/data
|
||||
- SERVERFILE_DIR=/servers
|
||||
- MODS_DIR=/servers/mods
|
||||
- CFG_DIR=/servers/cfg
|
||||
- PROFILES_DIR=/servers/profiles
|
||||
- LISTEN=:8080
|
||||
- FRONTEND_DIR=/usr/share/arma3-web-server/frontend
|
||||
- GIN_MODE=release
|
||||
restart: unless-stopped
|
||||
13
frontend/index.html
Normal file
13
frontend/index.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>arma3-frontend</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
1949
frontend/package-lock.json
generated
Normal file
1949
frontend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
33
frontend/package.json
Normal file
33
frontend/package.json
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "arma3-frontend",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc -b && vite build",
|
||||
"lint": "oxlint",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@monaco-editor/react": "^4.7.0",
|
||||
"@tailwindcss/vite": "^4.3.2",
|
||||
"@tanstack/react-query": "^5.101.2",
|
||||
"@xterm/addon-fit": "^0.11.0",
|
||||
"@xterm/xterm": "^6.0.0",
|
||||
"react": "^19.2.7",
|
||||
"react-dom": "^19.2.7",
|
||||
"react-router-dom": "^7.18.1",
|
||||
"tailwindcss": "^4.3.2",
|
||||
"zustand": "^5.0.14"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^24.13.2",
|
||||
"@types/react": "^19.2.17",
|
||||
"@types/react-dom": "^19.2.3",
|
||||
"@vitejs/plugin-react": "^6.0.3",
|
||||
"oxlint": "^1.71.0",
|
||||
"typescript": "~6.0.2",
|
||||
"vite": "^8.1.1"
|
||||
}
|
||||
}
|
||||
1
frontend/public/favicon.svg
Normal file
1
frontend/public/favicon.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 9.3 KiB |
28
frontend/src/App.tsx
Normal file
28
frontend/src/App.tsx
Normal file
@@ -0,0 +1,28 @@
|
||||
import { Routes, Route, Navigate } from 'react-router-dom'
|
||||
import Layout from './components/Layout'
|
||||
import Dashboard from './pages/Dashboard'
|
||||
import Settings from './pages/Settings'
|
||||
import Configs from './pages/Configs'
|
||||
import ConfigEditor from './pages/ConfigEditor'
|
||||
import Modlists from './pages/Modlists'
|
||||
import ModlistEditor from './pages/ModlistEditor'
|
||||
import Logs from './pages/Logs'
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<Layout>
|
||||
<Routes>
|
||||
<Route path="/" element={<Dashboard />} />
|
||||
<Route path="/settings" element={<Settings />} />
|
||||
<Route path="/configs" element={<Configs />} />
|
||||
<Route path="/configs/:name" element={<ConfigEditor />} />
|
||||
<Route path="/modlists" element={<Modlists />} />
|
||||
<Route path="/modlists/:id" element={<ModlistEditor />} />
|
||||
<Route path="/logs" element={<Logs />} />
|
||||
<Route path="*" element={<Navigate to="/" replace />} />
|
||||
</Routes>
|
||||
</Layout>
|
||||
)
|
||||
}
|
||||
|
||||
export default App
|
||||
91
frontend/src/api/client.ts
Normal file
91
frontend/src/api/client.ts
Normal file
@@ -0,0 +1,91 @@
|
||||
import type { ServerSettings, ServerPaths, ConfigInfo, Modlist, ModlistListItem, ModEntry } from '../types'
|
||||
|
||||
const BASE = '/api'
|
||||
|
||||
async function request<T>(path: string, options?: RequestInit): Promise<T> {
|
||||
const res = await fetch(`${BASE}${path}`, {
|
||||
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
||||
...options,
|
||||
})
|
||||
if (res.status === 204) return undefined as T
|
||||
if (!res.ok) {
|
||||
const err = await res.json().catch(() => ({ error: res.statusText }))
|
||||
throw new Error(err.error || res.statusText)
|
||||
}
|
||||
return res.json()
|
||||
}
|
||||
|
||||
export const settingsApi = {
|
||||
get: () => request<ServerSettings>('/server/settings'),
|
||||
update: (data: Partial<ServerSettings>) => request<ServerSettings>('/server/settings', { method: 'PUT', body: JSON.stringify(data) }),
|
||||
start: () => request<{ status: string }>('/server/start', { method: 'POST' }),
|
||||
stop: () => request<{ status: string }>('/server/stop', { method: 'POST' }),
|
||||
restart: () => request<{ status: string }>('/server/restart', { method: 'POST' }),
|
||||
status: () => request<{ running: boolean }>('/server/status'),
|
||||
steamcmd: () => request<{ branch: string; user: string; platform: string }>('/server/steamcmd'),
|
||||
paths: () => request<ServerPaths>('/server/paths'),
|
||||
}
|
||||
|
||||
export const configsApi = {
|
||||
list: () => request<ConfigInfo[]>('/configs'),
|
||||
get: async (name: string) => {
|
||||
const r = await fetch(`${BASE}/configs/${name}`)
|
||||
if (!r.ok) {
|
||||
const err = await r.json().catch(() => ({ error: r.statusText }))
|
||||
throw new Error(err.error || r.statusText)
|
||||
}
|
||||
return r.text()
|
||||
},
|
||||
create: (name: string, content?: string) => request<{ name: string }>('/configs', { method: 'POST', body: JSON.stringify({ name, content: content || '' }) }),
|
||||
update: (name: string, content: string) => request<{ status: string }>(`/configs/${name}`, { method: 'PUT', body: JSON.stringify({ content }) }),
|
||||
delete: (name: string) => request<void>(`/configs/${name}`, { method: 'DELETE' }),
|
||||
duplicate: (name: string, newName: string) => request<{ name: string }>(`/configs/${name}/duplicate`, { method: 'POST', body: JSON.stringify({ new_name: newName }) }),
|
||||
}
|
||||
|
||||
export interface ModStatus {
|
||||
id: string
|
||||
name: string
|
||||
enabled: boolean
|
||||
downloaded: boolean
|
||||
}
|
||||
|
||||
export const modlistsApi = {
|
||||
list: () => request<ModlistListItem[]>('/modlists'),
|
||||
get: (id: string) => request<Modlist>(`/modlists/${id}`),
|
||||
create: (name: string) => request<Modlist>('/modlists', { method: 'POST', body: JSON.stringify({ name }) }),
|
||||
update: (id: string, data: { name: string; mods: ModEntry[] }) => request<Modlist>(`/modlists/${id}`, { method: 'PUT', body: JSON.stringify(data) }),
|
||||
delete: (id: string) => request<void>(`/modlists/${id}`, { method: 'DELETE' }),
|
||||
duplicate: (id: string, name: string) => request<Modlist>(`/modlists/${id}/duplicate`, { method: 'POST', body: JSON.stringify({ name }) }),
|
||||
importHtml: (file: File) => {
|
||||
const form = new FormData()
|
||||
form.append('file', file)
|
||||
return fetch(`${BASE}/modlists/import`, { method: 'POST', body: form }).then(r => {
|
||||
if (!r.ok) return r.json().then(e => { throw new Error(e.error) })
|
||||
return r.json() as Promise<Modlist>
|
||||
})
|
||||
},
|
||||
checkMods: (id: string) => request<ModStatus[]>(`/modlists/${id}/check`),
|
||||
downloadMissing: (id: string) => request<{ status: string; count?: number }>(`/modlists/${id}/download-missing`, { method: 'POST' }),
|
||||
updateAll: (id: string) => request<{ status: string; count?: number }>(`/modlists/${id}/update-all`, { method: 'POST' }),
|
||||
}
|
||||
|
||||
function wsUrl(path: string): string {
|
||||
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'
|
||||
return `${protocol}//${window.location.host}${path}`
|
||||
}
|
||||
|
||||
export const steamcmdApi = {
|
||||
updateGame: (branch: string, user: string) =>
|
||||
request<{ status: string }>('/server/steamcmd/update-game', { method: 'POST', body: JSON.stringify({ branch, user }) }),
|
||||
downloadMod: (modId: string) =>
|
||||
request<{ status: string }>('/server/steamcmd/download-mod', { method: 'POST', body: JSON.stringify({ mod_id: modId }) }),
|
||||
status: () => request<{ running: boolean }>('/server/steamcmd/status'),
|
||||
}
|
||||
|
||||
export const logsApi = {
|
||||
list: () => request<string[]>('/server/logs'),
|
||||
get: (file: string) => fetch(`${BASE}/server/logs/${file}`).then(r => r.text()),
|
||||
wsUrl: () => wsUrl('/ws/server/logs'),
|
||||
steamcmdWsUrl: () => wsUrl('/ws/steamcmd/logs'),
|
||||
rptWsUrl: () => wsUrl('/ws/server/rpt'),
|
||||
}
|
||||
30
frontend/src/components/ConfigEditor.tsx
Normal file
30
frontend/src/components/ConfigEditor.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
import Editor from '@monaco-editor/react'
|
||||
|
||||
interface Props {
|
||||
value: string
|
||||
onChange: (value: string) => void
|
||||
language?: string
|
||||
}
|
||||
|
||||
export default function ConfigEditor({ value, onChange, language = 'plaintext' }: Props) {
|
||||
return (
|
||||
<div className="border border-neutral-800 rounded-lg overflow-hidden">
|
||||
<Editor
|
||||
height="500px"
|
||||
language={language}
|
||||
value={value}
|
||||
onChange={v => onChange(v ?? '')}
|
||||
theme="vs-dark"
|
||||
options={{
|
||||
minimap: { enabled: false },
|
||||
fontSize: 13,
|
||||
fontFamily: '"JetBrains Mono", "Fira Code", monospace',
|
||||
lineNumbers: 'on',
|
||||
scrollBeyondLastLine: false,
|
||||
automaticLayout: true,
|
||||
tabSize: 2,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
37
frontend/src/components/Layout.tsx
Normal file
37
frontend/src/components/Layout.tsx
Normal file
@@ -0,0 +1,37 @@
|
||||
import { Link, useLocation } from 'react-router-dom'
|
||||
import type { ReactNode } from 'react'
|
||||
|
||||
const nav = [
|
||||
{ to: '/', label: 'Dashboard', icon: '⊞' },
|
||||
{ to: '/settings', label: 'Settings', icon: '🖥' },
|
||||
{ to: '/configs', label: 'Configs', icon: '⚙' },
|
||||
{ to: '/modlists', label: 'Modlists', icon: '📦' },
|
||||
{ to: '/logs', label: 'Logs', icon: '📋' },
|
||||
]
|
||||
|
||||
export default function Layout({ children }: { children: ReactNode }) {
|
||||
const loc = useLocation()
|
||||
|
||||
return (
|
||||
<div className="flex h-screen bg-neutral-950 text-neutral-100">
|
||||
<aside className="w-56 border-r border-neutral-800 p-4 flex flex-col gap-2">
|
||||
<h1 className="text-lg font-bold mb-4 tracking-tight">Arma3 Web</h1>
|
||||
{nav.map(item => (
|
||||
<Link
|
||||
key={item.to}
|
||||
to={item.to}
|
||||
className={`flex items-center gap-2 px-3 py-2 rounded-md text-sm transition-colors ${
|
||||
loc.pathname === item.to || (item.to !== '/' && loc.pathname.startsWith(item.to))
|
||||
? 'bg-neutral-800 text-white'
|
||||
: 'text-neutral-400 hover:text-white hover:bg-neutral-800/50'
|
||||
}`}
|
||||
>
|
||||
<span>{item.icon}</span>
|
||||
{item.label}
|
||||
</Link>
|
||||
))}
|
||||
</aside>
|
||||
<main className="flex-1 overflow-auto p-6">{children}</main>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
87
frontend/src/components/LiveTerminal.tsx
Normal file
87
frontend/src/components/LiveTerminal.tsx
Normal file
@@ -0,0 +1,87 @@
|
||||
import { useEffect, useRef } from 'react'
|
||||
import { Terminal } from '@xterm/xterm'
|
||||
import { FitAddon } from '@xterm/addon-fit'
|
||||
import '@xterm/xterm/css/xterm.css'
|
||||
|
||||
interface Props {
|
||||
wsUrl: string
|
||||
}
|
||||
|
||||
export default function LiveTerminal({ wsUrl }: Props) {
|
||||
const containerRef = useRef<HTMLDivElement>(null)
|
||||
const terminalRef = useRef<Terminal | null>(null)
|
||||
const fitRef = useRef<FitAddon | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
if (!containerRef.current) return
|
||||
|
||||
const term = new Terminal({
|
||||
theme: { background: '#0a0a0a', foreground: '#e0e0e0', cursor: '#e0e0e0' },
|
||||
fontSize: 13,
|
||||
fontFamily: '"JetBrains Mono", "Fira Code", monospace',
|
||||
cursorBlink: true,
|
||||
convertEol: true,
|
||||
rows: 30,
|
||||
})
|
||||
|
||||
const fit = new FitAddon()
|
||||
term.loadAddon(fit)
|
||||
term.open(containerRef.current)
|
||||
fit.fit()
|
||||
term.write('Connecting...\r\n')
|
||||
|
||||
terminalRef.current = term
|
||||
fitRef.current = fit
|
||||
|
||||
let ws: WebSocket | null = null
|
||||
let reconnectTimer: ReturnType<typeof setTimeout>
|
||||
let disposed = false
|
||||
|
||||
function connect() {
|
||||
if (disposed) return
|
||||
ws = new WebSocket(wsUrl)
|
||||
ws.onopen = () => {
|
||||
if (disposed) { ws?.close(); return }
|
||||
term.clear()
|
||||
term.write('--- Connected ---\r\n')
|
||||
}
|
||||
ws.onmessage = (event) => {
|
||||
const line = event.data as string
|
||||
if (line === '[SERVER_PROCESS_EXITED]') {
|
||||
term.write('\r\n\x1b[31m--- Process exited ---\x1b[0m\r\n')
|
||||
} else if (line.startsWith('[STEAMCMD] SUCCESS:')) {
|
||||
term.write('\r\n\x1b[32m' + line + '\x1b[0m\r\n')
|
||||
} else if (line.startsWith('[STEAMCMD] ERROR:')) {
|
||||
term.write('\r\n\x1b[31m' + line + '\x1b[0m\r\n')
|
||||
} else if (line.startsWith('[STEAMCMD]')) {
|
||||
term.write('\r\n\x1b[33m' + line + '\x1b[0m\r\n')
|
||||
} else {
|
||||
term.writeln(line)
|
||||
}
|
||||
}
|
||||
ws.onclose = () => {
|
||||
if (disposed) return
|
||||
term.write('\r\n\x1b[33m--- Disconnected, reconnecting in 3s ---\x1b[0m\r\n')
|
||||
reconnectTimer = setTimeout(connect, 3000)
|
||||
}
|
||||
ws.onerror = () => ws?.close()
|
||||
}
|
||||
|
||||
connect()
|
||||
|
||||
const resizeObserver = new ResizeObserver(() => {
|
||||
try { fit.fit() } catch {}
|
||||
})
|
||||
resizeObserver.observe(containerRef.current)
|
||||
|
||||
return () => {
|
||||
disposed = true
|
||||
clearTimeout(reconnectTimer)
|
||||
resizeObserver.disconnect()
|
||||
ws?.close()
|
||||
term.dispose()
|
||||
}
|
||||
}, [wsUrl])
|
||||
|
||||
return <div ref={containerRef} className="h-full min-h-[400px] bg-[#0a0a0a] rounded-lg" />
|
||||
}
|
||||
1
frontend/src/index.css
Normal file
1
frontend/src/index.css
Normal file
@@ -0,0 +1 @@
|
||||
@import "tailwindcss";
|
||||
18
frontend/src/main.tsx
Normal file
18
frontend/src/main.tsx
Normal file
@@ -0,0 +1,18 @@
|
||||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import { BrowserRouter } from 'react-router-dom'
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import './index.css'
|
||||
import App from './App'
|
||||
|
||||
const queryClient = new QueryClient()
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<BrowserRouter>
|
||||
<App />
|
||||
</BrowserRouter>
|
||||
</QueryClientProvider>
|
||||
</StrictMode>,
|
||||
)
|
||||
56
frontend/src/pages/ConfigEditor.tsx
Normal file
56
frontend/src/pages/ConfigEditor.tsx
Normal file
@@ -0,0 +1,56 @@
|
||||
import { useParams, Link } from 'react-router-dom'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { configsApi } from '../api/client'
|
||||
import { useState, useEffect } from 'react'
|
||||
import Editor from '@monaco-editor/react'
|
||||
|
||||
export default function ConfigEditor() {
|
||||
const { name } = useParams<{ name: string }>()
|
||||
const qc = useQueryClient()
|
||||
const { data: content, isLoading } = useQuery({ queryKey: ['config', name], queryFn: () => configsApi.get(name!) })
|
||||
const [value, setValue] = useState('')
|
||||
const [dirty, setDirty] = useState(false)
|
||||
|
||||
useEffect(() => { if (content !== undefined) { setValue(content); setDirty(false) } }, [content])
|
||||
|
||||
const saveMut = useMutation({
|
||||
mutationFn: () => configsApi.update(name!, value),
|
||||
onSuccess: () => { qc.invalidateQueries({ queryKey: ['config', name] }); setDirty(false) },
|
||||
})
|
||||
|
||||
if (isLoading) return <p className="text-neutral-500">Loading...</p>
|
||||
if (!name) return <p className="text-red-400">No config specified</p>
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<div>
|
||||
<Link to="/configs" className="text-sm text-blue-400 hover:underline">← Configs</Link>
|
||||
<h2 className="text-2xl font-semibold mt-1">{name}.cfg</h2>
|
||||
</div>
|
||||
<button onClick={() => saveMut.mutate()} disabled={!dirty || saveMut.isPending} className="px-4 py-2 bg-blue-600 hover:bg-blue-500 disabled:opacity-50 rounded text-sm">
|
||||
{saveMut.isPending ? 'Saving...' : 'Save'}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="border border-neutral-800 rounded-lg overflow-hidden">
|
||||
<Editor
|
||||
height="600px"
|
||||
language="plaintext"
|
||||
value={value}
|
||||
onChange={v => { setValue(v ?? ''); setDirty(true) }}
|
||||
theme="vs-dark"
|
||||
options={{
|
||||
minimap: { enabled: false },
|
||||
fontSize: 13,
|
||||
fontFamily: '"JetBrains Mono", "Fira Code", monospace',
|
||||
lineNumbers: 'on',
|
||||
scrollBeyondLastLine: false,
|
||||
automaticLayout: true,
|
||||
tabSize: 2,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
59
frontend/src/pages/Configs.tsx
Normal file
59
frontend/src/pages/Configs.tsx
Normal file
@@ -0,0 +1,59 @@
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { configsApi } from '../api/client'
|
||||
import { Link, useNavigate } from 'react-router-dom'
|
||||
import { useState } from 'react'
|
||||
|
||||
export default function Configs() {
|
||||
const qc = useQueryClient()
|
||||
const navigate = useNavigate()
|
||||
const { data: configs, isLoading } = useQuery({ queryKey: ['configs'], queryFn: configsApi.list })
|
||||
const [showCreate, setShowCreate] = useState(false)
|
||||
const [name, setName] = useState('')
|
||||
|
||||
const createMut = useMutation({
|
||||
mutationFn: () => configsApi.create(name),
|
||||
onSuccess: (res) => { qc.invalidateQueries({ queryKey: ['configs'] }); setShowCreate(false); setName(''); navigate(`/configs/${res.name}`) },
|
||||
})
|
||||
|
||||
const deleteMut = useMutation({
|
||||
mutationFn: (name: string) => configsApi.delete(name),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: ['configs'] }),
|
||||
})
|
||||
|
||||
const duplicateMut = useMutation({
|
||||
mutationFn: (name: string) => configsApi.duplicate(name, `${name}-copy`),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: ['configs'] }),
|
||||
})
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<h2 className="text-2xl font-semibold">Configs</h2>
|
||||
<button onClick={() => setShowCreate(!showCreate)} className="px-4 py-2 bg-blue-600 hover:bg-blue-500 rounded-md text-sm font-medium">+ New Config</button>
|
||||
</div>
|
||||
|
||||
{showCreate && (
|
||||
<div className="mb-6 p-4 bg-neutral-900 border border-neutral-800 rounded-lg flex gap-3">
|
||||
<input value={name} onChange={e => setName(e.target.value)} placeholder="Config name" className="bg-neutral-800 border border-neutral-700 rounded px-3 py-2 text-sm flex-1" />
|
||||
<button onClick={() => createMut.mutate()} disabled={!name || createMut.isPending} className="px-4 py-2 bg-green-700 hover:bg-green-600 disabled:opacity-50 rounded text-sm">Create</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{isLoading && <p className="text-neutral-500">Loading...</p>}
|
||||
|
||||
<div className="space-y-2">
|
||||
{configs?.map(c => (
|
||||
<div key={c.name} className="flex items-center justify-between p-4 bg-neutral-900 border border-neutral-800 rounded-lg">
|
||||
<Link to={`/configs/${c.name}`} className="font-medium hover:text-blue-400 transition-colors">{c.name}.cfg</Link>
|
||||
<div className="flex items-center gap-3 text-sm">
|
||||
<span className="text-neutral-500">{(c.size / 1024).toFixed(1)} KB</span>
|
||||
<button onClick={() => duplicateMut.mutate(c.name)} className="text-neutral-400 hover:text-white">Duplicate</button>
|
||||
<button onClick={() => deleteMut.mutate(c.name)} className="text-red-500 hover:text-red-400">Delete</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{configs?.length === 0 && <p className="text-neutral-500 text-sm">No configs yet.</p>}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
66
frontend/src/pages/Dashboard.tsx
Normal file
66
frontend/src/pages/Dashboard.tsx
Normal file
@@ -0,0 +1,66 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { settingsApi, configsApi, modlistsApi } from '../api/client'
|
||||
|
||||
export default function Dashboard() {
|
||||
const { data: settings } = useQuery({ queryKey: ['settings'], queryFn: settingsApi.get })
|
||||
const { data: status } = useQuery({ queryKey: ['server-status'], queryFn: settingsApi.status, refetchInterval: 5000 })
|
||||
const { data: configs } = useQuery({ queryKey: ['configs'], queryFn: configsApi.list })
|
||||
const { data: modlists } = useQuery({ queryKey: ['modlists'], queryFn: modlistsApi.list })
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h2 className="text-2xl font-semibold mb-6">Dashboard</h2>
|
||||
|
||||
<div className="grid grid-cols-4 gap-4 mb-8">
|
||||
<div className="bg-neutral-900 border border-neutral-800 rounded-lg p-4">
|
||||
<div className="text-sm text-neutral-500">Server</div>
|
||||
<div className={`text-xl font-bold ${status?.running ? 'text-green-400' : 'text-neutral-400'}`}>
|
||||
{status?.running ? 'Running' : 'Stopped'}
|
||||
</div>
|
||||
</div>
|
||||
<div className="bg-neutral-900 border border-neutral-800 rounded-lg p-4">
|
||||
<div className="text-sm text-neutral-500">Configs</div>
|
||||
<div className="text-xl font-bold text-blue-400">{configs?.length ?? 0}</div>
|
||||
</div>
|
||||
<div className="bg-neutral-900 border border-neutral-800 rounded-lg p-4">
|
||||
<div className="text-sm text-neutral-500">Modlists</div>
|
||||
<div className="text-xl font-bold text-blue-400">{modlists?.length ?? 0}</div>
|
||||
</div>
|
||||
<div className="bg-neutral-900 border border-neutral-800 rounded-lg p-4">
|
||||
<div className="text-sm text-neutral-500">Platform</div>
|
||||
<div className="text-xl font-bold">{settings?.platform ?? '-'}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-6">
|
||||
<div className="bg-neutral-900 border border-neutral-800 rounded-lg p-4">
|
||||
<h3 className="font-medium mb-3">Server Info</h3>
|
||||
{settings ? (
|
||||
<div className="space-y-2 text-sm">
|
||||
<Row label="IP:Port" value={settings.ip_port} />
|
||||
<Row label="Branch" value={settings.steam_branch} />
|
||||
<Row label="User" value={settings.steam_user} />
|
||||
<Row label="Active Config" value={settings.active_config || 'none'} />
|
||||
<Row label="Active Modlist" value={settings.active_modlist || 'none'} />
|
||||
</div>
|
||||
) : <p className="text-sm text-neutral-500">Loading...</p>}
|
||||
</div>
|
||||
|
||||
<div className="bg-neutral-900 border border-neutral-800 rounded-lg p-4">
|
||||
<h3 className="font-medium mb-3">Quick Actions</h3>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Link to="/settings" className="px-3 py-1.5 bg-neutral-800 hover:bg-neutral-700 rounded text-sm">Settings</Link>
|
||||
<Link to="/configs" className="px-3 py-1.5 bg-neutral-800 hover:bg-neutral-700 rounded text-sm">Configs</Link>
|
||||
<Link to="/modlists" className="px-3 py-1.5 bg-neutral-800 hover:bg-neutral-700 rounded text-sm">Modlists</Link>
|
||||
<Link to="/logs" className="px-3 py-1.5 bg-neutral-800 hover:bg-neutral-700 rounded text-sm">Logs</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function Row({ label, value }: { label: string; value: string }) {
|
||||
return <div className="flex justify-between"><span className="text-neutral-500">{label}</span><span>{value}</span></div>
|
||||
}
|
||||
83
frontend/src/pages/Logs.tsx
Normal file
83
frontend/src/pages/Logs.tsx
Normal file
@@ -0,0 +1,83 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { logsApi } from '../api/client'
|
||||
import LiveTerminal from '../components/LiveTerminal'
|
||||
import { useState } from 'react'
|
||||
|
||||
type TermTab = 'server' | 'rpt' | 'steamcmd'
|
||||
|
||||
export default function Logs() {
|
||||
const { data: logFiles } = useQuery({ queryKey: ['logs'], queryFn: logsApi.list })
|
||||
const [selectedFile, setSelectedFile] = useState<string | null>(null)
|
||||
const { data: fileContent } = useQuery({
|
||||
queryKey: ['log', selectedFile],
|
||||
queryFn: () => logsApi.get(selectedFile!),
|
||||
enabled: !!selectedFile,
|
||||
})
|
||||
const [termTab, setTermTab] = useState<TermTab>('server')
|
||||
|
||||
const wsUrl = termTab === 'server' ? logsApi.wsUrl() : termTab === 'rpt' ? logsApi.rptWsUrl() : logsApi.steamcmdWsUrl()
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="flex items-center gap-2 mb-6">
|
||||
<h2 className="text-2xl font-semibold">Live Console</h2>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-1 mb-4 border-b border-neutral-800">
|
||||
<button
|
||||
onClick={() => setTermTab('server')}
|
||||
className={`px-4 py-2 text-sm font-medium transition-colors border-b-2 ${
|
||||
termTab === 'server' ? 'border-blue-500 text-white' : 'border-transparent text-neutral-500 hover:text-neutral-300'
|
||||
}`}
|
||||
>
|
||||
Server Console
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setTermTab('rpt')}
|
||||
className={`px-4 py-2 text-sm font-medium transition-colors border-b-2 ${
|
||||
termTab === 'rpt' ? 'border-blue-500 text-white' : 'border-transparent text-neutral-500 hover:text-neutral-300'
|
||||
}`}
|
||||
>
|
||||
RPT Log
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setTermTab('steamcmd')}
|
||||
className={`px-4 py-2 text-sm font-medium transition-colors border-b-2 ${
|
||||
termTab === 'steamcmd' ? 'border-blue-500 text-white' : 'border-transparent text-neutral-500 hover:text-neutral-300'
|
||||
}`}
|
||||
>
|
||||
SteamCMD Output
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="mb-8">
|
||||
<LiveTerminal wsUrl={wsUrl} />
|
||||
</div>
|
||||
|
||||
<h3 className="text-lg font-medium mb-3">Log Files</h3>
|
||||
<div className="flex gap-4">
|
||||
<div className="w-48 space-y-1">
|
||||
{logFiles?.map(f => (
|
||||
<button
|
||||
key={f}
|
||||
onClick={() => setSelectedFile(f)}
|
||||
className={`block w-full text-left px-3 py-1.5 rounded text-sm transition-colors ${
|
||||
selectedFile === f ? 'bg-neutral-800 text-white' : 'text-neutral-400 hover:text-white hover:bg-neutral-800/50'
|
||||
}`}
|
||||
>
|
||||
{f}
|
||||
</button>
|
||||
))}
|
||||
{(!logFiles || logFiles.length === 0) && <p className="text-neutral-500 text-sm">No log files</p>}
|
||||
</div>
|
||||
<div className="flex-1">
|
||||
{fileContent ? (
|
||||
<pre className="bg-neutral-900 border border-neutral-800 rounded-lg p-4 text-sm font-mono overflow-auto max-h-96 whitespace-pre-wrap">{fileContent}</pre>
|
||||
) : (
|
||||
<p className="text-neutral-500 text-sm">Select a log file</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
175
frontend/src/pages/ModlistEditor.tsx
Normal file
175
frontend/src/pages/ModlistEditor.tsx
Normal file
@@ -0,0 +1,175 @@
|
||||
import { useParams, Link } from 'react-router-dom'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { modlistsApi, steamcmdApi, logsApi } from '../api/client'
|
||||
import { useState, useEffect } from 'react'
|
||||
import LiveTerminal from '../components/LiveTerminal'
|
||||
|
||||
interface ModEntry {
|
||||
id: string
|
||||
name: string
|
||||
enabled: boolean
|
||||
}
|
||||
|
||||
export default function ModlistEditor() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const qc = useQueryClient()
|
||||
const { data: modlist, isLoading } = useQuery({ queryKey: ['modlist', id], queryFn: () => modlistsApi.get(id!) })
|
||||
const [name, setName] = useState('')
|
||||
const [mods, setMods] = useState<ModEntry[]>([])
|
||||
const [dirty, setDirty] = useState(false)
|
||||
const [newId, setNewId] = useState('')
|
||||
const [newName, setNewName] = useState('')
|
||||
|
||||
const { data: steamcmdStatus } = useQuery({ queryKey: ['steamcmd-status'], queryFn: steamcmdApi.status, refetchInterval: 3000 })
|
||||
const steamcmdBusy = steamcmdStatus?.running ?? false
|
||||
|
||||
const { data: modStatuses } = useQuery({
|
||||
queryKey: ['modlist-check', id],
|
||||
queryFn: () => modlistsApi.checkMods(id!),
|
||||
enabled: !!id,
|
||||
refetchInterval: steamcmdBusy ? 3000 : false,
|
||||
})
|
||||
const downloadedMap = new Map(modStatuses?.map(m => [m.id, m.downloaded]) ?? [])
|
||||
|
||||
useEffect(() => {
|
||||
if (modlist) { setName(modlist.name); setMods(modlist.mods); setDirty(false) }
|
||||
}, [modlist])
|
||||
|
||||
const saveMut = useMutation({
|
||||
mutationFn: () => modlistsApi.update(id!, { name, mods }),
|
||||
onSuccess: () => { qc.invalidateQueries({ queryKey: ['modlist', id] }); qc.invalidateQueries({ queryKey: ['modlists'] }); setDirty(false) },
|
||||
})
|
||||
|
||||
const toggleMod = (index: number) => {
|
||||
setMods(prev => prev.map((m, i) => i === index ? { ...m, enabled: !m.enabled } : m))
|
||||
setDirty(true)
|
||||
}
|
||||
|
||||
const removeMod = (index: number) => {
|
||||
setMods(prev => prev.filter((_, i) => i !== index))
|
||||
setDirty(true)
|
||||
}
|
||||
|
||||
const addMod = () => {
|
||||
if (!newId.trim() || !newName.trim()) return
|
||||
setMods(prev => [...prev, { id: newId.trim(), name: newName.trim(), enabled: true }])
|
||||
setNewId(''); setNewName('')
|
||||
setDirty(true)
|
||||
}
|
||||
|
||||
const moveMod = (index: number, direction: -1 | 1) => {
|
||||
const target = index + direction
|
||||
if (target < 0 || target >= mods.length) return
|
||||
setMods(prev => {
|
||||
const next = [...prev]
|
||||
;[next[index], next[target]] = [next[target], next[index]]
|
||||
return next
|
||||
})
|
||||
setDirty(true)
|
||||
}
|
||||
|
||||
const [showSteamCMD, setShowSteamCMD] = useState(false)
|
||||
|
||||
const downloadMissingMut = useMutation({
|
||||
mutationFn: () => modlistsApi.downloadMissing(id!),
|
||||
onSuccess: () => { setShowSteamCMD(true); qc.invalidateQueries({ queryKey: ['steamcmd-status'] }) },
|
||||
})
|
||||
const updateAllMut = useMutation({
|
||||
mutationFn: () => modlistsApi.updateAll(id!),
|
||||
onSuccess: () => { setShowSteamCMD(true); qc.invalidateQueries({ queryKey: ['steamcmd-status'] }) },
|
||||
})
|
||||
|
||||
if (isLoading) return <p className="text-neutral-500">Loading...</p>
|
||||
if (!modlist) return <p className="text-red-400">Modlist not found</p>
|
||||
|
||||
const modCount = mods.length
|
||||
const missingCount = mods.filter(m => m.id && !downloadedMap.get(m.id)).length
|
||||
const hasWorkshopMods = mods.some(m => m.id)
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<div>
|
||||
<Link to="/modlists" className="text-sm text-blue-400 hover:underline">← Modlists</Link>
|
||||
<h2 className="text-2xl font-semibold mt-1">{modlist.name}</h2>
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
{hasWorkshopMods && (
|
||||
<>
|
||||
<button
|
||||
onClick={() => downloadMissingMut.mutate()}
|
||||
disabled={missingCount === 0 || steamcmdBusy || downloadMissingMut.isPending}
|
||||
className="px-3 py-1.5 bg-green-800 hover:bg-green-700 disabled:opacity-50 rounded text-sm"
|
||||
>
|
||||
{downloadMissingMut.isPending ? 'Starting...' : `Download Missing (${missingCount})`}
|
||||
</button>
|
||||
<button
|
||||
onClick={() => updateAllMut.mutate()}
|
||||
disabled={steamcmdBusy || updateAllMut.isPending}
|
||||
className="px-3 py-1.5 bg-amber-800 hover:bg-amber-700 disabled:opacity-50 rounded text-sm"
|
||||
>
|
||||
{updateAllMut.isPending ? 'Starting...' : `Update All (${modCount})`}
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
<button onClick={() => saveMut.mutate()} disabled={!dirty || saveMut.isPending} className="px-4 py-2 bg-blue-600 hover:bg-blue-500 disabled:opacity-50 rounded text-sm">
|
||||
{saveMut.isPending ? 'Saving...' : 'Save'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mb-2 text-xs text-neutral-500">
|
||||
{steamcmdBusy ? (
|
||||
<span className="text-yellow-400">SteamCMD running — status auto-refreshing</span>
|
||||
) : modStatuses && (
|
||||
<span>{downloadedMap.size} mods checked — {missingCount} missing</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="mb-4">
|
||||
<label className="text-xs text-neutral-500 block mb-1">Name</label>
|
||||
<input value={name} onChange={e => { setName(e.target.value); setDirty(true) }} className="bg-neutral-800 border border-neutral-700 rounded px-3 py-2 text-sm w-full max-w-md" />
|
||||
</div>
|
||||
|
||||
<div className="mb-6 flex gap-2">
|
||||
<input value={newId} onChange={e => setNewId(e.target.value)} placeholder="Workshop ID" className="bg-neutral-800 border border-neutral-700 rounded px-3 py-2 text-sm w-40" />
|
||||
<input value={newName} onChange={e => setNewName(e.target.value)} placeholder="Mod name" className="bg-neutral-800 border border-neutral-700 rounded px-3 py-2 text-sm flex-1 max-w-xs" />
|
||||
<button onClick={addMod} disabled={!newId.trim() || !newName.trim()} className="px-3 py-2 bg-green-700 hover:bg-green-600 disabled:opacity-50 rounded text-sm">Add</button>
|
||||
</div>
|
||||
|
||||
<div className="space-y-1">
|
||||
{mods.map((mod, i) => {
|
||||
const status = downloadedMap.get(mod.id)
|
||||
return (
|
||||
<div key={i} className="flex items-center gap-3 p-3 bg-neutral-900 border border-neutral-800 rounded-lg">
|
||||
<button onClick={() => moveMod(i, -1)} disabled={i === 0} className="text-neutral-500 hover:text-white disabled:opacity-30 text-lg leading-none">↑</button>
|
||||
<button onClick={() => moveMod(i, 1)} disabled={i === mods.length - 1} className="text-neutral-500 hover:text-white disabled:opacity-30 text-lg leading-none">↓</button>
|
||||
<input type="checkbox" checked={mod.enabled} onChange={() => toggleMod(i)} className="accent-blue-500" />
|
||||
<div className="flex-1 flex items-center gap-2">
|
||||
<span className={`text-sm ${mod.enabled ? 'text-white' : 'text-neutral-500'}`}>{mod.name}</span>
|
||||
<span className="text-xs text-neutral-600">({mod.id})</span>
|
||||
</div>
|
||||
{mod.id && status !== undefined && (
|
||||
status
|
||||
? <span className="text-green-500 text-xs font-medium" title="Downloaded">✓</span>
|
||||
: <span className="text-red-500 text-xs font-medium" title="Not downloaded">✗</span>
|
||||
)}
|
||||
<button onClick={() => removeMod(i)} className="text-red-500 hover:text-red-400 text-sm">Remove</button>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
{mods.length === 0 && <p className="text-neutral-500 text-sm py-4">No mods. Add one using the form above.</p>}
|
||||
</div>
|
||||
|
||||
{showSteamCMD && (
|
||||
<div className="mt-6">
|
||||
<div className="flex items-center justify-between mb-2">
|
||||
<h4 className="text-sm font-medium text-neutral-400">SteamCMD Output</h4>
|
||||
<button onClick={() => setShowSteamCMD(false)} className="text-xs text-neutral-600 hover:text-neutral-400">Close</button>
|
||||
</div>
|
||||
<LiveTerminal wsUrl={logsApi.steamcmdWsUrl()} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
80
frontend/src/pages/Modlists.tsx
Normal file
80
frontend/src/pages/Modlists.tsx
Normal file
@@ -0,0 +1,80 @@
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { modlistsApi } from '../api/client'
|
||||
import { Link, useNavigate } from 'react-router-dom'
|
||||
import { useRef, useState } from 'react'
|
||||
|
||||
export default function Modlists() {
|
||||
const qc = useQueryClient()
|
||||
const navigate = useNavigate()
|
||||
const fileRef = useRef<HTMLInputElement>(null)
|
||||
const { data: modlists, isLoading } = useQuery({ queryKey: ['modlists'], queryFn: modlistsApi.list })
|
||||
const [showCreate, setShowCreate] = useState(false)
|
||||
const [name, setName] = useState('')
|
||||
|
||||
const createMut = useMutation({
|
||||
mutationFn: () => modlistsApi.create(name),
|
||||
onSuccess: (res) => { qc.invalidateQueries({ queryKey: ['modlists'] }); setShowCreate(false); setName(''); navigate(`/modlists/${res.id}`) },
|
||||
})
|
||||
|
||||
const deleteMut = useMutation({
|
||||
mutationFn: (id: string) => modlistsApi.delete(id),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: ['modlists'] }),
|
||||
})
|
||||
|
||||
const duplicateMut = useMutation({
|
||||
mutationFn: (id: string) => {
|
||||
const orig = modlists?.find(m => m.id === id)
|
||||
return modlistsApi.duplicate(id, `${orig?.name ?? 'copy'} (copy)`)
|
||||
},
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: ['modlists'] }),
|
||||
})
|
||||
|
||||
const importMut = useMutation({
|
||||
mutationFn: (file: File) => modlistsApi.importHtml(file),
|
||||
onSuccess: (res) => { qc.invalidateQueries({ queryKey: ['modlists'] }); navigate(`/modlists/${res.id}`) },
|
||||
})
|
||||
|
||||
const handleImport = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0]
|
||||
if (file) importMut.mutate(file)
|
||||
e.target.value = ''
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<input ref={fileRef} type="file" accept=".html" onChange={handleImport} className="hidden" />
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<h2 className="text-2xl font-semibold">Modlists</h2>
|
||||
<div className="flex gap-2">
|
||||
<button onClick={() => fileRef.current?.click()} disabled={importMut.isPending} className="px-4 py-2 bg-amber-700 hover:bg-amber-600 disabled:opacity-50 rounded-md text-sm font-medium">Import HTML</button>
|
||||
<button onClick={() => setShowCreate(!showCreate)} className="px-4 py-2 bg-blue-600 hover:bg-blue-500 rounded-md text-sm font-medium">+ New Modlist</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{showCreate && (
|
||||
<div className="mb-6 p-4 bg-neutral-900 border border-neutral-800 rounded-lg flex gap-3">
|
||||
<input value={name} onChange={e => setName(e.target.value)} placeholder="Modlist name" className="bg-neutral-800 border border-neutral-700 rounded px-3 py-2 text-sm flex-1" />
|
||||
<button onClick={() => createMut.mutate()} disabled={!name || createMut.isPending} className="px-4 py-2 bg-green-700 hover:bg-green-600 disabled:opacity-50 rounded text-sm">Create</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{isLoading && <p className="text-neutral-500">Loading...</p>}
|
||||
|
||||
<div className="space-y-2">
|
||||
{modlists?.map(m => (
|
||||
<div key={m.id} className="flex items-center justify-between p-4 bg-neutral-900 border border-neutral-800 rounded-lg">
|
||||
<div>
|
||||
<Link to={`/modlists/${m.id}`} className="font-medium hover:text-blue-400 transition-colors">{m.name}</Link>
|
||||
<span className="text-xs text-neutral-500 ml-2">{m.mod_count} mods</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-3 text-sm">
|
||||
<button onClick={() => duplicateMut.mutate(m.id)} className="text-neutral-400 hover:text-white">Duplicate</button>
|
||||
<button onClick={() => deleteMut.mutate(m.id)} className="text-red-500 hover:text-red-400">Delete</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{modlists?.length === 0 && <p className="text-neutral-500 text-sm">No modlists yet.</p>}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
247
frontend/src/pages/Settings.tsx
Normal file
247
frontend/src/pages/Settings.tsx
Normal file
@@ -0,0 +1,247 @@
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { settingsApi, configsApi, modlistsApi, steamcmdApi, logsApi } from '../api/client'
|
||||
import { useState, useEffect } from 'react'
|
||||
import ConfigEditor from '../components/ConfigEditor'
|
||||
import LiveTerminal from '../components/LiveTerminal'
|
||||
|
||||
type Tab = 'main' | 'cba' | 'ai' | 'difficulty'
|
||||
|
||||
export default function Settings() {
|
||||
const qc = useQueryClient()
|
||||
const { data: settings, isLoading } = useQuery({ queryKey: ['settings'], queryFn: settingsApi.get })
|
||||
const { data: configs } = useQuery({ queryKey: ['configs'], queryFn: configsApi.list })
|
||||
const { data: modlists } = useQuery({ queryKey: ['modlists'], queryFn: modlistsApi.list })
|
||||
const { data: paths } = useQuery({ queryKey: ['paths'], queryFn: settingsApi.paths })
|
||||
const { data: status } = useQuery({ queryKey: ['server-status'], queryFn: settingsApi.status, refetchInterval: 3000 })
|
||||
const [tab, setTab] = useState<Tab>('main')
|
||||
const [dirty, setDirty] = useState(false)
|
||||
|
||||
const [ipPort, setIpPort] = useState('')
|
||||
const [params, setParams] = useState('')
|
||||
const [branch, setBranch] = useState('stable')
|
||||
const [user, setUser] = useState('anonymous')
|
||||
const [platform, setPlatform] = useState<'linux' | 'windows'>('linux')
|
||||
const [cba, setCba] = useState('')
|
||||
const [aiLevel, setAiLevel] = useState('')
|
||||
const [difficulty, setDifficulty] = useState('')
|
||||
const [activeConfig, setActiveConfig] = useState('')
|
||||
const [activeModlist, setActiveModlist] = useState('')
|
||||
|
||||
useEffect(() => {
|
||||
if (settings) {
|
||||
setIpPort(settings.ip_port)
|
||||
setParams(settings.server_parameters)
|
||||
setBranch(settings.steam_branch)
|
||||
setUser(settings.steam_user)
|
||||
setPlatform(settings.platform)
|
||||
setCba(settings.cba_settings)
|
||||
setAiLevel(settings.ai_level_presets)
|
||||
setDifficulty(settings.difficulty_presets)
|
||||
setActiveConfig(settings.active_config)
|
||||
setActiveModlist(settings.active_modlist)
|
||||
}
|
||||
}, [settings])
|
||||
|
||||
const saveMut = useMutation({
|
||||
mutationFn: () => settingsApi.update({
|
||||
ip_port: ipPort,
|
||||
server_parameters: params,
|
||||
steam_branch: branch,
|
||||
steam_user: user,
|
||||
platform,
|
||||
cba_settings: cba,
|
||||
ai_level_presets: aiLevel,
|
||||
difficulty_presets: difficulty,
|
||||
active_config: activeConfig,
|
||||
active_modlist: activeModlist,
|
||||
}),
|
||||
onSuccess: () => { qc.invalidateQueries({ queryKey: ['settings'] }); setDirty(false) },
|
||||
})
|
||||
|
||||
const startMut = useMutation({ mutationFn: settingsApi.start, onSuccess: () => qc.invalidateQueries({ queryKey: ['server-status'] }) })
|
||||
const stopMut = useMutation({ mutationFn: settingsApi.stop, onSuccess: () => qc.invalidateQueries({ queryKey: ['server-status'] }) })
|
||||
const restartMut = useMutation({ mutationFn: settingsApi.restart, onSuccess: () => qc.invalidateQueries({ queryKey: ['server-status'] }) })
|
||||
|
||||
const [modId, setModId] = useState('')
|
||||
const [showSteamCMD, setShowSteamCMD] = useState(false)
|
||||
const { data: steamcmdStatus } = useQuery({ queryKey: ['steamcmd-status'], queryFn: steamcmdApi.status, refetchInterval: 3000 })
|
||||
|
||||
const updateGameMut = useMutation({
|
||||
mutationFn: () => steamcmdApi.updateGame(branch, user),
|
||||
onSuccess: () => { setShowSteamCMD(true); qc.invalidateQueries({ queryKey: ['steamcmd-status'] }) },
|
||||
})
|
||||
const downloadModMut = useMutation({
|
||||
mutationFn: () => steamcmdApi.downloadMod(modId),
|
||||
onSuccess: () => { setShowSteamCMD(true); qc.invalidateQueries({ queryKey: ['steamcmd-status'] }) },
|
||||
})
|
||||
|
||||
const handleSaveThen = async (action: () => Promise<unknown>) => {
|
||||
if (dirty) {
|
||||
await saveMut.mutateAsync()
|
||||
}
|
||||
await action()
|
||||
}
|
||||
|
||||
if (isLoading) return <p className="text-neutral-500">Loading...</p>
|
||||
|
||||
const tabs: { key: Tab; label: string; note?: string }[] = [
|
||||
{ key: 'main', label: 'Main' },
|
||||
{ key: 'cba', label: 'CBA Settings', note: 'userconfig/cba_settings.sqf' },
|
||||
{ key: 'ai', label: 'AI Level Presets', note: 'userconfig/CfgAILevelPresets.sqf' },
|
||||
{ key: 'difficulty', label: 'Difficulty Presets', note: 'userconfig/CfgDifficultyPresets.sqf' },
|
||||
]
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<h2 className="text-2xl font-semibold">Server Settings</h2>
|
||||
<div className="flex gap-2 items-center">
|
||||
<span className={`text-sm px-2 py-0.5 rounded ${status?.running ? 'bg-green-900 text-green-300' : 'bg-neutral-800 text-neutral-400'}`}>
|
||||
{status?.running ? 'Running' : 'Stopped'}
|
||||
</span>
|
||||
<button onClick={() => handleSaveThen(() => startMut.mutateAsync())} disabled={status?.running || saveMut.isPending} className="px-3 py-1.5 bg-green-700 hover:bg-green-600 disabled:opacity-50 rounded text-sm">Start</button>
|
||||
<button onClick={() => handleSaveThen(() => stopMut.mutateAsync())} disabled={!status?.running || saveMut.isPending} className="px-3 py-1.5 bg-red-700 hover:bg-red-600 disabled:opacity-50 rounded text-sm">Stop</button>
|
||||
<button onClick={() => handleSaveThen(() => restartMut.mutateAsync())} disabled={!status?.running || saveMut.isPending} className="px-3 py-1.5 bg-yellow-700 hover:bg-yellow-600 disabled:opacity-50 rounded text-sm">Restart</button>
|
||||
<button onClick={() => saveMut.mutate()} disabled={!dirty || saveMut.isPending} className="px-3 py-1.5 bg-blue-600 hover:bg-blue-500 disabled:opacity-50 rounded text-sm">
|
||||
{saveMut.isPending ? 'Saving...' : 'Save'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-1 mb-4 border-b border-neutral-800">
|
||||
{tabs.map(t => (
|
||||
<button
|
||||
key={t.key}
|
||||
onClick={() => setTab(t.key)}
|
||||
className={`px-4 py-2 text-sm font-medium transition-colors border-b-2 ${
|
||||
tab === t.key ? 'border-blue-500 text-white' : 'border-transparent text-neutral-500 hover:text-neutral-300'
|
||||
}`}
|
||||
>
|
||||
{t.label}
|
||||
{t.note && <span className="ml-1.5 text-[10px] opacity-60">{t.note}</span>}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{tab === 'main' ? (
|
||||
<div className="space-y-4 max-w-2xl">
|
||||
<div>
|
||||
<label className="text-xs text-neutral-500 block mb-1">IP:Port</label>
|
||||
<input value={ipPort} onChange={e => { setIpPort(e.target.value); setDirty(true) }} className="w-full bg-neutral-800 border border-neutral-700 rounded px-3 py-2 text-sm" />
|
||||
</div>
|
||||
<div>
|
||||
<label className="text-xs text-neutral-500 block mb-1">Server Parameters</label>
|
||||
<textarea value={params} onChange={e => { setParams(e.target.value); setDirty(true) }} rows={4} className="w-full bg-neutral-800 border border-neutral-700 rounded px-3 py-2 text-sm font-mono resize-none" />
|
||||
</div>
|
||||
<div className="grid grid-cols-3 gap-4">
|
||||
<div>
|
||||
<label className="text-xs text-neutral-500 block mb-1">Steam Branch</label>
|
||||
<select value={branch} onChange={e => { setBranch(e.target.value); setDirty(true) }} className="w-full bg-neutral-800 border border-neutral-700 rounded px-3 py-2 text-sm">
|
||||
<option value="stable">Stable</option>
|
||||
<option value="experimental">Experimental</option>
|
||||
<option value="creatordlc">Creator DLC</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="text-xs text-neutral-500 block mb-1">Steam User</label>
|
||||
<input value={user} onChange={e => { setUser(e.target.value); setDirty(true) }} className="w-full bg-neutral-800 border border-neutral-700 rounded px-3 py-2 text-sm" />
|
||||
</div>
|
||||
<div>
|
||||
<label className="text-xs text-neutral-500 block mb-1">Platform</label>
|
||||
<select value={platform} onChange={e => { setPlatform(e.target.value as 'linux' | 'windows'); setDirty(true) }} className="w-full bg-neutral-800 border border-neutral-700 rounded px-3 py-2 text-sm">
|
||||
<option value="linux">Linux</option>
|
||||
<option value="windows">Windows</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="text-xs text-neutral-500 block mb-1">Active Config</label>
|
||||
<select value={activeConfig} onChange={e => { setActiveConfig(e.target.value); setDirty(true) }} className="w-full bg-neutral-800 border border-neutral-700 rounded px-3 py-2 text-sm">
|
||||
<option value="">None</option>
|
||||
{configs?.map(c => <option key={c.name} value={c.name}>{c.name}</option>)}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="text-xs text-neutral-500 block mb-1">Active Modlist</label>
|
||||
<select value={activeModlist} onChange={e => { setActiveModlist(e.target.value); setDirty(true) }} className="w-full bg-neutral-800 border border-neutral-700 rounded px-3 py-2 text-sm">
|
||||
<option value="">None</option>
|
||||
{modlists?.map(m => <option key={m.id} value={m.id}>{m.name}</option>)}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<details className="text-xs text-neutral-400">
|
||||
<summary className="cursor-pointer hover:text-neutral-200 mb-2">Server Paths</summary>
|
||||
<div className="space-y-1 bg-neutral-900 rounded p-3 border border-neutral-800 font-mono">
|
||||
<div>SERVERFILE_DIR: {paths?.serverfile_dir}</div>
|
||||
<div>MODS_DIR: {paths?.mods_dir}</div>
|
||||
<div>CFG_DIR: {paths?.cfg_dir}</div>
|
||||
<div>PROFILES_DIR: {paths?.profiles_dir}</div>
|
||||
</div>
|
||||
</details>
|
||||
|
||||
<hr className="border-neutral-800 my-6" />
|
||||
|
||||
<div>
|
||||
<h3 className="text-lg font-medium mb-3">SteamCMD</h3>
|
||||
<div className="flex gap-3 items-end">
|
||||
<div className="flex-1">
|
||||
<label className="text-xs text-neutral-500 block mb-1">Update Arma 3 Server</label>
|
||||
<button
|
||||
onClick={() => updateGameMut.mutate()}
|
||||
disabled={steamcmdStatus?.running || updateGameMut.isPending}
|
||||
className="px-4 py-2 bg-amber-700 hover:bg-amber-600 disabled:opacity-50 rounded text-sm"
|
||||
>
|
||||
{updateGameMut.isPending ? 'Starting...' : 'Update Server'}
|
||||
</button>
|
||||
</div>
|
||||
<div className="flex-1">
|
||||
<label className="text-xs text-neutral-500 block mb-1">Download Workshop Mod</label>
|
||||
<div className="flex gap-2">
|
||||
<input
|
||||
value={modId}
|
||||
onChange={e => setModId(e.target.value)}
|
||||
placeholder="Workshop mod ID"
|
||||
className="flex-1 bg-neutral-800 border border-neutral-700 rounded px-3 py-2 text-sm font-mono"
|
||||
/>
|
||||
<button
|
||||
onClick={() => downloadModMut.mutate()}
|
||||
disabled={!modId || steamcmdStatus?.running || downloadModMut.isPending}
|
||||
className="px-4 py-2 bg-amber-700 hover:bg-amber-600 disabled:opacity-50 rounded text-sm"
|
||||
>
|
||||
Download
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<span className={`inline-block mt-2 text-xs ${steamcmdStatus?.running ? 'text-yellow-400' : 'text-neutral-500'}`}>
|
||||
SteamCMD: {steamcmdStatus?.running ? 'Running' : 'Idle'}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{showSteamCMD && (
|
||||
<div className="mt-4">
|
||||
<div className="flex items-center justify-between mb-2">
|
||||
<h4 className="text-sm font-medium text-neutral-400">SteamCMD Output</h4>
|
||||
<button onClick={() => setShowSteamCMD(false)} className="text-xs text-neutral-600 hover:text-neutral-400">Close</button>
|
||||
</div>
|
||||
<LiveTerminal wsUrl={logsApi.steamcmdWsUrl()} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<ConfigEditor
|
||||
value={tab === 'cba' ? cba : tab === 'ai' ? aiLevel : difficulty}
|
||||
onChange={v => {
|
||||
if (tab === 'cba') setCba(v)
|
||||
else if (tab === 'ai') setAiLevel(v)
|
||||
else setDifficulty(v)
|
||||
setDirty(true)
|
||||
}}
|
||||
language="plaintext"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
47
frontend/src/types/index.ts
Normal file
47
frontend/src/types/index.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
export interface ServerSettings {
|
||||
ip_port: string
|
||||
server_parameters: string
|
||||
steam_branch: string
|
||||
steam_user: string
|
||||
platform: 'linux' | 'windows'
|
||||
cba_settings: string
|
||||
ai_level_presets: string
|
||||
difficulty_presets: string
|
||||
active_config: string
|
||||
active_modlist: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export interface ModEntry {
|
||||
id: string
|
||||
name: string
|
||||
enabled: boolean
|
||||
}
|
||||
|
||||
export interface Modlist {
|
||||
id: string
|
||||
name: string
|
||||
mods: ModEntry[]
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export interface ModlistListItem {
|
||||
id: string
|
||||
name: string
|
||||
mod_count: number
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export interface ConfigInfo {
|
||||
name: string
|
||||
size: number
|
||||
}
|
||||
|
||||
export interface ServerPaths {
|
||||
serverfile_dir: string
|
||||
mods_dir: string
|
||||
cfg_dir: string
|
||||
profiles_dir: string
|
||||
}
|
||||
26
frontend/tsconfig.app.json
Normal file
26
frontend/tsconfig.app.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||
"target": "es2023",
|
||||
"lib": ["ES2023", "DOM"],
|
||||
"module": "esnext",
|
||||
"types": ["vite/client"],
|
||||
"allowArbitraryExtensions": true,
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
|
||||
/* Linting */
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
7
frontend/tsconfig.json
Normal file
7
frontend/tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"files": [],
|
||||
"references": [
|
||||
{ "path": "./tsconfig.app.json" },
|
||||
{ "path": "./tsconfig.node.json" }
|
||||
]
|
||||
}
|
||||
23
frontend/tsconfig.node.json
Normal file
23
frontend/tsconfig.node.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||
"target": "es2023",
|
||||
"lib": ["ES2023"],
|
||||
"types": ["node"],
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"module": "nodenext",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
|
||||
/* Linting */
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
||||
16
frontend/vite.config.ts
Normal file
16
frontend/vite.config.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
import tailwindcss from '@tailwindcss/vite'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react(), tailwindcss()],
|
||||
server: {
|
||||
proxy: {
|
||||
'/api': 'http://localhost:8080',
|
||||
'/ws': {
|
||||
target: 'ws://localhost:8080',
|
||||
ws: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user