diff --git a/OpenRA.Game/Network/GameServer.cs b/OpenRA.Game/Network/GameServer.cs index 952b3b7f2d..ad322e4e5d 100644 --- a/OpenRA.Game/Network/GameServer.cs +++ b/OpenRA.Game/Network/GameServer.cs @@ -33,5 +33,27 @@ namespace OpenRA.Network .ToDictionary(v => v.Split('@')[0], v => v.Split('@')[1]); } } + + static bool AreVersionsCompatible(string a, string b) + { + /* dev versions are assumed compatible; if you're using one, + * we trust that you know what you're doing. */ + + return a == "{DEV_VERSION}" || b == "{DEV_VERSION}" || a == b; + } + + public bool CanJoin() + { + //"waiting for players" + if (State != 1) + return false; + + // Mods won't match if there are a different number + if (Game.CurrentMods.Count != Mods.Count()) + return false; + + return UsefulMods.All(m => Game.CurrentMods.ContainsKey(m.Key) + && AreVersionsCompatible(m.Value, Game.CurrentMods[m.Key].Version)); + } } } diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncServerBrowserLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncServerBrowserLogic.cs index eece503e66..bbb7bc4b7f 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncServerBrowserLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncServerBrowserLogic.cs @@ -60,7 +60,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic }; var join = panel.GetWidget("JOIN_BUTTON"); - join.IsDisabled = () => currentServer == null || !ServerBrowserLogic.CanJoin(currentServer); + join.IsDisabled = () => currentServer == null || !currentServer.CanJoin(); join.OnClick = () => { if (currentServer == null) @@ -127,7 +127,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic return; } - var gamesWaiting = games.Where(g => ServerBrowserLogic.CanJoin(g)); + var gamesWaiting = games.Where(g => g.CanJoin()); if (gamesWaiting.Count() == 0) { diff --git a/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs index 841832d853..2bdea984fd 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/ServerBrowserLogic.cs @@ -112,7 +112,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic return; } - var gamesWaiting = games.Where(g => CanJoin(g)); + var gamesWaiting = games.Where(g => g.CanJoin()); if (gamesWaiting.Count() == 0) { @@ -135,27 +135,5 @@ namespace OpenRA.Mods.RA.Widgets.Logic sl.AddChild(item); } } - - static bool AreVersionsCompatible(string a, string b) - { - /* dev versions are assumed compatible; if you're using one, - * we trust that you know what you're doing. */ - - return a == "{DEV_VERSION}" || b == "{DEV_VERSION}" || a == b; - } - - public static 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) && AreVersionsCompatible(kv.Second, Game.CurrentMods[kv.First].Version)); - } } }