Merge branch 'main' of https://github.com/Derek-R-S/Light-Reflective-Mirror into main
This commit is contained in:
commit
2923a52279
3 changed files with 25 additions and 9 deletions
|
|
@ -84,7 +84,7 @@ namespace LightReflectiveMirror.LoadBalancing
|
||||||
|
|
||||||
if (servers.Count == 0)
|
if (servers.Count == 0)
|
||||||
{
|
{
|
||||||
await context.Response.SendResponseAsync(HttpStatusCode.ServiceUnavailable);
|
await context.Response.SendResponseAsync(HttpStatusCode.NoContent);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Buffers;
|
using System.Buffers;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace LightReflectiveMirror
|
namespace LightReflectiveMirror
|
||||||
{
|
{
|
||||||
|
|
@ -78,15 +79,30 @@ namespace LightReflectiveMirror
|
||||||
/// Generates a random server ID.
|
/// Generates a random server ID.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
int GetRandomServerID()
|
string GetRandomServerID()
|
||||||
{
|
{
|
||||||
Random rand = new Random();
|
if (!Program.conf.UseLoadBalancer)
|
||||||
int temp = rand.Next(int.MinValue, int.MaxValue);
|
{
|
||||||
|
const int LENGTH = 5;
|
||||||
|
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
var randomID = "";
|
||||||
|
|
||||||
while (DoesServerIdExist(temp))
|
do
|
||||||
temp = rand.Next(int.MinValue, int.MaxValue);
|
{
|
||||||
|
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>
|
/// <summary>
|
||||||
|
|
@ -94,7 +110,7 @@ namespace LightReflectiveMirror
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id">The ID to check for</param>
|
/// <param name="id">The ID to check for</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
bool DoesServerIdExist(int id)
|
bool DoesServerIdExist(string id)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < rooms.Count; i++)
|
for (int i = 0; i < rooms.Count; i++)
|
||||||
if (rooms[i].serverId == id)
|
if (rooms[i].serverId == id)
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ namespace LightReflectiveMirror
|
||||||
[JsonObject(MemberSerialization.OptOut)]
|
[JsonObject(MemberSerialization.OptOut)]
|
||||||
public class Room
|
public class Room
|
||||||
{
|
{
|
||||||
public int serverId;
|
public string serverId;
|
||||||
public int hostId;
|
public int hostId;
|
||||||
public string serverName;
|
public string serverName;
|
||||||
public string serverData;
|
public string serverData;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue