From 1153cd2f7c6c99b824ee2e9c1c780b374a3f97d1 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 8 Dec 2016 20:56:13 +0000 Subject: [PATCH] Reset slot configuration when all players leave a dedicated server. --- OpenRA.Game/Server/Server.cs | 4 +++- OpenRA.Game/Server/TraitInterfaces.cs | 1 + .../ServerTraits/LobbyCommands.cs | 19 ++++++++++++++++--- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/OpenRA.Game/Server/Server.cs b/OpenRA.Game/Server/Server.cs index 96f8af04ac..d8fc8ad550 100644 --- a/OpenRA.Game/Server/Server.cs +++ b/OpenRA.Game/Server/Server.cs @@ -590,8 +590,10 @@ namespace OpenRA.Server DispatchOrders(toDrop, frame, new byte[] { 0xbf }); + // All clients have left: clean up if (!Conns.Any()) - TempBans.Clear(); + foreach (var t in serverTraits.WithInterface()) + t.ServerEmpty(this); if (Conns.Any() || Dedicated) SyncLobbyClients(); diff --git a/OpenRA.Game/Server/TraitInterfaces.cs b/OpenRA.Game/Server/TraitInterfaces.cs index 8f3c0cc707..8065bc9424 100644 --- a/OpenRA.Game/Server/TraitInterfaces.cs +++ b/OpenRA.Game/Server/TraitInterfaces.cs @@ -18,6 +18,7 @@ namespace OpenRA.Server public interface IInterpretCommand { bool InterpretCommand(Server server, Connection conn, Session.Client client, string cmd); } public interface INotifySyncLobbyInfo { void LobbyInfoSynced(Server server); } public interface INotifyServerStart { void ServerStarted(Server server); } + public interface INotifyServerEmpty { void ServerEmpty(Server server); } public interface INotifyServerShutdown { void ServerShutdown(Server server); } public interface IStartGame { void GameStarted(Server server); } public interface IClientJoined { void ClientJoined(Server server, Connection conn); } diff --git a/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs b/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs index ba15c6ddf9..2238b75053 100644 --- a/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs +++ b/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs @@ -11,9 +11,7 @@ using System; using System.Collections.Generic; -using System.Drawing; using System.Linq; -using System.Threading; using OpenRA.Graphics; using OpenRA.Mods.Common.Traits; using OpenRA.Network; @@ -23,7 +21,7 @@ using S = OpenRA.Server.Server; namespace OpenRA.Mods.Common.Server { - public class LobbyCommands : ServerTrait, IInterpretCommand, INotifyServerStart, IClientJoined + public class LobbyCommands : ServerTrait, IInterpretCommand, INotifyServerStart, INotifyServerEmpty, IClientJoined { static bool ValidateSlotCommand(S server, Connection conn, Session.Client client, string arg, bool requiresHost) { @@ -871,6 +869,21 @@ namespace OpenRA.Mods.Common.Server server.SendOrderTo(conn, "Message", briefing); } + void INotifyServerEmpty.ServerEmpty(S server) + { + // Expire any temporary bans + server.TempBans.Clear(); + + // Re-enable spectators + server.LobbyInfo.GlobalSettings.AllowSpectators = true; + + // Reset player slots + server.LobbyInfo.Slots = server.Map.Players.Players + .Select(p => MakeSlotFromPlayerReference(p.Value)) + .Where(ss => ss != null) + .ToDictionary(ss => ss.PlayerReference, ss => ss); + } + public PlayerReference PlayerReferenceForSlot(S server, Session.Slot slot) { if (slot == null)