Shift Client creation to the client, sent in the handshake response. Fixes the `Newbie' bug and removes a lot of fragmented behaviour on player join.
This commit is contained in:
@@ -17,30 +17,36 @@ namespace OpenRA.Network
|
||||
{
|
||||
public class HandshakeResponse
|
||||
{
|
||||
public string Name;
|
||||
public Color Color1;
|
||||
public Color Color2;
|
||||
public string[] Mods = { "ra" }; // mod names
|
||||
public string Password;
|
||||
[FieldLoader.Load] public string[] Mods;
|
||||
[FieldLoader.Load] public string Password;
|
||||
public Session.Client Client;
|
||||
|
||||
public string Serialize()
|
||||
{
|
||||
var data = new List<MiniYamlNode>();
|
||||
data.Add(new MiniYamlNode("Handshake", FieldSaver.Save(this)));
|
||||
System.Console.WriteLine("Serializing handshake response:");
|
||||
System.Console.WriteLine(data.WriteToString());
|
||||
data.Add( new MiniYamlNode( "Handshake", null,
|
||||
new string[]{ "Mods", "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)
|
||||
{
|
||||
System.Console.WriteLine("Deserializing handshake response:");
|
||||
System.Console.WriteLine(data);
|
||||
|
||||
var handshake = new HandshakeResponse();
|
||||
handshake.Client = new Session.Client();
|
||||
|
||||
var ys = MiniYaml.FromString(data);
|
||||
FieldLoader.Load(handshake, ys.First().Value);
|
||||
foreach (var y in ys)
|
||||
switch (y.Key)
|
||||
{
|
||||
case "Handshake":
|
||||
FieldLoader.Load(handshake, y.Value);
|
||||
break;
|
||||
case "Client":
|
||||
FieldLoader.Load(handshake.Client, y.Value);
|
||||
break;
|
||||
}
|
||||
return handshake;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +100,6 @@ namespace OpenRA.Network
|
||||
|
||||
case "HandshakeRequest":
|
||||
{
|
||||
Console.WriteLine("Client: Recieved HandshakeRequest");
|
||||
// Check valid mods/versions
|
||||
var serverInfo = Session.Deserialize(order.TargetString);
|
||||
var serverMods = serverInfo.GlobalSettings.Mods;
|
||||
@@ -112,22 +111,31 @@ namespace OpenRA.Network
|
||||
if (serverMods.SymmetricDifference(localMods).Count() > 0)
|
||||
throw new InvalidOperationException("Version mismatch. Client: `{0}`, Server: `{1}`"
|
||||
.F(string.Join(",",localMods), string.Join(",",serverMods)));
|
||||
|
||||
|
||||
var info = new Session.Client()
|
||||
{
|
||||
Name = Game.Settings.Player.Name,
|
||||
Color1 = Game.Settings.Player.Color1,
|
||||
Color2 = Game.Settings.Player.Color2,
|
||||
Country = "random",
|
||||
SpawnPoint = 0,
|
||||
Team = 0,
|
||||
State = Session.ClientState.NotReady
|
||||
};
|
||||
|
||||
var response = new HandshakeResponse()
|
||||
{
|
||||
Name = "Test Player",
|
||||
Color1 = Color.PaleGreen,
|
||||
Color2 = Color.PeachPuff,
|
||||
Client = info,
|
||||
Mods = localMods,
|
||||
Password = "Foo"
|
||||
};
|
||||
|
||||
orderManager.IssueOrder(Order.HandshakeResponse(response.Serialize()));
|
||||
break;
|
||||
}
|
||||
|
||||
case "SyncInfo":
|
||||
{
|
||||
Console.WriteLine("Client: Recieved SyncInfo");
|
||||
orderManager.LobbyInfo = Session.Deserialize(order.TargetString);
|
||||
|
||||
if (orderManager.FramesAhead != orderManager.LobbyInfo.GlobalSettings.OrderLatency
|
||||
|
||||
Reference in New Issue
Block a user