feat: implement phases 3-5 of Arma 3 UX enhancement plan
Phase 3 - Mod display names + split-pane selector:
- Parse mod.cpp/meta.cpp for display_name and workshop_id
- Rewrite ModList as two-pane available/selected interface
Phase 4 - Player kick/ban from Players tab:
- Add get_by_slot() to PlayerRepository
- Add get_rcon_client() class method to ThreadRegistry
- Add /players/{slot_id}/kick and /ban endpoints
- Rewrite PlayerTable with kick/ban modals and ban presets
Phase 5 - Historical log file browser:
- Add list_log_files() and get_log_file_path() to RPTParser
- Add logfiles_router with GET/download/DELETE endpoints
- Update LogViewer with collapsible log files section (download + delete)
This commit is contained in:
@@ -62,6 +62,36 @@ class RPTParser:
|
||||
"message": (message or "").strip(),
|
||||
}
|
||||
|
||||
def list_log_files(self, server_dir: Path) -> list[dict]:
|
||||
"""Return all .rpt log files in server_dir/server/, newest first."""
|
||||
profile_dir = server_dir / "server"
|
||||
if not profile_dir.exists():
|
||||
return []
|
||||
files = []
|
||||
for p in profile_dir.glob("*.rpt"):
|
||||
try:
|
||||
stat = p.stat()
|
||||
files.append({
|
||||
"filename": p.name,
|
||||
"size_bytes": stat.st_size,
|
||||
"modified_at": stat.st_mtime,
|
||||
})
|
||||
except OSError:
|
||||
pass
|
||||
files.sort(key=lambda f: f["modified_at"], reverse=True)
|
||||
return files
|
||||
|
||||
def get_log_file_path(self, server_dir: Path, filename: str) -> Path | None:
|
||||
"""Return the Path for a specific log file, or None if not found / path traversal attempt."""
|
||||
import os
|
||||
profile_dir = server_dir / "server"
|
||||
target = (profile_dir / filename).resolve()
|
||||
if not str(target).startswith(str(profile_dir.resolve())):
|
||||
return None
|
||||
if not target.exists() or target.suffix != ".rpt":
|
||||
return None
|
||||
return target
|
||||
|
||||
def get_log_file_resolver(self, server_id: int) -> Callable[[Path], Path | None]:
|
||||
"""Return a callable that finds the current RPT log file."""
|
||||
def resolver(server_dir: Path) -> Path | None:
|
||||
|
||||
@@ -15,6 +15,24 @@ logger = logging.getLogger(__name__)
|
||||
_MOD_DIR_PATTERN = re.compile(r"^@.+", re.IGNORECASE)
|
||||
|
||||
|
||||
def _parse_mod_cpp(mod_dir: Path) -> str | None:
|
||||
mod_cpp = mod_dir / "mod.cpp"
|
||||
if not mod_cpp.exists():
|
||||
return None
|
||||
text = mod_cpp.read_text(errors="ignore")
|
||||
m = re.search(r'name\s*=\s*"([^"]+)"', text, re.IGNORECASE)
|
||||
return m.group(1) if m else None
|
||||
|
||||
|
||||
def _parse_meta_cpp(mod_dir: Path) -> str | None:
|
||||
meta_cpp = mod_dir / "meta.cpp"
|
||||
if not meta_cpp.exists():
|
||||
return None
|
||||
text = meta_cpp.read_text(errors="ignore")
|
||||
m = re.search(r'publishedid\s*=\s*(\d+)', text, re.IGNORECASE)
|
||||
return m.group(1) if m else None
|
||||
|
||||
|
||||
class Arma3ModData(BaseModel):
|
||||
"""Mod data schema for Arma 3."""
|
||||
workshop_id: str = ""
|
||||
@@ -60,6 +78,8 @@ class Arma3ModManager:
|
||||
"name": entry.name,
|
||||
"path": str(entry.resolve()),
|
||||
"size_bytes": size,
|
||||
"display_name": _parse_mod_cpp(entry),
|
||||
"workshop_id": _parse_meta_cpp(entry),
|
||||
})
|
||||
except OSError as exc:
|
||||
raise AdapterError(f"Cannot scan mod directory: {exc}") from exc
|
||||
|
||||
Reference in New Issue
Block a user