move CanJoin onto GameServer
This commit is contained in:
@@ -33,5 +33,27 @@ namespace OpenRA.Network
|
|||||||
.ToDictionary(v => v.Split('@')[0], v => v.Split('@')[1]);
|
.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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
};
|
};
|
||||||
|
|
||||||
var join = panel.GetWidget<ButtonWidget>("JOIN_BUTTON");
|
var join = panel.GetWidget<ButtonWidget>("JOIN_BUTTON");
|
||||||
join.IsDisabled = () => currentServer == null || !ServerBrowserLogic.CanJoin(currentServer);
|
join.IsDisabled = () => currentServer == null || !currentServer.CanJoin();
|
||||||
join.OnClick = () =>
|
join.OnClick = () =>
|
||||||
{
|
{
|
||||||
if (currentServer == null)
|
if (currentServer == null)
|
||||||
@@ -127,7 +127,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var gamesWaiting = games.Where(g => ServerBrowserLogic.CanJoin(g));
|
var gamesWaiting = games.Where(g => g.CanJoin());
|
||||||
|
|
||||||
if (gamesWaiting.Count() == 0)
|
if (gamesWaiting.Count() == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var gamesWaiting = games.Where(g => CanJoin(g));
|
var gamesWaiting = games.Where(g => g.CanJoin());
|
||||||
|
|
||||||
if (gamesWaiting.Count() == 0)
|
if (gamesWaiting.Count() == 0)
|
||||||
{
|
{
|
||||||
@@ -135,27 +135,5 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
sl.AddChild(item);
|
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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user