Skip to content

Commit 568a904

Browse files
committed
Example, to be reimplemented after the SteamSUImerge
1 parent 1dd813c commit 568a904

17 files changed

Lines changed: 148 additions & 300 deletions

File tree

src/advertiser/advertiser.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type ServerAdResponse struct {
3434
}
3535

3636
func StartAdvertiser() {
37-
if config.GetServerVisible() {
37+
if config.ServerVisible.Get() {
3838
logger.Advertiser.Warn("Server advertisement is enabled. Disable it in the config and restart SSUI to use manual advertisement. Skipping for now...")
3939
return
4040
}
@@ -44,9 +44,9 @@ func StartAdvertiser() {
4444
// Only advertise if we are running
4545
if gamemgr.InternalIsServerRunning() {
4646
// Get max players
47-
maxplayers, err := strconv.Atoi(config.GetServerMaxPlayers())
47+
maxplayers, err := strconv.Atoi(config.ServerMaxPlayers.Get())
4848
if err != nil {
49-
logger.Advertiser.Errorf("ServerAdvertiser failed to convert max players number to int: %s", config.GetServerMaxPlayers())
49+
logger.Advertiser.Errorf("ServerAdvertiser failed to convert max players number to int: %s", config.ServerMaxPlayers.Get())
5050
return
5151
}
5252
// Get connected players
@@ -62,11 +62,11 @@ func StartAdvertiser() {
6262
}
6363
adMessage := ServerAdMessage{
6464
SessionId: sessionId,
65-
Name: config.GetServerName(),
66-
Password: config.GetServerPassword() != "",
65+
Name: config.ServerName.Get(),
66+
Password: config.ServerPassword.Get() != "",
6767
Version: config.GetExtractedGameVersion(),
6868
Address: config.GetOverrideAdvertisedIp(),
69-
Port: config.GetGamePort(),
69+
Port: config.GamePort.Get(),
7070
Players: players,
7171
MaxPlayers: maxplayers,
7272
Type: platform,

src/cli/runtimecommands.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func exitfromcli() {
186186

187187
func deleteConfig() {
188188
//remove file at config.ConfigPath
189-
if err := os.Remove(config.GetConfigPath()); err != nil {
189+
if err := os.Remove(config.ConfigPath); err != nil {
190190
logger.Core.Error("Error deleting config file: " + err.Error())
191191
return
192192
}

src/config/config.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func LoadConfig() (*JsonConfig, error) {
110110
defer ConfigMu.Unlock()
111111

112112
var jsonConfig JsonConfig
113-
file, err := os.Open(configPath)
113+
file, err := os.Open(ConfigPath)
114114
if err == nil {
115115
// File exists, proceed to decode it
116116
defer file.Close()
@@ -169,16 +169,16 @@ func applyConfig(cfg *JsonConfig) {
169169
difficulty = getString(cfg.Difficulty, "DIFFICULTY", "")
170170
startCondition = getString(cfg.StartCondition, "START_CONDITION", "")
171171
startLocation = getString(cfg.StartLocation, "START_LOCATION", "")
172-
serverName = getString(cfg.ServerName, "SERVER_NAME", "Stationeers Server UI")
172+
ServerName.value = getString(cfg.ServerName, "SERVER_NAME", "Stationeers Server UI")
173173
saveInfo = getString(cfg.SaveInfo, "SAVE_INFO", "") // deprecated, kept for backwards compatibility - if set, this gets migrated to SaveName and WorldID and the field is not written back to config.json
174174
saveName = getString(cfg.SaveName, "SAVE_NAME", "MyMapName")
175175
worldID = getString(cfg.WorldID, "WORLD_ID", "Lunar")
176-
serverMaxPlayers = getString(cfg.ServerMaxPlayers, "SERVER_MAX_PLAYERS", "6")
177-
serverPassword = getString(cfg.ServerPassword, "SERVER_PASSWORD", "")
178-
serverAuthSecret = getString(cfg.ServerAuthSecret, "SERVER_AUTH_SECRET", "")
179-
adminPassword = getString(cfg.AdminPassword, "ADMIN_PASSWORD", "")
180-
gamePort = getString(cfg.GamePort, "GAME_PORT", "27016")
181-
updatePort = getString(cfg.UpdatePort, "UPDATE_PORT", "27015")
176+
ServerMaxPlayers.value = getString(cfg.ServerMaxPlayers, "SERVER_MAX_PLAYERS", "6")
177+
ServerPassword.value = getString(cfg.ServerPassword, "SERVER_PASSWORD", "")
178+
ServerAuthSecret.value = getString(cfg.ServerAuthSecret, "SERVER_AUTH_SECRET", "")
179+
AdminPassword.value = getString(cfg.AdminPassword, "ADMIN_PASSWORD", "")
180+
GamePort.value = getString(cfg.GamePort, "GAME_PORT", "27016")
181+
UpdatePort.value = getString(cfg.UpdatePort, "UPDATE_PORT", "27015")
182182
languageSetting = getString(cfg.LanguageSetting, "LANGUAGE_SETTING", "en-US")
183183
ssuiIdentifier = getString(cfg.SSUIIdentifier, "SSUI_IDENTIFIER", "")
184184
ssuiWebPort = getString(cfg.SSUIWebPort, "SSUI_WEB_PORT", "8443")
@@ -197,14 +197,14 @@ func applyConfig(cfg *JsonConfig) {
197197
autoPauseServer = autoPauseServerVal
198198
cfg.AutoPauseServer = &autoPauseServerVal
199199

200-
localIpAddress = getString(cfg.LocalIpAddress, "LOCAL_IP_ADDRESS", "0.0.0.0")
200+
LocalIpAddress.value = getString(cfg.LocalIpAddress, "LOCAL_IP_ADDRESS", "0.0.0.0")
201201

202202
startLocalHostVal := getBool(cfg.StartLocalHost, "START_LOCAL_HOST", true)
203203
startLocalHost = startLocalHostVal
204204
cfg.StartLocalHost = &startLocalHostVal
205205

206206
serverVisibleVal := getBool(cfg.ServerVisible, "SERVER_VISIBLE", true)
207-
serverVisible = serverVisibleVal
207+
ServerVisible.value = serverVisibleVal
208208
cfg.ServerVisible = &serverVisibleVal
209209

210210
useSteamP2PVal := getBool(cfg.UseSteamP2P, "USE_STEAM_P2P", false)
@@ -329,22 +329,22 @@ func safeSaveConfig() error {
329329
Difficulty: difficulty,
330330
StartCondition: startCondition,
331331
StartLocation: startLocation,
332-
ServerName: serverName,
332+
ServerName: ServerName.value,
333333
SaveName: saveName,
334334
WorldID: worldID,
335-
ServerMaxPlayers: serverMaxPlayers,
336-
ServerPassword: serverPassword,
337-
ServerAuthSecret: serverAuthSecret,
338-
AdminPassword: adminPassword,
339-
GamePort: gamePort,
340-
UpdatePort: updatePort,
335+
ServerMaxPlayers: ServerMaxPlayers.value,
336+
ServerPassword: ServerPassword.value,
337+
ServerAuthSecret: ServerAuthSecret.value,
338+
AdminPassword: AdminPassword.value,
339+
GamePort: GamePort.value,
340+
UpdatePort: UpdatePort.value,
341341
UPNPEnabled: &uPNPEnabled,
342342
AutoSave: &autoSave,
343343
SaveInterval: saveInterval,
344344
AutoPauseServer: &autoPauseServer,
345-
LocalIpAddress: localIpAddress,
345+
LocalIpAddress: LocalIpAddress.value,
346346
StartLocalHost: &startLocalHost,
347-
ServerVisible: &serverVisible,
347+
ServerVisible: &ServerVisible.value,
348348
UseSteamP2P: &useSteamP2P,
349349
ExePath: exePath,
350350
AdditionalParams: additionalParams,
@@ -371,7 +371,7 @@ func safeSaveConfig() error {
371371
OverrideAdvertisedIp: overrideAdvertisedIp,
372372
}
373373

374-
file, err := os.Create(configPath)
374+
file, err := os.Create(ConfigPath)
375375
if err != nil {
376376
return fmt.Errorf("error creating config.json: %v", err)
377377
}
@@ -394,7 +394,7 @@ func SaveConfigToFile(cfg *JsonConfig) error {
394394
ConfigMu.Lock()
395395
defer ConfigMu.Unlock()
396396

397-
file, err := os.Create(configPath)
397+
file, err := os.Create(ConfigPath)
398398
if err != nil {
399399
return fmt.Errorf("error creating config.json: %v", err)
400400
}

src/config/getters.go

Lines changed: 0 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,6 @@ func GetStartLocation() string {
154154
return startLocation
155155
}
156156

157-
func GetServerName() string {
158-
ConfigMu.RLock()
159-
defer ConfigMu.RUnlock()
160-
return serverName
161-
}
162-
163157
// special getter for backwards compatibility with SaveInfo
164158
func GetLegacySaveInfo() string {
165159
ConfigMu.RLock()
@@ -180,42 +174,6 @@ func GetWorldID() string {
180174
return worldID
181175
}
182176

183-
func GetServerMaxPlayers() string {
184-
ConfigMu.RLock()
185-
defer ConfigMu.RUnlock()
186-
return serverMaxPlayers
187-
}
188-
189-
func GetServerPassword() string {
190-
ConfigMu.RLock()
191-
defer ConfigMu.RUnlock()
192-
return serverPassword
193-
}
194-
195-
func GetServerAuthSecret() string {
196-
ConfigMu.RLock()
197-
defer ConfigMu.RUnlock()
198-
return serverAuthSecret
199-
}
200-
201-
func GetAdminPassword() string {
202-
ConfigMu.RLock()
203-
defer ConfigMu.RUnlock()
204-
return adminPassword
205-
}
206-
207-
func GetGamePort() string {
208-
ConfigMu.RLock()
209-
defer ConfigMu.RUnlock()
210-
return gamePort
211-
}
212-
213-
func GetUpdatePort() string {
214-
ConfigMu.RLock()
215-
defer ConfigMu.RUnlock()
216-
return updatePort
217-
}
218-
219177
func GetUPNPEnabled() bool {
220178
ConfigMu.RLock()
221179
defer ConfigMu.RUnlock()
@@ -240,24 +198,12 @@ func GetAutoPauseServer() bool {
240198
return autoPauseServer
241199
}
242200

243-
func GetLocalIpAddress() string {
244-
ConfigMu.RLock()
245-
defer ConfigMu.RUnlock()
246-
return localIpAddress
247-
}
248-
249201
func GetStartLocalHost() bool {
250202
ConfigMu.RLock()
251203
defer ConfigMu.RUnlock()
252204
return startLocalHost
253205
}
254206

255-
func GetServerVisible() bool {
256-
ConfigMu.RLock()
257-
defer ConfigMu.RUnlock()
258-
return serverVisible
259-
}
260-
261207
func GetUseSteamP2P() bool {
262208
ConfigMu.RLock()
263209
defer ConfigMu.RUnlock()
@@ -342,24 +288,6 @@ func GetIsSSCMEnabled() bool {
342288
return isSSCMEnabled
343289
}
344290

345-
func GetSSCMFilePath() string {
346-
ConfigMu.RLock()
347-
defer ConfigMu.RUnlock()
348-
return sscmFilePath
349-
}
350-
351-
func GetSSCMPluginDir() string {
352-
ConfigMu.RLock()
353-
defer ConfigMu.RUnlock()
354-
return sscmPluginDir
355-
}
356-
357-
func GetSSCMWebDir() string {
358-
ConfigMu.RLock()
359-
defer ConfigMu.RUnlock()
360-
return sscmWebDir
361-
}
362-
363291
func GetAutoRestartServerTimer() string {
364292
ConfigMu.RLock()
365293
defer ConfigMu.RUnlock()
@@ -415,12 +343,6 @@ func GetIsFirstTimeSetup() bool {
415343
return isFirstTimeSetup
416344
}
417345

418-
func GetConfigPath() string {
419-
ConfigMu.RLock()
420-
defer ConfigMu.RUnlock()
421-
return configPath
422-
}
423-
424346
func GetVersion() string {
425347
ConfigMu.RLock()
426348
defer ConfigMu.RUnlock()
@@ -433,24 +355,6 @@ func GetBranch() string {
433355
return Branch
434356
}
435357

436-
func GetTLSCertPath() string {
437-
ConfigMu.RLock()
438-
defer ConfigMu.RUnlock()
439-
return tlsCertPath
440-
}
441-
442-
func GetTLSKeyPath() string {
443-
ConfigMu.RLock()
444-
defer ConfigMu.RUnlock()
445-
return tlsKeyPath
446-
}
447-
448-
func GetUIModFolder() string {
449-
ConfigMu.RLock()
450-
defer ConfigMu.RUnlock()
451-
return uiModFolder
452-
}
453-
454358
func GetMaxSSEConnections() int {
455359
ConfigMu.RLock()
456360
defer ConfigMu.RUnlock()
@@ -463,12 +367,6 @@ func GetSSEMessageBufferSize() int {
463367
return sseMessageBufferSize
464368
}
465369

466-
func GetLogFolder() string {
467-
ConfigMu.RLock()
468-
defer ConfigMu.RUnlock()
469-
return logFolder
470-
}
471-
472370
func GetConfiguredBackupDir() string {
473371
ConfigMu.RLock()
474372
defer ConfigMu.RUnlock()
@@ -481,12 +379,6 @@ func GetConfiguredSafeBackupDir() string {
481379
return configuredSafeBackupDir
482380
}
483381

484-
func GetCustomDetectionsFilePath() string {
485-
ConfigMu.RLock()
486-
defer ConfigMu.RUnlock()
487-
return customDetectionsFilePath
488-
}
489-
490382
func GetGameServerAppID() string {
491383
ConfigMu.RLock()
492384
defer ConfigMu.RUnlock()

0 commit comments

Comments
 (0)