diff --git a/OpenRA.Game/Network/Session.cs b/OpenRA.Game/Network/Session.cs index 2dc549a270..953f0ceb5a 100644 --- a/OpenRA.Game/Network/Session.cs +++ b/OpenRA.Game/Network/Session.cs @@ -8,6 +8,7 @@ */ #endregion +using System; using System.Collections.Generic; using System.Drawing; using System.Linq; @@ -18,10 +19,49 @@ namespace OpenRA.Network public class Session { public List Clients = new List(); + // Keyed by the PlayerReference id that the slot corresponds to public Dictionary Slots = new Dictionary(); + public Global GlobalSettings = new Global(); + public static Session Deserialize(string data) + { + try + { + var session = new Session(Game.Settings.Game.Mods); + + var ys = MiniYaml.FromString(data); + foreach (var y in ys) + { + var yy = y.Key.Split('@'); + + switch (yy[0]) + { + case "GlobalSettings": + FieldLoader.Load(session.GlobalSettings, y.Value); + break; + + case "Client": + session.Clients.Add(FieldLoader.Load(y.Value)); + break; + + case "Slot": + var s = FieldLoader.Load(y.Value); + session.Slots.Add(s.PlayerReference, s); + break; + } + } + + return session; + } + catch (InvalidOperationException) + { + Log.Write("exception", "Session deserialized invalid MiniYaml:\n{0}".F(data)); + throw; + } + } + public Client ClientWithIndex(int clientID) { return Clients.SingleOrDefault(c => c.Index == clientID); @@ -64,7 +104,7 @@ namespace OpenRA.Network public bool IsObserver { get { return Slot == null; } } public int Latency = -1; public int LatencyJitter = -1; - public int[] LatencyHistory = {}; + public int[] LatencyHistory = { }; } public class Slot @@ -119,34 +159,5 @@ namespace OpenRA.Network return clientData.WriteToString(); } - - public static Session Deserialize(string data) - { - var session = new Session(Game.Settings.Game.Mods); - - var ys = MiniYaml.FromString(data); - foreach (var y in ys) - { - var yy = y.Key.Split('@'); - - switch (yy[0]) - { - case "GlobalSettings": - FieldLoader.Load(session.GlobalSettings, y.Value); - break; - - case "Client": - session.Clients.Add(FieldLoader.Load(y.Value)); - break; - - case "Slot": - var s = FieldLoader.Load(y.Value); - session.Slots.Add(s.PlayerReference, s); - break; - } - } - - return session; - } } }