Merge pull request #7187 from pchote/allmods

Show games from all compatible mods in the server browser.
This commit is contained in:
Oliver Brakmann
2014-12-25 23:22:05 +01:00
5 changed files with 161 additions and 141 deletions

View File

@@ -26,42 +26,31 @@ namespace OpenRA.Network
public readonly bool Protected = false;
public readonly string Started = null;
public bool CanJoin()
public readonly bool IsCompatible = false;
public readonly bool IsJoinable = false;
public readonly string ModLabel = "";
public readonly string ModId = "";
public readonly string ModVersion = "";
public GameServer(MiniYaml yaml)
{
// "waiting for players"
if (State != 1)
return false;
FieldLoader.Load(this, yaml);
if (!CompatibleVersion())
return false;
// Don't have the map locally
// TODO: We allow joining, then drop on game start if the map isn't available
if (Game.modData.MapCache[Map].Status != MapStatus.Available && !Game.Settings.Game.AllowDownloading)
return false;
return true;
}
public bool CompatibleVersion()
{
// Invalid game listing - we require one entry of id@version
ModMetadata mod;
var modVersion = Mods.Split('@');
if (modVersion.Length != 2)
return false;
if (modVersion.Length == 2 && ModMetadata.AllMods.TryGetValue(modVersion[0], out mod))
{
ModId = modVersion[0];
ModVersion = modVersion[1];
ModLabel = "{0} ({1})".F(mod.Title, modVersion[1]);
IsCompatible = Game.Settings.Debug.IgnoreVersionMismatch || ModVersion == mod.Version;
}
else
ModLabel = "Unknown mod: {0}".F(Mods);
var mod = Game.modData.Manifest.Mod;
// Different mod
// TODO: Allow mod switch when joining server
if (modVersion[0] != mod.Id)
return false;
// Same mod, but different version
if (modVersion[1] != mod.Version && !Game.Settings.Debug.IgnoreVersionMismatch)
return false;
return true;
var mapAvailable = Game.Settings.Game.AllowDownloading || Game.modData.MapCache[Map].Status == MapStatus.Available;
IsJoinable = IsCompatible && State == 1 && mapAvailable;
}
}
}

View File

@@ -93,6 +93,15 @@ namespace OpenRA.Network
case "StartGame":
{
if (Game.modData.MapCache[orderManager.LobbyInfo.GlobalSettings.Map].Status != MapStatus.Available)
{
Game.Disconnect();
Game.LoadShellMap();
// TODO: After adding a startup error dialog, notify the replay load failure.
break;
}
Game.AddChatLine(Color.White, "Server", "The game has started.");
Game.StartGame(orderManager.LobbyInfo.GlobalSettings.Map, false);
break;