Merge pull request #5115 from Mailaender/split-lobby-sync

Splitted LobbyInfo updates into smaller chunks
This commit is contained in:
Paul Chote
2014-05-17 18:37:36 +12:00
8 changed files with 317 additions and 90 deletions

View File

@@ -20,19 +20,19 @@ namespace OpenRA.Network
public string Version; public string Version;
public string Map; public string Map;
public string Serialize()
{
var data = new List<MiniYamlNode>();
data.Add(new MiniYamlNode("Handshake", FieldSaver.Save(this)));
return data.WriteToString();
}
public static HandshakeRequest Deserialize(string data) public static HandshakeRequest Deserialize(string data)
{ {
var handshake = new HandshakeRequest(); var handshake = new HandshakeRequest();
FieldLoader.Load(handshake, MiniYaml.FromString(data).First().Value); FieldLoader.Load(handshake, MiniYaml.FromString(data).First().Value);
return handshake; return handshake;
} }
public string Serialize()
{
var data = new List<MiniYamlNode>();
data.Add(new MiniYamlNode("Handshake", FieldSaver.Save(this)));
return data.WriteToString();
}
} }
public class HandshakeResponse public class HandshakeResponse
@@ -42,16 +42,6 @@ namespace OpenRA.Network
public string Password; public string Password;
[FieldLoader.Ignore] public Session.Client Client; [FieldLoader.Ignore] public Session.Client Client;
public string Serialize()
{
var data = new List<MiniYamlNode>();
data.Add( new MiniYamlNode( "Handshake", null,
new string[]{ "Mod", "Version", "Password" }.Select( p => FieldSaver.SaveField(this, p) ).ToList() ) );
data.Add(new MiniYamlNode("Client", FieldSaver.Save(Client)));
return data.WriteToString();
}
public static HandshakeResponse Deserialize(string data) public static HandshakeResponse Deserialize(string data)
{ {
var handshake = new HandshakeResponse(); var handshake = new HandshakeResponse();
@@ -59,6 +49,7 @@ namespace OpenRA.Network
var ys = MiniYaml.FromString(data); var ys = MiniYaml.FromString(data);
foreach (var y in ys) foreach (var y in ys)
{
switch (y.Key) switch (y.Key)
{ {
case "Handshake": case "Handshake":
@@ -68,7 +59,19 @@ namespace OpenRA.Network
FieldLoader.Load(handshake.Client, y.Value); FieldLoader.Load(handshake.Client, y.Value);
break; break;
} }
}
return handshake; return handshake;
} }
public string Serialize()
{
var data = new List<MiniYamlNode>();
data.Add(new MiniYamlNode("Handshake", null,
new string[] { "Mod", "Version", "Password" }.Select(p => FieldSaver.SaveField(this, p)).ToList()));
data.Add(new MiniYamlNode("Client", FieldSaver.Save(Client)));
return data.WriteToString();
}
} }
} }

View File

