Server support for host changing other client's race/color/team/spawn

This commit is contained in:
Paul Chote
2011-06-17 21:44:00 +12:00
parent d2df5722b5
commit 19d74fef52
3 changed files with 51 additions and 25 deletions

View File

@@ -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<LabelWidget>("LABEL").GetText = () => CountryNames[race];
var flag = item.GetWidget<ImageWidget>("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<LabelWidget>("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<ColorRamp> onChange = c =>

View File

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

View File

@@ -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<LabelWidget>("LABEL").GetText = () => CountryNames[race];
var flag = item.GetWidget<ImageWidget>("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<LabelWidget>("LABEL").GetText = () => ii == 0 ? "-" : ii.ToString();
return item;
};