nvm
This commit is contained in:
parent
97bd0999d3
commit
96dbf70777
4 changed files with 21 additions and 53 deletions
|
|
@ -53,5 +53,4 @@ namespace LightReflectiveMirror.LoadBalancing
|
|||
}
|
||||
|
||||
public enum LRMRegions { Any, NorthAmerica, SouthAmerica, Europe, Asia, Africa, Oceania }
|
||||
public enum LRMServerOpCode { Clear, Cache };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ namespace LightReflectiveMirror.LoadBalancing
|
|||
[RestResource]
|
||||
public partial class Endpoint
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Sent from an LRM server node
|
||||
/// adds it to the list if authenticated.
|
||||
|
|
@ -74,7 +75,7 @@ namespace LightReflectiveMirror.LoadBalancing
|
|||
if (!string.IsNullOrEmpty(auth) && auth == Program.conf.AuthKey)
|
||||
{
|
||||
var relays = Program.instance.availableRelayServers.ToList();
|
||||
PerformActionToAllServers(LRMServerOpCode.Clear);
|
||||
ClearAllServersLists();
|
||||
List<Room> requestedRooms;
|
||||
|
||||
for (int i = 0; i < relays.Count; i++)
|
||||
|
|
@ -105,7 +106,7 @@ namespace LightReflectiveMirror.LoadBalancing
|
|||
}
|
||||
}
|
||||
|
||||
PerformActionToAllServers(LRMServerOpCode.Cache);
|
||||
CacheAllServers();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,45 +1,29 @@
|
|||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LightReflectiveMirror.LoadBalancing
|
||||
{
|
||||
public partial class Endpoint
|
||||
{
|
||||
/// <summary>
|
||||
/// We can write all server operations in here,
|
||||
/// to make it more clean.
|
||||
/// </summary>
|
||||
/// <param name="operation"></param>
|
||||
/// <param name="onComplete"></param>
|
||||
public static void PerformActionToAllServers(LRMServerOpCode operation, Action onComplete = null)
|
||||
void CacheAllServers()
|
||||
{
|
||||
switch (operation)
|
||||
{
|
||||
case LRMServerOpCode.Clear:
|
||||
for (int i = 0; i < _allServersToPerformActionOn.Count; i++)
|
||||
_allServersToPerformActionOn[i].Item1.Clear();
|
||||
break;
|
||||
|
||||
// Removes the old cached string and reserialzes the new one
|
||||
case LRMServerOpCode.Cache:
|
||||
for (int i = 0; i < _allServersToPerformActionOn.Count; i++)
|
||||
{
|
||||
var tuple = _allServersToPerformActionOn[i];
|
||||
var serializedData = JsonConvert.SerializeObject(_allServersToPerformActionOn[i].Item1);
|
||||
|
||||
_allServersToPerformActionOn.Remove(tuple);
|
||||
_allServersToPerformActionOn.Add(new Tuple<List<Room>, string>(tuple.Item1, serializedData));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
allCachedServers = JsonConvert.SerializeObject(_allServers);
|
||||
NorthAmericaCachedServers = JsonConvert.SerializeObject(_northAmericaServers);
|
||||
SouthAmericaCachedServers = JsonConvert.SerializeObject(_southAmericaServers);
|
||||
EuropeCachedServers = JsonConvert.SerializeObject(_europeServers);
|
||||
AsiaCachedServers = JsonConvert.SerializeObject(_asiaServers);
|
||||
AfricaCachedServers = JsonConvert.SerializeObject(_africaServers);
|
||||
OceaniaCachedServers = JsonConvert.SerializeObject(_oceaniaServers);
|
||||
}
|
||||
|
||||
void ClearAllServersLists()
|
||||
{
|
||||
_northAmericaServers.Clear();
|
||||
_southAmericaServers.Clear();
|
||||
_europeServers.Clear();
|
||||
_asiaServers.Clear();
|
||||
_africaServers.Clear();
|
||||
_oceaniaServers.Clear();
|
||||
_allServers.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,22 +24,6 @@ namespace LightReflectiveMirror.LoadBalancing
|
|||
private static List<Room> _oceaniaServers = new();
|
||||
private static List<Room> _allServers = new();
|
||||
|
||||
/// <summary>
|
||||
/// This holds all the servers. It's a bit confusing,
|
||||
/// but basically if we have a container for them then we
|
||||
/// can shorten up methods that involve operations with all of them.
|
||||
/// </summary>
|
||||
private static List<Tuple<List<Room>, string>> _allServersToPerformActionOn = new()
|
||||
{
|
||||
new Tuple<List<Room>, string>(_northAmericaServers, NorthAmericaCachedServers),
|
||||
new Tuple<List<Room>, string>(_southAmericaServers, SouthAmericaCachedServers),
|
||||
new Tuple<List<Room>, string>(_europeServers, EuropeCachedServers),
|
||||
new Tuple<List<Room>, string>(_africaServers, AfricaCachedServers),
|
||||
new Tuple<List<Room>, string>(_asiaServers, AsiaCachedServers),
|
||||
new Tuple<List<Room>, string>(_oceaniaServers, OceaniaCachedServers),
|
||||
new Tuple<List<Room>, string>(_allServers, allCachedServers),
|
||||
};
|
||||
|
||||
private LoadBalancerStats _stats
|
||||
{
|
||||
get => new()
|
||||
|
|
|
|||
Loading…
Reference in a new issue