Start hacking on a server traits model
This commit is contained in:
@@ -15,7 +15,7 @@ using System.Net.Sockets;
|
|||||||
|
|
||||||
namespace OpenRA.Server
|
namespace OpenRA.Server
|
||||||
{
|
{
|
||||||
class Connection
|
public class Connection
|
||||||
{
|
{
|
||||||
public Socket socket;
|
public Socket socket;
|
||||||
public List<byte> data = new List<byte>();
|
public List<byte> data = new List<byte>();
|
||||||
@@ -93,5 +93,5 @@ namespace OpenRA.Server
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|
||||||
enum ReceiveState { Header, Data };
|
public enum ReceiveState { Header, Data };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,12 +23,28 @@ using OpenRA.Network;
|
|||||||
|
|
||||||
namespace OpenRA.Server
|
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 class Server
|
||||||
{
|
{
|
||||||
static List<Connection> conns = new List<Connection>();
|
static List<Connection> conns = new List<Connection>();
|
||||||
static TcpListener listener = null;
|
static TcpListener listener = null;
|
||||||
static Dictionary<int, List<Connection>> inFlightFrames
|
static Dictionary<int, List<Connection>> inFlightFrames
|
||||||
= new Dictionary<int, List<Connection>>();
|
= new Dictionary<int, List<Connection>>();
|
||||||
|
|
||||||
|
static TypeDictionary ServerTraits = new TypeDictionary();
|
||||||
static Session lobbyInfo;
|
static Session lobbyInfo;
|
||||||
static bool GameStarted = false;
|
static bool GameStarted = false;
|
||||||
static string Name;
|
static string Name;
|
||||||
@@ -62,6 +78,8 @@ namespace OpenRA.Server
|
|||||||
{
|
{
|
||||||
Log.AddChannel("server", "server.log");
|
Log.AddChannel("server", "server.log");
|
||||||
|
|
||||||
|
ServerTraits.Add( new DebugServerTrait() );
|
||||||
|
|
||||||
isInitialPing = true;
|
isInitialPing = true;
|
||||||
Server.masterServerUrl = settings.Server.MasterServer;
|
Server.masterServerUrl = settings.Server.MasterServer;
|
||||||
isInternetServer = settings.Server.AdvertiseOnline;
|
isInternetServer = settings.Server.AdvertiseOnline;
|
||||||
@@ -319,6 +337,9 @@ namespace OpenRA.Server
|
|||||||
|
|
||||||
static bool InterpretCommand(Connection conn, string cmd)
|
static bool InterpretCommand(Connection conn, string cmd)
|
||||||
{
|
{
|
||||||
|
foreach (var t in ServerTraits.WithInterface<IInterpretCommand>())
|
||||||
|
t.InterpretCommand(conn, cmd);
|
||||||
|
|
||||||
var dict = new Dictionary<string, Func<string, bool>>
|
var dict = new Dictionary<string, Func<string, bool>>
|
||||||
{
|
{
|
||||||
{ "ready",
|
{ "ready",
|
||||||
|
|||||||
Reference in New Issue
Block a user