diff --git a/Admin/Kayak.cs b/Admin/Kayak.cs index 1e9f18cd..d0896e40 100644 --- a/Admin/Kayak.cs +++ b/Admin/Kayak.cs @@ -75,8 +75,8 @@ namespace IW4MAdmin public IDisposable Connect(IDataConsumer channel) { - channel.OnData(data, null); - channel.OnEnd(); + channel?.OnData(data, null); + channel?.OnEnd(); return null; } } @@ -95,7 +95,7 @@ namespace IW4MAdmin public bool OnData(ArraySegment data, Action continuation) { - buffer.Add(data); + buffer?.Add(data); return false; } diff --git a/Admin/Server.cs b/Admin/Server.cs index 20a682b9..10e5586e 100644 --- a/Admin/Server.cs +++ b/Admin/Server.cs @@ -334,7 +334,7 @@ namespace IW4MAdmin } } - async Task PollPlayersAsync() + async Task PollPlayersAsync() { var CurrentPlayers = await this.GetStatusAsync(); @@ -346,7 +346,6 @@ namespace IW4MAdmin foreach (var P in CurrentPlayers) await AddPlayer(P); - } long l_size = -1; @@ -363,7 +362,23 @@ namespace IW4MAdmin try #endif { - await PollPlayersAsync(); + + if ((DateTime.Now - LastPoll).TotalMinutes < 5 && ConnectionErrors > 1) + return; + + try + { + await PollPlayersAsync(); + ConnectionErrors = 0; + LastPoll = DateTime.Now; + } + + catch(SharedLibrary.Exceptions.NetworkException e) + { + ConnectionErrors++; + if (ConnectionErrors > 1) + Logger.WriteError($"{e.Message} {IP}:{Port}, reducing polling rate"); + } lastMessage = DateTime.Now - start; lastCount = DateTime.Now; @@ -540,7 +555,9 @@ namespace IW4MAdmin { ChatHistory.Add(new Chat(E.Origin.Name, "DISCONNECTED", DateTime.Now)); - if (ClientNum == 0) + // the last client hasn't fully disconnected yet + // so there will still be at least 1 client left + if (ClientNum < 2) ChatHistory.Clear(); return; @@ -788,11 +805,9 @@ namespace IW4MAdmin override public void initCommands() { - foreach (Command C in PluginImporter.potentialCommands) Manager.GetCommands().Add(C); - Manager.GetCommands().Add(new Plugins("plugins", "view all loaded plugins. syntax: !plugins", "p", Player.Permission.Administrator, 0, false)); } diff --git a/Admin/lib/SharedLibrary.dll b/Admin/lib/SharedLibrary.dll index 0c858296..f897e40a 100644 Binary files a/Admin/lib/SharedLibrary.dll and b/Admin/lib/SharedLibrary.dll differ diff --git a/SharedLibrary/RCON.cs b/SharedLibrary/RCON.cs index 662e18db..804b00d1 100644 --- a/SharedLibrary/RCON.cs +++ b/SharedLibrary/RCON.cs @@ -69,7 +69,7 @@ namespace SharedLibrary.Network return SplitResponse; } - catch (SocketException) + catch (Exception) { attempts++; if (attempts > 5) @@ -131,7 +131,6 @@ namespace SharedLibrary.Network static byte[] GetRequestBytes(string Request) { - Byte[] initialRequestBytes = Encoding.Unicode.GetBytes(Request); Byte[] fixedRequest = new Byte[initialRequestBytes.Length / 2]; diff --git a/SharedLibrary/Server.cs b/SharedLibrary/Server.cs index 16f9bfd6..9e6b95dc 100644 --- a/SharedLibrary/Server.cs +++ b/SharedLibrary/Server.cs @@ -171,12 +171,6 @@ namespace SharedLibrary return null; } - /// - /// Set up the basic variables ( base path / hostname / etc ) that allow the monitor thread to work - /// - /// True if no issues initializing, false otherwise - //abstract public bool intializeBasics(); - /// /// Process any server event /// @@ -422,6 +416,9 @@ namespace SharedLibrary public List ChatHistory; public Queue playerHistory { get; private set; } + protected int ConnectionErrors; + protected DateTime LastPoll; + //Info protected String IP; protected int Port;