#34 multiplayer color clashes are banned

This commit is contained in:
Chris Forbes
2010-01-17 08:12:59 +13:00
parent fdf4d09738
commit f2053b6b7a
2 changed files with 18 additions and 3 deletions

View File

@@ -57,6 +57,15 @@ namespace OpenRA.Server
throw new InvalidOperationException("Already got 8 players");
}
static int ChooseFreePalette()
{
for (var i = 0; i < 8; i++)
if (lobbyInfo.Clients.All(c => c.Palette != i))
return i;
throw new InvalidOperationException("No free palettes");
}
static void AcceptConnection()
{
var newConn = new Connection { socket = listener.AcceptSocket() };
@@ -74,7 +83,7 @@ namespace OpenRA.Server
new Session.Client()
{
Index = newConn.PlayerIndex,
Palette = newConn.PlayerIndex,
Palette = ChooseFreePalette(),
Name = "Player {0}".F(1 + newConn.PlayerIndex),
Race = 1,
State = Session.ClientState.NotReady
@@ -303,6 +312,14 @@ namespace OpenRA.Server
return false;
}
if (lobbyInfo.Clients.Where( c => c != GetClient(conn) ).Any( c => c.Palette == pal ))
{
DispatchOrdersToClient(conn, 0,
new ServerOrder( conn.PlayerIndex, "Chat",
"You can't be the same color as another player" ).Serialize() );
return true;
}
GetClient(conn).Palette = pal;
SyncLobbyInfo();
return true;