clean up game server properties update implementation

This commit is contained in:
RaidMax 2023-04-15 14:30:13 -05:00
parent bb8f3fbe5b
commit b022b08bc7

View File

@ -725,12 +725,12 @@ namespace IW4MAdmin
{ {
if (dict.ContainsKey("gametype")) if (dict.ContainsKey("gametype"))
{ {
Gametype = dict["gametype"]; UpdateGametype(dict["gametype"]);
} }
if (dict.ContainsKey("hostname")) if (dict.ContainsKey("hostname"))
{ {
Hostname = dict["hostname"]; UpdateHostname(dict["hostname"]);
} }
var newMapName = dict.ContainsKey("mapname") var newMapName = dict.ContainsKey("mapname")
@ -743,29 +743,30 @@ namespace IW4MAdmin
else else
{ {
var dict = (Dictionary<string, string>)E.Extra; var dict = (Dictionary<string, string>)E.Extra;
if (dict.ContainsKey("g_gametype")) if (dict.ContainsKey("g_gametype"))
{ {
Gametype = dict["g_gametype"]; UpdateGametype(dict["g_gametype"]);
} }
if (dict.ContainsKey("sv_hostname")) if (dict.ContainsKey("sv_hostname"))
{ {
Hostname = dict["sv_hostname"]; UpdateHostname(dict["sv_hostname"]);
} }
if (dict.ContainsKey("sv_maxclients")) if (dict.ContainsKey("sv_maxclients"))
{ {
MaxClients = int.Parse(dict["sv_maxclients"]); UpdateMaxPlayers(int.Parse(dict["sv_maxclients"]));
} }
else if (dict.ContainsKey("com_maxclients")) else if (dict.ContainsKey("com_maxclients"))
{ {
MaxClients = int.Parse(dict["com_maxclients"]); UpdateMaxPlayers(int.Parse(dict["com_maxclients"]));
} }
else if (dict.ContainsKey("com_maxplayers")) else if (dict.ContainsKey("com_maxplayers"))
{ {
MaxClients = int.Parse(dict["com_maxplayers"]); UpdateMaxPlayers(int.Parse(dict["com_maxplayers"]));
} }
if (dict.ContainsKey("mapname")) if (dict.ContainsKey("mapname"))
@ -978,23 +979,44 @@ namespace IW4MAdmin
return id < 0 ? Math.Abs(id) : id; return id < 0 ? Math.Abs(id) : id;
} }
private void UpdateMap(string mapname) private void UpdateMap(string mapName)
{ {
if (!string.IsNullOrEmpty(mapname)) if (string.IsNullOrEmpty(mapName))
{ {
CurrentMap = Maps.Find(m => m.Name == mapname) ?? new Map() return;
{ }
Alias = mapname,
Name = mapname var foundMap = Maps.Find(m => m.Name == mapName) ?? new Map
}; {
Alias = mapName,
Name = mapName
};
if (foundMap == CurrentMap)
{
return;
}
CurrentMap = foundMap;
using(LogContext.PushProperty("Server", Id))
{
ServerLogger.LogDebug("Updating map to {@CurrentMap}", CurrentMap);
} }
} }
private void UpdateGametype(string gameType) private void UpdateGametype(string gameType)
{ {
if (!string.IsNullOrEmpty(gameType)) if (string.IsNullOrEmpty(gameType))
{ {
Gametype = gameType; return;
}
Gametype = gameType;
using(LogContext.PushProperty("Server", Id))
{
ServerLogger.LogDebug("Updating gametype to {Gametype}", gameType);
} }
} }
@ -1005,7 +1027,7 @@ namespace IW4MAdmin
return; return;
} }
using(LogContext.PushProperty("Server", ToString())) using(LogContext.PushProperty("Server", Id))
{ {
ServerLogger.LogDebug("Updating hostname to {HostName}", hostname); ServerLogger.LogDebug("Updating hostname to {HostName}", hostname);
} }
@ -1020,7 +1042,7 @@ namespace IW4MAdmin
return; return;
} }
using(LogContext.PushProperty("Server", ToString())) using(LogContext.PushProperty("Server", Id))
{ {
ServerLogger.LogDebug("Updating max clients to {MaxPlayers}", maxPlayers); ServerLogger.LogDebug("Updating max clients to {MaxPlayers}", maxPlayers);
} }