Mod version validation

- Game.CurrentMods property to query the current mods when no orderManager accessible
- Server sends mod versions to master server on ping
- Client sends mod versions on handshake response
- Validate match on server side of handshake, not client side
This commit is contained in:
alzeih
2011-01-08 00:25:30 +13:00
committed by Chris Forbes
parent 8264c6c8dc
commit 5c343caeaf
5 changed files with 57 additions and 50 deletions

View File

@@ -194,6 +194,11 @@ namespace OpenRA
{
get { return orderManager.Connection.LocalClientId == 0; }
}
public static Dictionary<String, Mod> CurrentMods
{
get { return Mod.AllMods.Where( k => orderManager.LobbyInfo.GlobalSettings.Mods.Contains( k.Key )).ToDictionary( k => k.Key, k => k.Value ); }
}
static Modifiers modifiers;
public static Modifiers GetModifierKeys() { return modifiers; }

View File

@@ -103,37 +103,6 @@ namespace OpenRA.Network
{
var request = HandshakeRequest.Deserialize(order.TargetString);
// Check valid mods/versions
var serverMods = request.Mods;
var localMods = orderManager.LobbyInfo.GlobalSettings.Mods;
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;
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));
@@ -149,6 +118,7 @@ namespace OpenRA.Network
State = Session.ClientState.NotReady
};
var localMods = orderManager.LobbyInfo.GlobalSettings.Mods.Select(m => "{0}@{1}".F(m,Mod.AllMods[m].Version)).ToArray();
var response = new HandshakeResponse()
{
Client = info,

View File

@@ -188,8 +188,24 @@ namespace OpenRA.Server
DropClient(newConn);
return;
}
var client = HandshakeResponse.Deserialize(data).Client;
var handshake = HandshakeResponse.Deserialize(data);
var client = handshake.Client;
var mods = handshake.Mods;
// Check that the client has compatable mods
var valid = mods.All( m => m.Contains('@')) && //valid format
mods.Count() == Game.CurrentMods.Count() && //same number
mods.Select( m => Pair.New(m.Split('@')[0], m.Split('@')[1])).All(kv => Game.CurrentMods.ContainsKey(kv.First) &&
(kv.Second == "{DEV_VERSION}" || Game.CurrentMods[kv.First].Version == "{DEV_VERSION}" || kv.Second == Game.CurrentMods[kv.First].Version));
if (!valid)
{
Log.Write("server", "Rejected connection from {0}; mods do not match.",
newConn.socket.RemoteEndPoint);
DropClient(newConn);
return;
}
// Promote connection to a valid client
preConns.Remove(newConn);