diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 88b42fa38b..abc443deab 100755 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -220,7 +220,12 @@ namespace OpenRA public static bool IsHost { - get { return orderManager.Connection.LocalClientId == 0; } + get + { + var client= orderManager.LobbyInfo.ClientWithIndex ( + orderManager.Connection.LocalClientId); + return ((client!=null) && client.IsAdmin); + } } public static Dictionary CurrentMods diff --git a/OpenRA.Game/Network/Session.cs b/OpenRA.Game/Network/Session.cs index d9e25285b6..38447a5a51 100644 --- a/OpenRA.Game/Network/Session.cs +++ b/OpenRA.Game/Network/Session.cs @@ -50,7 +50,7 @@ namespace OpenRA.Network public int Team; public string Slot; // slot ID, or null for observer public string Bot; // Bot type, null for real clients - + public bool IsAdmin; public bool IsReady { get { return State == ClientState.Ready; } } } diff --git a/OpenRA.Game/Server/Server.cs b/OpenRA.Game/Server/Server.cs index 319769579d..04a8f145b5 100644 --- a/OpenRA.Game/Server/Server.cs +++ b/OpenRA.Game/Server/Server.cs @@ -121,7 +121,7 @@ namespace OpenRA.Server catch { } } ) { IsBackground = true }.Start(); } - + int nextPlayerIndex; /* lobby rework todo: * - "teams together" option for team games -- will eliminate most need * for manual spawnpoint choosing. @@ -129,12 +129,8 @@ namespace OpenRA.Server */ public int ChooseFreePlayerIndex() { - for (var i = 0; i < 256; i++) - if (conns.All(c => c.PlayerIndex != i) && preConns.All(c => c.PlayerIndex != i) - && lobbyInfo.Clients.All(c => c.Index != i)) - return i; - - throw new InvalidOperationException("Already got 256 players"); + nextPlayerIndex++; + return nextPlayerIndex; } void AcceptConnection() @@ -221,6 +217,9 @@ namespace OpenRA.Server SyncClientToPlayerReference(client, Map.Players[client.Slot]); lobbyInfo.Clients.Add(client); + //Assume that first validated client is server admin + if(lobbyInfo.Clients.Count==1) + client.IsAdmin=true; Log.Write("server", "Client {0}: Accepted connection from {1}", newConn.PlayerIndex, newConn.socket.RemoteEndPoint); diff --git a/OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs b/OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs index 20cfd55f6d..fbd8eec400 100644 --- a/OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs +++ b/OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs @@ -20,15 +20,15 @@ namespace OpenRA.Mods.RA.Server { public class LobbyCommands : ServerTrait, IInterpretCommand, INotifyServerStart { - static bool ValidateSlotCommand(S server, Connection conn, string arg, bool requiresHost) + static bool ValidateSlotCommand(S server, Connection conn, Session.Client client, string arg, bool requiresHost) { if (!server.lobbyInfo.Slots.ContainsKey(arg)) { Log.Write("server", "Invalid slot: {0}", arg ); return false; } - - if (requiresHost && conn.PlayerIndex != 0) + + if (requiresHost && !client.IsAdmin) { server.SendChatTo( conn, "Only the host can do that" ); return false; @@ -127,7 +127,7 @@ namespace OpenRA.Mods.RA.Server { "slot_close", s => { - if (!ValidateSlotCommand( server, conn, s, true )) + if (!ValidateSlotCommand( server, conn, client, s, true )) return false; // kick any player that's in the slot @@ -154,7 +154,7 @@ namespace OpenRA.Mods.RA.Server { "slot_open", s => { - if (!ValidateSlotCommand( server, conn, s, true )) + if (!ValidateSlotCommand( server, conn, client, s, true )) return false; var slot = server.lobbyInfo.Slots[s]; @@ -179,7 +179,7 @@ namespace OpenRA.Mods.RA.Server return true; } - if (!ValidateSlotCommand( server, conn, parts[0], true )) + if (!ValidateSlotCommand( server, conn, client, parts[0], true )) return false; var slot = server.lobbyInfo.Slots[parts[0]]; @@ -231,7 +231,7 @@ namespace OpenRA.Mods.RA.Server { "map", s => { - if (conn.PlayerIndex != 0) + if (!client.IsAdmin) { server.SendChatTo( conn, "Only the host can change the map" ); return true; @@ -267,7 +267,7 @@ namespace OpenRA.Mods.RA.Server { "lockteams", s => { - if (conn.PlayerIndex != 0) + if (!client.IsAdmin) { server.SendChatTo( conn, "Only the host can set that option" ); return true; @@ -280,7 +280,7 @@ namespace OpenRA.Mods.RA.Server { "allowcheats", s => { - if (conn.PlayerIndex != 0) + if (!client.IsAdmin) { server.SendChatTo( conn, "Only the host can set that option" ); return true; @@ -294,7 +294,7 @@ namespace OpenRA.Mods.RA.Server s => { - if (conn.PlayerIndex != 0) + if (!client.IsAdmin) { server.SendChatTo( conn, "Only the host can kick players" ); return true; @@ -330,7 +330,7 @@ namespace OpenRA.Mods.RA.Server var targetClient = server.lobbyInfo.ClientWithIndex(int.Parse(parts[0])); // Only the host can change other client's info - if (targetClient.Index != client.Index && conn.PlayerIndex != 0) + if (targetClient.Index != client.Index && !client.IsAdmin) return true; // Map has disabled race changes @@ -348,7 +348,7 @@ namespace OpenRA.Mods.RA.Server var targetClient = server.lobbyInfo.ClientWithIndex(int.Parse(parts[0])); // Only the host can change other client's info - if (targetClient.Index != client.Index && conn.PlayerIndex != 0) + if (targetClient.Index != client.Index && !client.IsAdmin) return true; // Map has disabled team changes @@ -369,7 +369,7 @@ namespace OpenRA.Mods.RA.Server var targetClient = server.lobbyInfo.ClientWithIndex(int.Parse(parts[0])); // Only the host can change other client's info - if (targetClient.Index != client.Index && conn.PlayerIndex != 0) + if (targetClient.Index != client.Index && !client.IsAdmin) return true; // Spectators don't need a spawnpoint @@ -404,7 +404,7 @@ namespace OpenRA.Mods.RA.Server var targetClient = server.lobbyInfo.ClientWithIndex(int.Parse(parts[0])); // Only the host can change other client's info - if (targetClient.Index != client.Index && conn.PlayerIndex != 0) + if (targetClient.Index != client.Index && !client.IsAdmin) return true; // Map has disabled color changes