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

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