use List<MiniYamlNode> instead of System.Text.StringBuilder
add Deserialize methods for everything in Network.Session
This commit is contained in:
@@ -31,27 +31,27 @@ namespace OpenRA.Network
|
|||||||
{
|
{
|
||||||
var session = new Session();
|
var session = new Session();
|
||||||
|
|
||||||
var ys = MiniYaml.FromString(data);
|
var nodes = MiniYaml.FromString(data);
|
||||||
foreach (var y in ys)
|
foreach (var node in nodes)
|
||||||
{
|
{
|
||||||
var yy = y.Key.Split('@');
|
var strings = node.Key.Split('@');
|
||||||
|
|
||||||
switch (yy[0])
|
switch (strings[0])
|
||||||
{
|
{
|
||||||
case "Client":
|
case "Client":
|
||||||
session.Clients.Add(FieldLoader.Load<Client>(y.Value));
|
session.Clients.Add(Client.Deserialize(node.Value));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "ClientPing":
|
case "ClientPing":
|
||||||
session.ClientPings.Add(FieldLoader.Load<ClientPing>(y.Value));
|
session.ClientPings.Add(ClientPing.Deserialize(node.Value));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "GlobalSettings":
|
case "GlobalSettings":
|
||||||
FieldLoader.Load(session.GlobalSettings, y.Value);
|
session.GlobalSettings = Global.Deserialize(node.Value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "Slot":
|
case "Slot":
|
||||||
var s = FieldLoader.Load<Slot>(y.Value);
|
var s = Slot.Deserialize(node.Value);
|
||||||
session.Slots.Add(s.PlayerReference, s);
|
session.Slots.Add(s.PlayerReference, s);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -113,11 +113,14 @@ namespace OpenRA.Network
|
|||||||
public bool IsInvalid { get { return State == ClientState.Invalid; } }
|
public bool IsInvalid { get { return State == ClientState.Invalid; } }
|
||||||
public bool IsObserver { get { return Slot == null; } }
|
public bool IsObserver { get { return Slot == null; } }
|
||||||
|
|
||||||
public string Serialize()
|
public MiniYamlNode Serialize()
|
||||||
{
|
{
|
||||||
var clientData = new List<MiniYamlNode>();
|
return new MiniYamlNode("Client@{0}".F(this.Index), FieldSaver.Save(this));
|
||||||
clientData.Add(new MiniYamlNode("Client@{0}".F(this.Index), FieldSaver.Save(this)));
|
}
|
||||||
return clientData.WriteToString();
|
|
||||||
|
public static Client Deserialize(MiniYaml data)
|
||||||
|
{
|
||||||
|
return FieldLoader.Load<Client>(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,11 +136,14 @@ namespace OpenRA.Network
|
|||||||
public int LatencyJitter = -1;
|
public int LatencyJitter = -1;
|
||||||
public int[] LatencyHistory = { };
|
public int[] LatencyHistory = { };
|
||||||
|
|
||||||
public string Serialize()
|
public MiniYamlNode Serialize()
|
||||||
{
|
{
|
||||||
var clientData = new List<MiniYamlNode>();
|
return new MiniYamlNode("ClientPing@{0}".F(this.Index), FieldSaver.Save(this));
|
||||||
clientData.Add(new MiniYamlNode("ClientPing@{0}".F(this.Index), FieldSaver.Save(this)));
|
}
|
||||||
return clientData.WriteToString();
|
|
||||||
|
public static ClientPing Deserialize(MiniYaml data)
|
||||||
|
{
|
||||||
|
return FieldLoader.Load<ClientPing>(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,11 +159,14 @@ namespace OpenRA.Network
|
|||||||
public bool LockSpawn;
|
public bool LockSpawn;
|
||||||
public bool Required;
|
public bool Required;
|
||||||
|
|
||||||
public string Serialize()
|
public MiniYamlNode Serialize()
|
||||||
{
|
{
|
||||||
var slotData = new List<MiniYamlNode>();
|
return new MiniYamlNode("Slot@{0}".F(this.PlayerReference), FieldSaver.Save(this));
|
||||||
slotData.Add(new MiniYamlNode("Slot@{0}".F(this.PlayerReference), FieldSaver.Save(this)));
|
}
|
||||||
return slotData.WriteToString();
|
|
||||||
|
public static Slot Deserialize(MiniYaml data)
|
||||||
|
{
|
||||||
|
return FieldLoader.Load<Slot>(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,30 +190,33 @@ namespace OpenRA.Network
|
|||||||
public bool AllowVersionMismatch;
|
public bool AllowVersionMismatch;
|
||||||
public string GameUid;
|
public string GameUid;
|
||||||
|
|
||||||
public string Serialize()
|
public MiniYamlNode Serialize()
|
||||||
{
|
{
|
||||||
var globalData = new List<MiniYamlNode>();
|
return new MiniYamlNode("GlobalSettings", FieldSaver.Save(this));
|
||||||
globalData.Add(new MiniYamlNode("GlobalSettings", FieldSaver.Save(this)));
|
}
|
||||||
return globalData.WriteToString();
|
|
||||||
|
public static Global Deserialize(MiniYaml data)
|
||||||
|
{
|
||||||
|
return FieldLoader.Load<Global>(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Serialize()
|
public string Serialize()
|
||||||
{
|
{
|
||||||
var sessionData = new System.Text.StringBuilder();
|
var sessionData = new List<MiniYamlNode>();
|
||||||
|
|
||||||
foreach (var client in Clients)
|
foreach (var client in Clients)
|
||||||
sessionData.Append(client.Serialize());
|
sessionData.Add(client.Serialize());
|
||||||
|
|
||||||
foreach (var clientPing in ClientPings)
|
foreach (var clientPing in ClientPings)
|
||||||
sessionData.Append(clientPing.Serialize());
|
sessionData.Add(clientPing.Serialize());
|
||||||
|
|
||||||
foreach (var slot in Slots)
|
foreach (var slot in Slots)
|
||||||
sessionData.Append(slot.Value.Serialize());
|
sessionData.Add(slot.Value.Serialize());
|
||||||
|
|
||||||
sessionData.Append(GlobalSettings.Serialize());
|
sessionData.Add(GlobalSettings.Serialize());
|
||||||
|
|
||||||
return sessionData.ToString();
|
return sessionData.WriteToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ namespace OpenRA.Network
|
|||||||
{
|
{
|
||||||
var strings = node.Key.Split('@');
|
var strings = node.Key.Split('@');
|
||||||
if (strings[0] == "Client")
|
if (strings[0] == "Client")
|
||||||
clients.Add(FieldLoader.Load<Session.Client>(node.Value));
|
clients.Add(Session.Client.Deserialize(node.Value));
|
||||||
}
|
}
|
||||||
|
|
||||||
orderManager.LobbyInfo.Clients = clients;
|
orderManager.LobbyInfo.Clients = clients;
|
||||||
@@ -193,7 +193,7 @@ namespace OpenRA.Network
|
|||||||
var strings = node.Key.Split('@');
|
var strings = node.Key.Split('@');
|
||||||
if (strings[0] == "Slot")
|
if (strings[0] == "Slot")
|
||||||
{
|
{
|
||||||
var slot = FieldLoader.Load<Session.Slot>(node.Value);
|
var slot = Session.Slot.Deserialize(node.Value);
|
||||||
slots.Add(slot.PlayerReference, slot);
|
slots.Add(slot.PlayerReference, slot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -210,7 +210,7 @@ namespace OpenRA.Network
|
|||||||
{
|
{
|
||||||
var strings = node.Key.Split('@');
|
var strings = node.Key.Split('@');
|
||||||
if (strings[0] == "GlobalSettings")
|
if (strings[0] == "GlobalSettings")
|
||||||
FieldLoader.Load(orderManager.LobbyInfo.GlobalSettings, node.Value);
|
orderManager.LobbyInfo.GlobalSettings = Session.Global.Deserialize(node.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
SetOrderLag(orderManager);
|
SetOrderLag(orderManager);
|
||||||
@@ -226,7 +226,7 @@ namespace OpenRA.Network
|
|||||||
{
|
{
|
||||||
var strings = node.Key.Split('@');
|
var strings = node.Key.Split('@');
|
||||||
if (strings[0] == "ClientPing")
|
if (strings[0] == "ClientPing")
|
||||||
pings.Add(FieldLoader.Load<Session.ClientPing>(node.Value));
|
pings.Add(Session.ClientPing.Deserialize(node.Value));
|
||||||
}
|
}
|
||||||
|
|
||||||
orderManager.LobbyInfo.ClientPings = pings;
|
orderManager.LobbyInfo.ClientPings = pings;
|
||||||
|
|||||||
@@ -583,12 +583,12 @@ namespace OpenRA.Server
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// TODO: only need to sync the specific client that has changed to avoid conflicts
|
// TODO: only need to sync the specific client that has changed to avoid conflicts
|
||||||
var clientData = new System.Text.StringBuilder();
|
var clientData = new List<MiniYamlNode>();
|
||||||
foreach (var client in LobbyInfo.Clients)
|
foreach (var client in LobbyInfo.Clients)
|
||||||
clientData.Append(client.Serialize());
|
clientData.Add(client.Serialize());
|
||||||
|
|
||||||
DispatchOrders(null, 0,
|
DispatchOrders(null, 0,
|
||||||
new ServerOrder("SyncLobbyClients", clientData.ToString()).Serialize());
|
new ServerOrder("SyncLobbyClients", clientData.WriteToString()).Serialize());
|
||||||
|
|
||||||
foreach (var t in serverTraits.WithInterface<INotifySyncLobbyInfo>())
|
foreach (var t in serverTraits.WithInterface<INotifySyncLobbyInfo>())
|
||||||
t.LobbyInfoSynced(this);
|
t.LobbyInfoSynced(this);
|
||||||
@@ -600,12 +600,12 @@ namespace OpenRA.Server
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// TODO: don't sync all the slots if just one changed
|
// TODO: don't sync all the slots if just one changed
|
||||||
var slotData = new System.Text.StringBuilder();
|
var slotData = new List<MiniYamlNode>();
|
||||||
foreach (var slot in LobbyInfo.Slots)
|
foreach (var slot in LobbyInfo.Slots)
|
||||||
slotData.Append(slot.Value.Serialize());
|
slotData.Add(slot.Value.Serialize());
|
||||||
|
|
||||||
DispatchOrders(null, 0,
|
DispatchOrders(null, 0,
|
||||||
new ServerOrder("SyncLobbySlots", slotData.ToString()).Serialize());
|
new ServerOrder("SyncLobbySlots", slotData.WriteToString()).Serialize());
|
||||||
|
|
||||||
foreach (var t in serverTraits.WithInterface<INotifySyncLobbyInfo>())
|
foreach (var t in serverTraits.WithInterface<INotifySyncLobbyInfo>())
|
||||||
t.LobbyInfoSynced(this);
|
t.LobbyInfoSynced(this);
|
||||||
@@ -616,8 +616,11 @@ namespace OpenRA.Server
|
|||||||
if (State != ServerState.WaitingPlayers)
|
if (State != ServerState.WaitingPlayers)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
var sessionData = new List<MiniYamlNode>();
|
||||||
|
sessionData.Add(LobbyInfo.GlobalSettings.Serialize());
|
||||||
|
|
||||||
DispatchOrders(null, 0,
|
DispatchOrders(null, 0,
|
||||||
new ServerOrder("SyncLobbyGlobalSettings", LobbyInfo.GlobalSettings.Serialize()).Serialize());
|
new ServerOrder("SyncLobbyGlobalSettings", sessionData.WriteToString()).Serialize());
|
||||||
|
|
||||||
foreach (var t in serverTraits.WithInterface<INotifySyncLobbyInfo>())
|
foreach (var t in serverTraits.WithInterface<INotifySyncLobbyInfo>())
|
||||||
t.LobbyInfoSynced(this);
|
t.LobbyInfoSynced(this);
|
||||||
@@ -626,12 +629,12 @@ namespace OpenRA.Server
|
|||||||
public void SyncClientPing()
|
public void SyncClientPing()
|
||||||
{
|
{
|
||||||
// TODO: split this further into per client ping orders
|
// TODO: split this further into per client ping orders
|
||||||
var clientPings = new System.Text.StringBuilder();
|
var clientPings = new List<MiniYamlNode>();
|
||||||
foreach (var ping in LobbyInfo.ClientPings)
|
foreach (var ping in LobbyInfo.ClientPings)
|
||||||
clientPings.Append(ping.Serialize());
|
clientPings.Add(ping.Serialize());
|
||||||
|
|
||||||
DispatchOrders(null, 0,
|
DispatchOrders(null, 0,
|
||||||
new ServerOrder("SyncClientPings", clientPings.ToString()).Serialize());
|
new ServerOrder("SyncClientPings", clientPings.WriteToString()).Serialize());
|
||||||
|
|
||||||
foreach (var t in serverTraits.WithInterface<INotifySyncLobbyInfo>())
|
foreach (var t in serverTraits.WithInterface<INotifySyncLobbyInfo>())
|
||||||
t.LobbyInfoSynced(this);
|
t.LobbyInfoSynced(this);
|
||||||
@@ -669,7 +672,7 @@ namespace OpenRA.Server
|
|||||||
|
|
||||||
foreach (var t in serverTraits.WithInterface<IStartGame>())
|
foreach (var t in serverTraits.WithInterface<IStartGame>())
|
||||||
t.GameStarted(this);
|
t.GameStarted(this);
|
||||||
|
|
||||||
// Check TimeOut
|
// Check TimeOut
|
||||||
if (Settings.TimeOut > 10000)
|
if (Settings.TimeOut > 10000)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user