From 8fcb0ef1177c8b771e212928b9f90a5eefbaf7b1 Mon Sep 17 00:00:00 2001 From: cxxpxr <60411087+cxxpxr@users.noreply.github.com> Date: Mon, 29 Mar 2021 15:18:29 -0400 Subject: [PATCH 1/3] server side refactorings --- .../.vs/LRM-Server/v16/.suo | Bin 60416 -> 60416 bytes .../Program.cs | 52 ++--- .../RelayHandler.cs | 214 +++++++++--------- 3 files changed, 127 insertions(+), 139 deletions(-) diff --git a/ServerProject-DONT-IMPORT-INTO-UNITY/.vs/LRM-Server/v16/.suo b/ServerProject-DONT-IMPORT-INTO-UNITY/.vs/LRM-Server/v16/.suo index c550625dbcae2b8e74a518c9db1a883b85913429..9305656caa78f313a288969b3bcbd97de32996a9 100644 GIT binary patch delta 1490 zcmb_bZ)jUp6wkTId+VQwzjWJ$mZy5s++B)Xp3x5!;q`2mR^OFXGg8E@b7}lZS27+HiKXgtDE}omdK&Hbldf~^p z_jm5S=l8qsyws{WwQ4@CG%=GgY$j7JP0fUx#bS}O=9Rr}CQdzjp)0=?XW0_mrC(>; zAj$K082hRz(y}x*(fm$=o!}?92#tgmLJfg$>Y!*Pv>WR>ia29w+%6jg=_qZiqPUIV zCHM@kjbamFOM3KCvaBgx0^UjF= z`(zbl&NHwe1P8&1&j;Uw*YT>`foFrm=v4<$7+T0EO!LL8z`Lg0dR(MF=No3)Lo)tw zD5&+GGY`$o;BxQ7*{&E^fy)TrQnLG0CMu%Xr`mej>YnpezZE$8<;1nizE@t;lhF&H zC30H-VU+K!#zJBWKT~&DqKf|>JklT1VP_HaVhot}bO=v|dK!Wee<*k&F+Fqaz?)R0 zegClov&mUKwOa*zQdMCUhnfdbZT`B&Q>YbwTD~NGGIqT9Qrlu|cJIZPe;z;hxi=8` z_T6zurzt(^z=XRO)o2PIczgf{{7Z(Xf9OQp_Fpr@3`ci)@a)hOPVKVm>G30mbW14c zkKh-HLzUVOa=CT4le;0dFsR~+T923ecj8#M6LaAPk^iBJf^UZ$_(907MZRk}*LiWJ z@Zs`DCl^0H@!P96eo3!gslW8;BV+0Fxc*?@;Tt6rUquw0-tETk`}=Sr-0>f;%8WD3 LpZnLBm^}R#{J0BD delta 1403 zcmchW-%FEW6vyA^+4kz@rd!*ZndatxxS8x%&V?+SP3(s@oTOMm%nL)&EKI=?YD7U7 zUAP@2L?T%cU6${4Fp#<^=obWDc%%Ibc41WOobf8ttmvi#AI^E6=RD_p&%0--WkqUP zG2@44*VQJyAXo%JP#{0@`8+y-JwIK`#f8YL&q_Ot^INQ3`oim3Hy-D8avok2Xl;_$ z6z|2j0#PGc#D+ML{YWcfKpY6=lEJ95(zB;%!-cU1sYl#M17b!zNKHD?$x71+3+Poj zRtX_? z)u={ai_{_1vq}(Lf*lw85Gqt6dy2_u6!P0gIgn2H7OQVFCDnwxHB(tFZ)Z#pI6`}b z3S$u|K}zL)4f--fi|FJ%%H1?**SO)S#$>SJVI5*e9F!=f^nI93CBXLi+7lXzy`Dcb^*CA|4)Ugy@kfxZrg`?#v3T z^g6N!c=oXPr)K8gH+#(Hw=~QqnhS02_@;|KQc_~a@=VId7|%p=QYzlhU@|f!r8=Sv zYWrHm`#8C?7xWP~9QU>UyEL6~&LX-$7#K`U*XFPZrXc$?_u diff --git a/ServerProject-DONT-IMPORT-INTO-UNITY/Program.cs b/ServerProject-DONT-IMPORT-INTO-UNITY/Program.cs index b12a7bf..4cc8ca3 100644 --- a/ServerProject-DONT-IMPORT-INTO-UNITY/Program.cs +++ b/ServerProject-DONT-IMPORT-INTO-UNITY/Program.cs @@ -12,15 +12,17 @@ namespace LightReflectiveMirror { public static Transport transport; public static Config conf; - RelayHandler relay; - MethodInfo awakeMethod; - MethodInfo startMethod; - MethodInfo updateMethod; - MethodInfo lateUpdateMethod; + private RelayHandler relay; + private MethodInfo awakeMethod; + private MethodInfo startMethod; + private MethodInfo updateMethod; + private MethodInfo lateUpdateMethod; - List _currentConnections = new List(); - int _currentHeartbeatTimer = 0; + private List _currentConnections = new List(); + private int _currentHeartbeatTimer = 0; + + private const string CONFIG_PATH = "config.json"; public static void Main(string[] args) => new Program().MainAsync().GetAwaiter().GetResult(); @@ -29,19 +31,18 @@ namespace LightReflectiveMirror { WriteTitle(); - if (!File.Exists("config.json")) + if (!File.Exists(CONFIG_PATH)) { - File.WriteAllText("config.json", JsonConvert.SerializeObject(new Config(), Formatting.Indented)); + File.WriteAllText(CONFIG_PATH, JsonConvert.SerializeObject(new Config(), Formatting.Indented)); WriteLogMessage("A config.json file was generated. Please configure it to the proper settings and re-run!", ConsoleColor.Yellow); Console.ReadKey(); Environment.Exit(0); } else { - conf = JsonConvert.DeserializeObject(File.ReadAllText("config.json")); + conf = JsonConvert.DeserializeObject(File.ReadAllText(CONFIG_PATH)); try - { - Console.WriteLine(Directory.GetCurrentDirectory()); + { var asm = Assembly.LoadFile(Directory.GetCurrentDirectory() + @"\" + conf.TransportDLL); WriteLogMessage($"Loaded Assembly: {asm.FullName}", ConsoleColor.Green); @@ -68,7 +69,8 @@ namespace LightReflectiveMirror WriteLogMessage("Starting Transport...", ConsoleColor.Green); - transport.OnServerError = (clientID, error) => { + transport.OnServerError = (clientID, error) => + { WriteLogMessage($"Transport Error, Client: {clientID}, Error: {error}", ConsoleColor.Red); }; @@ -109,11 +111,8 @@ namespace LightReflectiveMirror while (true) { - if (updateMethod != null) - updateMethod.Invoke(transport, null); - - if (lateUpdateMethod != null) - lateUpdateMethod.Invoke(transport, null); + if (updateMethod != null) { updateMethod.Invoke(transport, null); } + if (lateUpdateMethod != null) { lateUpdateMethod.Invoke(transport, null); } _currentHeartbeatTimer++; @@ -122,9 +121,7 @@ namespace LightReflectiveMirror _currentHeartbeatTimer = 0; for(int i = 0; i < _currentConnections.Count; i++) - { transport.ServerSend(_currentConnections[i], 0, new ArraySegment(new byte[] { 200 })); - } GC.Collect(); } @@ -146,17 +143,10 @@ namespace LightReflectiveMirror updateMethod = type.GetMethod("Update", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); lateUpdateMethod = type.GetMethod("LateUpdate", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); - if (awakeMethod != null) - WriteLogMessage("'Awake' Loaded!", ConsoleColor.Yellow); - - if (startMethod != null) - WriteLogMessage("'Start' Loaded!", ConsoleColor.Yellow); - - if (updateMethod != null) - WriteLogMessage("'Update' Loaded!", ConsoleColor.Yellow); - - if (lateUpdateMethod != null) - WriteLogMessage("'LateUpdate' Loaded!", ConsoleColor.Yellow); + if (awakeMethod != null) { WriteLogMessage("'Awake' Loaded!", ConsoleColor.Yellow); } + if (startMethod != null) { WriteLogMessage("'Start' Loaded!", ConsoleColor.Yellow); } + if (updateMethod != null) { WriteLogMessage("'Update' Loaded!", ConsoleColor.Yellow); } + if (lateUpdateMethod != null) { WriteLogMessage("'LateUpdate' Loaded!", ConsoleColor.Yellow); } } void WriteTitle() diff --git a/ServerProject-DONT-IMPORT-INTO-UNITY/RelayHandler.cs b/ServerProject-DONT-IMPORT-INTO-UNITY/RelayHandler.cs index 57aca00..9becbaf 100644 --- a/ServerProject-DONT-IMPORT-INTO-UNITY/RelayHandler.cs +++ b/ServerProject-DONT-IMPORT-INTO-UNITY/RelayHandler.cs @@ -7,25 +7,25 @@ namespace LightReflectiveMirror { public class RelayHandler { - List rooms = new List(); - List pendingAuthentication = new List(); - ArrayPool sendBuffers; - int maxPacketSize = 0; + private List _rooms = new List(); + private List _pendingAuthentication = new List(); + private ArrayPool _sendBuffers; + private int _maxPacketSize = 0; public RelayHandler(int maxPacketSize) { - this.maxPacketSize = maxPacketSize; - sendBuffers = ArrayPool.Create(maxPacketSize, 50); + this._maxPacketSize = maxPacketSize; + _sendBuffers = ArrayPool.Create(maxPacketSize, 50); } public void ClientConnected(int clientId) { - pendingAuthentication.Add(clientId); - var buffer = sendBuffers.Rent(1); + _pendingAuthentication.Add(clientId); + var buffer = _sendBuffers.Rent(1); int pos = 0; buffer.WriteByte(ref pos, (byte)OpCodes.AuthenticationRequest); Program.transport.ServerSend(clientId, 0, new ArraySegment(buffer, 0, pos)); - sendBuffers.Return(buffer); + _sendBuffers.Return(buffer); } public void HandleMessage(int clientId, ArraySegment segmentData, int channel) @@ -37,16 +37,16 @@ namespace LightReflectiveMirror OpCodes opcode = (OpCodes)data.ReadByte(ref pos); - if (pendingAuthentication.Contains(clientId)) + if (_pendingAuthentication.Contains(clientId)) { if (opcode == OpCodes.AuthenticationResponse) { string authResponse = data.ReadString(ref pos); if (authResponse == Program.conf.AuthenticationKey) { - pendingAuthentication.Remove(clientId); + _pendingAuthentication.Remove(clientId); int writePos = 0; - var sendBuffer = sendBuffers.Rent(1); + var sendBuffer = _sendBuffers.Rent(1); sendBuffer.WriteByte(ref writePos, (byte)OpCodes.Authenticated); Program.transport.ServerSend(clientId, 0, new ArraySegment(sendBuffer, 0, writePos)); } @@ -108,31 +108,28 @@ namespace LightReflectiveMirror } } - public void HandleDisconnect(int clientId) - { - LeaveRoom(clientId); - } + public void HandleDisconnect(int clientId) => LeaveRoom(clientId); void SendServerList(int clientId) { int pos = 0; - var buffer = sendBuffers.Rent(500); + var buffer = _sendBuffers.Rent(500); buffer.WriteByte(ref pos, (byte)OpCodes.ServerListReponse); - for(int i = 0; i < rooms.Count; i++) + for(int i = 0; i < _rooms.Count; i++) { - if (rooms[i].isPublic) + if (_rooms[i].isPublic) { buffer.WriteBool(ref pos, true); - buffer.WriteString(ref pos, rooms[i].serverName); - buffer.WriteString(ref pos, rooms[i].serverData); - buffer.WriteInt(ref pos, rooms[i].serverId); - buffer.WriteInt(ref pos, rooms[i].maxPlayers); - buffer.WriteInt(ref pos, rooms[i].clients.Count + 1); + buffer.WriteString(ref pos, _rooms[i].serverName); + buffer.WriteString(ref pos, _rooms[i].serverData); + buffer.WriteInt(ref pos, _rooms[i].serverId); + buffer.WriteInt(ref pos, _rooms[i].maxPlayers); + buffer.WriteInt(ref pos, _rooms[i].clients.Count + 1); } } buffer.WriteBool(ref pos, false); Program.transport.ServerSend(clientId, 0, new ArraySegment(buffer, 0, pos)); - sendBuffers.Return(buffer); + _sendBuffers.Return(buffer); } void ProcessData(int clientId, byte[] clientData, int channel, int sendTo = -1) @@ -148,40 +145,40 @@ namespace LightReflectiveMirror if (room.clients.Contains(sendTo)) { int pos = 0; - byte[] sendBuffer = sendBuffers.Rent(maxPacketSize); + byte[] sendBuffer = _sendBuffers.Rent(_maxPacketSize); sendBuffer.WriteByte(ref pos, (byte)OpCodes.GetData); sendBuffer.WriteBytes(ref pos, clientData); Program.transport.ServerSend(sendTo, channel, new ArraySegment(sendBuffer, 0, pos)); - sendBuffers.Return(sendBuffer); + _sendBuffers.Return(sendBuffer); } } else { // We are not the host, so send the data to the host. int pos = 0; - byte[] sendBuffer = sendBuffers.Rent(maxPacketSize); + byte[] sendBuffer = _sendBuffers.Rent(_maxPacketSize); sendBuffer.WriteByte(ref pos, (byte)OpCodes.GetData); sendBuffer.WriteBytes(ref pos, clientData); sendBuffer.WriteInt(ref pos, clientId); Program.transport.ServerSend(room.hostId, channel, new ArraySegment(sendBuffer, 0, pos)); - sendBuffers.Return(sendBuffer); + _sendBuffers.Return(sendBuffer); } } } Room GetRoomForPlayer(int clientId) { - for(int i = 0; i < rooms.Count; i++) + for(int i = 0; i < _rooms.Count; i++) { - if (rooms[i].hostId == clientId) - return rooms[i]; + if (_rooms[i].hostId == clientId) + return _rooms[i]; - if (rooms[i].clients.Contains(clientId)) - return rooms[i]; + if (_rooms[i].clients.Contains(clientId)) + return _rooms[i]; } return null; @@ -191,23 +188,23 @@ namespace LightReflectiveMirror { LeaveRoom(clientId); - for(int i = 0; i < rooms.Count; i++) + for(int i = 0; i < _rooms.Count; i++) { - if(rooms[i].serverId == serverId) + if(_rooms[i].serverId == serverId) { - if(rooms[i].clients.Count < rooms[i].maxPlayers) + if(_rooms[i].clients.Count < _rooms[i].maxPlayers) { - rooms[i].clients.Add(clientId); + _rooms[i].clients.Add(clientId); int sendJoinPos = 0; - byte[] sendJoinBuffer = sendBuffers.Rent(5); + byte[] sendJoinBuffer = _sendBuffers.Rent(5); sendJoinBuffer.WriteByte(ref sendJoinPos, (byte)OpCodes.ServerJoined); sendJoinBuffer.WriteInt(ref sendJoinPos, clientId); Program.transport.ServerSend(clientId, 0, new ArraySegment(sendJoinBuffer, 0, sendJoinPos)); - Program.transport.ServerSend(rooms[i].hostId, 0, new ArraySegment(sendJoinBuffer, 0, sendJoinPos)); - sendBuffers.Return(sendJoinBuffer); + Program.transport.ServerSend(_rooms[i].hostId, 0, new ArraySegment(sendJoinBuffer, 0, sendJoinPos)); + _sendBuffers.Return(sendJoinBuffer); return; } } @@ -215,37 +212,90 @@ namespace LightReflectiveMirror // If it got to here, then the server was not found, or full. Tell the client. int pos = 0; - byte[] sendBuffer = sendBuffers.Rent(1); + byte[] sendBuffer = _sendBuffers.Rent(1); sendBuffer.WriteByte(ref pos, (byte)OpCodes.ServerLeft); Program.transport.ServerSend(clientId, 0, new ArraySegment(sendBuffer, 0, pos)); - sendBuffers.Return(sendBuffer); + _sendBuffers.Return(sendBuffer); } void CreateRoom(int clientId, int maxPlayers, string serverName, bool isPublic, string serverData) { LeaveRoom(clientId); - Room room = new Room(); - room.hostId = clientId; - room.maxPlayers = maxPlayers; - room.serverName = serverName; - room.isPublic = isPublic; - room.serverData = serverData; - room.clients = new List(); + Room room = new Room + { + hostId = clientId, + maxPlayers = maxPlayers, + serverName = serverName, + isPublic = isPublic, + serverData = serverData, + clients = new List(), - room.serverId = GetRandomServerID(); - rooms.Add(room); + serverId = GetRandomServerID() + }; + + _rooms.Add(room); int pos = 0; - byte[] sendBuffer = sendBuffers.Rent(5); + byte[] sendBuffer = _sendBuffers.Rent(5); sendBuffer.WriteByte(ref pos, (byte)OpCodes.RoomCreated); sendBuffer.WriteInt(ref pos, clientId); Program.transport.ServerSend(clientId, 0, new ArraySegment(sendBuffer, 0, pos)); - sendBuffers.Return(sendBuffer); + _sendBuffers.Return(sendBuffer); + } + + void LeaveRoom(int clientId, int requiredHostId = -1) + { + for(int i = 0; i < _rooms.Count; i++) + { + if(_rooms[i].hostId == clientId) + { + int pos = 0; + byte[] sendBuffer = _sendBuffers.Rent(1); + sendBuffer.WriteByte(ref pos, (byte)OpCodes.ServerLeft); + + for(int x = 0; x < _rooms[i].clients.Count; x++) + Program.transport.ServerSend(_rooms[i].clients[x], 0, new ArraySegment(sendBuffer, 0, pos)); + + _sendBuffers.Return(sendBuffer); + _rooms[i].clients.Clear(); + _rooms.RemoveAt(i); + return; + } + else + { + if (requiredHostId >= 0 && _rooms[i].hostId != requiredHostId) + continue; + + if(_rooms[i].clients.RemoveAll(x => x == clientId) > 0) + { + int pos = 0; + byte[] sendBuffer = _sendBuffers.Rent(5); + + sendBuffer.WriteByte(ref pos, (byte)OpCodes.PlayerDisconnected); + sendBuffer.WriteInt(ref pos, clientId); + + Program.transport.ServerSend(_rooms[i].hostId, 0, new ArraySegment(sendBuffer, 0, pos)); + _sendBuffers.Return(sendBuffer); + } + } + } + } + + void SendClientID(int clientId) + { + int pos = 0; + byte[] sendBuffer = _sendBuffers.Rent(5); + + sendBuffer.WriteByte(ref pos, (byte)OpCodes.GetID); + sendBuffer.WriteInt(ref pos, clientId); + + Program.transport.ServerSend(clientId, 0, new ArraySegment(sendBuffer, 0, pos)); + _sendBuffers.Return(sendBuffer); } int GetRandomServerID() @@ -261,64 +311,12 @@ namespace LightReflectiveMirror bool DoesServerIdExist(int id) { - for (int i = 0; i < rooms.Count; i++) - { - if (rooms[i].serverId == id) + for (int i = 0; i < _rooms.Count; i++) + if (_rooms[i].serverId == id) return true; - } return false; } - - void LeaveRoom(int clientId, int requiredHostId = -1) - { - for(int i = 0; i < rooms.Count; i++) - { - if(rooms[i].hostId == clientId) - { - int pos = 0; - byte[] sendBuffer = sendBuffers.Rent(1); - sendBuffer.WriteByte(ref pos, (byte)OpCodes.ServerLeft); - - for(int x = 0; x < rooms[i].clients.Count; x++) - Program.transport.ServerSend(rooms[i].clients[x], 0, new ArraySegment(sendBuffer, 0, pos)); - - sendBuffers.Return(sendBuffer); - rooms[i].clients.Clear(); - rooms.RemoveAt(i); - return; - } - else - { - if (requiredHostId >= 0 && rooms[i].hostId != requiredHostId) - continue; - - if(rooms[i].clients.RemoveAll(x => x == clientId) > 0) - { - int pos = 0; - byte[] sendBuffer = sendBuffers.Rent(5); - - sendBuffer.WriteByte(ref pos, (byte)OpCodes.PlayerDisconnected); - sendBuffer.WriteInt(ref pos, clientId); - - Program.transport.ServerSend(rooms[i].hostId, 0, new ArraySegment(sendBuffer, 0, pos)); - sendBuffers.Return(sendBuffer); - } - } - } - } - - void SendClientID(int clientId) - { - int pos = 0; - byte[] sendBuffer = sendBuffers.Rent(5); - - sendBuffer.WriteByte(ref pos, (byte)OpCodes.GetID); - sendBuffer.WriteInt(ref pos, clientId); - - Program.transport.ServerSend(clientId, 0, new ArraySegment(sendBuffer, 0, pos)); - sendBuffers.Return(sendBuffer); - } } public enum OpCodes From 84209facac3888fe303ec61a49ff105a86ef3714 Mon Sep 17 00:00:00 2001 From: cxxpxr <60411087+cxxpxr@users.noreply.github.com> Date: Mon, 29 Mar 2021 15:18:57 -0400 Subject: [PATCH 2/3] Delete ServerProject-DONT-IMPORT-INTO-UNITY/.vs/LRM-Server/v16 directory --- .../.vs/LRM-Server/v16/.suo | Bin 60416 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 ServerProject-DONT-IMPORT-INTO-UNITY/.vs/LRM-Server/v16/.suo diff --git a/ServerProject-DONT-IMPORT-INTO-UNITY/.vs/LRM-Server/v16/.suo b/ServerProject-DONT-IMPORT-INTO-UNITY/.vs/LRM-Server/v16/.suo deleted file mode 100644 index 9305656caa78f313a288969b3bcbd97de32996a9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 60416 zcmeHQ349yHxnJi7k^m)za0O$I2C$4R%d(sVh%MQPgB_dLIUo)oOKV4oEQytD$HWF+ zpraBH)zh z^%5M<0Qj!sqJ9iV+KZ#tEED=I!0|o6a^Uo+-$^(g4;&l4X1MWi=i&WLz#3pJ&e~)5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}q;!pikF8l2#$3K<+$;1ZxvGOaZ{wX=V$=4~;U(`QA zlQpsWrv&}k_~@Us=vPFu>(9ojf6~HTo?tMfYF+8S5s}Y8t|0u(KfV&73uYHr% zRu<{se^wMx@k^AkRea`pLQdzX!PxQ?HFWF)rQuC(W0RAiKcv;cPN?ar-Q5YjC@tBj zH>^Sq@SiR=%a}9_VvTtb8pZr(?<30E=;TAL-xn0K_hRxv>dEulFDvu6j>W9fWu{U% zi2A{A3cH~_rVU4`xf}~PGrvqM?o}vzOQv()xzQ>@s3pc$GqK-)N?bE)j7PlninVu- zn<~TPDYB`uTjd75mCEmID+<5Cv)xpRa;cT+@{gMSpPQmKRr62q2>H!=@wIY(#p%gu z-Ts`Y74qA-B2AvZJafvP1+Sm^>PbNP}xKk)p^vuYmu>6?E$9R->2 zy(cbx&(Cs~`@&I%*f**5qQ?yT9D5V^>hkb+kF9k)7P_|Q_6Kj8bLFo}UVH!7&wJuD z?X};R&0h2~EmgMCFRRmHv%LBBUh)fvYticj(C=`{Ueh^p7_?^t)4ScK>S6GqDx~Yx zNv(HdEjRPBr-GUFsVifVe;6J0A;# From 5a490c888f8baad19f96edb615a077882e1d783f Mon Sep 17 00:00:00 2001 From: cxxpxr <60411087+cxxpxr@users.noreply.github.com> Date: Mon, 29 Mar 2021 15:30:06 -0400 Subject: [PATCH 3/3] refactor --- .../Program.cs | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/ServerProject-DONT-IMPORT-INTO-UNITY/Program.cs b/ServerProject-DONT-IMPORT-INTO-UNITY/Program.cs index 4cc8ca3..95effd8 100644 --- a/ServerProject-DONT-IMPORT-INTO-UNITY/Program.cs +++ b/ServerProject-DONT-IMPORT-INTO-UNITY/Program.cs @@ -13,11 +13,11 @@ namespace LightReflectiveMirror public static Transport transport; public static Config conf; - private RelayHandler relay; - private MethodInfo awakeMethod; - private MethodInfo startMethod; - private MethodInfo updateMethod; - private MethodInfo lateUpdateMethod; + private RelayHandler _relay; + private MethodInfo _awakeMethod; + private MethodInfo _startMethod; + private MethodInfo _updateMethod; + private MethodInfo _lateUpdateMethod; private List _currentConnections = new List(); private int _currentHeartbeatTimer = 0; @@ -55,15 +55,15 @@ namespace LightReflectiveMirror WriteLogMessage($"Loaded Transport: {transportClass.Name}! Loading Methods...", ConsoleColor.Green); CheckMethods(transportClass); - if (awakeMethod != null) + if (_awakeMethod != null) { - awakeMethod.Invoke(transport, null); + _awakeMethod.Invoke(transport, null); WriteLogMessage("Called Awake on transport.", ConsoleColor.Yellow); } - if (startMethod != null) + if (_startMethod != null) { - awakeMethod.Invoke(transport, null); + _awakeMethod.Invoke(transport, null); WriteLogMessage("Called Start on transport.", ConsoleColor.Yellow); } @@ -78,16 +78,16 @@ namespace LightReflectiveMirror { WriteLogMessage($"Transport Connected, Client: {clientID}", ConsoleColor.Cyan); _currentConnections.Add(clientID); - relay.ClientConnected(clientID); + _relay.ClientConnected(clientID); }; - relay = new RelayHandler(transport.GetMaxPacketSize(0)); + _relay = new RelayHandler(transport.GetMaxPacketSize(0)); - transport.OnServerDataReceived = relay.HandleMessage; + transport.OnServerDataReceived = _relay.HandleMessage; transport.OnServerDisconnected = (clientID) => { _currentConnections.Remove(clientID); - relay.HandleDisconnect(clientID); + _relay.HandleDisconnect(clientID); }; transport.ServerStart(); @@ -111,8 +111,8 @@ namespace LightReflectiveMirror while (true) { - if (updateMethod != null) { updateMethod.Invoke(transport, null); } - if (lateUpdateMethod != null) { lateUpdateMethod.Invoke(transport, null); } + if (_updateMethod != null) _updateMethod.Invoke(transport, null); + if (_lateUpdateMethod != null) _lateUpdateMethod.Invoke(transport, null); _currentHeartbeatTimer++; @@ -138,15 +138,15 @@ namespace LightReflectiveMirror void CheckMethods(Type type) { - awakeMethod = type.GetMethod("Awake", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); - startMethod = type.GetMethod("Start", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); - updateMethod = type.GetMethod("Update", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); - lateUpdateMethod = type.GetMethod("LateUpdate", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); + _awakeMethod = type.GetMethod("Awake", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); + _startMethod = type.GetMethod("Start", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); + _updateMethod = type.GetMethod("Update", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); + _lateUpdateMethod = type.GetMethod("LateUpdate", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); - if (awakeMethod != null) { WriteLogMessage("'Awake' Loaded!", ConsoleColor.Yellow); } - if (startMethod != null) { WriteLogMessage("'Start' Loaded!", ConsoleColor.Yellow); } - if (updateMethod != null) { WriteLogMessage("'Update' Loaded!", ConsoleColor.Yellow); } - if (lateUpdateMethod != null) { WriteLogMessage("'LateUpdate' Loaded!", ConsoleColor.Yellow); } + if (_awakeMethod != null) WriteLogMessage("'Awake' Loaded!", ConsoleColor.Yellow); + if (_startMethod != null) WriteLogMessage("'Start' Loaded!", ConsoleColor.Yellow); + if (_updateMethod != null) WriteLogMessage("'Update' Loaded!", ConsoleColor.Yellow); + if (_lateUpdateMethod != null) WriteLogMessage("'LateUpdate' Loaded!", ConsoleColor.Yellow); } void WriteTitle()