StyleCop cleanup

This commit is contained in:
Matthias Mailänder
2013-11-10 07:34:52 +01:00
parent 7de2dd7083
commit bc133d199e
5 changed files with 165 additions and 166 deletions

View File

@@ -22,7 +22,7 @@ namespace OpenRA.Mods.RA.Server
{
static bool ValidateSlotCommand(S server, Connection conn, Session.Client client, string arg, bool requiresHost)
{
if (!server.lobbyInfo.Slots.ContainsKey(arg))
if (!server.LobbyInfo.Slots.ContainsKey(arg))
{
Log.Write("server", "Invalid slot: {0}", arg);
return false;
@@ -55,14 +55,14 @@ namespace OpenRA.Mods.RA.Server
void CheckAutoStart(S server, Connection conn, Session.Client client)
{
var playerClients = server.lobbyInfo.Clients.Where(c => c.Bot == null && c.Slot != null);
var playerClients = server.LobbyInfo.Clients.Where(c => c.Bot == null && c.Slot != null);
// Are all players ready?
if (playerClients.Count() == 0 || playerClients.Any(c => c.State != Session.ClientState.Ready))
return;
// Are the map conditions satisfied?
if (server.lobbyInfo.Slots.Any(sl => sl.Value.Required && server.lobbyInfo.ClientInSlot(sl.Key) == null))
if (server.LobbyInfo.Slots.Any(sl => sl.Value.Required && server.LobbyInfo.ClientInSlot(sl.Key) == null))
return;
server.StartGame();
@@ -102,8 +102,8 @@ namespace OpenRA.Mods.RA.Server
return true;
}
if (server.lobbyInfo.Slots.Any(sl => sl.Value.Required &&
server.lobbyInfo.ClientInSlot(sl.Key) == null))
if (server.LobbyInfo.Slots.Any(sl => sl.Value.Required &&
server.LobbyInfo.ClientInSlot(sl.Key) == null))
{
server.SendOrderTo(conn, "Message", "Unable to start the game until required slots are full.");
return true;
@@ -114,14 +114,14 @@ namespace OpenRA.Mods.RA.Server
{ "slot",
s =>
{
if (!server.lobbyInfo.Slots.ContainsKey(s))
if (!server.LobbyInfo.Slots.ContainsKey(s))
{
Log.Write("server", "Invalid slot: {0}", s );
return false;
}
var slot = server.lobbyInfo.Slots[s];
var slot = server.LobbyInfo.Slots[s];
if (slot.Closed || server.lobbyInfo.ClientInSlot(s) != null)
if (slot.Closed || server.LobbyInfo.ClientInSlot(s) != null)
return false;
client.Slot = s;
@@ -148,14 +148,14 @@ namespace OpenRA.Mods.RA.Server
return false;
// kick any player that's in the slot
var occupant = server.lobbyInfo.ClientInSlot(s);
var occupant = server.LobbyInfo.ClientInSlot(s);
if (occupant != null)
{
if (occupant.Bot != null)
server.lobbyInfo.Clients.Remove(occupant);
server.LobbyInfo.Clients.Remove(occupant);
else
{
var occupantConn = server.conns.FirstOrDefault( c => c.PlayerIndex == occupant.Index );
var occupantConn = server.Conns.FirstOrDefault( c => c.PlayerIndex == occupant.Index );
if (occupantConn != null)
{
server.SendOrderTo(occupantConn, "ServerError", "Your slot was closed by the host");
@@ -164,7 +164,7 @@ namespace OpenRA.Mods.RA.Server
}
}
server.lobbyInfo.Slots[s].Closed = true;
server.LobbyInfo.Slots[s].Closed = true;
server.SyncLobbyInfo();
return true;
}},
@@ -174,13 +174,13 @@ namespace OpenRA.Mods.RA.Server
if (!ValidateSlotCommand( server, conn, client, s, true ))
return false;
var slot = server.lobbyInfo.Slots[s];
var slot = server.LobbyInfo.Slots[s];
slot.Closed = false;
// Slot may have a bot in it
var occupant = server.lobbyInfo.ClientInSlot(s);
var occupant = server.LobbyInfo.ClientInSlot(s);
if (occupant != null && occupant.Bot != null)
server.lobbyInfo.Clients.Remove(occupant);
server.LobbyInfo.Clients.Remove(occupant);
server.SyncLobbyInfo();
return true;
@@ -199,8 +199,8 @@ namespace OpenRA.Mods.RA.Server
if (!ValidateSlotCommand(server, conn, client, parts[0], true))
return false;
var slot = server.lobbyInfo.Slots[parts[0]];
var bot = server.lobbyInfo.ClientInSlot(parts[0]);
var slot = server.LobbyInfo.Slots[parts[0]];
var bot = server.LobbyInfo.ClientInSlot(parts[0]);
int controllerClientIndex;
if (!int.TryParse(parts[1], out controllerClientIndex))
{
@@ -239,7 +239,7 @@ namespace OpenRA.Mods.RA.Server
var lum = (byte)server.Random.Next(51,255);
bot.Color = bot.PreferredColor = new HSLColor(hue, sat, lum);
server.lobbyInfo.Clients.Add(bot);
server.LobbyInfo.Clients.Add(bot);
}
else
{
@@ -266,8 +266,8 @@ namespace OpenRA.Mods.RA.Server
server.SendOrderTo(conn, "Message", "Map not found");
return true;
}
server.lobbyInfo.GlobalSettings.Map = s;
var oldSlots = server.lobbyInfo.Slots.Keys.ToArray();
server.LobbyInfo.GlobalSettings.Map = s;
var oldSlots = server.LobbyInfo.Slots.Keys.ToArray();
LoadMap(server);
SetDefaultDifficulty(server);
@@ -275,11 +275,11 @@ namespace OpenRA.Mods.RA.Server
// - Observers remain as observers
// - Players who now lack a slot are made observers
// - Bots who now lack a slot are dropped
var slots = server.lobbyInfo.Slots.Keys.ToArray();
var slots = server.LobbyInfo.Slots.Keys.ToArray();
int i = 0;
foreach (var os in oldSlots)
{
var c = server.lobbyInfo.ClientInSlot(os);
var c = server.LobbyInfo.ClientInSlot(os);
if (c == null)
continue;
@@ -290,11 +290,11 @@ namespace OpenRA.Mods.RA.Server
{
// Remove Bot from slot if slot forbids bots
if (c.Bot != null && !server.Map.Players[c.Slot].AllowBots)
server.lobbyInfo.Clients.Remove(c);
server.LobbyInfo.Clients.Remove(c);
S.SyncClientToPlayerReference(c, server.Map.Players[c.Slot]);
}
else if (c.Bot != null)
server.lobbyInfo.Clients.Remove(c);
server.LobbyInfo.Clients.Remove(c);
}
server.SyncLobbyInfo();
@@ -315,7 +315,7 @@ namespace OpenRA.Mods.RA.Server
return true;
}
bool.TryParse(s, out server.lobbyInfo.GlobalSettings.FragileAlliances);
bool.TryParse(s, out server.LobbyInfo.GlobalSettings.FragileAlliances);
server.SyncLobbyInfo();
return true;
}},
@@ -334,7 +334,7 @@ namespace OpenRA.Mods.RA.Server
return true;
}
bool.TryParse(s, out server.lobbyInfo.GlobalSettings.AllowCheats);
bool.TryParse(s, out server.LobbyInfo.GlobalSettings.AllowCheats);
server.SyncLobbyInfo();
return true;
}},
@@ -353,7 +353,7 @@ namespace OpenRA.Mods.RA.Server
return true;
}
bool.TryParse(s, out server.lobbyInfo.GlobalSettings.Shroud);
bool.TryParse(s, out server.LobbyInfo.GlobalSettings.Shroud);
server.SyncLobbyInfo();
return true;
}},
@@ -373,7 +373,7 @@ namespace OpenRA.Mods.RA.Server
}
bool.TryParse(s, out server.lobbyInfo.GlobalSettings.Fog);
bool.TryParse(s, out server.LobbyInfo.GlobalSettings.Fog);
server.SyncLobbyInfo();
return true;
}},
@@ -393,11 +393,11 @@ namespace OpenRA.Mods.RA.Server
return true;
}
var maxTeams = (server.lobbyInfo.Clients.Count(c => c.Slot != null) + 1) / 2;
var maxTeams = (server.LobbyInfo.Clients.Count(c => c.Slot != null) + 1) / 2;
teamCount = teamCount.Clamp(0, maxTeams);
var players = server.lobbyInfo.Slots
.Select(slot => server.lobbyInfo.ClientInSlot(slot.Key))
.Where(c => c != null && !server.lobbyInfo.Slots[c.Slot].LockTeam);
var players = server.LobbyInfo.Slots
.Select(slot => server.LobbyInfo.ClientInSlot(slot.Key))
.Where(c => c != null && !server.LobbyInfo.Slots[c.Slot].LockTeam);
var assigned = 0;
var playerCount = players.Count();
@@ -433,7 +433,7 @@ namespace OpenRA.Mods.RA.Server
return true;
}
bool.TryParse(s, out server.lobbyInfo.GlobalSettings.Crates);
bool.TryParse(s, out server.LobbyInfo.GlobalSettings.Crates);
server.SyncLobbyInfo();
return true;
}},
@@ -452,7 +452,7 @@ namespace OpenRA.Mods.RA.Server
return true;
}
bool.TryParse(s, out server.lobbyInfo.GlobalSettings.AllyBuildRadius);
bool.TryParse(s, out server.LobbyInfo.GlobalSettings.AllyBuildRadius);
server.SyncLobbyInfo();
return true;
}},
@@ -472,7 +472,7 @@ namespace OpenRA.Mods.RA.Server
return true;
}
server.lobbyInfo.GlobalSettings.Difficulty = s;
server.LobbyInfo.GlobalSettings.Difficulty = s;
server.SyncLobbyInfo();
return true;
}},
@@ -491,7 +491,7 @@ namespace OpenRA.Mods.RA.Server
return true;
}
server.lobbyInfo.GlobalSettings.StartingUnitsClass = s;
server.LobbyInfo.GlobalSettings.StartingUnitsClass = s;
server.SyncLobbyInfo();
return true;
}},
@@ -510,7 +510,7 @@ namespace OpenRA.Mods.RA.Server
return true;
}
server.lobbyInfo.GlobalSettings.StartingCash = int.Parse(s);
server.LobbyInfo.GlobalSettings.StartingCash = int.Parse(s);
server.SyncLobbyInfo();
return true;
}},
@@ -533,7 +533,7 @@ namespace OpenRA.Mods.RA.Server
int kickClientID;
int.TryParse(split[0], out kickClientID);
var kickConn = server.conns.SingleOrDefault(c => server.GetClient(c) != null && server.GetClient(c).Index == kickClientID);
var kickConn = server.Conns.SingleOrDefault(c => server.GetClient(c) != null && server.GetClient(c).Index == kickClientID);
if (kickConn == null)
{
server.SendOrderTo(conn, "Message", "Noone in that slot.");
@@ -570,14 +570,14 @@ namespace OpenRA.Mods.RA.Server
s =>
{
var parts = s.Split(' ');
var targetClient = server.lobbyInfo.ClientWithIndex(int.Parse(parts[0]));
var targetClient = server.LobbyInfo.ClientWithIndex(int.Parse(parts[0]));
// Only the host can change other client's info
if (targetClient.Index != client.Index && !client.IsAdmin)
return true;
// Map has disabled race changes
if (server.lobbyInfo.Slots[targetClient.Slot].LockRace)
if (server.LobbyInfo.Slots[targetClient.Slot].LockRace)
return true;
targetClient.Country = parts[1];
@@ -588,14 +588,14 @@ namespace OpenRA.Mods.RA.Server
s =>
{
var parts = s.Split(' ');
var targetClient = server.lobbyInfo.ClientWithIndex(int.Parse(parts[0]));
var targetClient = server.LobbyInfo.ClientWithIndex(int.Parse(parts[0]));
// Only the host can change other client's info
if (targetClient.Index != client.Index && !client.IsAdmin)
return true;
// Map has disabled team changes
if (server.lobbyInfo.Slots[targetClient.Slot].LockTeam)
if (server.LobbyInfo.Slots[targetClient.Slot].LockTeam)
return true;
int team;
@@ -613,7 +613,7 @@ namespace OpenRA.Mods.RA.Server
s =>
{
var parts = s.Split(' ');
var targetClient = server.lobbyInfo.ClientWithIndex(int.Parse(parts[0]));
var targetClient = server.LobbyInfo.ClientWithIndex(int.Parse(parts[0]));
// Only the host can change other client's info
if (targetClient.Index != client.Index && !client.IsAdmin)
@@ -624,7 +624,7 @@ namespace OpenRA.Mods.RA.Server
return true;
// Map has disabled spawn changes
if (server.lobbyInfo.Slots[targetClient.Slot].LockSpawn)
if (server.LobbyInfo.Slots[targetClient.Slot].LockSpawn)
return true;
int spawnPoint;
@@ -634,7 +634,7 @@ namespace OpenRA.Mods.RA.Server
return true;
}
if (server.lobbyInfo.Clients.Where( cc => cc != client ).Any( cc => (cc.SpawnPoint == spawnPoint) && (cc.SpawnPoint != 0) ))
if (server.LobbyInfo.Clients.Where( cc => cc != client ).Any( cc => (cc.SpawnPoint == spawnPoint) && (cc.SpawnPoint != 0) ))
{
server.SendOrderTo(conn, "Message", "You can't be at the same spawn point as another player");
return true;
@@ -648,14 +648,14 @@ namespace OpenRA.Mods.RA.Server
s =>
{
var parts = s.Split(' ');
var targetClient = server.lobbyInfo.ClientWithIndex(int.Parse(parts[0]));
var targetClient = server.LobbyInfo.ClientWithIndex(int.Parse(parts[0]));
// Only the host can change other client's info
if (targetClient.Index != client.Index && !client.IsAdmin)
return true;
// Spectator or map has disabled color changes
if (targetClient.Slot == null || server.lobbyInfo.Slots[targetClient.Slot].LockColor)
if (targetClient.Slot == null || server.LobbyInfo.Slots[targetClient.Slot].LockColor)
return true;
var ci = parts[1].Split(',').Select(cc => int.Parse(cc)).ToArray();
@@ -701,25 +701,25 @@ namespace OpenRA.Mods.RA.Server
static void LoadMap(S server)
{
server.Map = new Map(server.ModData.AvailableMaps[server.lobbyInfo.GlobalSettings.Map].Path);
server.lobbyInfo.Slots = server.Map.Players
server.Map = new Map(server.ModData.AvailableMaps[server.LobbyInfo.GlobalSettings.Map].Path);
server.LobbyInfo.Slots = server.Map.Players
.Select(p => MakeSlotFromPlayerReference(p.Value))
.Where(s => s != null)
.ToDictionary(s => s.PlayerReference, s => s);
server.Map.Options.UpdateServerSettings(server.lobbyInfo.GlobalSettings);
server.Map.Options.UpdateServerSettings(server.LobbyInfo.GlobalSettings);
}
static void SetDefaultDifficulty(S server)
{
if (!server.Map.Options.Difficulties.Any())
{
server.lobbyInfo.GlobalSettings.Difficulty = null;
server.LobbyInfo.GlobalSettings.Difficulty = null;
return;
}
if (!server.Map.Options.Difficulties.Contains(server.lobbyInfo.GlobalSettings.Difficulty))
server.lobbyInfo.GlobalSettings.Difficulty = server.Map.Options.Difficulties.First();
if (!server.Map.Options.Difficulties.Contains(server.LobbyInfo.GlobalSettings.Difficulty))
server.LobbyInfo.GlobalSettings.Difficulty = server.Map.Options.Difficulties.First();
}
}
}