diff --git a/Barotrauma/BarotraumaClient/Source/Networking/WhiteList.cs b/Barotrauma/BarotraumaClient/Source/Networking/WhiteList.cs index ff30c85a9..58427e1e1 100644 --- a/Barotrauma/BarotraumaClient/Source/Networking/WhiteList.cs +++ b/Barotrauma/BarotraumaClient/Source/Networking/WhiteList.cs @@ -61,6 +61,7 @@ namespace Barotrauma.Networking localEnabled = box.Selected; + return true; } }; @@ -145,16 +146,12 @@ namespace Barotrauma.Networking { if (obj is WhiteListedPlayer) { - WhiteListedPlayer wlp = obj as WhiteListedPlayer; - if (wlp == null) return false; - + if (!(obj is WhiteListedPlayer wlp)) return false; if (!localRemoved.Contains(wlp.UniqueIdentifier)) localRemoved.Add(wlp.UniqueIdentifier); } else if (obj is LocalAdded) { - LocalAdded lad = obj as LocalAdded; - if (lad == null) return false; - + if (!(obj is LocalAdded lad)) return false; if (localAdded.Contains(lad)) localAdded.Remove(lad); } diff --git a/Barotrauma/BarotraumaServer/Source/Networking/WhiteList.cs b/Barotrauma/BarotraumaServer/Source/Networking/WhiteList.cs index 2efdb46fa..c5e27a867 100644 --- a/Barotrauma/BarotraumaServer/Source/Networking/WhiteList.cs +++ b/Barotrauma/BarotraumaServer/Source/Networking/WhiteList.cs @@ -25,47 +25,45 @@ namespace Barotrauma.Networking { partial void InitProjSpecific() { - if (File.Exists(SavePath)) + if (!File.Exists(SavePath)) { return; } + + string[] lines; + try { - string[] lines; - try - { - lines = File.ReadAllLines(SavePath); - } - catch (Exception e) - { - DebugConsole.ThrowError("Failed to open whitelist in " + SavePath, e); - return; - } + lines = File.ReadAllLines(SavePath); + } + catch (Exception e) + { + DebugConsole.ThrowError("Failed to open whitelist in " + SavePath, e); + return; + } - foreach (string line in lines) + foreach (string line in lines) + { + if (line[0] == '#') { - if (line[0] == '#') + string lineval = line.Substring(1, line.Length - 1); + Int32.TryParse(lineval, out int intVal); + if (lineval.ToLower() == "true" || intVal != 0) { - string lineval = line.Substring(1, line.Length - 1); - int intVal = 0; - Int32.TryParse(lineval, out intVal); - if (lineval.ToLower() == "true" || intVal != 0) - { - Enabled = true; - } - else - { - Enabled = false; - } + Enabled = true; } else { - string[] separatedLine = line.Split(','); - if (separatedLine.Length < 2) continue; - - string name = String.Join(",", separatedLine.Take(separatedLine.Length - 1)); - string ip = separatedLine.Last(); - - whitelistedPlayers.Add(new WhiteListedPlayer(name, ip)); + Enabled = false; } } - } + else + { + string[] separatedLine = line.Split(','); + if (separatedLine.Length < 2) continue; + + string name = string.Join(",", separatedLine.Take(separatedLine.Length - 1)); + string ip = separatedLine.Last(); + + whitelistedPlayers.Add(new WhiteListedPlayer(name, ip)); + } + } } public void Save() @@ -119,9 +117,7 @@ namespace Barotrauma.Networking private void RemoveFromWhiteList(WhiteListedPlayer wlp) { GameServer.Log("Removing " + wlp.Name + " from whitelist", ServerLog.MessageType.ServerMessage); - whitelistedPlayers.Remove(wlp); - Save(); } private void AddToWhiteList(string name, string ip) @@ -129,7 +125,6 @@ namespace Barotrauma.Networking if (string.IsNullOrWhiteSpace(name)) return; if (whitelistedPlayers.Any(x => x.Name.ToLower() == name.ToLower() && x.IP == ip)) return; whitelistedPlayers.Add(new WhiteListedPlayer(name, ip)); - Save(); } public void ServerAdminWrite(NetBuffer outMsg, Client c) @@ -201,8 +196,10 @@ namespace Barotrauma.Networking GameServer.Log(c.Name + " added " + name + " to whitelist (" + ip + ")", ServerLog.MessageType.ConsoleUsage); AddToWhiteList(name, ip); } - - return removeCount > 0 || addCount > 0 || prevEnabled!=enabled; + + bool changed = removeCount > 0 || addCount > 0 || prevEnabled != enabled; + if (changed) { Save(); } + return changed; } } }