remove MasterServerQuery in favour of ServerList
This commit is contained in:
@@ -18,7 +18,6 @@ using OpenRA.FileFormats;
|
|||||||
using OpenRA.GameRules;
|
using OpenRA.GameRules;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Network;
|
using OpenRA.Network;
|
||||||
using OpenRA.Server;
|
|
||||||
using OpenRA.Support;
|
using OpenRA.Support;
|
||||||
using OpenRA.Widgets;
|
using OpenRA.Widgets;
|
||||||
|
|
||||||
@@ -149,8 +148,6 @@ namespace OpenRA
|
|||||||
PerfHistory.items["render"].Tick();
|
PerfHistory.items["render"].Tick();
|
||||||
PerfHistory.items["batches"].Tick();
|
PerfHistory.items["batches"].Tick();
|
||||||
|
|
||||||
MasterServerQuery.Tick();
|
|
||||||
|
|
||||||
afterTickActions.PerformActions();
|
afterTickActions.PerformActions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
37
OpenRA.Game/Network/GameServer.cs
Normal file
37
OpenRA.Game/Network/GameServer.cs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
52
OpenRA.Game/Network/ServerList.cs
Normal file
52
OpenRA.Game/Network/ServerList.cs
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
#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;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using OpenRA.FileFormats;
|
||||||
|
|
||||||
|
namespace OpenRA.Network
|
||||||
|
{
|
||||||
|
public static class ServerList
|
||||||
|
{
|
||||||
|
public static void Query(Action<GameServer[]> onComplete)
|
||||||
|
{
|
||||||
|
var masterServerUrl = Game.Settings.Server.MasterServer;
|
||||||
|
|
||||||
|
new Thread(() =>
|
||||||
|
{
|
||||||
|
GameServer[] games = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var str = GetData(new Uri(masterServerUrl + "list.php"));
|
||||||
|
|
||||||
|
var yaml = MiniYaml.FromString(str);
|
||||||
|
|
||||||
|
games = yaml.Select(a => FieldLoader.Load<GameServer>(a.Value))
|
||||||
|
.Where(gs => gs.Address != null).ToArray();
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
|
||||||
|
Game.RunAfterTick(() => onComplete(games));
|
||||||
|
}) { IsBackground = true }.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
static string GetData(Uri uri)
|
||||||
|
{
|
||||||
|
var wc = new WebClient();
|
||||||
|
wc.Proxy = null;
|
||||||
|
var data = wc.DownloadData(uri);
|
||||||
|
return Encoding.UTF8.GetString(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -100,7 +100,6 @@
|
|||||||
<Compile Include="Selection.cs" />
|
<Compile Include="Selection.cs" />
|
||||||
<Compile Include="Server\Connection.cs" />
|
<Compile Include="Server\Connection.cs" />
|
||||||
<Compile Include="Server\Exts.cs" />
|
<Compile Include="Server\Exts.cs" />
|
||||||
<Compile Include="Server\MasterServerQuery.cs" />
|
|
||||||
<Compile Include="Server\Server.cs" />
|
<Compile Include="Server\Server.cs" />
|
||||||
<Compile Include="Server\ServerOrder.cs" />
|
<Compile Include="Server\ServerOrder.cs" />
|
||||||
<Compile Include="Sound.cs" />
|
<Compile Include="Sound.cs" />
|
||||||
@@ -198,10 +197,12 @@
|
|||||||
<Compile Include="ModData.cs" />
|
<Compile Include="ModData.cs" />
|
||||||
<Compile Include="Map.cs" />
|
<Compile Include="Map.cs" />
|
||||||
<Compile Include="Network\FrameData.cs" />
|
<Compile Include="Network\FrameData.cs" />
|
||||||
|
<Compile Include="Network\GameServer.cs" />
|
||||||
<Compile Include="Network\ReplayConnection.cs" />
|
<Compile Include="Network\ReplayConnection.cs" />
|
||||||
<Compile Include="Network\Session.cs" />
|
<Compile Include="Network\Session.cs" />
|
||||||
<Compile Include="ObjectCreator.cs" />
|
<Compile Include="ObjectCreator.cs" />
|
||||||
<Compile Include="Network\SyncReport.cs" />
|
<Compile Include="Network\SyncReport.cs" />
|
||||||
|
<Compile Include="Network\ServerList.cs" />
|
||||||
<Compile Include="Traits\EditorAppearance.cs" />
|
<Compile Include="Traits\EditorAppearance.cs" />
|
||||||
<Compile Include="Traits\SubcellInit.cs" />
|
<Compile Include="Traits\SubcellInit.cs" />
|
||||||
<Compile Include="Traits\Target.cs" />
|
<Compile Include="Traits\Target.cs" />
|
||||||
|
|||||||
@@ -1,90 +0,0 @@
|
|||||||
#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;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using OpenRA.FileFormats;
|
|
||||||
using OpenRA.Widgets;
|
|
||||||
|
|
||||||
namespace OpenRA.Server
|
|
||||||
{
|
|
||||||
// TODO: This can die once ra is sane
|
|
||||||
[Obsolete] public static class MasterServerQuery
|
|
||||||
{
|
|
||||||
public static event Action<GameServer[]> OnComplete = _ => { };
|
|
||||||
public static event Action<string> OnVersion = _ => { };
|
|
||||||
|
|
||||||
static GameServer[] Games = { };
|
|
||||||
public static string ClientVersion = "";
|
|
||||||
public static string ServerVersion = "";
|
|
||||||
static AutoResetEvent ev = new AutoResetEvent(false);
|
|
||||||
static AutoResetEvent ev2 = new AutoResetEvent(false);
|
|
||||||
|
|
||||||
public static void Refresh(string masterServerUrl)
|
|
||||||
{
|
|
||||||
new Thread(() =>
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var str = GetData(new Uri(masterServerUrl + "list.php"));
|
|
||||||
|
|
||||||
var yaml = MiniYaml.FromString(str);
|
|
||||||
|
|
||||||
Games = yaml.Select(a => FieldLoader.Load<GameServer>(a.Value))
|
|
||||||
.Where(gs => gs.Address != null).ToArray();
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
Games = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
ev.Set();
|
|
||||||
}).Start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Tick()
|
|
||||||
{
|
|
||||||
if (ev.WaitOne(TimeSpan.FromMilliseconds(0)))
|
|
||||||
OnComplete(Games);
|
|
||||||
if (ev2.WaitOne(TimeSpan.FromMilliseconds(0)))
|
|
||||||
OnVersion(ServerVersion);
|
|
||||||
}
|
|
||||||
|
|
||||||
static string GetData(Uri uri)
|
|
||||||
{
|
|
||||||
var wc = new WebClient();
|
|
||||||
wc.Proxy = null;
|
|
||||||
var data = wc.DownloadData(uri);
|
|
||||||
return Encoding.UTF8.GetString(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -11,49 +11,12 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading;
|
|
||||||
using OpenRA.FileFormats;
|
|
||||||
using OpenRA.Graphics;
|
|
||||||
using OpenRA.Mods.RA.Widgets.Delegates;
|
using OpenRA.Mods.RA.Widgets.Delegates;
|
||||||
using OpenRA.Server;
|
using OpenRA.Network;
|
||||||
using OpenRA.Widgets;
|
using OpenRA.Widgets;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Cnc.Widgets
|
namespace OpenRA.Mods.Cnc.Widgets
|
||||||
{
|
{
|
||||||
public class ServerList
|
|
||||||
{
|
|
||||||
public static void Query(Action<GameServer[]> onComplete)
|
|
||||||
{
|
|
||||||
var masterServerUrl = Game.Settings.Server.MasterServer;
|
|
||||||
new Thread(() =>
|
|
||||||
{
|
|
||||||
GameServer[] games = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var str = GetData(new Uri(masterServerUrl + "list.php"));
|
|
||||||
|
|
||||||
var yaml = MiniYaml.FromString(str);
|
|
||||||
|
|
||||||
games = yaml.Select(a => FieldLoader.Load<GameServer>(a.Value))
|
|
||||||
.Where(gs => gs.Address != null).ToArray();
|
|
||||||
}
|
|
||||||
catch { }
|
|
||||||
|
|
||||||
Game.RunAfterTick(() => onComplete(games));
|
|
||||||
}) { IsBackground = true }.Start();
|
|
||||||
}
|
|
||||||
|
|
||||||
static string GetData(Uri uri)
|
|
||||||
{
|
|
||||||
var wc = new WebClient();
|
|
||||||
wc.Proxy = null;
|
|
||||||
var data = wc.DownloadData(uri);
|
|
||||||
return Encoding.UTF8.GetString(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class CncServerBrowserLogic : IWidgetDelegate
|
public class CncServerBrowserLogic : IWidgetDelegate
|
||||||
{
|
{
|
||||||
GameServer currentServer;
|
GameServer currentServer;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
|
using OpenRA.Network;
|
||||||
using OpenRA.Server;
|
using OpenRA.Server;
|
||||||
using OpenRA.Widgets;
|
using OpenRA.Widgets;
|
||||||
|
|
||||||
@@ -28,15 +29,13 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
|||||||
{
|
{
|
||||||
var bg = widget.GetWidget("JOINSERVER_BG");
|
var bg = widget.GetWidget("JOINSERVER_BG");
|
||||||
|
|
||||||
MasterServerQuery.OnComplete += games => RefreshServerList(games);
|
|
||||||
|
|
||||||
bg.GetWidget("JOINSERVER_PROGRESS_TITLE").Visible = true;
|
bg.GetWidget("JOINSERVER_PROGRESS_TITLE").Visible = true;
|
||||||
bg.GetWidget<LabelWidget>("JOINSERVER_PROGRESS_TITLE").Text = "Fetching game list...";
|
bg.GetWidget<LabelWidget>("JOINSERVER_PROGRESS_TITLE").Text = "Fetching game list...";
|
||||||
|
|
||||||
bg.Children.RemoveAll(a => GameButtons.Contains(a));
|
bg.Children.RemoveAll(a => GameButtons.Contains(a));
|
||||||
GameButtons.Clear();
|
GameButtons.Clear();
|
||||||
|
|
||||||
MasterServerQuery.Refresh(Game.Settings.Server.MasterServer);
|
ServerList.Query(RefreshServerList);
|
||||||
|
|
||||||
bg.GetWidget("SERVER_INFO").IsVisible = () => currentServer != null;
|
bg.GetWidget("SERVER_INFO").IsVisible = () => currentServer != null;
|
||||||
var preview = bg.GetWidget<MapPreviewWidget>("MAP_PREVIEW");
|
var preview = bg.GetWidget<MapPreviewWidget>("MAP_PREVIEW");
|
||||||
@@ -68,7 +67,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
|||||||
bg.Children.RemoveAll(a => GameButtons.Contains(a));
|
bg.Children.RemoveAll(a => GameButtons.Contains(a));
|
||||||
GameButtons.Clear();
|
GameButtons.Clear();
|
||||||
|
|
||||||
MasterServerQuery.Refresh(Game.Settings.Server.MasterServer);
|
ServerList.Query(RefreshServerList);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user