@@ -18,6 +18,7 @@ namespace OpenRA.Network
public class Session public class Session
{ {
public List<Client> Clients = new List<Client>(); public List<Client> Clients = new List<Client>();
public List<ClientPing> ClientPings = new List<ClientPing>();
// Keyed by the PlayerReference id that the slot corresponds to // Keyed by the PlayerReference id that the slot corresponds to
public Dictionary<string, Slot> Slots = new Dictionary<string, Slot>(); public Dictionary<string, Slot> Slots = new Dictionary<string, Slot>();
@@ -30,23 +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":
session.Clients.Add(Client.Deserialize(node.Value));
break;
case "ClientPing":
session.ClientPings.Add(ClientPing.Deserialize(node.Value));
break;
case "GlobalSettings": case "GlobalSettings":
FieldLoader.Load(session.GlobalSettings, y.Value); session.GlobalSettings = Global.Deserialize(node.Value);
break; break;
case "Client": case "Slot":
session.Clients.Add(FieldLoader.Load<Client>(y.Value)); var s = Slot.Deserialize(node.Value);
break;
case "Slot":
var s = FieldLoader.Load<Slot>(y.Value);
session.Slots.Add(s.PlayerReference, s); session.Slots.Add(s.PlayerReference, s);
break; break;
} }
@@ -107,9 +112,39 @@ namespace OpenRA.Network
public bool IsReady { get { return State == ClientState.Ready; } } public bool IsReady { get { return State == ClientState.Ready; } }
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 MiniYamlNode Serialize()
{
return new MiniYamlNode("Client@{0}".F(this.Index), FieldSaver.Save(this));
}
public static Client Deserialize(MiniYaml data)
{
return FieldLoader.Load<Client>(data);
}
}
public ClientPing PingFromClient(Client client)
{
return ClientPings.SingleOrDefault(p => p.Index == client.Index);
}
public class ClientPing
{
public int Index;
public int Latency = -1; public int Latency = -1;
public int LatencyJitter = -1; public int LatencyJitter = -1;
public int[] LatencyHistory = { }; public int[] LatencyHistory = { };
public MiniYamlNode Serialize()
{
return new MiniYamlNode("ClientPing@{0}".F(this.Index), FieldSaver.Save(this));
}
public static ClientPing Deserialize(MiniYaml data)
{
return FieldLoader.Load<ClientPing>(data);
}
} }
public class Slot public class Slot
@@ -123,6 +158,16 @@ namespace OpenRA.Network
public bool LockTeam; public bool LockTeam;
public bool LockSpawn; public bool LockSpawn;
public bool Required; public bool Required;
public MiniYamlNode Serialize()
{
return new MiniYamlNode("Slot@{0}".F(this.PlayerReference), FieldSaver.Save(this));
}
public static Slot Deserialize(MiniYaml data)
{
return FieldLoader.Load<Slot>(data);
}
} }
public class Global public class Global
@@ -144,21 +189,34 @@ namespace OpenRA.Network
public string StartingUnitsClass = "none"; public string StartingUnitsClass = "none";
public bool AllowVersionMismatch; public bool AllowVersionMismatch;
public string GameUid; public string GameUid;
public MiniYamlNode Serialize()
{
return new MiniYamlNode("GlobalSettings", FieldSaver.Save(this));
}
public static Global Deserialize(MiniYaml data)
{
return FieldLoader.Load<Global>(data);
}
} }
public string Serialize() public string Serialize()
{ {
var clientData = new List<MiniYamlNode>(); var sessionData = new List<MiniYamlNode>();
foreach (var client in Clients) foreach (var client in Clients)
clientData.Add(new MiniYamlNode("Client@{0}".F(client.Index), FieldSaver.Save(client))); sessionData.Add(client.Serialize());
foreach (var clientPing in ClientPings)
sessionData.Add(clientPing.Serialize());
foreach (var slot in Slots) foreach (var slot in Slots)
clientData.Add(new MiniYamlNode("Slot@{0}".F(slot.Key), FieldSaver.Save(slot.Value))); sessionData.Add(slot.Value.Serialize());
clientData.Add(new MiniYamlNode("GlobalSettings", FieldSaver.Save(GlobalSettings))); sessionData.Add(GlobalSettings.Serialize());
return clientData.WriteToString(); return sessionData.WriteToString();
} }
} }
} }

View File

