Reduce poll rate for servers that have stopped responding to RCON requests.

Actually fixed the extra chat lines on disconnect.
This commit is contained in:
RaidMax 2017-06-12 07:28:08 -05:00
parent 25b3e3abc1
commit 7a81f6c2bd
5 changed files with 28 additions and 17 deletions

View File

@ -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<byte> data, Action continuation)
{
buffer.Add(data);
buffer?.Add(data);
return false;
}

View File

@ -346,7 +346,6 @@ namespace IW4MAdmin
foreach (var P in CurrentPlayers)
await AddPlayer(P);
}
long l_size = -1;
@ -362,8 +361,24 @@ namespace IW4MAdmin
#if DEBUG == false
try
#endif
{
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, "<i>DISCONNECTED</i>", 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));
}

Binary file not shown.

View File

@ -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];

View File

@ -171,12 +171,6 @@ namespace SharedLibrary
return null;
}
/// <summary>
/// Set up the basic variables ( base path / hostname / etc ) that allow the monitor thread to work
/// </summary>
/// <returns>True if no issues initializing, false otherwise</returns>
//abstract public bool intializeBasics();
/// <summary>
/// Process any server event
/// </summary>
@ -422,6 +416,9 @@ namespace SharedLibrary
public List<Chat> ChatHistory;
public Queue<PlayerHistory> playerHistory { get; private set; }
protected int ConnectionErrors;
protected DateTime LastPoll;
//Info
protected String IP;
protected int Port;