From d73399109b604249538c58cba8cb7f09275d2580 Mon Sep 17 00:00:00 2001 From: cxxpxr <60411087+cxxpxr@users.noreply.github.com> Date: Wed, 31 Mar 2021 15:35:07 -0400 Subject: [PATCH] added server list endpoint --- ServerProject-DONT-IMPORT-INTO-UNITY/Config.cs | 1 + ServerProject-DONT-IMPORT-INTO-UNITY/Endpoint.cs | 14 ++++++++++++++ ServerProject-DONT-IMPORT-INTO-UNITY/Room.cs | 1 + 3 files changed, 16 insertions(+) diff --git a/ServerProject-DONT-IMPORT-INTO-UNITY/Config.cs b/ServerProject-DONT-IMPORT-INTO-UNITY/Config.cs index 0411180..7e54ad1 100644 --- a/ServerProject-DONT-IMPORT-INTO-UNITY/Config.cs +++ b/ServerProject-DONT-IMPORT-INTO-UNITY/Config.cs @@ -13,5 +13,6 @@ namespace LightReflectiveMirror public int UpdateHeartbeatInterval = 100; public bool UseEndpoint = false; public ushort EndpointPort = 6969; + public bool EndpointServerList = false; } } diff --git a/ServerProject-DONT-IMPORT-INTO-UNITY/Endpoint.cs b/ServerProject-DONT-IMPORT-INTO-UNITY/Endpoint.cs index 5020b55..459db41 100644 --- a/ServerProject-DONT-IMPORT-INTO-UNITY/Endpoint.cs +++ b/ServerProject-DONT-IMPORT-INTO-UNITY/Endpoint.cs @@ -31,6 +31,20 @@ namespace LightReflectiveMirror.Endpoints string json = JsonConvert.SerializeObject(stats, Formatting.Indented); await context.Response.SendResponseAsync(json); } + + [RestRoute("Get", "/api/servers")] + public async Task ServerList(IHttpContext context) + { + if (Program.conf.EndpointServerList) + { + string json = JsonConvert.SerializeObject(Program.instance.GetRooms(), Formatting.Indented); + await context.Response.SendResponseAsync(json); + } + else + { + await context.Response.SendResponseAsync("Access Denied"); + } + } } public class EndpointServer diff --git a/ServerProject-DONT-IMPORT-INTO-UNITY/Room.cs b/ServerProject-DONT-IMPORT-INTO-UNITY/Room.cs index 6f39594..32c032b 100644 --- a/ServerProject-DONT-IMPORT-INTO-UNITY/Room.cs +++ b/ServerProject-DONT-IMPORT-INTO-UNITY/Room.cs @@ -4,6 +4,7 @@ using System.Text; namespace LightReflectiveMirror { + [Serializable] public class Room { public int serverId;