@@ -8,6 +8,7 @@
*/ */
#endregion #endregion
using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using OpenRA.Traits; using OpenRA.Traits;
@@ -162,17 +163,76 @@ namespace OpenRA.Network
case "SyncInfo": case "SyncInfo":
{ {
orderManager.LobbyInfo = Session.Deserialize(order.TargetString); orderManager.LobbyInfo = Session.Deserialize(order.TargetString);
SetOrderLag(orderManager);
if (orderManager.FramesAhead != orderManager.LobbyInfo.GlobalSettings.OrderLatency
&& !orderManager.GameStarted)
{
orderManager.FramesAhead = orderManager.LobbyInfo.GlobalSettings.OrderLatency;
Log.Write("server", "Order lag is now {0} frames.", orderManager.LobbyInfo.GlobalSettings.OrderLatency);
}
Game.SyncLobbyInfo(); Game.SyncLobbyInfo();
break; break;
} }
case "SyncLobbyClients":
{
var clients = new List<Session.Client>();
var nodes = MiniYaml.FromString(order.TargetString);
foreach (var node in nodes)
{
var strings = node.Key.Split('@');
if (strings[0] == "Client")
clients.Add(Session.Client.Deserialize(node.Value));
}
orderManager.LobbyInfo.Clients = clients;
Game.SyncLobbyInfo();
break;
}
case "SyncLobbySlots":
{
var slots = new Dictionary<string, Session.Slot>();
var nodes = MiniYaml.FromString(order.TargetString);
foreach (var node in nodes)
{
var strings = node.Key.Split('@');
if (strings[0] == "Slot")
{
var slot = Session.Slot.Deserialize(node.Value);
slots.Add(slot.PlayerReference, slot);
}
}
orderManager.LobbyInfo.Slots = slots;
Game.SyncLobbyInfo();
break;
}
case "SyncLobbyGlobalSettings":
{
var nodes = MiniYaml.FromString(order.TargetString);
foreach (var node in nodes)
{
var strings = node.Key.Split('@');
if (strings[0] == "GlobalSettings")
orderManager.LobbyInfo.GlobalSettings = Session.Global.Deserialize(node.Value);
}
SetOrderLag(orderManager);
Game.SyncLobbyInfo();
break;
}
case "SyncClientPings":
{
var pings = new List<Session.ClientPing>();
var nodes = MiniYaml.FromString(order.TargetString);
foreach (var node in nodes)
{
var strings = node.Key.Split('@');
if (strings[0] == "ClientPing")
pings.Add(Session.ClientPing.Deserialize(node.Value));
}
orderManager.LobbyInfo.ClientPings = pings;
break;
}
case "SetStance": case "SetStance":
{ {
if (!Game.orderManager.LobbyInfo.GlobalSettings.FragileAlliances) if (!Game.orderManager.LobbyInfo.GlobalSettings.FragileAlliances)
@@ -227,5 +287,14 @@ namespace OpenRA.Network
foreach (var nsc in w.ActorsWithTrait<INotifyStanceChanged>()) foreach (var nsc in w.ActorsWithTrait<INotifyStanceChanged>())
nsc.Trait.StanceChanged(nsc.Actor, p, target, oldStance, s); nsc.Trait.StanceChanged(nsc.Actor, p, target, oldStance, s);
} }
static void SetOrderLag(OrderManager o)
{
if (o.FramesAhead != o.LobbyInfo.GlobalSettings.OrderLatency && !o.GameStarted)
{
o.FramesAhead = o.LobbyInfo.GlobalSettings.OrderLatency;
Log.Write("server", "Order lag is now {0} frames.", o.LobbyInfo.GlobalSettings.OrderLatency);
}
}
} }
} }

View File

