diff --git a/LoadBalancerProject-DONT-IMPORT-INTO-UNITY/LRM_LoadBalancer/Program.cs b/LoadBalancerProject-DONT-IMPORT-INTO-UNITY/LRM_LoadBalancer/Program.cs index 5e9d7bb..256513b 100644 --- a/LoadBalancerProject-DONT-IMPORT-INTO-UNITY/LRM_LoadBalancer/Program.cs +++ b/LoadBalancerProject-DONT-IMPORT-INTO-UNITY/LRM_LoadBalancer/Program.cs @@ -48,7 +48,7 @@ namespace LightReflectiveMirror.LoadBalancing WriteLogMessage("Endpoint server started unsuccessfully", ConsoleColor.Red); } - var pingThread = new Thread(new ThreadStart(() => PingServers())); + var pingThread = new Thread(new ThreadStart(PingServers)); pingThread.Start(); // keep console alive @@ -99,7 +99,7 @@ namespace LightReflectiveMirror.LoadBalancing } } - async Task PingServers() + async void PingServers() { while (true) { @@ -154,7 +154,7 @@ namespace LightReflectiveMirror.LoadBalancing | | | | | | / \ | | | | w /| | | | | | | / /\ \ | | | | | \ | |____ | |__| | / ____ \ | |__| | m m copyright monkesoft 2021 - |______| \____/ /_/ \_\ |_____/ + |______| \____/ /_/ \_\ |_____/ ____ _ _ _ _____ ______ _____ | _ \ /\ | | /\ | \ | | / ____| | ____| | __ \ | |_) | / \ | | / \ | \| | | | | |__ | |__) | diff --git a/ServerProject-DONT-IMPORT-INTO-UNITY/LRM/Endpoint.cs b/ServerProject-DONT-IMPORT-INTO-UNITY/LRM/Endpoint.cs index fddac18..8a44057 100644 --- a/ServerProject-DONT-IMPORT-INTO-UNITY/LRM/Endpoint.cs +++ b/ServerProject-DONT-IMPORT-INTO-UNITY/LRM/Endpoint.cs @@ -23,7 +23,9 @@ namespace LightReflectiveMirror.Endpoints [RestResource] public class Endpoint { - private List _rooms { get => Program.instance.GetRooms().Where(x => x.isPublic).ToList(); } + private static string _cachedServerList = "[]"; + private static string _cachedCompressedServerList; + private static List _rooms { get => Program.instance.GetRooms().Where(x => x.isPublic).ToList(); } private RelayStats _stats { get => new RelayStats { @@ -33,6 +35,12 @@ namespace LightReflectiveMirror.Endpoints Uptime = Program.instance.GetUptime() }; } + public static void RoomsModified() + { + _cachedServerList = JsonConvert.SerializeObject(_rooms, Formatting.Indented); + _cachedCompressedServerList = _cachedServerList.Compress(); + } + [RestRoute("Get", "/api/stats")] public async Task Stats(IHttpContext context) { @@ -45,8 +53,7 @@ namespace LightReflectiveMirror.Endpoints { if (Program.conf.EndpointServerList) { - string json = JsonConvert.SerializeObject(_rooms, Formatting.Indented); - await context.Response.SendResponseAsync(json); + await context.Response.SendResponseAsync(_cachedServerList); } else await context.Response.SendResponseAsync(HttpStatusCode.Forbidden); @@ -57,8 +64,7 @@ namespace LightReflectiveMirror.Endpoints { if (Program.conf.EndpointServerList) { - string json = JsonConvert.SerializeObject(_rooms); - await context.Response.SendResponseAsync(json.Compress()); + await context.Response.SendResponseAsync(_cachedCompressedServerList); } else await context.Response.SendResponseAsync(HttpStatusCode.Forbidden); diff --git a/ServerProject-DONT-IMPORT-INTO-UNITY/LRM/Program/Program.cs b/ServerProject-DONT-IMPORT-INTO-UNITY/LRM/Program/Program.cs index 1fa6f10..b173120 100644 --- a/ServerProject-DONT-IMPORT-INTO-UNITY/LRM/Program/Program.cs +++ b/ServerProject-DONT-IMPORT-INTO-UNITY/LRM/Program/Program.cs @@ -110,11 +110,12 @@ namespace LightReflectiveMirror if (conf.UseEndpoint) { WriteLogMessage("\nStarting Endpoint Service... ", ConsoleColor.White, true); - var endpoint = new EndpointServer(); + var endpointService = new EndpointServer(); - if (endpoint.Start(conf.EndpointPort)) + if (endpointService.Start(conf.EndpointPort)) { WriteLogMessage("OK", ConsoleColor.Green); + Endpoint.RoomsModified(); } else { diff --git a/ServerProject-DONT-IMPORT-INTO-UNITY/LRM/Program/ProgramVariables.cs b/ServerProject-DONT-IMPORT-INTO-UNITY/LRM/Program/ProgramVariables.cs index 44f1f6f..545a6e0 100644 --- a/ServerProject-DONT-IMPORT-INTO-UNITY/LRM/Program/ProgramVariables.cs +++ b/ServerProject-DONT-IMPORT-INTO-UNITY/LRM/Program/ProgramVariables.cs @@ -1,4 +1,5 @@ -using Mirror; +using LightReflectiveMirror.Endpoints; +using Mirror; using System; using System.Collections.Generic; using System.Net; @@ -12,7 +13,7 @@ namespace LightReflectiveMirror public static Transport transport; public static Program instance; public static Config conf; - + private RelayHandler _relay; private MethodInfo _awakeMethod; private MethodInfo _startMethod; diff --git a/ServerProject-DONT-IMPORT-INTO-UNITY/LRM/RelayHandler/RelayHandlerRoomMethods.cs b/ServerProject-DONT-IMPORT-INTO-UNITY/LRM/RelayHandler/RelayHandlerRoomMethods.cs index 59ce180..63f0d43 100644 --- a/ServerProject-DONT-IMPORT-INTO-UNITY/LRM/RelayHandler/RelayHandlerRoomMethods.cs +++ b/ServerProject-DONT-IMPORT-INTO-UNITY/LRM/RelayHandler/RelayHandlerRoomMethods.cs @@ -1,4 +1,5 @@ -using System; +using LightReflectiveMirror.Endpoints; +using System; using System.Collections.Generic; using System.Net; @@ -75,6 +76,7 @@ namespace LightReflectiveMirror _sendBuffers.Return(sendJoinBuffer); + Endpoint.RoomsModified(); return; } else @@ -86,6 +88,8 @@ namespace LightReflectiveMirror Program.transport.ServerSend(clientId, 0, new ArraySegment(sendJoinBuffer, 0, sendJoinPos)); Program.transport.ServerSend(rooms[i].hostId, 0, new ArraySegment(sendJoinBuffer, 0, sendJoinPos)); _sendBuffers.Return(sendJoinBuffer); + + Endpoint.RoomsModified(); return; } } @@ -151,6 +155,8 @@ namespace LightReflectiveMirror Program.transport.ServerSend(clientId, 0, new ArraySegment(sendBuffer, 0, pos)); _sendBuffers.Return(sendBuffer); + + Endpoint.RoomsModified(); } /// @@ -174,6 +180,7 @@ namespace LightReflectiveMirror _sendBuffers.Return(sendBuffer); rooms[i].clients.Clear(); rooms.RemoveAt(i); + Endpoint.RoomsModified(); return; } else @@ -191,6 +198,7 @@ namespace LightReflectiveMirror Program.transport.ServerSend(rooms[i].hostId, 0, new ArraySegment(sendBuffer, 0, pos)); _sendBuffers.Return(sendBuffer); + Endpoint.RoomsModified(); } } }