From f1841021c4681e8de8a7a8a7cc491c9ec2398030 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Mon, 15 Mar 2010 20:51:57 +1300 Subject: [PATCH] added MasterServerQuery. downloads the server list and constructs IEnumerable from it. --- OpenRA.Game/OpenRA.Game.csproj | 1 + OpenRA.Game/Server/MasterServerQuery.cs | 33 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 OpenRA.Game/Server/MasterServerQuery.cs diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 5065c891b2..0c313a8739 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -104,6 +104,7 @@ + diff --git a/OpenRA.Game/Server/MasterServerQuery.cs b/OpenRA.Game/Server/MasterServerQuery.cs new file mode 100644 index 0000000000..4b09e4cd27 --- /dev/null +++ b/OpenRA.Game/Server/MasterServerQuery.cs @@ -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 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; + } +}