@@ -322,6 +322,9 @@ namespace OpenRA.Server
PreConns.Remove(newConn); PreConns.Remove(newConn);
Conns.Add(newConn); Conns.Add(newConn);
LobbyInfo.Clients.Add(client); LobbyInfo.Clients.Add(client);
var clientPing = new Session.ClientPing();
clientPing.Index = client.Index;
LobbyInfo.ClientPings.Add(clientPing);
Log.Write("server", "Client {0}: Accepted connection from {1}.", Log.Write("server", "Client {0}: Accepted connection from {1}.",
newConn.PlayerIndex, newConn.socket.RemoteEndPoint); newConn.PlayerIndex, newConn.socket.RemoteEndPoint);
@@ -361,7 +364,7 @@ namespace OpenRA.Server
else else
LobbyInfo.GlobalSettings.OrderLatency = 3; LobbyInfo.GlobalSettings.OrderLatency = 3;
SyncLobbyInfo(); SyncLobbyGlobalSettings();
} }
public void UpdateInFlightFrames(Connection conn) public void UpdateInFlightFrames(Connection conn)
@@ -442,6 +445,7 @@ namespace OpenRA.Server
switch (so.Name) switch (so.Name)
{ {
case "Command": case "Command":
{
bool handled = false; bool handled = false;
foreach (var t in serverTraits.WithInterface<IInterpretCommand>()) foreach (var t in serverTraits.WithInterface<IInterpretCommand>())
if (handled = t.InterpretCommand(this, conn, GetClient(conn), so.Data)) if (handled = t.InterpretCommand(this, conn, GetClient(conn), so.Data))
@@ -454,7 +458,8 @@ namespace OpenRA.Server
} }
break; break;
}
case "HandshakeResponse": case "HandshakeResponse":
ValidateClient(conn, so.Data); ValidateClient(conn, so.Data);
break; break;
@@ -472,20 +477,22 @@ namespace OpenRA.Server
break; break;
} }
var fromClient = GetClient(conn); var pingFromClient = LobbyInfo.PingFromClient(GetClient(conn));
var history = fromClient.LatencyHistory.ToList(); if (pingFromClient == null)
return;
var history = pingFromClient.LatencyHistory.ToList();
history.Add(Environment.TickCount - pingSent); history.Add(Environment.TickCount - pingSent);
// Cap ping history at 5 values (25 seconds) // Cap ping history at 5 values (25 seconds)
if (history.Count > 5) if (history.Count > 5)
history.RemoveRange(0, history.Count - 5); history.RemoveRange(0, history.Count - 5);
fromClient.Latency = history.Sum() / history.Count; pingFromClient.Latency = history.Sum() / history.Count;
fromClient.LatencyJitter = (history.Max() - history.Min()) / 2; pingFromClient.LatencyJitter = (history.Max() - history.Min()) / 2;
fromClient.LatencyHistory = history.ToArray(); pingFromClient.LatencyHistory = history.ToArray();
if (State == ServerState.WaitingPlayers) SyncClientPing();
SyncLobbyInfo();
break; break;
} }
@@ -545,7 +552,7 @@ namespace OpenRA.Server
} }
if (Conns.Any() || LobbyInfo.GlobalSettings.Dedicated) if (Conns.Any() || LobbyInfo.GlobalSettings.Dedicated)
SyncLobbyInfo(); SyncLobbyClients();
if (!LobbyInfo.GlobalSettings.Dedicated && dropClient.IsAdmin) if (!LobbyInfo.GlobalSettings.Dedicated && dropClient.IsAdmin)
Shutdown(); Shutdown();
@@ -570,6 +577,69 @@ namespace OpenRA.Server
t.LobbyInfoSynced(this); t.LobbyInfoSynced(this);
} }
public void SyncLobbyClients()
{
if (State != ServerState.WaitingPlayers)
return;
// TODO: only need to sync the specific client that has changed to avoid conflicts
var clientData = new List<MiniYamlNode>();
foreach (var client in LobbyInfo.Clients)
clientData.Add(client.Serialize());
DispatchOrders(null, 0,
new ServerOrder("SyncLobbyClients", clientData.WriteToString()).Serialize());
foreach (var t in serverTraits.WithInterface<INotifySyncLobbyInfo>())
t.LobbyInfoSynced(this);
}
public void SyncLobbySlots()
{
if (State != ServerState.WaitingPlayers)
return;
// TODO: don't sync all the slots if just one changed
var slotData = new List<MiniYamlNode>();
foreach (var slot in LobbyInfo.Slots)
slotData.Add(slot.Value.Serialize());
DispatchOrders(null, 0,
new ServerOrder("SyncLobbySlots", slotData.WriteToString()).Serialize());
foreach (var t in serverTraits.WithInterface<INotifySyncLobbyInfo>())
t.LobbyInfoSynced(this);
}
public void SyncLobbyGlobalSettings()
{
if (State != ServerState.WaitingPlayers)
return;
var sessionData = new List<MiniYamlNode>();
sessionData.Add(LobbyInfo.GlobalSettings.Serialize());
DispatchOrders(null, 0,
new ServerOrder("SyncLobbyGlobalSettings", sessionData.WriteToString()).Serialize());
foreach (var t in serverTraits.WithInterface<INotifySyncLobbyInfo>())
t.LobbyInfoSynced(this);
}
public void SyncClientPing()
{
// TODO: split this further into per client ping orders
var clientPings = new List<MiniYamlNode>();
foreach (var ping in LobbyInfo.ClientPings)
clientPings.Add(ping.Serialize());
DispatchOrders(null, 0,
new ServerOrder("SyncClientPings", clientPings.WriteToString()).Serialize());
foreach (var t in serverTraits.WithInterface<INotifySyncLobbyInfo>())
t.LobbyInfoSynced(this);
}
public void StartGame() public void StartGame()
{ {
listener.Stop(); listener.Stop();
@@ -602,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)
{ {

View File

@@ -91,7 +91,13 @@ namespace OpenRA.Mods.RA
case "Disconnected": case "Disconnected":
case "ServerError": case "ServerError":
case "AuthenticationError": case "AuthenticationError":
case "SyncInfo": case "SyncLobbyInfo":
case "SyncClientInfo":
case "SyncLobbySlots":
case "SyncLobbyGlobalSettings":
case "SyncClientPing":
case "Ping":
case "Pong":
return; return;
} }
if (order.OrderString.StartsWith("Dev")) if (order.OrderString.StartsWith("Dev"))

View File

@@ -91,7 +91,7 @@ namespace OpenRA.Mods.RA.Server
Log.Write("server", "Player @{0} is {1}", Log.Write("server", "Player @{0} is {1}",
conn.socket.RemoteEndPoint, client.State); conn.socket.RemoteEndPoint, client.State);
server.SyncLobbyInfo(); server.SyncLobbyClients();
CheckAutoStart(server, conn, client); CheckAutoStart(server, conn, client);
@@ -106,7 +106,7 @@ namespace OpenRA.Mods.RA.Server
return true; return true;
} }
if (server.LobbyInfo.Slots.Any(sl => sl.Value.Required && if (server.LobbyInfo.Slots.Any(sl => sl.Value.Required &&
server.LobbyInfo.ClientInSlot(sl.Key) == null)) server.LobbyInfo.ClientInSlot(sl.Key) == null))
{ {
server.SendOrderTo(conn, "Message", "Unable to start the game until required slots are full."); server.SendOrderTo(conn, "Message", "Unable to start the game until required slots are full.");
@@ -130,8 +130,7 @@ namespace OpenRA.Mods.RA.Server
client.Slot = s; client.Slot = s;
S.SyncClientToPlayerReference(client, server.Map.Players[s]); S.SyncClientToPlayerReference(client, server.Map.Players[s]);
server.SyncLobbyClients();
server.SyncLobbyInfo();
CheckAutoStart(server, conn, client); CheckAutoStart(server, conn, client);
return true; return true;
@@ -141,7 +140,7 @@ namespace OpenRA.Mods.RA.Server
{ {
if (bool.TryParse(s, out server.LobbyInfo.GlobalSettings.AllowSpectators)) if (bool.TryParse(s, out server.LobbyInfo.GlobalSettings.AllowSpectators))
{ {
server.SyncLobbyInfo(); server.SyncLobbyGlobalSettings();
return true; return true;
} }
else else
@@ -158,7 +157,7 @@ namespace OpenRA.Mods.RA.Server
client.Slot = null; client.Slot = null;
client.SpawnPoint = 0; client.SpawnPoint = 0;
client.Color = HSLColor.FromRGB(255, 255, 255); client.Color = HSLColor.FromRGB(255, 255, 255);
server.SyncLobbyInfo(); server.SyncLobbyClients();
return true; return true;
} }
else else
@@ -167,7 +166,7 @@ namespace OpenRA.Mods.RA.Server
{ "slot_close", { "slot_close",
s => s =>
{ {
if (!ValidateSlotCommand( server, conn, client, s, true )) if (!ValidateSlotCommand(server, conn, client, s, true))
return false; return false;
// kick any player that's in the slot // kick any player that's in the slot
@@ -175,10 +174,14 @@ namespace OpenRA.Mods.RA.Server
if (occupant != null) if (occupant != null)
{ {
if (occupant.Bot != null) if (occupant.Bot != null)
{
server.LobbyInfo.Clients.Remove(occupant); server.LobbyInfo.Clients.Remove(occupant);
var ping = server.LobbyInfo.PingFromClient(occupant);
server.LobbyInfo.ClientPings.Remove(ping);
}
else else
{ {
var occupantConn = server.Conns.FirstOrDefault( c => c.PlayerIndex == occupant.Index ); var occupantConn = server.Conns.FirstOrDefault(c => c.PlayerIndex == occupant.Index);
if (occupantConn != null) if (occupantConn != null)
{ {
server.SendOrderTo(occupantConn, "ServerError", "Your slot was closed by the host"); server.SendOrderTo(occupantConn, "ServerError", "Your slot was closed by the host");
@@ -188,7 +191,7 @@ namespace OpenRA.Mods.RA.Server
} }
server.LobbyInfo.Slots[s].Closed = true; server.LobbyInfo.Slots[s].Closed = true;
server.SyncLobbyInfo(); server.SyncLobbySlots();
return true; return true;
}}, }},
{ "slot_open", { "slot_open",
@@ -199,13 +202,18 @@ namespace OpenRA.Mods.RA.Server
var slot = server.LobbyInfo.Slots[s]; var slot = server.LobbyInfo.Slots[s];
slot.Closed = false; slot.Closed = false;
server.SyncLobbySlots();
// Slot may have a bot in it // 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) if (occupant != null && occupant.Bot != null)
{
server.LobbyInfo.Clients.Remove(occupant); server.LobbyInfo.Clients.Remove(occupant);
var ping = server.LobbyInfo.PingFromClient(occupant);
server.LobbyInfo.ClientPings.Remove(ping);
}
server.SyncLobbyClients();
server.SyncLobbyInfo();
return true; return true;
}}, }},
{ "slot_bot", { "slot_bot",
@@ -272,7 +280,8 @@ namespace OpenRA.Mods.RA.Server
} }
S.SyncClientToPlayerReference(bot, server.Map.Players[parts[0]]); S.SyncClientToPlayerReference(bot, server.Map.Players[parts[0]]);
server.SyncLobbyInfo(); server.SyncLobbyClients();
server.SyncLobbySlots();
return true; return true;
}}, }},
{ "map", { "map",
@@ -290,6 +299,7 @@ namespace OpenRA.Mods.RA.Server
return true; return true;
} }
server.LobbyInfo.GlobalSettings.Map = s; server.LobbyInfo.GlobalSettings.Map = s;
var oldSlots = server.LobbyInfo.Slots.Keys.ToArray(); var oldSlots = server.LobbyInfo.Slots.Keys.ToArray();
LoadMap(server); LoadMap(server);
SetDefaultDifficulty(server); SetDefaultDifficulty(server);
@@ -342,7 +352,7 @@ namespace OpenRA.Mods.RA.Server
} }
bool.TryParse(s, out server.LobbyInfo.GlobalSettings.FragileAlliances); bool.TryParse(s, out server.LobbyInfo.GlobalSettings.FragileAlliances);
server.SyncLobbyInfo(); server.SyncLobbyGlobalSettings();
return true; return true;
}}, }},
{ "allowcheats", { "allowcheats",
@@ -361,7 +371,7 @@ namespace OpenRA.Mods.RA.Server
} }
bool.TryParse(s, out server.LobbyInfo.GlobalSettings.AllowCheats); bool.TryParse(s, out server.LobbyInfo.GlobalSettings.AllowCheats);
server.SyncLobbyInfo(); server.SyncLobbyGlobalSettings();
return true; return true;
}}, }},
{ "shroud", { "shroud",
@@ -380,7 +390,7 @@ namespace OpenRA.Mods.RA.Server
} }
bool.TryParse(s, out server.LobbyInfo.GlobalSettings.Shroud); bool.TryParse(s, out server.LobbyInfo.GlobalSettings.Shroud);
server.SyncLobbyInfo(); server.SyncLobbyGlobalSettings();
return true; return true;
}}, }},
{ "fog", { "fog",
@@ -400,7 +410,7 @@ namespace OpenRA.Mods.RA.Server
bool.TryParse(s, out server.LobbyInfo.GlobalSettings.Fog); bool.TryParse(s, out server.LobbyInfo.GlobalSettings.Fog);
server.SyncLobbyInfo(); server.SyncLobbyGlobalSettings();
return true; return true;
}}, }},
{ "assignteams", { "assignteams",
@@ -441,7 +451,7 @@ namespace OpenRA.Mods.RA.Server
player.Team = assigned++ * teamCount / playerCount + 1; player.Team = assigned++ * teamCount / playerCount + 1;
} }
server.SyncLobbyInfo(); server.SyncLobbyClients();
return true; return true;
}}, }},
{ "crates", { "crates",
@@ -460,7 +470,7 @@ namespace OpenRA.Mods.RA.Server
} }
bool.TryParse(s, out server.LobbyInfo.GlobalSettings.Crates); bool.TryParse(s, out server.LobbyInfo.GlobalSettings.Crates);
server.SyncLobbyInfo(); server.SyncLobbyGlobalSettings();
return true; return true;
}}, }},
{ "allybuildradius", { "allybuildradius",
@@ -479,7 +489,7 @@ namespace OpenRA.Mods.RA.Server
} }
bool.TryParse(s, out server.LobbyInfo.GlobalSettings.AllyBuildRadius); bool.TryParse(s, out server.LobbyInfo.GlobalSettings.AllyBuildRadius);
server.SyncLobbyInfo(); server.SyncLobbyGlobalSettings();
return true; return true;
}}, }},
{ "difficulty", { "difficulty",
@@ -499,7 +509,7 @@ namespace OpenRA.Mods.RA.Server
} }
server.LobbyInfo.GlobalSettings.Difficulty = s; server.LobbyInfo.GlobalSettings.Difficulty = s;
server.SyncLobbyInfo(); server.SyncLobbyGlobalSettings();
return true; return true;
}}, }},
{ "startingunits", { "startingunits",
@@ -518,7 +528,7 @@ namespace OpenRA.Mods.RA.Server
} }
server.LobbyInfo.GlobalSettings.StartingUnitsClass = s; server.LobbyInfo.GlobalSettings.StartingUnitsClass = s;
server.SyncLobbyInfo(); server.SyncLobbyGlobalSettings();
return true; return true;
}}, }},
{ "startingcash", { "startingcash",
@@ -537,7 +547,8 @@ namespace OpenRA.Mods.RA.Server
} }
server.LobbyInfo.GlobalSettings.StartingCash = Exts.ParseIntegerInvariant(s); server.LobbyInfo.GlobalSettings.StartingCash = Exts.ParseIntegerInvariant(s);
server.SyncLobbyInfo(); server.SyncLobbyGlobalSettings();
return true; return true;
}}, }},
{ "kick", { "kick",
@@ -581,7 +592,8 @@ namespace OpenRA.Mods.RA.Server
server.TempBans.Add(kickConnIP); server.TempBans.Add(kickConnIP);
} }
server.SyncLobbyInfo(); server.SyncLobbyClients();
server.SyncLobbySlots();
return true; return true;
}}, }},
{ "name", { "name",
@@ -589,7 +601,7 @@ namespace OpenRA.Mods.RA.Server
{ {
Log.Write("server", "Player@{0} is now known as {1}", conn.socket.RemoteEndPoint, s); Log.Write("server", "Player@{0} is now known as {1}", conn.socket.RemoteEndPoint, s);
client.Name = s; client.Name = s;
server.SyncLobbyInfo(); server.SyncLobbyClients();
return true; return true;
}}, }},
{ "race", { "race",
@@ -607,7 +619,7 @@ namespace OpenRA.Mods.RA.Server
return true; return true;
targetClient.Country = parts[1]; targetClient.Country = parts[1];
server.SyncLobbyInfo(); server.SyncLobbyClients();
return true; return true;
}}, }},
{ "team", { "team",
@@ -632,7 +644,7 @@ namespace OpenRA.Mods.RA.Server
} }
targetClient.Team = team; targetClient.Team = team;
server.SyncLobbyInfo(); server.SyncLobbyClients();
return true; return true;
}}, }},
{ "spawn", { "spawn",
@@ -668,7 +680,7 @@ namespace OpenRA.Mods.RA.Server
} }
targetClient.SpawnPoint = spawnPoint; targetClient.SpawnPoint = spawnPoint;
server.SyncLobbyInfo(); server.SyncLobbyClients();
return true; return true;
}}, }},
{ "color", { "color",
@@ -687,7 +699,7 @@ namespace OpenRA.Mods.RA.Server
var ci = parts[1].Split(',').Select(cc => Exts.ParseIntegerInvariant(cc)).ToArray(); var ci = parts[1].Split(',').Select(cc => Exts.ParseIntegerInvariant(cc)).ToArray();
targetClient.Color = targetClient.PreferredColor = new HSLColor((byte)ci[0], (byte)ci[1], (byte)ci[2]); targetClient.Color = targetClient.PreferredColor = new HSLColor((byte)ci[0], (byte)ci[1], (byte)ci[2]);
server.SyncLobbyInfo(); server.SyncLobbyClients();
return true; return true;
}} }}
}; };

View File

@@ -71,8 +71,10 @@ namespace OpenRA.Mods.RA.Widgets.Logic
}; };
admin.IsVisible = () => orderManager.LobbyInfo.ClientWithIndex(clientIndex).IsAdmin; admin.IsVisible = () => orderManager.LobbyInfo.ClientWithIndex(clientIndex).IsAdmin;
latency.GetText = () => LobbyUtils.LatencyDescription(orderManager.LobbyInfo.ClientWithIndex(clientIndex).Latency); var client = orderManager.LobbyInfo.ClientWithIndex(clientIndex);
latency.GetColor = () => LobbyUtils.LatencyColor(orderManager.LobbyInfo.ClientWithIndex(clientIndex).Latency); var ping = orderManager.LobbyInfo.PingFromClient(client);
latency.GetText = () => LobbyUtils.LatencyDescription(ping);
latency.GetColor = () => LobbyUtils.LatencyColor(ping);
var address = orderManager.LobbyInfo.ClientWithIndex(clientIndex).IpAddress; var address = orderManager.LobbyInfo.ClientWithIndex(clientIndex).IpAddress;
if (address == "127.0.0.1" && UPnP.NatDevice != null) if (address == "127.0.0.1" && UPnP.NatDevice != null)
address = UPnP.NatDevice.GetExternalIP().ToString(); address = UPnP.NatDevice.GetExternalIP().ToString();

