making that a bit more readable.

This commit is contained in:
Chris Forbes
2010-01-25 12:44:25 +13:00
parent e6ded0e491
commit 0998e1f17b
2 changed files with 23 additions and 36 deletions

View File

@@ -96,8 +96,7 @@ namespace OpenRA.Server
Console.WriteLine("Accepted connection from {0}.", Console.WriteLine("Accepted connection from {0}.",
newConn.socket.RemoteEndPoint); newConn.socket.RemoteEndPoint);
DispatchOrders(newConn, 0, new ServerOrder(newConn.PlayerIndex, SendChat(newConn, "has joined the game.");
"Chat", "has joined the game.").Serialize());
SyncLobbyInfo(); SyncLobbyInfo();
} }
@@ -282,9 +281,7 @@ namespace OpenRA.Server
{ {
if (GameStarted) if (GameStarted)
{ {
DispatchOrdersToClient(conn, 0, 0, SendChatTo( conn, "You can't change your race after the game has started" );
new ServerOrder( conn.PlayerIndex, "Chat",
"You can't change your race after the game has started" ).Serialize() );
return true; return true;
} }
@@ -304,9 +301,7 @@ namespace OpenRA.Server
{ {
if (GameStarted) if (GameStarted)
{ {
DispatchOrdersToClient(conn, 0, 0, SendChatTo( conn, "You can't change your color after the game has started" );
new ServerOrder( conn.PlayerIndex, "Chat",
"You can't change your color after the game has started" ).Serialize() );
return true; return true;
} }
@@ -319,9 +314,7 @@ namespace OpenRA.Server
if (lobbyInfo.Clients.Where( c => c != GetClient(conn) ).Any( c => c.Palette == pal )) if (lobbyInfo.Clients.Where( c => c != GetClient(conn) ).Any( c => c.Palette == pal ))
{ {
DispatchOrdersToClient(conn, 0, 0, SendChatTo( conn, "You can't be the same color as another player" );
new ServerOrder( conn.PlayerIndex, "Chat",
"You can't be the same color as another player" ).Serialize() );
return true; return true;
} }
@@ -334,17 +327,13 @@ namespace OpenRA.Server
{ {
if (conn.PlayerIndex != 0) if (conn.PlayerIndex != 0)
{ {
DispatchOrdersToClient(conn, 0, 0, SendChatTo( conn, "Only the host can change the map" );
new ServerOrder( conn.PlayerIndex, "Chat",
"Only the host can change the map" ).Serialize() );
return true; return true;
} }
if (GameStarted) if (GameStarted)
{ {
DispatchOrdersToClient(conn, 0, 0, SendChatTo( conn, "You can't change the map after the game has started" );
new ServerOrder( conn.PlayerIndex, "Chat",
"You can't change the map after the game has started" ).Serialize() );
return true; return true;
} }
@@ -357,9 +346,8 @@ namespace OpenRA.Server
{ {
if (GameStarted) if (GameStarted)
{ {
DispatchOrdersToClient(conn, 0, 0, SendChatTo( conn, "You can't change packages after the game has started" );
new ServerOrder( conn.PlayerIndex, "Chat", return true;
"You can't change packages after the game has started" ).Serialize() );
} }
Console.WriteLine("** Added package: `{0}`", s); Console.WriteLine("** Added package: `{0}`", s);
@@ -373,10 +361,8 @@ namespace OpenRA.Server
} }
catch catch
{ {
Console.WriteLine("That went horribly wrong."); Console.WriteLine("Adding the package failed.");
DispatchOrdersToClient(conn, 0, 0, SendChatTo( conn, "Adding the package failed." );
new ServerOrder( conn.PlayerIndex, "Chat",
"Adding the package failed." ).Serialize() );
return true; return true;
} }
}}, }},
@@ -385,9 +371,8 @@ namespace OpenRA.Server
{ {
if (GameStarted) if (GameStarted)
{ {
DispatchOrdersToClient(conn, 0, 0, SendChatTo( conn, "You can't change mods after the game has started" );
new ServerOrder( conn.PlayerIndex, "Chat", return true;
"You can't change mods after the game has started" ).Serialize() );
} }
Console.WriteLine("** Added mod: `{0}`", s); Console.WriteLine("** Added mod: `{0}`", s);
@@ -396,17 +381,13 @@ namespace OpenRA.Server
lobbyInfo.GlobalSettings.Mods = lobbyInfo.GlobalSettings.Mods =
lobbyInfo.GlobalSettings.Mods.Concat( new[] { s } ).ToArray(); lobbyInfo.GlobalSettings.Mods.Concat( new[] { s } ).ToArray();
SyncLobbyInfo(); SyncLobbyInfo();
DispatchOrdersToClient(conn, 0, 0, SendChatTo(conn, "Added mod: " + s );
new ServerOrder( conn.PlayerIndex, "Chat",
"Added mod: " + s ).Serialize() );
return true; return true;
} }
catch catch
{ {
Console.WriteLine("That went horribly wrong."); Console.WriteLine("Adding the mod failed.");
DispatchOrdersToClient(conn, 0, 0, SendChatTo( conn, "Adding the mod failed.");
new ServerOrder( conn.PlayerIndex, "Chat",
"Adding the mod failed." ).Serialize() );
return true; return true;
} }
}}, }},
@@ -422,6 +403,12 @@ namespace OpenRA.Server
return a(cmdValue); return a(cmdValue);
} }
static void SendChatTo(Connection conn, string text)
{
DispatchOrdersToClient(conn, 0, 0,
new ServerOrder(conn.PlayerIndex, "Chat", text).Serialize());
}
static void SendChat(Connection asConn, string text) static void SendChat(Connection asConn, string text)
{ {
DispatchOrders(null, 0, new ServerOrder(asConn.PlayerIndex, "Chat", text).Serialize()); DispatchOrders(null, 0, new ServerOrder(asConn.PlayerIndex, "Chat", text).Serialize());
@@ -463,7 +450,7 @@ namespace OpenRA.Server
if (!InterpretCommand(conn, so.Data.Substring(1))) if (!InterpretCommand(conn, so.Data.Substring(1)))
{ {
Console.WriteLine("Bad server command: {0}", so.Data.Substring(1)); Console.WriteLine("Bad server command: {0}", so.Data.Substring(1));
DispatchOrdersToClient(conn, 0, 0, new ServerOrder(conn.PlayerIndex, "Chat", "Bad server command.").Serialize()); SendChatTo(conn, "Bad server command.");
} }
} }
else else

View File

@@ -5,7 +5,7 @@ namespace OpenRa.Traits
{ {
class ConstructionYardInfo : ITraitInfo class ConstructionYardInfo : ITraitInfo
{ {
public readonly bool AllowUndeploy; public readonly bool AllowUndeploy = false;
public object Create(Actor self) { return new ConstructionYard(self); } public object Create(Actor self) { return new ConstructionYard(self); }
} }