move CanJoin onto GameServer

This commit is contained in:
Chris Forbes
2011-09-25 15:35:40 +13:00
parent f9eb62beee
commit 567a82fd5d
3 changed files with 25 additions and 25 deletions

View File

@@ -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));
}
}
}

View File

@@ -60,7 +60,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
};
var join = panel.GetWidget<ButtonWidget>("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)
{

View File

@@ -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));
}
}
}