View File

@@ -183,26 +183,32 @@ namespace OpenRA.Mods.RA.Widgets.Logic
orderManager.IssueOrder(Order.Command("spawn {0} {1}".F((playerToMove ?? orderManager.LocalClient).Index, selectedSpawn))); orderManager.IssueOrder(Order.Command("spawn {0} {1}".F((playerToMove ?? orderManager.LocalClient).Index, selectedSpawn)));
} }
public static Color LatencyColor(int latency) public static Color LatencyColor(Session.ClientPing ping)
{ {
if (ping == null)
return Color.Gray;
// Levels set relative to the default order lag of 3 net ticks (360ms) // Levels set relative to the default order lag of 3 net ticks (360ms)
// TODO: Adjust this once dynamic lag is implemented // TODO: Adjust this once dynamic lag is implemented
if (latency < 0) if (ping.Latency < 0)
return Color.Gray; return Color.Gray;
if (latency < 300) if (ping.Latency < 300)
return Color.LimeGreen; return Color.LimeGreen;
if (latency < 600) if (ping.Latency < 600)
return Color.Orange; return Color.Orange;
return Color.Red; return Color.Red;
} }
public static string LatencyDescription(int latency) public static string LatencyDescription(Session.ClientPing ping)
{ {
if (latency < 0) if (ping == null)
return "Unknown"; return "Unknown";
if (latency < 300)
if (ping.Latency < 0)
return "Unknown";
if (ping.Latency < 300)
return "Good"; return "Good";
if (latency < 600) if (ping.Latency < 600)
return "Moderate"; return "Moderate";
return "Poor"; return "Poor";
} }
@@ -236,7 +242,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
block.IsVisible = () => visible; block.IsVisible = () => visible;
if (visible) if (visible)
block.Get<ColorBlockWidget>("LATENCY_COLOR").GetColor = () => LatencyColor(c.Latency); block.Get<ColorBlockWidget>("LATENCY_COLOR").GetColor = () => LatencyColor(
orderManager.LobbyInfo.PingFromClient(c));
var tooltip = parent.Get<ClientTooltipRegionWidget>("CLIENT_REGION"); var tooltip = parent.Get<ClientTooltipRegionWidget>("CLIENT_REGION");
tooltip.IsVisible = () => visible; tooltip.IsVisible = () => visible;