added MasterServerQuery. downloads the server list and constructs IEnumerable<GameServer> from it.
This commit is contained in:
@@ -104,6 +104,7 @@
|
||||
<Compile Include="Selection.cs" />
|
||||
<Compile Include="Server\Connection.cs" />
|
||||
<Compile Include="Server\Exts.cs" />
|
||||
<Compile Include="Server\MasterServerQuery.cs" />
|
||||
<Compile Include="Server\Server.cs" />
|
||||
<Compile Include="Server\ServerOrder.cs" />
|
||||
<Compile Include="Shroud.cs" />
|
||||
|
||||
33
OpenRA.Game/Server/MasterServerQuery.cs
Normal file
33
OpenRA.Game/Server/MasterServerQuery.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user