added server list endpoint

This commit is contained in:
cxxpxr 2021-03-31 15:35:07 -04:00
parent ec875235aa
commit d73399109b
3 changed files with 16 additions and 0 deletions

View file

@ -13,5 +13,6 @@ namespace LightReflectiveMirror
public int UpdateHeartbeatInterval = 100;
public bool UseEndpoint = false;
public ushort EndpointPort = 6969;
public bool EndpointServerList = false;
}
}

View file

@ -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

View file

@ -4,6 +4,7 @@ using System.Text;
namespace LightReflectiveMirror
{
[Serializable]
public class Room
{
public int serverId;