diff --git a/OpenRA.Game/Server/Server.cs b/OpenRA.Game/Server/Server.cs index 95f552a733..44fe53c1c7 100644 --- a/OpenRA.Game/Server/Server.cs +++ b/OpenRA.Game/Server/Server.cs @@ -263,7 +263,7 @@ namespace OpenRA.Server { bool handled = false; foreach (var t in ServerTraits.WithInterface()) - if ((handled = t.InterpretCommand(conn, so.Data))) + if ((handled = t.InterpretCommand(conn, GetClient(conn), so.Data))) break; if (!handled) diff --git a/OpenRA.Game/ServerTraits/LobbyCommands.cs b/OpenRA.Game/ServerTraits/LobbyCommands.cs index 2e35f64ab2..e3e0b082e0 100644 --- a/OpenRA.Game/ServerTraits/LobbyCommands.cs +++ b/OpenRA.Game/ServerTraits/LobbyCommands.cs @@ -18,7 +18,7 @@ namespace OpenRA.Server.Traits { public class LobbyCommands : IInterpretCommand, IStartServer, IClientJoined { - public bool InterpretCommand(Connection conn, string cmd) + public bool InterpretCommand(Connection conn, Session.Client client, string cmd) { var dict = new Dictionary> { @@ -26,8 +26,6 @@ namespace OpenRA.Server.Traits s => { // if we're downloading, we can't ready up. - - var client = Server.GetClient(conn); if (client.State == Session.ClientState.NotReady) client.State = Session.ClientState.Ready; else if (client.State == Session.ClientState.Ready) @@ -39,7 +37,7 @@ namespace OpenRA.Server.Traits Server.SyncLobbyInfo(); if (Server.conns.Count > 0 && Server.conns.All(c => Server.GetClient(c).State == Session.ClientState.Ready)) - InterpretCommand(conn, "startgame"); + InterpretCommand(conn, client, "startgame"); return true; }}, @@ -68,9 +66,8 @@ namespace OpenRA.Server.Traits if (slotData == null) return true; - var cl = Server.GetClient(conn); - cl.Slot = slotData.Index; - SyncClientToPlayerReference(cl, slotData.MapPlayer != null ? Server.Map.Players[slotData.MapPlayer] : null); + client.Slot = slotData.Index; + SyncClientToPlayerReference(client, slotData.MapPlayer != null ? Server.Map.Players[slotData.MapPlayer] : null); Server.SyncLobbyInfo(); return true; @@ -86,9 +83,8 @@ namespace OpenRA.Server.Traits || Server.lobbyInfo.Clients.Any( c => c.Slot == slot )) return false; - var cl = Server.GetClient(conn); - cl.Slot = slot; - SyncClientToPlayerReference(cl, slotData.MapPlayer != null ? Server.Map.Players[slotData.MapPlayer] : null); + client.Slot = slot; + SyncClientToPlayerReference(client, slotData.MapPlayer != null ? Server.Map.Players[slotData.MapPlayer] : null); Server.SyncLobbyInfo(); return true; @@ -186,14 +182,14 @@ namespace OpenRA.Server.Traits Server.lobbyInfo.GlobalSettings.Map = s; LoadMap(); - foreach(var client in Server.lobbyInfo.Clients) + foreach(var c in Server.lobbyInfo.Clients) { - client.SpawnPoint = 0; - var slotData = Server.lobbyInfo.Slots.FirstOrDefault( x => x.Index == client.Slot ); + c.SpawnPoint = 0; + var slotData = Server.lobbyInfo.Slots.FirstOrDefault( x => x.Index == c.Slot ); if (slotData != null && slotData.MapPlayer != null) - SyncClientToPlayerReference(client, Server.Map.Players[slotData.MapPlayer]); + SyncClientToPlayerReference(c, Server.Map.Players[slotData.MapPlayer]); - client.State = Session.ClientState.NotReady; + c.State = Session.ClientState.NotReady; } Server.SyncLobbyInfo(); diff --git a/OpenRA.Game/ServerTraits/PlayerCommands.cs b/OpenRA.Game/ServerTraits/PlayerCommands.cs index de339c2dd3..a530b2feab 100644 --- a/OpenRA.Game/ServerTraits/PlayerCommands.cs +++ b/OpenRA.Game/ServerTraits/PlayerCommands.cs @@ -18,7 +18,7 @@ namespace OpenRA.Server.Traits { public class PlayerCommands : IInterpretCommand { - public bool InterpretCommand(Connection conn, string cmd) + public bool InterpretCommand(Connection conn, Session.Client client, string cmd) { var dict = new Dictionary> { @@ -26,14 +26,14 @@ namespace OpenRA.Server.Traits s => { Log.Write("server", "Player@{0} is now known as {1}", conn.socket.RemoteEndPoint, s); - Server.GetClient(conn).Name = s; + client.Name = s; Server.SyncLobbyInfo(); return true; }}, { "race", s => { - Server.GetClient(conn).Country = s; + client.Country = s; Server.SyncLobbyInfo(); return true; }}, @@ -43,7 +43,7 @@ namespace OpenRA.Server.Traits int team; if (!int.TryParse(s, out team)) { Log.Write("server", "Invalid team: {0}", s ); return false; } - Server.GetClient(conn).Team = team; + client.Team = team; Server.SyncLobbyInfo(); return true; }}, @@ -57,13 +57,13 @@ namespace OpenRA.Server.Traits return false; } - if (Server.lobbyInfo.Clients.Where( c => c != Server.GetClient(conn) ).Any( c => (c.SpawnPoint == spawnPoint) && (c.SpawnPoint != 0) )) + if (Server.lobbyInfo.Clients.Where( c => c != client ).Any( c => (c.SpawnPoint == spawnPoint) && (c.SpawnPoint != 0) )) { Server.SendChatTo( conn, "You can't be at the same spawn point as another player" ); return true; } - Server.GetClient(conn).SpawnPoint = spawnPoint; + client.SpawnPoint = spawnPoint; Server.SyncLobbyInfo(); return true; }}, @@ -71,8 +71,8 @@ namespace OpenRA.Server.Traits s => { var c = s.Split(',').Select(cc => int.Parse(cc)).ToArray(); - Server.GetClient(conn).Color1 = Color.FromArgb(c[0],c[1],c[2]); - Server.GetClient(conn).Color2 = Color.FromArgb(c[3],c[4],c[5]); + client.Color1 = Color.FromArgb(c[0],c[1],c[2]); + client.Color2 = Color.FromArgb(c[3],c[4],c[5]); Server.SyncLobbyInfo(); return true; }} diff --git a/OpenRA.Game/ServerTraits/TraitInterfaces.cs b/OpenRA.Game/ServerTraits/TraitInterfaces.cs index b90544ddf2..51f8ded7b0 100644 --- a/OpenRA.Game/ServerTraits/TraitInterfaces.cs +++ b/OpenRA.Game/ServerTraits/TraitInterfaces.cs @@ -8,25 +8,26 @@ */ #endregion using System; +using OpenRA.Network; + namespace OpenRA.Server.Traits { // Returns true if order is handled - public interface IInterpretCommand { bool InterpretCommand(Connection conn, string cmd); } + public interface IInterpretCommand { bool InterpretCommand(Connection conn, Session.Client client, string cmd); } + public interface INotifySyncLobbyInfo { void LobbyInfoSynced(); } + public interface IStartServer { void ServerStarted(); } + public interface IStartGame { void GameStarted(); } + public interface IClientJoined { void ClientJoined(Connection conn); } public interface ITick { void Tick(); int TickTimeout { get; } } - public interface INotifySyncLobbyInfo { void LobbyInfoSynced(); } - public interface IStartServer { void ServerStarted(); } - public interface IStartGame { void GameStarted(); } - - public interface IClientJoined { void ClientJoined(Connection conn); } public class DebugServerTrait : IInterpretCommand, IStartGame, INotifySyncLobbyInfo { - public bool InterpretCommand(Connection conn, string cmd) + public bool InterpretCommand(Connection conn, Session.Client client, string cmd) { Console.WriteLine("Server received command from player {1}: {0}",cmd, conn.PlayerIndex); return false;