Async motd grab. Client and server version in MasterServerQuery
This commit is contained in:
33
OpenRA.Game/Server/MasterServerQuery.cs
Normal file → Executable file
33
OpenRA.Game/Server/MasterServerQuery.cs
Normal file → Executable file
@@ -14,6 +14,7 @@ using System.Net;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
|
using OpenRA.Widgets;
|
||||||
|
|
||||||
namespace OpenRA.Server
|
namespace OpenRA.Server
|
||||||
{
|
{
|
||||||
@@ -23,7 +24,8 @@ namespace OpenRA.Server
|
|||||||
public static event Action<string> OnVersion = _ => { };
|
public static event Action<string> OnVersion = _ => { };
|
||||||
|
|
||||||
static GameServer[] Games = { };
|
static GameServer[] Games = { };
|
||||||
static string Version = "";
|
public static string ClientVersion = "";
|
||||||
|
public static string ServerVersion = "";
|
||||||
static AutoResetEvent ev = new AutoResetEvent(false);
|
static AutoResetEvent ev = new AutoResetEvent(false);
|
||||||
static AutoResetEvent ev2 = new AutoResetEvent(false);
|
static AutoResetEvent ev2 = new AutoResetEvent(false);
|
||||||
|
|
||||||
@@ -49,12 +51,35 @@ namespace OpenRA.Server
|
|||||||
}).Start();
|
}).Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void GetMOTD(string masterServerUrl)
|
||||||
|
{
|
||||||
|
new Thread(() =>
|
||||||
|
{
|
||||||
|
var motd = Widget.RootWidget.GetWidget<ScrollingTextWidget>("MOTD_SCROLLER");
|
||||||
|
if (motd != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
motd.Text = GetData(new Uri(masterServerUrl + "motd.php?v=" + ClientVersion));
|
||||||
|
motd.ResetScroll();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
motd.Text = "Welcome to OpenRA. MOTD unable to be loaded from server.";
|
||||||
|
motd.ResetScroll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ev.Set();
|
||||||
|
}).Start();
|
||||||
|
}
|
||||||
|
|
||||||
public static void Tick()
|
public static void Tick()
|
||||||
{
|
{
|
||||||
if (ev.WaitOne(TimeSpan.FromMilliseconds(0)))
|
if (ev.WaitOne(TimeSpan.FromMilliseconds(0)))
|
||||||
OnComplete(Games);
|
OnComplete(Games);
|
||||||
if (ev2.WaitOne(TimeSpan.FromMilliseconds(0)))
|
if (ev2.WaitOne(TimeSpan.FromMilliseconds(0)))
|
||||||
OnVersion(Version);
|
OnVersion(ServerVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
static string GetData(Uri uri)
|
static string GetData(Uri uri)
|
||||||
@@ -70,11 +95,11 @@ namespace OpenRA.Server
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Version = GetData(new Uri(masterServerUrl + "VERSION"));
|
ServerVersion = GetData(new Uri(masterServerUrl + "VERSION"));
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
Version = "";
|
ServerVersion = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
ev2.Set();
|
ev2.Set();
|
||||||
|
|||||||
@@ -29,8 +29,6 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
|
|
||||||
var version = widget.GetWidget<LabelWidget>("VERSION_STRING");
|
var version = widget.GetWidget<LabelWidget>("VERSION_STRING");
|
||||||
|
|
||||||
var motd = widget.GetWidget<ScrollingTextWidget>("MOTD_SCROLLER");
|
|
||||||
|
|
||||||
if (FileSystem.Exists("VERSION"))
|
if (FileSystem.Exists("VERSION"))
|
||||||
{
|
{
|
||||||
var s = FileSystem.Open("VERSION");
|
var s = FileSystem.Open("VERSION");
|
||||||
@@ -43,29 +41,9 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
{
|
{
|
||||||
version.Text = "Dev Build";
|
version.Text = "Dev Build";
|
||||||
}
|
}
|
||||||
|
MasterServerQuery.ClientVersion = version.Text;
|
||||||
|
|
||||||
if (motd != null)
|
MasterServerQuery.GetMOTD(Game.Settings.Server.MasterServer);
|
||||||
{
|
|
||||||
motd.Text = "Welcome to OpenRA. MOTD unable to be loaded from server.";
|
|
||||||
|
|
||||||
string URL = "http://open-ra.org/master/motd.php?v=" + version.Text;
|
|
||||||
|
|
||||||
WebRequest req = WebRequest.Create(URL);
|
|
||||||
StreamReader reader = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
reader = new StreamReader(req.GetResponse().GetResponseStream());
|
|
||||||
}
|
|
||||||
catch (WebException e)
|
|
||||||
{
|
|
||||||
reader.Close();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var result = reader.ReadToEnd();
|
|
||||||
reader.Close();
|
|
||||||
|
|
||||||
motd.Text = result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,12 @@ namespace OpenRA.Widgets
|
|||||||
UpdateScrollBuffer();
|
UpdateScrollBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ResetScroll()
|
||||||
|
{
|
||||||
|
ScrollLocation = 0;
|
||||||
|
ScrollTick = 0;
|
||||||
|
}
|
||||||
|
|
||||||
private void UpdateScrollBuffer()
|
private void UpdateScrollBuffer()
|
||||||
{
|
{
|
||||||
ScrollTick++;
|
ScrollTick++;
|
||||||
|
|||||||
Reference in New Issue
Block a user