This repository has been archived by the owner on Sep 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
113 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
LoadBalancerProject-DONT-IMPORT-INTO-UNITY/LRM_LoadBalancer/Endpoint/EndpointExtra.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
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) | ||
{ | ||
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; | ||
} | ||
|
||
|
||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
LoadBalancerProject-DONT-IMPORT-INTO-UNITY/LRM_LoadBalancer/Endpoint/EndpointVariables.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace LightReflectiveMirror.LoadBalancing | ||
{ | ||
public partial class Endpoint | ||
{ | ||
public static string allCachedServers = "[]"; | ||
public static string NorthAmericaCachedServers = "[]"; | ||
public static string SouthAmericaCachedServers = "[]"; | ||
public static string EuropeCachedServers = "[]"; | ||
public static string AsiaCachedServers = "[]"; | ||
public static string AfricaCachedServers = "[]"; | ||
public static string OceaniaCachedServers = "[]"; | ||
|
||
private static List<Room> _northAmericaServers = new(); | ||
private static List<Room> _southAmericaServers = new(); | ||
private static List<Room> _europeServers = new(); | ||
private static List<Room> _africaServers = new(); | ||
private static List<Room> _asiaServers = new(); | ||
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() | ||
{ | ||
nodeCount = Program.instance.availableRelayServers.Count, | ||
uptime = DateTime.Now - Program.startupTime, | ||
CCU = Program.instance.GetTotalCCU(), | ||
totalServerCount = Program.instance.GetTotalServers(), | ||
}; | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.