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

@@ -13,13 +13,14 @@ using System.Collections.Generic;
using System.Net;
using OpenRA.Server;
using S = OpenRA.Server.Server;
using System.Linq;
namespace OpenRA.Mods.RA.Server
{
public class MasterServerPinger : ServerTrait, ITick, INotifySyncLobbyInfo, IStartGame
{
const int MasterPingInterval = 60 * 3; // 3 minutes. server has a 5 minute TTL for games, so give ourselves a bit
// of leeway.
// of leeway.
public int TickTimeout { get { return MasterPingInterval * 10000; } }
public void Tick(S server)
{
@@ -29,10 +30,10 @@ namespace OpenRA.Mods.RA.Server
lock (masterServerMessages)
while (masterServerMessages.Count > 0)
server.SendChat(null, masterServerMessages.Dequeue());
}
public void LobbyInfoSynced(S server) { PingMasterServer(server); }
public void GameStarted(S server) { PingMasterServer(server); }
@@ -42,7 +43,7 @@ namespace OpenRA.Mods.RA.Server
static string masterServerUrl = Game.Settings.Server.MasterServer;
static int externalPort = Game.Settings.Server.ExternalPort;
static bool isInitialPing = true;
static volatile bool isBusy;
static Queue<string> masterServerMessages = new Queue<string>();
public static void PingMasterServer(S server)
@@ -62,13 +63,13 @@ namespace OpenRA.Mods.RA.Server
using (var wc = new WebClient())
{
wc.Proxy = null;
wc.DownloadData(
masterServerUrl + url.F(
externalPort, Uri.EscapeUriString(server.Name),
server.GameStarted ? 2 : 1, // todo: post-game states, etc.
server.lobbyInfo.Clients.Count,
string.Join(",", server.lobbyInfo.GlobalSettings.Mods),
server.lobbyInfo.GlobalSettings.Map));
wc.DownloadData(
masterServerUrl + url.F(
externalPort, Uri.EscapeUriString(server.Name),
server.GameStarted ? 2 : 1, // todo: post-game states, etc.
server.lobbyInfo.Clients.Count,
string.Join(",", Game.CurrentMods.Select(f => "{0}@{1}".F(f.Key, f.Value.Version)).ToArray()),
server.lobbyInfo.GlobalSettings.Map));
if (isInitialPing)
{
@@ -78,11 +79,11 @@ namespace OpenRA.Mods.RA.Server
}
}
}
catch (Exception ex)
catch(Exception ex)
{
Log.Write("server", ex.ToString());
lock (masterServerMessages)
masterServerMessages.Enqueue("Master server communication failed.");
lock( masterServerMessages )
masterServerMessages.Enqueue( "Master server communication failed." );
}
isBusy = false;

View File

@@ -149,8 +149,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
return;
}
// only "waiting for players"
var gamesWaiting = games.Where(g => g.State == 1);
var gamesWaiting = games.Where(g => CanJoin(g));
if (gamesWaiting.Count() == 0)
{
@@ -179,6 +178,22 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
i++;
}
}
bool CanJoin(GameServer game)
{
//"waiting for players"
if (game.State != 1)
return false;
// Mods won't match if there are a different number
if (Game.CurrentMods.Count != game.Mods.Count())
return false;
return game.Mods.All( m => m.Contains('@')) && game.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));
}
}
public class DirectConnectDelegate : IWidgetDelegate