added MasterServerQuery. downloads the server list and constructs IEnumerable<GameServer> from it.

This commit is contained in:
Chris Forbes
2010-03-15 20:51:57 +13:00
parent 15170694e5
commit f1841021c4
2 changed files with 34 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using OpenRA.FileFormats;
namespace OpenRA.Server
{
static class MasterServerQuery
{
public static IEnumerable<GameServer> GetGameList(string masterServerUrl)
{
var wc = new WebClient();
var data = wc.DownloadData(masterServerUrl + "list.php");
var str = Encoding.UTF8.GetString(data);
var yaml = MiniYaml.FromString(str);
return yaml.Select(a => { var gs = new GameServer(); FieldLoader.Load(gs, a.Value); return gs; });
}
}
class GameServer
{
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;
}
}