private void ListPlayersLoop()
{
/*
Strategy: Control the rate of listPlayers commands by keeping track of the
timestamp of the last event. Only issue a new command if no new event occurs within
the required time.
TBD: This ought to be retired in favor of a TimerLoop request
*/
try {
while (fIsEnabled) {
DelayedRequest request = null;
lock (fListPlayersQ) {
while (fListPlayersQ.Count == 0) {
Monitor.Wait(fListPlayersQ);
if (!fIsEnabled) return;
}
request = fListPlayersQ.Dequeue();
// Wait until event handler updates fListPlayersTimestamp or MaxDelay has elapsed
while (request.LastUpdate == fListPlayersTimestamp
&& DateTime.Now.Subtract(request.LastUpdate).TotalSeconds < request.MaxDelay) {
Monitor.Wait(fListPlayersQ, 1000);
if (!fIsEnabled) return;
}
}
// If there has been no event, ask for one
if (request.LastUpdate == fListPlayersTimestamp) ServerCommand("admin.listPlayers", "all");
}
} catch (ThreadAbortException) {
fAborted = true;
return;
} catch (Exception e) {
ConsoleException(e);
} finally {
if (!fAborted) ConsoleWrite("^bListPlayersLoop^n thread stopped", 0);
}
}