From a98d20ea7262cbe2dff204ab0e157e5d80ba7920 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 8 Nov 2010 13:46:03 +1300 Subject: [PATCH] Start hacking on a server traits model --- OpenRA.Game/Server/Connection.cs | 4 ++-- OpenRA.Game/Server/Server.cs | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/OpenRA.Game/Server/Connection.cs b/OpenRA.Game/Server/Connection.cs index e9621a05eb..425ff4523a 100644 --- a/OpenRA.Game/Server/Connection.cs +++ b/OpenRA.Game/Server/Connection.cs @@ -15,7 +15,7 @@ using System.Net.Sockets; namespace OpenRA.Server { - class Connection + public class Connection { public Socket socket; public List data = new List(); @@ -93,5 +93,5 @@ namespace OpenRA.Server } }} - enum ReceiveState { Header, Data }; + public enum ReceiveState { Header, Data }; } diff --git a/OpenRA.Game/Server/Server.cs b/OpenRA.Game/Server/Server.cs index ec15ee70e0..50caf36aa4 100644 --- a/OpenRA.Game/Server/Server.cs +++ b/OpenRA.Game/Server/Server.cs @@ -23,12 +23,28 @@ using OpenRA.Network; namespace OpenRA.Server { + // Todo: Refactor this stuff elsewhere once it does something useful + + // Returns true if order is handled + public interface IInterpretCommand { bool InterpretCommand(Connection conn, string cmd); } + + public class DebugServerTrait : IInterpretCommand + { + public bool InterpretCommand(Connection conn, string cmd) + { + Game.Debug("Server recieved command from player {1}: {0}".F(cmd, conn.PlayerIndex)); + return false; + } + } + static class Server { static List conns = new List(); static TcpListener listener = null; static Dictionary> inFlightFrames = new Dictionary>(); + + static TypeDictionary ServerTraits = new TypeDictionary(); static Session lobbyInfo; static bool GameStarted = false; static string Name; @@ -62,6 +78,8 @@ namespace OpenRA.Server { Log.AddChannel("server", "server.log"); + ServerTraits.Add( new DebugServerTrait() ); + isInitialPing = true; Server.masterServerUrl = settings.Server.MasterServer; isInternetServer = settings.Server.AdvertiseOnline; @@ -319,6 +337,9 @@ namespace OpenRA.Server static bool InterpretCommand(Connection conn, string cmd) { + foreach (var t in ServerTraits.WithInterface()) + t.InterpretCommand(conn, cmd); + var dict = new Dictionary> { { "ready",