add more loggers and fix models

This commit is contained in:
Fran Jurmanović
2025-05-07 00:25:02 +02:00
parent a22ab15a02
commit 31a2b73cf9
4 changed files with 80 additions and 61 deletions

View File

@@ -60,7 +60,10 @@ func (ac *ConfigController) updateConfig(c *fiber.Ctx) error {
return c.Status(400).SendString(err.Error()) return c.Status(400).SendString(err.Error())
} }
if restart { if restart {
ac.apiService.ApiRestartServer(c) _, err := ac.apiService.ApiRestartServer(c)
if err != nil {
log.Print(err.Error())
}
} }
return c.JSON(ConfigModel) return c.JSON(ConfigModel)

View File

@@ -1,6 +1,13 @@
package model package model
import "time" import (
"encoding/json"
"fmt"
"strconv"
"time"
)
type IntString int
// Config tracks configuration modifications // Config tracks configuration modifications
type Config struct { type Config struct {
@@ -24,77 +31,101 @@ type ServerSettings struct {
ServerName string `json:"serverName"` ServerName string `json:"serverName"`
AdminPassword string `json:"adminPassword"` AdminPassword string `json:"adminPassword"`
CarGroup string `json:"carGroup"` CarGroup string `json:"carGroup"`
TrackMedalsRequirement int `json:"trackMedalsRequirement"` TrackMedalsRequirement IntString `json:"trackMedalsRequirement"`
SafetyRatingRequirement int `json:"safetyRatingRequirement"` SafetyRatingRequirement IntString `json:"safetyRatingRequirement"`
RacecraftRatingRequirement int `json:"racecraftRatingRequirement"` RacecraftRatingRequirement IntString `json:"racecraftRatingRequirement"`
Password string `json:"password"` Password string `json:"password"`
SpectatorPassword string `json:"spectatorPassword"` SpectatorPassword string `json:"spectatorPassword"`
MaxCarSlots int `json:"maxCarSlots"` MaxCarSlots IntString `json:"maxCarSlots"`
DumpLeaderboards int `json:"dumpLeaderboards"` DumpLeaderboards IntString `json:"dumpLeaderboards"`
IsRaceLocked int `json:"isRaceLocked"` IsRaceLocked IntString `json:"isRaceLocked"`
RandomizeTrackWhenEmpty int `json:"randomizeTrackWhenEmpty"` RandomizeTrackWhenEmpty IntString `json:"randomizeTrackWhenEmpty"`
CentralEntryListPath string `json:"centralEntryListPath"` CentralEntryListPath string `json:"centralEntryListPath"`
AllowAutoDQ int `json:"allowAutoDQ"` AllowAutoDQ IntString `json:"allowAutoDQ"`
ShortFormationLap int `json:"shortFormationLap"` ShortFormationLap IntString `json:"shortFormationLap"`
FormationLapType int `json:"formationLapType"` FormationLapType IntString `json:"formationLapType"`
IgnorePrematureDisconnects int `json:"ignorePrematureDisconnects"` IgnorePrematureDisconnects IntString `json:"ignorePrematureDisconnects"`
} }
type EventConfig struct { type EventConfig struct {
Track string `json:"track"` Track string `json:"track"`
PreRaceWaitingTimeSeconds int `json:"preRaceWaitingTimeSeconds"` PreRaceWaitingTimeSeconds IntString `json:"preRaceWaitingTimeSeconds"`
SessionOverTimeSeconds int `json:"sessionOverTimeSeconds"` SessionOverTimeSeconds IntString `json:"sessionOverTimeSeconds"`
AmbientTemp int `json:"ambientTemp"` AmbientTemp IntString `json:"ambientTemp"`
CloudLevel float64 `json:"cloudLevel"` CloudLevel float64 `json:"cloudLevel"`
Rain float64 `json:"rain"` Rain float64 `json:"rain"`
WeatherRandomness int `json:"weatherRandomness"` WeatherRandomness IntString `json:"weatherRandomness"`
PostQualySeconds int `json:"postQualySeconds"` PostQualySeconds IntString `json:"postQualySeconds"`
PostRaceSeconds int `json:"postRaceSeconds"` PostRaceSeconds IntString `json:"postRaceSeconds"`
SimracerWeatherConditions int `json:"simracerWeatherConditions"` SimracerWeatherConditions IntString `json:"simracerWeatherConditions"`
IsFixedConditionQualification int `json:"isFixedConditionQualification"` IsFixedConditionQualification IntString `json:"isFixedConditionQualification"`
Sessions []Session `json:"sessions"` Sessions []Session `json:"sessions"`
} }
type Session struct { type Session struct {
HourOfDay int `json:"hourOfDay"` HourOfDay IntString `json:"hourOfDay"`
DayOfWeekend int `json:"dayOfWeekend"` DayOfWeekend IntString `json:"dayOfWeekend"`
TimeMultiplier int `json:"timeMultiplier"` TimeMultiplier IntString `json:"timeMultiplier"`
SessionType string `json:"sessionType"` SessionType string `json:"sessionType"`
SessionDurationMinutes int `json:"sessionDurationMinutes"` SessionDurationMinutes IntString `json:"sessionDurationMinutes"`
} }
type AssistRules struct { type AssistRules struct {
StabilityControlLevelMax int `json:"stabilityControlLevelMax"` StabilityControlLevelMax IntString `json:"stabilityControlLevelMax"`
DisableAutosteer int `json:"disableAutosteer"` DisableAutosteer IntString `json:"disableAutosteer"`
DisableAutoLights int `json:"disableAutoLights"` DisableAutoLights IntString `json:"disableAutoLights"`
DisableAutoWiper int `json:"disableAutoWiper"` DisableAutoWiper IntString `json:"disableAutoWiper"`
DisableAutoEngineStart int `json:"disableAutoEngineStart"` DisableAutoEngineStart IntString `json:"disableAutoEngineStart"`
DisableAutoPitLimiter int `json:"disableAutoPitLimiter"` DisableAutoPitLimiter IntString `json:"disableAutoPitLimiter"`
DisableAutoGear int `json:"disableAutoGear"` DisableAutoGear IntString `json:"disableAutoGear"`
DisableAutoClutch int `json:"disableAutoClutch"` DisableAutoClutch IntString `json:"disableAutoClutch"`
DisableIdealLine int `json:"disableIdealLine"` DisableIdealLine IntString `json:"disableIdealLine"`
} }
type EventRules struct { type EventRules struct {
QualifyStandingType int `json:"qualifyStandingType"` QualifyStandingType IntString `json:"qualifyStandingType"`
PitWindowLengthSec int `json:"pitWindowLengthSec"` PitWindowLengthSec IntString `json:"pitWindowLengthSec"`
DriverStintTimeSec int `json:"driverStintTimeSec"` DriverStIntStringTimeSec IntString `json:"driverStIntStringTimeSec"`
MandatoryPitstopCount int `json:"mandatoryPitstopCount"` MandatoryPitstopCount IntString `json:"mandatoryPitstopCount"`
MaxTotalDrivingTime int `json:"maxTotalDrivingTime"` MaxTotalDrivingTime IntString `json:"maxTotalDrivingTime"`
IsRefuellingAllowedInRace bool `json:"isRefuellingAllowedInRace"` IsRefuellingAllowedInRace bool `json:"isRefuellingAllowedInRace"`
IsRefuellingTimeFixed bool `json:"isRefuellingTimeFixed"` IsRefuellingTimeFixed bool `json:"isRefuellingTimeFixed"`
IsMandatoryPitstopRefuellingRequired bool `json:"isMandatoryPitstopRefuellingRequired"` IsMandatoryPitstopRefuellingRequired bool `json:"isMandatoryPitstopRefuellingRequired"`
IsMandatoryPitstopTyreChangeRequired bool `json:"isMandatoryPitstopTyreChangeRequired"` IsMandatoryPitstopTyreChangeRequired bool `json:"isMandatoryPitstopTyreChangeRequired"`
IsMandatoryPitstopSwapDriverRequired bool `json:"isMandatoryPitstopSwapDriverRequired"` IsMandatoryPitstopSwapDriverRequired bool `json:"isMandatoryPitstopSwapDriverRequired"`
TyreSetCount int `json:"tyreSetCount"` TyreSetCount IntString `json:"tyreSetCount"`
} }
type Configuration struct { type Configuration struct {
UdpPort int `json:"udpPort"` UdpPort IntString `json:"udpPort"`
TcpPort int `json:"tcpPort"` TcpPort IntString `json:"tcpPort"`
MaxConnections int `json:"maxConnections"` MaxConnections IntString `json:"maxConnections"`
LanDiscovery int `json:"lanDiscovery"` LanDiscovery IntString `json:"lanDiscovery"`
RegisterToLobby int `json:"registerToLobby"` RegisterToLobby IntString `json:"registerToLobby"`
ConfigVersion int `json:"configVersion"` ConfigVersion IntString `json:"configVersion"`
}
func (i *IntString) UnmarshalJSON(b []byte) error {
var str string
if err := json.Unmarshal(b, &str); err == nil {
if (str == "") {
*i = IntString(0)
} else {
n, err := strconv.Atoi(str)
if err != nil {
return err
}
*i = IntString(n)
}
return nil
}
var num int
if err := json.Unmarshal(b, &num); err == nil {
*i = IntString(num)
return nil
}
return fmt.Errorf("invalid postQualySeconds value")
} }

View File

@@ -14,9 +14,6 @@ type Server struct {
Port int `gorm:"not null" json:"-"` Port int `gorm:"not null" json:"-"`
ConfigPath string `gorm:"not null" json:"-"` // e.g. "/acc/servers/server1/" ConfigPath string `gorm:"not null" json:"-"` // e.g. "/acc/servers/server1/"
ServiceName string `gorm:"not null" json:"-"` // Windows service name ServiceName string `gorm:"not null" json:"-"` // Windows service name
BroadcastIP string `json:"-"`
BroadcastPort int `json:"-"`
BroadcastPassword string `json:"-"`
} }
type PlayerState struct { type PlayerState struct {

View File

@@ -127,18 +127,6 @@ func (as ConfigService) UpdateConfig(ctx *fiber.Ctx, body *map[string]interface{
context := ctx.UserContext() context := ctx.UserContext()
if (configFile == ConfigurationJson) {
config, err := DecodeToMap[model.Configuration](newDataUTF16)
if err != nil {
return nil, err
}
if (server.BroadcastPort != config.UdpPort || server.Port != config.TcpPort) {
server.BroadcastPort = config.UdpPort
server.Port = config.TcpPort
as.serverRepository.UpdateServer(context, server)
}
}
if err := os.WriteFile(configPath, newDataUTF16, 0644); err != nil { if err := os.WriteFile(configPath, newDataUTF16, 0644); err != nil {
return nil, err return nil, err
} }