-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UI rework v1; CommandLineString detection doesn't work yet
- Loading branch information
Showing
6 changed files
with
310 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.CSharp.RuntimeBinder; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace TribesLauncherSharp | ||
{ | ||
class LoginServerStatus | ||
{ | ||
public int? PlayersOnline { get; private set; } = null; | ||
public int? ServersOnline { get; private set; } = null; | ||
|
||
public void Update(string loginServerHost, int loginServerWebPort = 9080) | ||
{ | ||
System.Diagnostics.Debug.WriteLine("Updatarino"); | ||
using (var wc = new WebClient()) | ||
{ | ||
string rawData; | ||
|
||
try | ||
{ | ||
rawData = wc.DownloadString($"http://{loginServerHost}:{loginServerWebPort}/status"); | ||
} catch (WebException) | ||
{ | ||
// Failed to get from server status API | ||
Clear(); | ||
return; | ||
} | ||
|
||
dynamic data = null; | ||
try | ||
{ | ||
data = JObject.Parse(rawData); | ||
} | ||
catch (JsonReaderException) | ||
{ | ||
// Failed to get data, just clear | ||
Clear(); | ||
return; | ||
} | ||
|
||
try | ||
{ | ||
PlayersOnline = data["online_players"]; | ||
PlayersOnline = data["online_servers"]; | ||
} | ||
catch (RuntimeBinderException) | ||
{ | ||
// Failed to parse response, just clear | ||
Clear(); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
public void Clear() | ||
{ | ||
PlayersOnline = null; | ||
ServersOnline = null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.