diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncLobbyLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncLobbyLogic.cs index 831a90f87d..0cbae2fce1 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncLobbyLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncLobbyLogic.cs @@ -130,7 +130,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic var owned = orderManager.LobbyInfo.Clients.Any(c => c.SpawnPoint == p); if (p == 0 || !owned) - orderManager.IssueOrder(Order.Command("spawn {0}".F(p))); + orderManager.IssueOrder(Order.Command("spawn {0} {1}".F(orderManager.LocalClient.Index, p))); return true; }; @@ -330,7 +330,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic { var item = ScrollItemWidget.Setup(itemTemplate, () => client.Country == race, - () => orderManager.IssueOrder(Order.Command("race "+race))); + () => orderManager.IssueOrder(Order.Command("race {0} {1}".F(client.Index, race)))); item.GetWidget("LABEL").GetText = () => CountryNames[race]; var flag = item.GetWidget("FLAG"); flag.GetImageCollection = () => "flags"; @@ -348,7 +348,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic { var item = ScrollItemWidget.Setup(itemTemplate, () => client.Team == ii, - () => orderManager.IssueOrder(Order.Command("team "+ii))); + () => orderManager.IssueOrder(Order.Command("team {0} {1}".F(client.Index, ii)))); item.GetWidget("LABEL").GetText = () => ii == 0 ? "-" : ii.ToString(); return item; }; @@ -365,7 +365,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic Game.Settings.Player.ColorRamp = c; Game.Settings.Save(); color.RemovePanel(); - orderManager.IssueOrder(Order.Command("color {0}".F(c))); + orderManager.IssueOrder(Order.Command("color {0} {1}".F(client.Index, c))); }; Action onChange = c => diff --git a/OpenRA.Mods.RA/ServerTraits/PlayerCommands.cs b/OpenRA.Mods.RA/ServerTraits/PlayerCommands.cs index 9bfa5cdae1..bce094501b 100644 --- a/OpenRA.Mods.RA/ServerTraits/PlayerCommands.cs +++ b/OpenRA.Mods.RA/ServerTraits/PlayerCommands.cs @@ -47,51 +47,77 @@ namespace OpenRA.Mods.RA.Server { "race", s => { - client.Country = s; + var parts = s.Split(' '); + 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) + return true; + + targetClient.Country = parts[1]; server.SyncLobbyInfo(); return true; }}, { "team", s => { - int team; - if (!int.TryParse(s, out team)) { Log.Write("server", "Invalid team: {0}", s ); return false; } + var parts = s.Split(' '); + var targetClient = server.lobbyInfo.ClientWithIndex(int.Parse(parts[0])); - client.Team = team; + // Only the host can change other client's info + if (targetClient.Index != client.Index && conn.PlayerIndex != 0) + return true; + + int team; + if (!int.TryParse(parts[1], out team)) { Log.Write("server", "Invalid team: {0}", s ); return false; } + + targetClient.Team = team; server.SyncLobbyInfo(); return true; }}, { "spawn", s => { - int spawnPoint; - if (!int.TryParse(s, out spawnPoint) || spawnPoint < 0 || spawnPoint > server.Map.SpawnPoints.Count()) - { - Log.Write("server", "Invalid spawn point: {0}", s); - return false; - } - + var parts = s.Split(' '); + 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) + return true; + + // Spectators don't need a spawnpoint if (client.Slot == null) + return true; + + int spawnPoint; + if (!int.TryParse(parts[1], out spawnPoint) || spawnPoint < 0 || spawnPoint > server.Map.SpawnPoints.Count()) { - server.SendChatTo( conn, "Can't select a spawnpoint as a spectator" ); - return false; + Log.Write("server", "Invalid spawn point: {0}", parts[1]); + return true; } - if (server.lobbyInfo.Clients.Where( c => c != client ).Any( c => (c.SpawnPoint == spawnPoint) && (c.SpawnPoint != 0) )) + if (server.lobbyInfo.Clients.Where( cc => cc != client ).Any( cc => (cc.SpawnPoint == spawnPoint) && (cc.SpawnPoint != 0) )) { server.SendChatTo( conn, "You can't be at the same spawn point as another player" ); return true; } - client.SpawnPoint = spawnPoint; + targetClient.SpawnPoint = spawnPoint; server.SyncLobbyInfo(); return true; }}, { "color", s => { - var c = s.Split(',').Select(cc => int.Parse(cc)).ToArray(); - client.ColorRamp = new ColorRamp((byte)c[0], (byte)c[1], (byte)c[2], (byte)c[3]); + var parts = s.Split(' '); + 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) + return true; + + var ci = parts[1].Split(',').Select(cc => int.Parse(cc)).ToArray(); + targetClient.ColorRamp = new ColorRamp((byte)ci[0], (byte)ci[1], (byte)ci[2], (byte)ci[3]); server.SyncLobbyInfo(); return true; }} diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs index b40944add4..bc2c97e3d0 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs @@ -73,7 +73,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic var owned = orderManager.LobbyInfo.Clients.Any(c => c.SpawnPoint == p); if (p == 0 || !owned) - orderManager.IssueOrder(Order.Command("spawn {0}".F(p))); + orderManager.IssueOrder(Order.Command("spawn {0} {1}".F(orderManager.LocalClient.Index, p))); return true; }; @@ -189,7 +189,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic var ramp = new ColorRamp((byte) (hf*255), (byte) (sf*255), (byte) (lf*255), (byte)(r*255)); Game.Settings.Player.ColorRamp = ramp; Game.Settings.Save(); - orderManager.IssueOrder(Order.Command("color {0}".F(ramp))); + orderManager.IssueOrder(Order.Command("color {0} {1}".F(orderManager.LocalClient.Index, ramp))); } void UpdateColorPreview(float hf, float sf, float lf, float r) @@ -255,7 +255,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic { var item = ScrollItemWidget.Setup(itemTemplate, () => client.Country == race, - () => orderManager.IssueOrder(Order.Command("race "+race))); + () => orderManager.IssueOrder(Order.Command("race {0} {1}".F(client.Index, race)))); item.GetWidget("LABEL").GetText = () => CountryNames[race]; var flag = item.GetWidget("FLAG"); flag.GetImageCollection = () => "flags"; @@ -273,7 +273,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic { var item = ScrollItemWidget.Setup(itemTemplate, () => client.Team == ii, - () => orderManager.IssueOrder(Order.Command("team "+ii))); + () => orderManager.IssueOrder(Order.Command("team {0} {1}".F(client.Index, ii)))); item.GetWidget("LABEL").GetText = () => ii == 0 ? "-" : ii.ToString(); return item; };