Client/server handshake. Only checks that the correct mods are active.

This commit is contained in:
Paul Chote
2010-12-31 11:41:25 +13:00
parent dc012c0faf
commit 8f9e32dcc0
5 changed files with 145 additions and 24 deletions

View File

@@ -0,0 +1,47 @@
#region Copyright & License Information
/*
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see LICENSE.
*/
#endregion
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.FileFormats;
namespace OpenRA.Network
{
public class HandshakeResponse
{
public string Name;
public Color Color1;
public Color Color2;
public string[] Mods = { "ra" }; // mod names
public string Password;
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());
return data.WriteToString();
}
public static HandshakeResponse Deserialize(string data)
{
System.Console.WriteLine("Deserializing handshake response:");
System.Console.WriteLine(data);
var handshake = new HandshakeResponse();
var ys = MiniYaml.FromString(data);
FieldLoader.Load(handshake, ys.First().Value);
return handshake;
}
}
}

View File

@@ -195,6 +195,11 @@ namespace OpenRA
return new Order("TeamChat", null, false) { IsImmediate = true, TargetString = text };
}
public static Order HandshakeResponse(string text)
{
return new Order("HandshakeResponse", null, false) { IsImmediate = true, TargetString = text };
}
public static Order Command(string text)
{
return new Order("Command", null, false) { IsImmediate = true, TargetString = text };

View File

@@ -11,6 +11,7 @@
using System.Drawing;
using System.Linq;
using OpenRA.Traits;
using System;
namespace OpenRA.Network
{
@@ -96,8 +97,37 @@ namespace OpenRA.Network
Game.StartGame(orderManager.LobbyInfo.GlobalSettings.Map);
break;
}
case "HandshakeRequest":
{
Console.WriteLine("Client: Recieved HandshakeRequest");
// Check valid mods/versions
var serverInfo = Session.Deserialize(order.TargetString);
var serverMods = serverInfo.GlobalSettings.Mods;
var localMods = orderManager.LobbyInfo.GlobalSettings.Mods;
// TODO: Check that the map exists on the client
// Todo: Display a friendly dialog
if (serverMods.SymmetricDifference(localMods).Count() > 0)
throw new InvalidOperationException("Version mismatch. Client: `{0}`, Server: `{1}`"
.F(string.Join(",",localMods), string.Join(",",serverMods)));
var response = new HandshakeResponse()
{
Name = "Test Player",
Color1 = Color.PaleGreen,
Color2 = Color.PeachPuff,
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