From bc133d199e416d9f8c528f91563ad024a4b248e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 10 Nov 2013 07:34:52 +0100 Subject: [PATCH] StyleCop cleanup --- OpenRA.Game/Game.cs | 2 +- OpenRA.Game/Server/Server.cs | 215 +++++++++--------- OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs | 106 ++++----- .../ServerTraits/MasterServerPinger.cs | 6 +- OpenRA.Mods.RA/ServerTraits/PlayerPinger.cs | 2 +- 5 files changed, 165 insertions(+), 166 deletions(-) diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 2626b01b6d..054dda2dd0 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -386,7 +386,7 @@ namespace OpenRA System.Threading.Thread.Sleep(100); if ((server.State == Server.ServerState.GameStarted) - && (server.conns.Count<=1)) + && (server.Conns.Count<=1)) { Console.WriteLine("No one is playing, shutting down..."); server.Shutdown(); diff --git a/OpenRA.Game/Server/Server.cs b/OpenRA.Game/Server/Server.cs index b09c4db530..c8db24d5cd 100644 --- a/OpenRA.Game/Server/Server.cs +++ b/OpenRA.Game/Server/Server.cs @@ -14,8 +14,8 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; -using System.Net.Sockets; using System.Net.NetworkInformation; +using System.Net.Sockets; using System.Threading; using OpenRA.FileFormats; @@ -35,35 +35,51 @@ namespace OpenRA.Server public class Server { - // Valid player connections - public List conns = new List(); - - // Pre-verified player connections - public List preConns = new List(); - - TcpListener listener = null; - Dictionary> inFlightFrames - = new Dictionary>(); - - TypeDictionary ServerTraits = new TypeDictionary(); - public Session lobbyInfo; - public readonly IPAddress Ip; public readonly int Port; int randomSeed; public readonly Thirdparty.Random Random = new Thirdparty.Random(); + // Valid player connections + public List Conns = new List(); + + // Pre-verified player connections + public List PreConns = new List(); + + TcpListener listener = null; + Dictionary> inFlightFrames + = new Dictionary>(); + + TypeDictionary serverTraits = new TypeDictionary(); + public Session LobbyInfo; + public ServerSettings Settings; public ModData ModData; public Map Map; XTimer gameTimeout; - protected volatile ServerState pState = new ServerState(); + public static void SyncClientToPlayerReference(Session.Client c, PlayerReference pr) + { + if (pr == null) + return; + if (pr.LockColor) + c.Color = pr.Color; + else + c.Color = c.PreferredColor; + if (pr.LockRace) + c.Country = pr.Race; + if (pr.LockSpawn) + c.SpawnPoint = pr.Spawn; + if (pr.LockTeam) + c.Team = pr.Team; + } + + protected volatile ServerState internalState = new ServerState(); public ServerState State { - get { return pState; } - protected set { pState = value; } + get { return internalState; } + protected set { internalState = value; } } public List TempBans = new List(); @@ -75,7 +91,7 @@ namespace OpenRA.Server public void EndGame() { - foreach (var t in ServerTraits.WithInterface()) + foreach (var t in serverTraits.WithInterface()) t.GameEnded(this); } @@ -83,7 +99,7 @@ namespace OpenRA.Server { Log.AddChannel("server", "server.log"); - pState = ServerState.WaitingPlayers; + internalState = ServerState.WaitingPlayers; listener = new TcpListener(endpoint); listener.Start(); var localEndpoint = (IPEndPoint)listener.LocalEndpoint; @@ -99,33 +115,33 @@ namespace OpenRA.Server UPnP.ForwardPort(); foreach (var trait in modData.Manifest.ServerTraits) - ServerTraits.Add(modData.ObjectCreator.CreateObject(trait)); + serverTraits.Add(modData.ObjectCreator.CreateObject(trait)); - lobbyInfo = new Session(mods); - lobbyInfo.GlobalSettings.RandomSeed = randomSeed; - lobbyInfo.GlobalSettings.Map = settings.Map; - lobbyInfo.GlobalSettings.ServerName = settings.Name; - lobbyInfo.GlobalSettings.Dedicated = settings.Dedicated; - FieldLoader.Load(lobbyInfo.GlobalSettings, modData.Manifest.LobbyDefaults); + LobbyInfo = new Session(mods); + LobbyInfo.GlobalSettings.RandomSeed = randomSeed; + LobbyInfo.GlobalSettings.Map = settings.Map; + LobbyInfo.GlobalSettings.ServerName = settings.Name; + LobbyInfo.GlobalSettings.Dedicated = settings.Dedicated; + FieldLoader.Load(LobbyInfo.GlobalSettings, modData.Manifest.LobbyDefaults); - foreach (var t in ServerTraits.WithInterface()) + foreach (var t in serverTraits.WithInterface()) t.ServerStarted(this); Log.Write("server", "Initial mods: "); - foreach (var m in lobbyInfo.GlobalSettings.Mods) - Log.Write("server","- {0}", m); + foreach (var m in LobbyInfo.GlobalSettings.Mods) + Log.Write("server", "- {0}", m); - Log.Write("server", "Initial map: {0}",lobbyInfo.GlobalSettings.Map); + Log.Write("server", "Initial map: {0}", LobbyInfo.GlobalSettings.Map); - new Thread( _ => + new Thread(_ => { - var timeout = ServerTraits.WithInterface().Min(t => t.TickTimeout); + var timeout = serverTraits.WithInterface().Min(t => t.TickTimeout); for (;;) { var checkRead = new List(); checkRead.Add(listener.Server); - foreach (var c in conns) checkRead.Add(c.socket); - foreach (var c in preConns) checkRead.Add(c.socket); + foreach (var c in Conns) checkRead.Add(c.socket); + foreach (var c in PreConns) checkRead.Add(c.socket); Socket.Select(checkRead, null, null, timeout); if (State == ServerState.ShuttingDown) @@ -136,18 +152,18 @@ namespace OpenRA.Server foreach (var s in checkRead) if (s == listener.Server) AcceptConnection(); - else if (preConns.Count > 0) + else if (PreConns.Count > 0) { - var p = preConns.SingleOrDefault(c => c.socket == s); + var p = PreConns.SingleOrDefault(c => c.socket == s); if (p != null) p.ReadData(this); } - else if (conns.Count > 0) + else if (Conns.Count > 0) { - var conn = conns.SingleOrDefault(c => c.socket == s); + var conn = Conns.SingleOrDefault(c => c.socket == s); if (conn != null) conn.ReadData(this); } - foreach (var t in ServerTraits.WithInterface()) + foreach (var t in serverTraits.WithInterface()) t.Tick(this); if (State == ServerState.ShuttingDown) @@ -158,15 +174,14 @@ namespace OpenRA.Server } } - foreach (var t in ServerTraits.WithInterface()) + foreach (var t in serverTraits.WithInterface()) t.ServerShutdown(this); - preConns.Clear(); - conns.Clear(); + PreConns.Clear(); + Conns.Clear(); try { listener.Stop(); } catch { } - } ) { IsBackground = true }.Start(); - + }) { IsBackground = true }.Start(); } /* lobby rework TODO: @@ -206,13 +221,13 @@ namespace OpenRA.Server newConn.PlayerIndex = ChooseFreePlayerIndex(); SendData(newConn.socket, BitConverter.GetBytes(ProtocolVersion.Version)); SendData(newConn.socket, BitConverter.GetBytes(newConn.PlayerIndex)); - preConns.Add(newConn); + PreConns.Add(newConn); // Dispatch a handshake order var request = new HandshakeRequest() { - Map = lobbyInfo.GlobalSettings.Map, - Mods = lobbyInfo.GlobalSettings.Mods.Select(m => "{0}@{1}".F(m, Mod.AllMods[m].Version)).ToArray() + Map = LobbyInfo.GlobalSettings.Map, + Mods = LobbyInfo.GlobalSettings.Mods.Select(m => "{0}@{1}".F(m, Mod.AllMods[m].Version)).ToArray() }; DispatchOrdersToClient(newConn, 0, 0, new ServerOrder("HandshakeRequest", request.Serialize()).Serialize()); } @@ -252,14 +267,14 @@ namespace OpenRA.Server Name = handshake.Client.Name, IpAddress = ((IPEndPoint)newConn.socket.RemoteEndPoint).Address.ToString(), Index = newConn.PlayerIndex, - Slot = lobbyInfo.FirstEmptySlot(), + Slot = LobbyInfo.FirstEmptySlot(), PreferredColor = handshake.Client.Color, Color = handshake.Client.Color, Country = "random", SpawnPoint = 0, Team = 0, State = Session.ClientState.NotReady, - IsAdmin = !lobbyInfo.Clients.Any(c1 => c1.IsAdmin) + IsAdmin = !LobbyInfo.Clients.Any(c1 => c1.IsAdmin) }; if (client.Slot != null) @@ -269,8 +284,8 @@ namespace OpenRA.Server // Check that the client has compatible mods var mods = handshake.Mods; - var validMod = mods.All(m => m.Contains('@')) && //valid format - mods.Count() == Game.CurrentMods.Count() && //same number + var validMod = mods.All(m => m.Contains('@')) && // valid format + mods.Count() == Game.CurrentMods.Count() && // same number mods.Select(m => Pair.New(m.Split('@')[0], m.Split('@')[1])).All(kv => Game.CurrentMods.ContainsKey(kv.First)); if (!validMod) @@ -286,7 +301,7 @@ namespace OpenRA.Server var validVersion = mods.Select(m => Pair.New(m.Split('@')[0], m.Split('@')[1])).All( kv => kv.Second == Game.CurrentMods[kv.First].Version); - if (!validVersion && !lobbyInfo.GlobalSettings.AllowVersionMismatch) + if (!validVersion && !LobbyInfo.GlobalSettings.AllowVersionMismatch) { Log.Write("server", "Rejected connection from {0}; Not running the same version.", newConn.socket.RemoteEndPoint); @@ -307,14 +322,14 @@ namespace OpenRA.Server } // Promote connection to a valid client - preConns.Remove(newConn); - conns.Add(newConn); - lobbyInfo.Clients.Add(client); + PreConns.Remove(newConn); + Conns.Add(newConn); + LobbyInfo.Clients.Add(client); Log.Write("server", "Client {0}: Accepted connection from {1}.", newConn.PlayerIndex, newConn.socket.RemoteEndPoint); - foreach (var t in ServerTraits.WithInterface()) + foreach (var t in serverTraits.WithInterface()) t.ClientJoined(this, newConn); SyncLobbyInfo(); @@ -323,9 +338,9 @@ namespace OpenRA.Server // Send initial ping SendOrderTo(newConn, "Ping", Environment.TickCount.ToString()); - if (File.Exists("{0}motd_{1}.txt".F(Platform.SupportDir, lobbyInfo.GlobalSettings.Mods[0]))) + if (File.Exists("{0}motd_{1}.txt".F(Platform.SupportDir, LobbyInfo.GlobalSettings.Mods[0]))) { - var motd = System.IO.File.ReadAllText("{0}motd_{1}.txt".F(Platform.SupportDir, lobbyInfo.GlobalSettings.Mods[0])); + var motd = System.IO.File.ReadAllText("{0}motd_{1}.txt".F(Platform.SupportDir, LobbyInfo.GlobalSettings.Mods[0])); SendOrderTo(newConn, "Message", motd); } @@ -340,30 +355,14 @@ namespace OpenRA.Server void SetOrderLag() { - if (lobbyInfo.IsSinglePlayer) - lobbyInfo.GlobalSettings.OrderLatency = 1; + if (LobbyInfo.IsSinglePlayer) + LobbyInfo.GlobalSettings.OrderLatency = 1; else - lobbyInfo.GlobalSettings.OrderLatency = 3; + LobbyInfo.GlobalSettings.OrderLatency = 3; SyncLobbyInfo(); } - public static void SyncClientToPlayerReference(Session.Client c, PlayerReference pr) - { - if (pr == null) - return; - if (pr.LockColor) - c.Color = pr.Color; - else - c.Color = c.PreferredColor; - if (pr.LockRace) - c.Country = pr.Race; - if (pr.LockSpawn) - c.SpawnPoint = pr.Spawn; - if (pr.LockTeam) - c.Team = pr.Team; - } - public void UpdateInFlightFrames(Connection conn) { if (conn.Frame == 0) @@ -374,7 +373,7 @@ namespace OpenRA.Server else inFlightFrames[conn.Frame].Add(conn); - if (conns.All(c => inFlightFrames[conn.Frame].Contains(c))) + if (Conns.All(c => inFlightFrames[conn.Frame].Contains(c))) inFlightFrames.Remove(conn.Frame); } @@ -397,7 +396,7 @@ namespace OpenRA.Server public void DispatchOrdersToClients(Connection conn, int frame, byte[] data) { var from = conn != null ? conn.PlayerIndex : 0; - foreach (var c in conns.Except(conn).ToArray()) + foreach (var c in Conns.Except(conn).ToArray()) DispatchOrdersToClient(c, from, frame, data); } @@ -416,7 +415,7 @@ namespace OpenRA.Server try { - for (; ; ) + for (;;) { var so = ServerOrder.Deserialize(br); if (so == null) return; @@ -443,8 +442,8 @@ namespace OpenRA.Server { case "Command": bool handled = false; - foreach (var t in ServerTraits.WithInterface()) - if ((handled = t.InterpretCommand(this, conn, GetClient(conn), so.Data))) + foreach (var t in serverTraits.WithInterface()) + if (handled = t.InterpretCommand(this, conn, GetClient(conn), so.Data)) break; if (!handled) @@ -481,7 +480,7 @@ namespace OpenRA.Server history.RemoveRange(0, history.Count - 5); fromClient.Latency = history.Sum() / history.Count; - fromClient.LatencyJitter = (history.Max() - history.Min())/2; + fromClient.LatencyJitter = (history.Max() - history.Min()) / 2; fromClient.LatencyHistory = history.ToArray(); if (State == ServerState.WaitingPlayers) @@ -494,18 +493,18 @@ namespace OpenRA.Server public Session.Client GetClient(Connection conn) { - return lobbyInfo.ClientWithIndex(conn.PlayerIndex); + return LobbyInfo.ClientWithIndex(conn.PlayerIndex); } public void DropClient(Connection toDrop) { - if (preConns.Contains(toDrop)) - preConns.Remove(toDrop); + if (PreConns.Contains(toDrop)) + PreConns.Remove(toDrop); else { - conns.Remove(toDrop); + Conns.Remove(toDrop); - var dropClient = lobbyInfo.Clients.FirstOrDefault(c1 => c1.Index == toDrop.PlayerIndex); + var dropClient = LobbyInfo.Clients.FirstOrDefault(c1 => c1.Index == toDrop.PlayerIndex); if (dropClient == null) return; @@ -517,16 +516,16 @@ namespace OpenRA.Server // Send disconnected order, even if still in the lobby DispatchOrdersToClients(toDrop, 0, new ServerOrder("Disconnected", "").Serialize()); - lobbyInfo.Clients.RemoveAll(c => c.Index == toDrop.PlayerIndex); + LobbyInfo.Clients.RemoveAll(c => c.Index == toDrop.PlayerIndex); // Client was the server admin // TODO: Reassign admin for game in progress via an order - if (lobbyInfo.GlobalSettings.Dedicated && dropClient.IsAdmin && State == ServerState.WaitingPlayers) + if (LobbyInfo.GlobalSettings.Dedicated && dropClient.IsAdmin && State == ServerState.WaitingPlayers) { // Remove any bots controlled by the admin - lobbyInfo.Clients.RemoveAll(c => c.Bot != null && c.BotControllerClientIndex == toDrop.PlayerIndex); + LobbyInfo.Clients.RemoveAll(c => c.Bot != null && c.BotControllerClientIndex == toDrop.PlayerIndex); - var nextAdmin = lobbyInfo.Clients.Where(c1 => c1.Bot == null) + var nextAdmin = LobbyInfo.Clients.Where(c1 => c1.Bot == null) .OrderBy(c => c.Index).FirstOrDefault(); if (nextAdmin != null) @@ -536,18 +535,18 @@ namespace OpenRA.Server } } - DispatchOrders(toDrop, toDrop.MostRecentFrame, new byte[] {0xbf}); + DispatchOrders(toDrop, toDrop.MostRecentFrame, new byte[] { 0xbf }); - if (!conns.Any()) + if (!Conns.Any()) { - FieldLoader.Load(lobbyInfo.GlobalSettings, ModData.Manifest.LobbyDefaults); + FieldLoader.Load(LobbyInfo.GlobalSettings, ModData.Manifest.LobbyDefaults); TempBans.Clear(); } - if (conns.Any() || lobbyInfo.GlobalSettings.Dedicated) + if (Conns.Any() || LobbyInfo.GlobalSettings.Dedicated) SyncLobbyInfo(); - if (!lobbyInfo.GlobalSettings.Dedicated && dropClient.IsAdmin) + if (!LobbyInfo.GlobalSettings.Dedicated && dropClient.IsAdmin) Shutdown(); } @@ -564,9 +563,9 @@ namespace OpenRA.Server { if (State == ServerState.WaitingPlayers) // Don't do this while the game is running, it breaks things! DispatchOrders(null, 0, - new ServerOrder("SyncInfo", lobbyInfo.Serialize()).Serialize()); + new ServerOrder("SyncInfo", LobbyInfo.Serialize()).Serialize()); - foreach (var t in ServerTraits.WithInterface()) + foreach (var t in serverTraits.WithInterface()) t.LobbyInfoSynced(this); } @@ -577,29 +576,29 @@ namespace OpenRA.Server Console.WriteLine("Game started"); - foreach (var c in conns) - foreach (var d in conns) + foreach (var c in Conns) + foreach (var d in Conns) DispatchOrdersToClient(c, d.PlayerIndex, 0x7FFFFFFF, new byte[] { 0xBF }); // Drop any unvalidated clients - foreach (var c in preConns.ToArray()) + foreach (var c in PreConns.ToArray()) DropClient(c); DispatchOrders(null, 0, new ServerOrder("StartGame", "").Serialize()); - foreach (var t in ServerTraits.WithInterface()) + foreach (var t in serverTraits.WithInterface()) t.GameStarted(this); // Check TimeOut if (Settings.TimeOut > 10000) { gameTimeout = new XTimer(Settings.TimeOut); - gameTimeout.Elapsed += (_,e) => - { - Console.WriteLine("Timeout at {0}!!!", e.SignalTime); - Environment.Exit(0); - }; + gameTimeout.Elapsed += (_, e) => + { + Console.WriteLine("Timeout at {0}!!!", e.SignalTime); + Environment.Exit(0); + }; gameTimeout.Enabled = true; } } diff --git a/OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs b/OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs index a2d627d602..353d948a4d 100644 --- a/OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs +++ b/OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs @@ -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(); } } } diff --git a/OpenRA.Mods.RA/ServerTraits/MasterServerPinger.cs b/OpenRA.Mods.RA/ServerTraits/MasterServerPinger.cs index dfe3de8d17..93ee72ad17 100644 --- a/OpenRA.Mods.RA/ServerTraits/MasterServerPinger.cs +++ b/OpenRA.Mods.RA/ServerTraits/MasterServerPinger.cs @@ -65,10 +65,10 @@ namespace OpenRA.Mods.RA.Server server.Settings.MasterServer + url.F( server.Settings.ExternalPort, Uri.EscapeUriString(server.Settings.Name), (int)server.State, - server.lobbyInfo.Clients.Where(c1 => c1.Bot == null).Count(), - server.lobbyInfo.Clients.Where(c1 => c1.Bot != null).Count(), + server.LobbyInfo.Clients.Where(c1 => c1.Bot == null).Count(), + server.LobbyInfo.Clients.Where(c1 => c1.Bot != null).Count(), Game.CurrentMods.Select(f => "{0}@{1}".F(f.Key, f.Value.Version)).JoinWith(","), - server.lobbyInfo.GlobalSettings.Map, + server.LobbyInfo.GlobalSettings.Map, server.Map.PlayerCount)); if (isInitialPing) diff --git a/OpenRA.Mods.RA/ServerTraits/PlayerPinger.cs b/OpenRA.Mods.RA/ServerTraits/PlayerPinger.cs index cf94efda72..0b32107b8d 100644 --- a/OpenRA.Mods.RA/ServerTraits/PlayerPinger.cs +++ b/OpenRA.Mods.RA/ServerTraits/PlayerPinger.cs @@ -33,7 +33,7 @@ namespace OpenRA.Mods.RA.Server { isInitialPing = false; lastPing = Environment.TickCount; - foreach (var p in server.conns) + foreach (var p in server.Conns) server.SendOrderTo(p, "Ping", Environment.TickCount.ToString()); } }