public void Tick(S server) { // Force an update if the last one was too long ago so the advertisement doesn't time out if (Game.RunTime - lastChanged > MasterPingInterval) { lastChanged = Game.RunTime; } // Update the master server and LAN clients if something has changed // Note that isBusy is set while the master server ping is running on a // background thread, and limits LAN pings as well as master server pings for simplicity. if (!isBusy && ((lastChanged > lastPing && Game.RunTime - lastPing > RateLimitInterval) || isInitialPing)) { var gs = new GameServer(server); if (server.Settings.AdvertiseOnline) { UpdateMasterServer(server, gs.ToPOSTData(false)); } if (LanGameBeacon != null) { LanGameBeacon.BeaconData = gs.ToPOSTData(true); } lastPing = Game.RunTime; } lock (masterServerMessages) while (masterServerMessages.Count > 0) { server.SendLocalizedMessage(masterServerMessages.Dequeue()); } }
public void Tick(S server) { if ((Game.RunTime - lastPing > PingInterval) || isInitialPing) { isInitialPing = false; lastPing = Game.RunTime; // Ignore client timeout in singleplayer games to make debugging easier var nonBotClientCount = 0; lock (server.LobbyInfo) nonBotClientCount = server.LobbyInfo.NonBotClients.Count(); if (nonBotClientCount >= 2 || server.Type == ServerType.Dedicated) { foreach (var c in server.Conns.ToList()) { if (!c.Validated) { continue; } var client = server.GetClient(c); if (client == null) { server.DropClient(c); server.SendLocalizedMessage(PlayerDropped); continue; } if (c.TimeSinceLastResponse < ConnTimeout) { if (!c.TimeoutMessageShown && c.TimeSinceLastResponse > PingInterval * 2) { server.SendLocalizedMessage(ConnectionProblems, Translation.Arguments("player", client.Name)); c.TimeoutMessageShown = true; } } else { server.SendLocalizedMessage(Timeout, Translation.Arguments("player", client.Name)); server.DropClient(c); } } if (Game.RunTime - lastConnReport > ConnReportInterval) { lastConnReport = Game.RunTime; var timeouts = server.Conns .Where(c => c.Validated && c.TimeSinceLastResponse > ConnReportInterval && c.TimeSinceLastResponse < ConnTimeout) .OrderBy(c => c.TimeSinceLastResponse); foreach (var c in timeouts) { var client = server.GetClient(c); if (client != null) { var timeout = (ConnTimeout - c.TimeSinceLastResponse) / 1000; server.SendLocalizedMessage(TimeoutIn, new Dictionary <string, object>() { { "player", client.Name }, { "timeout", timeout } }); } } } } } }