Skip to content

Commit

Permalink
config updater
Browse files Browse the repository at this point in the history
  • Loading branch information
ohmcodes committed Jan 24, 2024
1 parent 8e1c96b commit 478cc37
Showing 1 changed file with 33 additions and 20 deletions.
53 changes: 33 additions & 20 deletions Enshrouded.cs/Enshrouded.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,7 @@ public class Enshrouded: SteamCMDAgent
// - Create a default cfg for the game server after installation
public async void CreateServerCFG()
{
var serverConfig = new
{
name = $"{_serverData.ServerName}",
password = "",
saveDirectory = "./savegame",
logDirectory = "./logs",
ip = $"{_serverData.ServerIP}",
gamePort = _serverData.ServerPort,
queryPort = _serverData.ServerQueryPort,
slotCount = _serverData.ServerMaxPlayer
};

// Convert the object to JSON format
string jsonContent = JsonConvert.SerializeObject(serverConfig, Formatting.Indented);

// Specify the file path
string filePath = Functions.ServerPath.GetServersServerFiles(_serverData.ServerID, "enshrouded_server.json");

// Write the JSON content to the file
File.WriteAllText(filePath, jsonContent);
UpdateConfig();
}

// - Start server function, return its Process to WindowsGSM
Expand All @@ -96,6 +77,8 @@ public async Task<Process> Start()
param += $"-slotCount={_serverData.ServerMaxPlayer} ";
param += $"-name=\"\"\"{_serverData.ServerName}\"\"\"";

UpdateConfig();

// Prepare Process
var p = new Process
{
Expand Down Expand Up @@ -161,6 +144,12 @@ public async Task<Process> Update(bool validate = false, string custom = null)
var (p, error) = await Installer.SteamCMD.UpdateEx(serverData.ServerID, AppId, validate, custom: custom, loginAnonymous: loginAnonymous);
Error = error;
await Task.Run(() => { p.WaitForExit(); });

if( error != null && p != null)
{
UpdateConfig();
}

return p;
}

Expand All @@ -184,5 +173,29 @@ public async Task<string> GetRemoteBuild()
var steamCMD = new Installer.SteamCMD();
return await steamCMD.GetRemoteBuild(AppId);
}

public void UpdateConfig()
{
var serverConfig = new
{
name = $"{_serverData.ServerName}",
password = "",
saveDirectory = "./savegame",
logDirectory = "./logs",
ip = $"{_serverData.ServerIP}",
gamePort = _serverData.ServerPort,
queryPort = _serverData.ServerQueryPort,
slotCount = _serverData.ServerMaxPlayer
};

// Convert the object to JSON format
string jsonContent = JsonConvert.SerializeObject(serverConfig, Formatting.Indented);

// Specify the file path
string filePath = Functions.ServerPath.GetServersServerFiles(_serverData.ServerID, "enshrouded_server.json");

// Write the JSON content to the file
File.WriteAllText(filePath, jsonContent);
}
}
}

0 comments on commit 478cc37

Please sign in to comment.