Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ frontend/node_modules
frontend/dist
frontend/build
UIMod/onboard_bundled/v2
UIMod/logs/*
9 changes: 7 additions & 2 deletions UIMod/onboard_bundled/localization/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"UIText_UPNPEnabled": "UPNP Enabled",
"UIText_UPNPEnabledInfo": "Enable automatic UPNP port forwarding",
"UIText_LocalIpAddress": "Local IP Address",
"UIText_LocalIpAddressInfo": "IP address to bind to",
"UIText_LocalIpAddressInfo": "IP address to bind to. Recommended to leave at 0.0.0.0 unless you really know what you're doing.",
"UIText_StartLocalHost": "Start Local Host",
"UIText_StartLocalHostInfo": "Keep this true. This is required for the server to work.",
"UIText_ServerVisible": "Server Visible",
Expand All @@ -84,7 +84,12 @@
"UIText_AllowAutoGameServerUpdates": "Enable Auto Game Server Updates",
"UIText_AllowAutoGameServerUpdatesInfo": "Allow the gameserver to automatically query for and update to the latest version. Attention: Restarts the server when a new version was found and installed. Will send multiple warning messages to the sever with SAY commands 60-10 seconds before the restart.",
"UIText_AutoStartServerOnStartup": "Auto Start Server on Startup",
"UIText_AutoStartServerOnStartupInfo": "Automatically start the gameserver when the SSUI is started. Defaults to false."
"UIText_AutoStartServerOnStartupInfo": "Automatically start the gameserver when the SSUI is started. Defaults to false.",
"UIText_CreateSSUILogFile": "Create SSUI Log Files",
"UIText_CreateSSUILogFileInfo": "Create log files for the SSUI log in UIMod/logs. Defaults to false.",
"UIText_CreateGameServerLogFile": "Create Game Server Log File",
"UIText_CreateGameServerLogFileInfo": "Create a unique log file per server start for the gameserver in UIMod/logs. Defaults to false."

},
"terrain": {
"UIText_TerrainSettingsHeader": "Optional world generation settings",
Expand Down
18 changes: 18 additions & 0 deletions UIMod/onboard_bundled/ui/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,24 @@ <h3 class="section-title">{{.UIText_AdvancedConfiguration}}</h3>
</select>
<div class="input-info">{{.UIText_AllowAutoGameServerUpdatesInfo}}</div>
</div>

<div class="form-group">
<label for="CreateSSUILogFile">{{.UIText_CreateSSUILogFile}}:</label>
<select id="CreateSSUILogFile" name="CreateSSUILogFile" required>
<option value="true" {{.CreateSSUILogFileTrueSelected}}>TRUE</option>
<option value="false" {{.CreateSSUILogFileFalseSelected}}>FALSE</option>
</select>
<div class="input-info">{{.UIText_CreateSSUILogFileInfo}}</div>
</div>

<div class="form-group">
<label for="CreateGameServerLogFile">{{.UIText_CreateGameServerLogFile}}:</label>
<select id="CreateGameServerLogFile" name="CreateGameServerLogFile" required>
<option value="true" {{.CreateGameServerLogFileTrueSelected}}>TRUE</option>
<option value="false" {{.CreateGameServerLogFileFalseSelected}}>FALSE</option>
</select>
<div class="input-info">{{.UIText_CreateGameServerLogFileInfo}}</div>
</div>

</div>
</div>
Expand Down
16 changes: 11 additions & 5 deletions src/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ type JsonConfig struct {
StartLocation string `json:"StartLocation"`

// Logging and debug settings
Debug *bool `json:"Debug"`
CreateSSUILogFile *bool `json:"CreateSSUILogFile"`
LogLevel int `json:"LogLevel"`
SubsystemFilters []string `json:"subsystemFilters"`
AdvertiserOverride string `json:"AdvertiserOverride"`
Debug *bool `json:"Debug"`
CreateSSUILogFile *bool `json:"CreateSSUILogFile"`
CreateGameServerLogFile *bool `json:"CreateGameServerLogFile"`
LogLevel int `json:"LogLevel"`
SubsystemFilters []string `json:"subsystemFilters"`
AdvertiserOverride string `json:"AdvertiserOverride"`

// Authentication Settings
Users map[string]string `json:"users"` // Map of username to hashed password
Expand Down Expand Up @@ -230,6 +231,10 @@ func applyConfig(cfg *JsonConfig) {
CreateSSUILogFile = createSSUILogFileVal
cfg.CreateSSUILogFile = &createSSUILogFileVal

createGameServerLogFileVal := getBool(cfg.CreateGameServerLogFile, "CREATE_GAMESERVER_LOGFILE", false)
CreateGameServerLogFile = createGameServerLogFileVal
cfg.CreateGameServerLogFile = &createGameServerLogFileVal

LogLevel = getInt(cfg.LogLevel, "LOG_LEVEL", 20)

isUpdateEnabledVal := getBool(cfg.IsUpdateEnabled, "IS_UPDATE_ENABLED", true)
Expand Down Expand Up @@ -369,6 +374,7 @@ func safeSaveConfig() error {
AuthTokenLifetime: AuthTokenLifetime,
Debug: &IsDebugMode,
CreateSSUILogFile: &CreateSSUILogFile,
CreateGameServerLogFile: &CreateGameServerLogFile,
LogLevel: LogLevel,
LogClutterToConsole: &LogClutterToConsole,
SubsystemFilters: SubsystemFilters,
Expand Down
6 changes: 6 additions & 0 deletions src/config/getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,12 @@ func GetCreateSSUILogFile() bool {
return CreateSSUILogFile
}

func GetCreateGameServerLogFile() bool {
ConfigMu.RLock()
defer ConfigMu.RUnlock()
return CreateGameServerLogFile
}

func GetLogLevel() int {
ConfigMu.RLock()
defer ConfigMu.RUnlock()
Expand Down
1 change: 1 addition & 0 deletions src/config/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var (
var (
IsDebugMode bool //only used for pprof server, keep it like this and check the log level instead. Debug = 10
CreateSSUILogFile bool
CreateGameServerLogFile bool
LogLevel int
IsFirstTimeSetup bool
SSEMessageBufferSize = 2000
Expand Down
48 changes: 48 additions & 0 deletions src/managers/gamemgr/serverlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,28 @@ import (
"io"
"os"
"os/exec"
"path"
"runtime"
"strconv"
"time"

"github.com/JacksonTheMaster/StationeersServerUI/v5/src/config"
"github.com/JacksonTheMaster/StationeersServerUI/v5/src/core/ssestream"
"github.com/JacksonTheMaster/StationeersServerUI/v5/src/logger"
"github.com/google/uuid"
)

const defaultLogFolderMode = 0755
const defaultLogFileMode = 0644

// readPipe for Windows
func readPipe(pipe io.ReadCloser) {
scanner := bufio.NewScanner(pipe)
logger.Core.Debug("Started reading pipe")
for scanner.Scan() {
output := scanner.Text()
ssestream.BroadcastConsoleOutput(output)
logToFile(output)
}
if err := scanner.Err(); err != nil {
logger.Core.Debug("Pipe error: " + err.Error())
Expand Down Expand Up @@ -91,6 +98,7 @@ func tailLogFile(logFilePath string) {
for scanner.Scan() {
output := scanner.Text()
ssestream.BroadcastConsoleOutput(output)
logToFile(output)
}
if err := scanner.Err(); err != nil {

Expand All @@ -106,3 +114,43 @@ func tailLogFile(logFilePath string) {
logger.Core.Debug("Received logDone signal, stopping tail -F")

}

func logToFile(message string) {
if config.GetCreateGameServerLogFile() {
logFileFolder := config.GetLogFolder()
// Check if the log folder exists, if not create it
_, err := os.Stat(logFileFolder)
if os.IsNotExist(err) {
err := os.Mkdir(logFileFolder, defaultLogFolderMode)
if err != nil {
logger.Core.Error("Error creating log folder: " + err.Error())
return
}
} else if err != nil {
logger.Core.Error("Error checking log folder: " + err.Error())
return
}

if GameServerUUID != uuid.Nil {
logFileName := fmt.Sprintf("serverlog_%s_%s.log", time.Now().Format("200601021504"), GameServerUUID.String())
logFilePath := path.Join(logFileFolder, logFileName)

// append the log file to the log folder
file, err := os.OpenFile(logFilePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, defaultLogFileMode)
if err != nil {
logger.Core.Error("Error opening log file: " + err.Error())
return
}
defer file.Close()

_, err = file.WriteString(message + "\n")
if err != nil {
logger.Core.Error("Error writing to log file: " + err.Error())
return
}
} else {
logger.Core.Error("Game Server UUID not set, cannot log to file")
return
}
}
}
26 changes: 26 additions & 0 deletions src/web/configpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,22 @@ func ServeConfigPage(w http.ResponseWriter, r *http.Request) {
autoGameServerUpdatesFalseSelected = "selected"
}

createSSUILogFileTrueSelected := ""
createSSUILogFileFalseSelected := ""
if config.GetCreateSSUILogFile() {
createSSUILogFileTrueSelected = "selected"
} else {
createSSUILogFileFalseSelected = "selected"
}

createGameServerLogFileTrueSelected := ""
createGameServerLogFileFalseSelected := ""
if config.GetCreateGameServerLogFile() {
createGameServerLogFileTrueSelected = "selected"
} else {
createGameServerLogFileFalseSelected = "selected"
}

data := ConfigTemplateData{
// Config values
DiscordToken: config.GetDiscordToken(),
Expand Down Expand Up @@ -163,6 +179,12 @@ func ServeConfigPage(w http.ResponseWriter, r *http.Request) {
AllowAutoGameServerUpdates: fmt.Sprintf("%v", config.GetAllowAutoGameServerUpdates()),
AllowAutoGameServerUpdatesTrueSelected: autoGameServerUpdatesTrueSelected,
AllowAutoGameServerUpdatesFalseSelected: autoGameServerUpdatesFalseSelected,
CreateSSUILogFile: fmt.Sprintf("%v", config.GetCreateSSUILogFile()),
CreateSSUILogFileTrueSelected: createSSUILogFileTrueSelected,
CreateSSUILogFileFalseSelected: createSSUILogFileFalseSelected,
CreateGameServerLogFile: fmt.Sprintf("%v", config.GetCreateGameServerLogFile()),
CreateGameServerLogFileTrueSelected: createGameServerLogFileTrueSelected,
CreateGameServerLogFileFalseSelected: createGameServerLogFileFalseSelected,

// Localized UI text
UIText_ServerConfig: localization.GetString("UIText_ServerConfig"),
Expand Down Expand Up @@ -235,6 +257,10 @@ func ServeConfigPage(w http.ResponseWriter, r *http.Request) {
UIText_AutoStartServerOnStartupInfo: localization.GetString("UIText_AutoStartServerOnStartupInfo"),
UIText_AllowAutoGameServerUpdates: localization.GetString("UIText_AllowAutoGameServerUpdates"),
UIText_AllowAutoGameServerUpdatesInfo: localization.GetString("UIText_AllowAutoGameServerUpdatesInfo"),
UIText_CreateSSUILogFile: localization.GetString("UIText_CreateSSUILogFile"),
UIText_CreateSSUILogFileInfo: localization.GetString("UIText_CreateSSUILogFileInfo"),
UIText_CreateGameServerLogFile: localization.GetString("UIText_CreateGameServerLogFile"),
UIText_CreateGameServerLogFileInfo: localization.GetString("UIText_CreateGameServerLogFileInfo"),

UIText_DiscordIntegrationTitle: localization.GetString("UIText_DiscordIntegrationTitle"),
UIText_DiscordBotToken: localization.GetString("UIText_DiscordBotToken"),
Expand Down
10 changes: 10 additions & 0 deletions src/web/templatevars.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ type ConfigTemplateData struct {
AllowAutoGameServerUpdates string
AllowAutoGameServerUpdatesTrueSelected string
AllowAutoGameServerUpdatesFalseSelected string
CreateSSUILogFile string
CreateSSUILogFileTrueSelected string
CreateSSUILogFileFalseSelected string
CreateGameServerLogFile string
CreateGameServerLogFileTrueSelected string
CreateGameServerLogFileFalseSelected string

UIText_ServerConfig string
UIText_DiscordIntegration string
Expand Down Expand Up @@ -153,6 +159,10 @@ type ConfigTemplateData struct {
UIText_AutoStartServerOnStartupInfo string
UIText_AllowAutoGameServerUpdates string
UIText_AllowAutoGameServerUpdatesInfo string
UIText_CreateSSUILogFile string
UIText_CreateSSUILogFileInfo string
UIText_CreateGameServerLogFile string
UIText_CreateGameServerLogFileInfo string

UIText_DiscordIntegrationTitle string
UIText_DiscordBotToken string
Expand Down