Compare commits
13 Commits
feature/ac
...
v0.13.0
| Author | SHA1 | Date | |
|---|---|---|---|
| efc6b72838 | |||
| 0e04da031b | |||
| 908adf4468 | |||
| 6c1e9b236e | |||
| f563d52396 | |||
| a490a73392 | |||
| 0ef47ef241 | |||
| ea2e871c9b | |||
| c2c6543068 | |||
| a6f67dd652 | |||
| e637b5e649 | |||
| 1100072245 | |||
| 49dfa38475 |
@@ -1,78 +1,26 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Use a display number derived from the server port to avoid conflicts
|
||||
# between containers (each server gets its own unique display).
|
||||
DISPLAY_NUM=$((SERVER_PORT % 1000 + 100))
|
||||
export DISPLAY=:${DISPLAY_NUM}
|
||||
|
||||
# Clean up any stale X lock from a previous container run.
|
||||
rm -f /tmp/.X${DISPLAY_NUM}-lock /tmp/.X11-unix/X${DISPLAY_NUM} 2>/dev/null || true
|
||||
|
||||
Xvfb ${DISPLAY} -screen 0 1024x768x16 -nolisten tcp &
|
||||
XVFB_PID=$!
|
||||
|
||||
TCPDUMP_PID=""
|
||||
|
||||
cleanup() {
|
||||
echo "Stopping ACC server..."
|
||||
[ -n "${TCPDUMP_PID}" ] && kill "${TCPDUMP_PID}" 2>/dev/null || true
|
||||
kill "${XVFB_PID}" 2>/dev/null || true
|
||||
kill $XVFB_PID 2>/dev/null || true
|
||||
}
|
||||
trap cleanup SIGTERM SIGINT EXIT
|
||||
|
||||
# Initialize Wine prefix (no-op if already done)
|
||||
wineboot -u 2>/dev/null
|
||||
trap cleanup SIGTERM SIGINT
|
||||
|
||||
mkdir -p /acc/game/log
|
||||
|
||||
# ─── Debug mode ───────────────────────────────────────────────────────────────
|
||||
# Set DEBUG_MODE=1 on the container to enable extra diagnostics:
|
||||
#
|
||||
# docker run -e DEBUG_MODE=1 ...
|
||||
# or in docker-compose:
|
||||
# environment:
|
||||
# DEBUG_MODE: "1"
|
||||
#
|
||||
# Produces:
|
||||
# /acc/game/log/tcpdump_<port>.pcap — raw packet capture (open in Wireshark)
|
||||
# /acc/game/log/wine_debug.log — Wine debug output
|
||||
# Stderr: Wine version, WINEDEBUG channel, prefix state
|
||||
#
|
||||
# You can also override which Wine debug channels are enabled:
|
||||
# WINEDEBUG_CHANNELS="+loaddll,+seh,+relay" (relay is very verbose)
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
if [ "${DEBUG_MODE:-0}" = "1" ]; then
|
||||
echo "[debug] Debug mode enabled for port ${SERVER_PORT}"
|
||||
echo "[debug] Wine: $(wine --version 2>/dev/null || echo unknown)"
|
||||
echo "[debug] WINEPREFIX: ${WINEPREFIX}"
|
||||
echo "Starting ACC server on port ${SERVER_PORT}..."
|
||||
|
||||
# Configure Wine debug channels (default: loader + exception + module info)
|
||||
export WINEDEBUG="${WINEDEBUG_CHANNELS:-+loaddll,+module,+seh,+ntdll}"
|
||||
echo "[debug] WINEDEBUG=${WINEDEBUG}"
|
||||
|
||||
# Start packet capture on the server port — captures both TCP and UDP.
|
||||
# The pcap file records every byte Kunos sends/receives so you can inspect
|
||||
# the 2-byte "pakSizeMax" packet and anything that follows.
|
||||
#
|
||||
# NOTE: requires CAP_NET_RAW capability on the container:
|
||||
# docker-compose: cap_add: [NET_RAW]
|
||||
# docker run: --cap-add=NET_RAW
|
||||
# Without it tcpdump will be skipped (no crash, just no capture).
|
||||
CAPTURE_FILE="/acc/game/log/tcpdump_${SERVER_PORT}.pcap"
|
||||
echo "[debug] Starting packet capture → ${CAPTURE_FILE}"
|
||||
echo "[debug] (requires cap_add: [NET_RAW] in docker-compose — will exit silently if missing)"
|
||||
tcpdump -i any -nn -s 0 -w "${CAPTURE_FILE}" \
|
||||
"port ${SERVER_PORT}" 2>/acc/game/log/tcpdump.err &
|
||||
TCPDUMP_PID=$!
|
||||
|
||||
# Redirect Wine debug output to a log file (Wine writes to stderr).
|
||||
WINE_LOG="/acc/game/log/wine_debug.log"
|
||||
echo "[debug] Wine debug log → ${WINE_LOG}"
|
||||
echo "Starting ACC server on port ${SERVER_PORT} (DEBUG)..."
|
||||
cd /acc/game
|
||||
exec wine /acc/game/accServer.exe 2>"${WINE_LOG}"
|
||||
else
|
||||
# Production: suppress all Wine debug output.
|
||||
export WINEDEBUG=-all
|
||||
echo "Starting ACC server on port ${SERVER_PORT}..."
|
||||
cd /acc/game
|
||||
exec wine /acc/game/accServer.exe
|
||||
fi
|
||||
cd /acc/game
|
||||
exec wine /acc/game/accServer.exe
|
||||
|
||||
@@ -36,6 +36,7 @@ func Init(di *dig.Container, app *fiber.App) {
|
||||
Steam: groups.Group("/steam"),
|
||||
ActivityLog: serverIdGroup.Group("/activity-log"),
|
||||
Groups: groups,
|
||||
Log: serverIdGroup.Group("/log"),
|
||||
}
|
||||
|
||||
accessKeyMiddleware := middleware.NewAccessKeyMiddleware()
|
||||
|
||||
@@ -21,36 +21,12 @@ func NewActivityLogController(as *service.ActivityLogService, routeGroups *commo
|
||||
errorHandler: error_handler.NewControllerErrorHandler(),
|
||||
}
|
||||
|
||||
// Per-server activity log: GET /server/:id/activity-log
|
||||
routeGroups.ActivityLog.Use(auth.Authenticate)
|
||||
routeGroups.ActivityLog.Get("/", ac.GetServerLogs)
|
||||
|
||||
// Global activity log: GET /activity-log (admin use)
|
||||
routeGroups.Groups.Group("/activity-log").Use(auth.Authenticate).Get("/", ac.GetAllLogs)
|
||||
|
||||
return ac
|
||||
}
|
||||
|
||||
// GetServerLogs returns activity logs for a specific server.
|
||||
//
|
||||
// @Summary Return activity logs for a server
|
||||
// @Tags ActivityLog
|
||||
// @Success 200 {array} model.ActivityLog
|
||||
// @Router /server/{id}/activity-log [get]
|
||||
func (ac *ActivityLogController) GetServerLogs(c *fiber.Ctx) error {
|
||||
var filter model.ActivityLogFilter
|
||||
if err := common.ParseQueryFilter(c, &filter); err != nil {
|
||||
return ac.errorHandler.HandleValidationError(c, err, "query_filter")
|
||||
}
|
||||
|
||||
result, err := ac.service.GetAll(c.UserContext(), &filter)
|
||||
if err != nil {
|
||||
return ac.errorHandler.HandleServiceError(c, err)
|
||||
}
|
||||
|
||||
return c.JSON(result)
|
||||
}
|
||||
|
||||
// GetAllLogs returns activity logs across all servers (admin).
|
||||
//
|
||||
// @Summary Return all activity logs
|
||||
|
||||
@@ -74,4 +74,9 @@ func InitializeControllers(c *dig.Container) {
|
||||
if err != nil {
|
||||
logging.Panic("unable to initialize activity log controller")
|
||||
}
|
||||
|
||||
err = c.Invoke(NewLogController)
|
||||
if err != nil {
|
||||
logging.Panic("unable to initialize log controller")
|
||||
}
|
||||
}
|
||||
|
||||
62
local/controller/log.go
Normal file
62
local/controller/log.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"acc-server-manager/local/middleware"
|
||||
"acc-server-manager/local/model"
|
||||
"acc-server-manager/local/service"
|
||||
"acc-server-manager/local/utl/common"
|
||||
"acc-server-manager/local/utl/error_handler"
|
||||
"strconv"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type LogController struct {
|
||||
service *service.ServerService
|
||||
errorHandler *error_handler.ControllerErrorHandler
|
||||
}
|
||||
|
||||
func NewLogController(ss *service.ServerService, routeGroups *common.RouteGroups, auth *middleware.AuthMiddleware) *LogController {
|
||||
lc := &LogController{
|
||||
service: ss,
|
||||
errorHandler: error_handler.NewControllerErrorHandler(),
|
||||
}
|
||||
|
||||
logRoutes := routeGroups.Log
|
||||
logRoutes.Use(auth.Authenticate)
|
||||
logRoutes.Get("/", auth.HasPermission(model.ServerView), lc.GetLogLines)
|
||||
|
||||
return lc
|
||||
}
|
||||
|
||||
// GetLogLines godoc
|
||||
// @Summary Get last N lines of server log
|
||||
// @Tags Server
|
||||
// @Param id path string true "Server ID"
|
||||
// @Param lines query int false "Number of lines to return (default 100)"
|
||||
// @Success 200 {object} object{lines=[]string}
|
||||
// @Security BearerAuth
|
||||
// @Router /server/{id}/log [get]
|
||||
func (lc *LogController) GetLogLines(c *fiber.Ctx) error {
|
||||
serverIDStr := c.Params("id")
|
||||
serverID, err := uuid.Parse(serverIDStr)
|
||||
if err != nil {
|
||||
return lc.errorHandler.HandleUUIDError(c, "server ID")
|
||||
}
|
||||
|
||||
n, _ := strconv.Atoi(c.Query("lines", "100"))
|
||||
if n <= 0 {
|
||||
n = 100
|
||||
}
|
||||
if n > 10000 {
|
||||
n = 10000
|
||||
}
|
||||
|
||||
lines, err := lc.service.GetLastLogLines(c, serverID, n)
|
||||
if err != nil {
|
||||
return lc.errorHandler.HandleServiceError(c, err)
|
||||
}
|
||||
|
||||
return c.JSON(fiber.Map{"lines": lines})
|
||||
}
|
||||
@@ -29,6 +29,7 @@ func NewServiceControlController(as *service.ServiceControlService, routeGroups
|
||||
}
|
||||
|
||||
serviceRoutes := routeGroups.Server.Group("/:id/service")
|
||||
serviceRoutes.Use(auth.Authenticate)
|
||||
serviceRoutes.Get("/:service", ac.getStatus)
|
||||
serviceRoutes.Post("/start", ac.startServer)
|
||||
serviceRoutes.Post("/stop", ac.stopServer)
|
||||
|
||||
@@ -20,6 +20,7 @@ const (
|
||||
type ActivityLog struct {
|
||||
ID uuid.UUID `json:"id" gorm:"type:uuid;primary_key;"`
|
||||
ServerID uuid.UUID `json:"serverId" gorm:"not null;type:uuid;index"`
|
||||
Server *Server `json:"server,omitempty" gorm:"foreignKey:ServerID"`
|
||||
UserID string `json:"userId" gorm:"not null"`
|
||||
Username string `json:"username" gorm:"not null"`
|
||||
Action ActionType `json:"action" gorm:"not null"`
|
||||
@@ -39,10 +40,10 @@ func (a *ActivityLog) BeforeCreate(tx *gorm.DB) error {
|
||||
|
||||
type ActivityLogFilter struct {
|
||||
BaseFilter
|
||||
ServerBasedFilter
|
||||
DateRangeFilter
|
||||
UserID string `query:"user_id"`
|
||||
Action ActionType `query:"action"`
|
||||
UserID string `query:"user_id"`
|
||||
Action ActionType `query:"action"`
|
||||
ServerID string `query:"server_id"`
|
||||
}
|
||||
|
||||
func (f *ActivityLogFilter) ApplyFilter(query *gorm.DB) *gorm.DB {
|
||||
|
||||
@@ -33,6 +33,7 @@ const (
|
||||
MessageTypeSteamOutput WebSocketMessageType = "steam_output"
|
||||
MessageTypeError WebSocketMessageType = "error"
|
||||
MessageTypeComplete WebSocketMessageType = "complete"
|
||||
MessageTypeLogLine WebSocketMessageType = "log_line"
|
||||
)
|
||||
|
||||
type WebSocketMessage struct {
|
||||
@@ -65,6 +66,10 @@ type CompleteMessage struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
type LogLineMessage struct {
|
||||
Line string `json:"line"`
|
||||
}
|
||||
|
||||
func GetStepDescription(step ServerCreationStep) string {
|
||||
descriptions := map[ServerCreationStep]string{
|
||||
StepValidation: "Validating server configuration",
|
||||
|
||||
@@ -25,4 +25,5 @@ type FirewallManager interface {
|
||||
type LogStreamer interface {
|
||||
Start(ctx context.Context, server *model.Server, handleLine func(string)) error
|
||||
Stop(serverID uuid.UUID)
|
||||
GetLastLines(ctx context.Context, server *model.Server, n int) ([]string, error)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package repository
|
||||
import (
|
||||
"acc-server-manager/local/model"
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -24,7 +25,27 @@ func (r *ActivityLogRepository) Insert(ctx context.Context, entry *model.Activit
|
||||
}
|
||||
|
||||
func (r *ActivityLogRepository) GetAll(ctx context.Context, filter *model.ActivityLogFilter) (*[]model.ActivityLog, error) {
|
||||
return r.BaseRepository.GetAll(ctx, filter)
|
||||
result := &[]model.ActivityLog{}
|
||||
query := r.BaseRepository.db.WithContext(ctx).
|
||||
Model(&model.ActivityLog{}).
|
||||
Preload("Server")
|
||||
|
||||
query = filter.ApplyFilter(query)
|
||||
|
||||
offset, limit := filter.Pagination()
|
||||
query = query.Offset(offset).Limit(limit)
|
||||
|
||||
field, desc := filter.GetSorting()
|
||||
if desc {
|
||||
query = query.Order(field + " DESC")
|
||||
} else {
|
||||
query = query.Order(field)
|
||||
}
|
||||
|
||||
if err := query.Find(result).Error; err != nil {
|
||||
return nil, fmt.Errorf("error getting activity logs: %w", err)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
type lastActivityRow struct {
|
||||
|
||||
@@ -57,6 +57,9 @@ func BuildConfigDetails(file string, oldJSON, newJSON []byte) string {
|
||||
}
|
||||
}
|
||||
|
||||
if len(changedKeys) == 0 {
|
||||
return ""
|
||||
}
|
||||
keysJSON, _ := json.Marshal(changedKeys)
|
||||
return fmt.Sprintf(`{"file":%q,"changed_keys":%s}`, file, string(keysJSON))
|
||||
}
|
||||
|
||||
@@ -137,6 +137,16 @@ func (as *ConfigService) UpdateAllConfigs(ctx *fiber.Ctx, req *model.Configurati
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if entry.fileName == SettingsJson {
|
||||
if nameVal, ok := (*entry.body)["serverName"]; ok {
|
||||
if nameStr, ok := nameVal.(string); ok && nameStr != "" && nameStr != server.Name {
|
||||
server.Name = nameStr
|
||||
if err := as.serverRepository.Update(ctx.UserContext(), server); err != nil {
|
||||
logging.Error("Failed to update server name in DB: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
result := as.repository.UpdateConfig(ctx.UserContext(), &model.Config{
|
||||
ServerID: serverUUID,
|
||||
ConfigFile: entry.fileName,
|
||||
@@ -147,16 +157,17 @@ func (as *ConfigService) UpdateAllConfigs(ctx *fiber.Ctx, req *model.Configurati
|
||||
results = append(results, result)
|
||||
|
||||
if as.activityLog != nil {
|
||||
details := BuildConfigDetails(entry.fileName, oldDataUTF8, newData)
|
||||
go func(details string) {
|
||||
_ = as.activityLog.Log(context.Background(), &model.ActivityLog{
|
||||
ServerID: serverUUID,
|
||||
UserID: actorID,
|
||||
Username: actorUsername,
|
||||
Action: model.ActionConfigUpdate,
|
||||
Details: details,
|
||||
})
|
||||
}(details)
|
||||
if details := BuildConfigDetails(entry.fileName, oldDataUTF8, newData); details != "" {
|
||||
go func(details string) {
|
||||
_ = as.activityLog.Log(context.Background(), &model.ActivityLog{
|
||||
ServerID: serverUUID,
|
||||
UserID: actorID,
|
||||
Username: actorUsername,
|
||||
Action: model.ActionConfigUpdate,
|
||||
Details: details,
|
||||
})
|
||||
}(details)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,20 +267,32 @@ func (as *ConfigService) updateConfigInternal(ctx context.Context, serverID stri
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if configFile == SettingsJson {
|
||||
if nameVal, ok := (*body)["serverName"]; ok {
|
||||
if nameStr, ok := nameVal.(string); ok && nameStr != "" && nameStr != server.Name {
|
||||
server.Name = nameStr
|
||||
if err := as.serverRepository.Update(ctx, server); err != nil {
|
||||
logging.Error("Failed to update server name in DB: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
as.configCache.InvalidateServerCache(serverID)
|
||||
as.serverService.StartAccServerRuntime(server)
|
||||
|
||||
if as.activityLog != nil {
|
||||
details := BuildConfigDetails(configFile, oldDataUTF8, newData)
|
||||
go func() {
|
||||
_ = as.activityLog.Log(context.Background(), &model.ActivityLog{
|
||||
ServerID: serverUUID,
|
||||
UserID: actorID,
|
||||
Username: actorUsername,
|
||||
Action: model.ActionConfigUpdate,
|
||||
Details: details,
|
||||
})
|
||||
}()
|
||||
if details := BuildConfigDetails(configFile, oldDataUTF8, newData); details != "" {
|
||||
go func() {
|
||||
_ = as.activityLog.Log(context.Background(), &model.ActivityLog{
|
||||
ServerID: serverUUID,
|
||||
UserID: actorID,
|
||||
Username: actorUsername,
|
||||
Action: model.ActionConfigUpdate,
|
||||
Details: details,
|
||||
})
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
return as.repository.UpdateConfig(ctx, &model.Config{
|
||||
@@ -537,3 +560,11 @@ func (as *ConfigService) SaveConfiguration(server *model.Server, config *model.C
|
||||
_, _, err = as.updateConfigFiles(context.Background(), server, ConfigurationJson, &configMap, true)
|
||||
return err
|
||||
}
|
||||
|
||||
func (as *ConfigService) SetServerName(server *model.Server, name string) error {
|
||||
configMap := map[string]interface{}{
|
||||
"serverName": name,
|
||||
}
|
||||
_, _, err := as.updateConfigFiles(context.Background(), server, SettingsJson, &configMap, false)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -6,7 +6,9 @@ import (
|
||||
"bufio"
|
||||
"context"
|
||||
"io"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
dockerclient "github.com/docker/docker/client"
|
||||
@@ -24,14 +26,14 @@ func NewDockerLogStreamer(client *dockerclient.Client) *DockerLogStreamer {
|
||||
}
|
||||
|
||||
func (s *DockerLogStreamer) Start(ctx context.Context, server *model.Server, handleLine func(string)) error {
|
||||
if _, exists := s.cancels.Load(server.ID); exists {
|
||||
return nil
|
||||
}
|
||||
s.Stop(server.ID)
|
||||
|
||||
if server.ContainerID == "" {
|
||||
logging.Warn("DockerLogStreamer.Start: no container ID for server %s, skipping", server.ID)
|
||||
return nil
|
||||
}
|
||||
|
||||
since := time.Now().UTC().Format(time.RFC3339)
|
||||
streamCtx, cancel := context.WithCancel(ctx)
|
||||
s.cancels.Store(server.ID, cancel)
|
||||
|
||||
@@ -43,6 +45,7 @@ func (s *DockerLogStreamer) Start(ctx context.Context, server *model.Server, han
|
||||
ShowStderr: true,
|
||||
Follow: true,
|
||||
Timestamps: false,
|
||||
Since: since,
|
||||
})
|
||||
if err != nil {
|
||||
logging.Error("DockerLogStreamer: failed to attach to container %s: %v", server.ContainerID[:12], err)
|
||||
@@ -72,3 +75,34 @@ func (s *DockerLogStreamer) Stop(serverID uuid.UUID) {
|
||||
v.(context.CancelFunc)()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerLogStreamer) GetLastLines(ctx context.Context, server *model.Server, n int) ([]string, error) {
|
||||
if n <= 0 || server.ContainerID == "" {
|
||||
return []string{}, nil
|
||||
}
|
||||
|
||||
rc, err := s.client.ContainerLogs(ctx, server.ContainerID, types.ContainerLogsOptions{
|
||||
ShowStdout: true,
|
||||
ShowStderr: true,
|
||||
Tail: strconv.Itoa(n),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rc.Close()
|
||||
|
||||
pr, pw := io.Pipe()
|
||||
go func() {
|
||||
defer pw.Close()
|
||||
if _, err := stdcopy.StdCopy(pw, pw, rc); err != nil && err != io.EOF {
|
||||
logging.Warn("DockerLogStreamer.GetLastLines: stdcopy error for %s: %v", server.ServiceName, err)
|
||||
}
|
||||
}()
|
||||
|
||||
var lines []string
|
||||
scanner := bufio.NewScanner(pr)
|
||||
for scanner.Scan() {
|
||||
lines = append(lines, scanner.Text())
|
||||
}
|
||||
return lines, scanner.Err()
|
||||
}
|
||||
|
||||
@@ -3,7 +3,9 @@ package service
|
||||
import (
|
||||
"acc-server-manager/local/model"
|
||||
"acc-server-manager/local/utl/tracking"
|
||||
"bufio"
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
@@ -36,3 +38,40 @@ func (s *FileLogStreamer) Stop(serverID uuid.UUID) {
|
||||
v.(*tracking.LogTailer).Stop()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *FileLogStreamer) GetLastLines(_ context.Context, server *model.Server, n int) ([]string, error) {
|
||||
if n <= 0 {
|
||||
return []string{}, nil
|
||||
}
|
||||
logPath := filepath.Join(server.GetLogPath(), "server.log")
|
||||
f, err := os.Open(logPath)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return []string{}, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
ring := make([]string, n)
|
||||
head := 0
|
||||
count := 0
|
||||
scanner := bufio.NewScanner(f)
|
||||
for scanner.Scan() {
|
||||
ring[head] = scanner.Text()
|
||||
head = (head + 1) % n
|
||||
if count < n {
|
||||
count++
|
||||
}
|
||||
}
|
||||
if err := scanner.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if count < n {
|
||||
return ring[:count], nil
|
||||
}
|
||||
out := make([]string, n)
|
||||
copy(out, ring[head:])
|
||||
copy(out[n-head:], ring[:head])
|
||||
return out, nil
|
||||
}
|
||||
|
||||
@@ -48,12 +48,27 @@ type pendingState struct {
|
||||
|
||||
func (s *ServerService) ensureLogTailing(server *model.Server, instance *tracking.AccServerInstance) {
|
||||
go func() {
|
||||
if err := s.logStreamer.Start(context.Background(), server, instance.HandleLogLine); err != nil {
|
||||
handleFn := func(line string) {
|
||||
instance.HandleLogLine(line)
|
||||
s.webSocketService.BroadcastLogLine(server.ID, line)
|
||||
}
|
||||
if err := s.logStreamer.Start(context.Background(), server, handleFn); err != nil {
|
||||
logging.Error("Failed to start log streaming for server %s: %v", server.ID, err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func (s *ServerService) GetLastLogLines(ctx *fiber.Ctx, serverID uuid.UUID, n int) ([]string, error) {
|
||||
server, err := s.repository.GetByID(ctx.UserContext(), serverID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if n <= 0 {
|
||||
n = 100
|
||||
}
|
||||
return s.logStreamer.GetLastLines(ctx.UserContext(), server, n)
|
||||
}
|
||||
|
||||
func NewServerService(
|
||||
repository *repository.ServerRepository,
|
||||
stateHistoryRepo *repository.StateHistoryRepository,
|
||||
@@ -421,6 +436,10 @@ func (s *ServerService) createServerBackground(ctx context.Context, server *mode
|
||||
return "", fmt.Errorf("failed to update server configuration: %v", err)
|
||||
}
|
||||
|
||||
if err := s.configService.SetServerName(server, server.Name); err != nil {
|
||||
logging.Error("Failed to set server name in config: %v", err)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("Server configuration generated (Port: %d)", serverPort), nil
|
||||
},
|
||||
},
|
||||
|
||||
@@ -103,6 +103,16 @@ func (ws *WebSocketService) BroadcastError(serverID uuid.UUID, error string, det
|
||||
ws.broadcastToServer(serverID, wsMsg)
|
||||
}
|
||||
|
||||
func (ws *WebSocketService) BroadcastLogLine(serverID uuid.UUID, line string) {
|
||||
msg := model.WebSocketMessage{
|
||||
Type: model.MessageTypeLogLine,
|
||||
ServerID: &serverID,
|
||||
Timestamp: time.Now().Unix(),
|
||||
Data: model.LogLineMessage{Line: line},
|
||||
}
|
||||
ws.broadcastToServer(serverID, msg)
|
||||
}
|
||||
|
||||
func (ws *WebSocketService) BroadcastComplete(serverID uuid.UUID, success bool, message string) {
|
||||
completeMsg := model.CompleteMessage{
|
||||
ServerID: serverID,
|
||||
|
||||
@@ -30,6 +30,7 @@ type RouteGroups struct {
|
||||
Steam fiber.Router
|
||||
ActivityLog fiber.Router
|
||||
Groups fiber.Router
|
||||
Log fiber.Router
|
||||
}
|
||||
|
||||
func CheckError(err error) {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
Version = "0.12.3"
|
||||
Version = "0.13.0"
|
||||
Prefix = "v1"
|
||||
Secret string
|
||||
SecretCode string
|
||||
|
||||
Reference in New Issue
Block a user