This commit is contained in:
Derek S 2021-04-06 20:24:59 -05:00
commit 2923a52279
3 changed files with 25 additions and 9 deletions

View file

@ -84,7 +84,7 @@ namespace LightReflectiveMirror.LoadBalancing
if (servers.Count == 0)
{
await context.Response.SendResponseAsync(HttpStatusCode.ServiceUnavailable);
await context.Response.SendResponseAsync(HttpStatusCode.NoContent);
return;
}

View file

@ -1,5 +1,6 @@
using System;
using System.Buffers;
using System.Linq;
namespace LightReflectiveMirror
{
@ -78,15 +79,30 @@ namespace LightReflectiveMirror
/// Generates a random server ID.
/// </summary>
/// <returns></returns>
int GetRandomServerID()
string GetRandomServerID()
{
Random rand = new Random();
int temp = rand.Next(int.MinValue, int.MaxValue);
if (!Program.conf.UseLoadBalancer)
{
const int LENGTH = 5;
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var randomID = "";
while (DoesServerIdExist(temp))
temp = rand.Next(int.MinValue, int.MaxValue);
do
{
var random = new System.Random();
randomID = new string(Enumerable.Repeat(chars, LENGTH)
.Select(s => s[random.Next(s.Length)]).ToArray());
}
while (DoesServerIdExist(randomID));
return temp;
return randomID;
}
else
{
// ping load balancer here
return "";
}
}
/// <summary>
@ -94,7 +110,7 @@ namespace LightReflectiveMirror
/// </summary>
/// <param name="id">The ID to check for</param>
/// <returns></returns>
bool DoesServerIdExist(int id)
bool DoesServerIdExist(string id)
{
for (int i = 0; i < rooms.Count; i++)
if (rooms[i].serverId == id)

View file

@ -8,7 +8,7 @@ namespace LightReflectiveMirror
[JsonObject(MemberSerialization.OptOut)]
public class Room
{
public int serverId;
public string serverId;
public int hostId;
public string serverName;
public string serverData;