diff options
| author | RogueAI42 <[email protected]> | 2017-06-11 17:34:38 +1000 |
|---|---|---|
| committer | RogueAI42 <[email protected]> | 2017-06-11 17:38:53 +1000 |
| commit | 107a98686a105468b5f200ebcbd27343c1210ce4 (patch) | |
| tree | f6b8403368ddf0b4be2569c0ac8c237635e7b764 /ShiftOS_TheReturn/ServerManager.cs | |
| parent | c3deaa23fffb7011efb2b5b0f7fc3e754d21f600 (diff) | |
| download | shiftos_thereturn-107a98686a105468b5f200ebcbd27343c1210ce4.tar.gz shiftos_thereturn-107a98686a105468b5f200ebcbd27343c1210ce4.tar.bz2 shiftos_thereturn-107a98686a105468b5f200ebcbd27343c1210ce4.zip | |
ReflectMan Saves The Day..............
Refactored every part in the code that used that damn foreach loop.
All assemblies are now loaded on startup into an array, and the
results of GetType() on each are concatenated into another array.
The parts of the code that were loading the assemblies and scanning
them themselves now look to ReflectMan.Types, and all disk I/O is
limited to the first time ReflectMan is accessed. While I was there
I also replaced some other foreach loops with array comprehensions
and such to speed things up - there is a noticeable improvement.
It doesn't seem to have broken anything, but I'd appreciate if
someone could do more stress testing for me.
Diffstat (limited to 'ShiftOS_TheReturn/ServerManager.cs')
| -rw-r--r-- | ShiftOS_TheReturn/ServerManager.cs | 27 |
1 files changed, 7 insertions, 20 deletions
diff --git a/ShiftOS_TheReturn/ServerManager.cs b/ShiftOS_TheReturn/ServerManager.cs index be4f086..e6baa9a 100644 --- a/ShiftOS_TheReturn/ServerManager.cs +++ b/ShiftOS_TheReturn/ServerManager.cs @@ -110,32 +110,19 @@ Ping: {ServerManager.DigitalSocietyPing} ms { string[] split = msg.GUID.Split('|'); bool finished = false; - foreach (var exec in Directory.GetFiles(Environment.CurrentDirectory)) - { - if(exec.ToLower().EndsWith(".exe") || exec.ToLower().EndsWith(".dll")) + if (split[0] == SaveSystem.CurrentSave.SystemName) + foreach(var type in Array.FindAll(ReflectMan.Types, x => x.GetInterfaces().Contains(typeof(Server)) && Shiftorium.UpgradeAttributesUnlocked(x))) { - try + var attrib = type.GetCustomAttributes().FirstOrDefault(x => x is ServerAttribute) as ServerAttribute; + if(attrib != null) { - var asm = Assembly.LoadFile(exec); - foreach(var type in asm.GetTypes().Where(x => x.GetInterfaces().Contains(typeof(Server)))) + if(split[1] == attrib.Port.ToString()) { - var attrib = type.GetCustomAttributes().FirstOrDefault(x => x is ServerAttribute) as ServerAttribute; - if(attrib != null) - { - if(split[0] == SaveSystem.CurrentSave.SystemName && split[1] == attrib.Port.ToString()) - { - if (Shiftorium.UpgradeAttributesUnlocked(type)) - { - type.GetMethods(BindingFlags.Public | BindingFlags.Instance).FirstOrDefault(x => x.Name == "MessageReceived")?.Invoke(Activator.CreateInstance(type), null); - finished = true; - } - } - } + type.GetMethods(BindingFlags.Public | BindingFlags.Instance).FirstOrDefault(x => x.Name == "MessageReceived")?.Invoke(Activator.CreateInstance(type), null); + finished = true; } } - catch { } } - } if (finished == false) { Forward(split[2], "Error", $"{split[0]}:{split[1]}: connection refused"); |
