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
@@ -77,7 +77,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="CommsTransmitter.cs" />
<Compile Include="Program.cs" />
<Compile Include="BackendLoop.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
File diff suppressed because it is too large Load Diff
+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());
}
}
+7 -1
View File
@@ -10,7 +10,7 @@ function _masterInitializeSocket(authenticationTicket) {
_masterSocket = null;
}
alertify.log("Opening socket " + getMasterSocketAddress() + "...");
alertify.log("DEBUG: Opening socket " + getMasterSocketAddress() + "...");
var socketUrl = getMasterSocketAddress() + "?Auth=" + authenticationTicket;
@@ -37,6 +37,12 @@ function _masterInitializeSocket(authenticationTicket) {
if (message.messageType == "Heartbeat") {
alertify.log("Master socket heartbeat");
}
else if (message.messageType == "SandboxUpdate") {
if (odoLocalParticipation != undefined) { // Real ugly accessing specific page elements here, but it's temporary
odoLocalParticipation.innerHTML = message.local;
odoProfitLossToDate.innerHTML = (message.profit / 100.0) + 0.001;
}
}
};
}
+25 -11
View File
@@ -2,11 +2,11 @@ ServerName swarmops-frontend
ServerAdmin swarmops-frontend@swarmops.com
DocumentRoot /usr/share/swarmops/frontend/
# Redirect websocket requests to Swarmops FrontSocket server
# With mod_proxy enabled, kill the ability to make unsolicited proxy requests
ProxyRequests Off
ProxyPass "/ws/" "ws://localhost:12172/"
# Explicitly specify Mono version 4
# Point out application folder, explicitly specify Mono version 4
MonoApplications swarmops-frontend "/:/usr/share/swarmops/frontend/"
MonoServerPath swarmops-frontend "/usr/bin/mod-mono-server4"
# Uncomment the line below to enable debugging:
@@ -15,16 +15,30 @@ MonoServerPath swarmops-frontend "/usr/bin/mod-mono-server4"
# Uncomment the line below and enter FQDNs (one or more) for Swarmops if
# running virtual hosts:
# ServerAlias FQDN1 FQDN2 FQDN3 ...
MonoApplications swarmops-frontend "/:/usr/share/swarmops/frontend/"
<Location "/">
# Redirect websocket requests to Swarmops FrontSocket server
<Location "/ws/">
Allow from all
Order allow,deny
SetHandler mono
MonoSetServerAlias swarmops-frontend
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI "\.(?:gif|jpe?g|png)$" no-gzip dont-vary
ProxyPass "ws://localhost:12172/"
ProxyPassReverse "ws://localhost:12172/"
</Location>
# Trigger main handler only if Upgrade header is not [Ww]ebsocket
# (because in that particular case, we're passing to socket above)
<Location "/">
<If "! %{HTTP:Upgrade} =~ /[Ww]ebsocket/">
Allow from all
Order allow,deny
SetHandler mono
MonoSetServerAlias swarmops-frontend
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI "\.(?:gif|jpe?g|png)$" no-gzip dont-vary
</If>
</Location>
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript
</IfModule>