Handshake mod versions and map. Bump the protocol version.
This commit is contained in:
@@ -15,6 +15,26 @@ using OpenRA.FileFormats;
|
||||
|
||||
namespace OpenRA.Network
|
||||
{
|
||||
public class HandshakeRequest
|
||||
{
|
||||
[FieldLoader.Load] public string[] Mods;
|
||||
[FieldLoader.Load] 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)
|
||||
{
|
||||
var handshake = new HandshakeRequest();
|
||||
FieldLoader.Load(handshake, MiniYaml.FromString(data).First().Value);
|
||||
return handshake;
|
||||
}
|
||||
}
|
||||
|
||||
public class HandshakeResponse
|
||||
{
|
||||
[FieldLoader.Load] public string[] Mods;
|
||||
|
||||
@@ -12,6 +12,7 @@ using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
using System;
|
||||
using OpenRA.FileFormats;
|
||||
|
||||
namespace OpenRA.Network
|
||||
{
|
||||
@@ -100,17 +101,42 @@ namespace OpenRA.Network
|
||||
|
||||
case "HandshakeRequest":
|
||||
{
|
||||
var request = HandshakeRequest.Deserialize(order.TargetString);
|
||||
|
||||
// Check valid mods/versions
|
||||
var serverInfo = Session.Deserialize(order.TargetString);
|
||||
var serverMods = serverInfo.GlobalSettings.Mods;
|
||||
var serverMods = request.Mods;
|
||||
var localMods = orderManager.LobbyInfo.GlobalSettings.Mods;
|
||||
|
||||
// TODO: Check that the map exists on the client
|
||||
bool valid = true;
|
||||
if (localMods.Length != serverMods.Length)
|
||||
valid = false;
|
||||
else
|
||||
foreach (var m in serverMods)
|
||||
{
|
||||
var parts = m.Split('@');
|
||||
if (!localMods.Contains(parts[0]))
|
||||
{
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
if (parts[1] == "{DEV_VERSION}" || Mod.AllMods[parts[0]].Version == "{DEV_VERSION}")
|
||||
continue;
|
||||
|
||||
// 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)));
|
||||
if (parts[1] != Mod.AllMods[parts[0]].Version)
|
||||
{
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!valid)
|
||||
throw new InvalidOperationException("Mod/Version mismatch. Client: `{0}`, Server: `{1}`".F(
|
||||
string.Join(",",localMods.Select(m => "{0}@{1}".F(m, Mod.AllMods[m].Version)).ToArray()),
|
||||
string.Join(",",serverMods)));
|
||||
|
||||
// Check that the map exists on the client
|
||||
if (!Game.modData.AvailableMaps.ContainsKey(request.Map))
|
||||
throw new InvalidOperationException("Missing map {0}".F(request.Map));
|
||||
|
||||
var info = new Session.Client()
|
||||
{
|
||||
|
||||
@@ -13,6 +13,6 @@ namespace OpenRA.Server
|
||||
public static class ProtocolVersion
|
||||
{
|
||||
// you *must* increment this whenever you make an incompatible protocol change
|
||||
public static readonly int Version = 6;
|
||||
public static readonly int Version = 7;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,7 +167,12 @@ namespace OpenRA.Server
|
||||
preConns.Add(newConn);
|
||||
|
||||
// Dispatch a handshake order
|
||||
DispatchOrdersToClient(newConn, 0, 0, new ServerOrder("HandshakeRequest", lobbyInfo.Serialize()).Serialize());
|
||||
var request = new HandshakeRequest()
|
||||
{
|
||||
Map = lobbyInfo.GlobalSettings.Map,
|
||||
Mods = lobbyInfo.GlobalSettings.Mods.Select(m => "{0}@{1}".F(m,Mod.AllMods[m].Version)).ToArray()
|
||||
};
|
||||
DispatchOrdersToClient(newConn, 0, 0, new ServerOrder("HandshakeRequest", request.Serialize()).Serialize());
|
||||
}
|
||||
catch (Exception) { DropClient(newConn); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user