From d33806e9327d96c5f9c2d1001016ab848e11289a Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 8 Nov 2010 17:15:50 +1300 Subject: [PATCH] More refactoring --- OpenRA.Game/Game.cs | 2 +- OpenRA.Game/Server/Server.cs | 13 ++++++------- OpenRA.Game/ServerTraits/LobbyCommands.cs | 6 ++++-- OpenRA.Game/ServerTraits/TraitInterfaces.cs | 15 +++++++++++++-- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index f2d47d9276..f10daec77f 100755 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -259,7 +259,7 @@ namespace OpenRA public static void Disconnect() { if (IsHost) - Server.Server.StopListening(); + Server.Server.Shutdown(); orderManager.Dispose(); var shellmap = modData.Manifest.ShellmapUid; diff --git a/OpenRA.Game/Server/Server.cs b/OpenRA.Game/Server/Server.cs index 44fe53c1c7..02cb73d2ea 100644 --- a/OpenRA.Game/Server/Server.cs +++ b/OpenRA.Game/Server/Server.cs @@ -37,17 +37,16 @@ namespace OpenRA.Server public static string Name; static int randomSeed; - const int DownloadChunkInterval = 20000; - const int DownloadChunkSize = 16384; - - public static int MaxSpectators = 4; // How many spectators to allow // @todo Expose this as an option public static ModData ModData; public static Map Map; - public static void StopListening() + public static void Shutdown() { conns.Clear(); GameStarted = false; + foreach (var t in ServerTraits.WithInterface()) + t.ServerShutdown(); + try { listener.Stop(); } catch { } } @@ -72,14 +71,14 @@ namespace OpenRA.Server lobbyInfo.GlobalSettings.AllowCheats = settings.Server.AllowCheats; lobbyInfo.GlobalSettings.ServerName = settings.Server.Name; - foreach (var t in ServerTraits.WithInterface()) + foreach (var t in ServerTraits.WithInterface()) t.ServerStarted(); Log.Write("server", "Initial mods: "); foreach( var m in lobbyInfo.GlobalSettings.Mods ) Log.Write("server","- {0}", m); - //Log.Write("server", "Initial map: {0}",lobbyInfo.GlobalSettings.Map); + Log.Write("server", "Initial map: {0}",lobbyInfo.GlobalSettings.Map); try { diff --git a/OpenRA.Game/ServerTraits/LobbyCommands.cs b/OpenRA.Game/ServerTraits/LobbyCommands.cs index e3e0b082e0..d0b26ef611 100644 --- a/OpenRA.Game/ServerTraits/LobbyCommands.cs +++ b/OpenRA.Game/ServerTraits/LobbyCommands.cs @@ -16,8 +16,10 @@ using OpenRA.FileFormats; namespace OpenRA.Server.Traits { - public class LobbyCommands : IInterpretCommand, IStartServer, IClientJoined + public class LobbyCommands : IInterpretCommand, INotifyServerStart, IClientJoined { + public static int MaxSpectators = 4; // How many spectators to allow // @todo Expose this as an option + public bool InterpretCommand(Connection conn, Session.Client client, string cmd) { var dict = new Dictionary> @@ -242,7 +244,7 @@ namespace OpenRA.Server.Traits .ToList(); // Generate slots for spectators - for (int i = 0; i < Server.MaxSpectators; i++) + for (int i = 0; i < MaxSpectators; i++) Server.lobbyInfo.Slots.Add(new Session.Slot { Spectator = true, diff --git a/OpenRA.Game/ServerTraits/TraitInterfaces.cs b/OpenRA.Game/ServerTraits/TraitInterfaces.cs index 51f8ded7b0..d77d9f213a 100644 --- a/OpenRA.Game/ServerTraits/TraitInterfaces.cs +++ b/OpenRA.Game/ServerTraits/TraitInterfaces.cs @@ -15,7 +15,8 @@ namespace OpenRA.Server.Traits // Returns true if order is handled public interface IInterpretCommand { bool InterpretCommand(Connection conn, Session.Client client, string cmd); } public interface INotifySyncLobbyInfo { void LobbyInfoSynced(); } - public interface IStartServer { void ServerStarted(); } + public interface INotifyServerStart { void ServerStarted(); } + public interface INotifyServerShutdown { void ServerShutdown(); } public interface IStartGame { void GameStarted(); } public interface IClientJoined { void ClientJoined(Connection conn); } public interface ITick @@ -25,7 +26,7 @@ namespace OpenRA.Server.Traits } - public class DebugServerTrait : IInterpretCommand, IStartGame, INotifySyncLobbyInfo + public class DebugServerTrait : IInterpretCommand, IStartGame, INotifySyncLobbyInfo, INotifyServerStart, INotifyServerShutdown { public bool InterpretCommand(Connection conn, Session.Client client, string cmd) { @@ -42,5 +43,15 @@ namespace OpenRA.Server.Traits { Console.WriteLine("LobbyInfoSynced()"); } + + public void ServerStarted() + { + Console.WriteLine("ServerStarted()"); + } + + public void ServerShutdown() + { + Console.WriteLine("ServerShutdown()"); + } } }