Files
OpenRA/OpenRA.Game/Network/GameServer.cs
2011-09-26 08:40:40 +13:00

60 lines
1.5 KiB
C#

#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System.Collections.Generic;
using System.Linq;
namespace OpenRA.Network
{
public class GameServer
{
public readonly int Id = 0;
public readonly string Name = null;
public readonly string Address = null;
public readonly int State = 0;
public readonly int Players = 0;
public readonly string Map = null;
public readonly string[] Mods = { };
public readonly int TTL = 0;
public Dictionary<string, string> UsefulMods
{
get
{
return Mods
.Where(v => v.Contains('@'))
.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));
}
}
}