Work on testing sockets, odometers

This commit is contained in:
Rick Falkvinge
2017-01-13 13:42:28 +01:00
parent d09da97810
commit 0e25cd8cdd
7 changed files with 857 additions and 812 deletions
+1 -1
View File
@@ -57,7 +57,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="MasterServices.cs" />
<Compile Include="Program.cs" />
<Compile Include="FrontendLoop.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Net;
using System.Net.Security;
@@ -11,14 +12,22 @@ using Newtonsoft.Json.Linq;
using Swarmops.Logic.Communications;
using Swarmops.Logic.Communications.Payload;
using Swarmops.Logic.ExtensionMethods;
using Swarmops.Logic.Support;
using WebSocketSharp.Server;
namespace Swarmops.Frontend.Socket
{
internal class Program
internal class FrontendLoop
{
static void Main(string[] args)
{
// Check if we're Sandbox
if (PilotInstallationIds.IsPilot(PilotInstallationIds.DevelopmentSandbox))
{
_isSandbox = true;
}
// Disable SSL cert checking (because Mono doesn't have a cert repo, dammit)
Swarmops.Logic.Support.SupportFunctions.DisableSslCertificateChecks();
@@ -147,11 +156,27 @@ namespace Swarmops.Frontend.Socket
Console.WriteLine(" * Swarmops Frontend Socket Server exiting");
}
private static WebSocketServer _socketServer;
private static WebSocketServer _socketServer;
private static bool _isSandbox = false;
private static int _sandboxDummy1 = 500;
private static int _sandboxDummy2 = 50000;
private static void OnEveryTenSeconds()
{
_socketServer.WebSocketServices.Broadcast ("{\"messageType\":\"Heartbeat\"}");
if (_isSandbox)
{
_sandboxDummy1 += new Random().Next(10) - 3;
_sandboxDummy1 += new Random().Next(1000) - 200;
JObject data = new JObject();
data["messageType"] = "SandboxUpdate";
data["local"] = _sandboxDummy1.ToString(CultureInfo.InvariantCulture);
data["profit"] = _sandboxDummy2.ToString(CultureInfo.InvariantCulture);
_socketServer.WebSocketServices.Broadcast(data.ToString());
}
}
+2 -2
View File
@@ -34,7 +34,7 @@ namespace Swarmops.Frontend.Socket
switch (serverRequest)
{
case "UpdateQueueCounts":
Sessions.Broadcast (Program.GetQueueInfoJson());
Sessions.Broadcast (FrontendLoop.GetQueueInfoJson());
break;
case "Ping":
Sessions.Broadcast("{\"messageType\":\"Heartbeat\"}");
@@ -62,7 +62,7 @@ namespace Swarmops.Frontend.Socket
{
Sessions.Broadcast ("{\"messageType\":\"EditorCount\"," +
String.Format("\"editorCount\":\"{0}\"", Sessions.ActiveIDs.ToArray().Length) + '}');
Send(Program.GetQueueInfoJson());
Send(FrontendLoop.GetQueueInfoJson());
}
}