Pass the client into InterpretCommand

This commit is contained in:
Paul Chote
2010-11-08 17:07:27 +13:00
parent b77dcd476c
commit e83838e9ff
4 changed files with 28 additions and 31 deletions

View File

@@ -263,7 +263,7 @@ namespace OpenRA.Server
{
bool handled = false;
foreach (var t in ServerTraits.WithInterface<IInterpretCommand>())
if ((handled = t.InterpretCommand(conn, so.Data)))
if ((handled = t.InterpretCommand(conn, GetClient(conn), so.Data)))
break;
if (!handled)

View File

@@ -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<string, Func<string, bool>>
{
@@ -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();

View File

@@ -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<string, Func<string, bool>>
{
@@ -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;
}}

View File

@@ -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;