diff --git a/ServerProject-DONT-IMPORT-INTO-UNITY/.vs/LRM-Server/v16/.suo b/ServerProject-DONT-IMPORT-INTO-UNITY/.vs/LRM-Server/v16/.suo new file mode 100644 index 0000000..c550625 Binary files /dev/null and b/ServerProject-DONT-IMPORT-INTO-UNITY/.vs/LRM-Server/v16/.suo differ diff --git a/ServerProject-DONT-IMPORT-INTO-UNITY/Program.cs b/ServerProject-DONT-IMPORT-INTO-UNITY/Program.cs index 23f6117..b12a7bf 100644 --- a/ServerProject-DONT-IMPORT-INTO-UNITY/Program.cs +++ b/ServerProject-DONT-IMPORT-INTO-UNITY/Program.cs @@ -10,13 +10,15 @@ namespace LightReflectiveMirror { class Program { + public static Transport transport; public static Config conf; RelayHandler relay; - public static Transport transport; + MethodInfo awakeMethod; MethodInfo startMethod; MethodInfo updateMethod; MethodInfo lateUpdateMethod; + List _currentConnections = new List(); int _currentHeartbeatTimer = 0; @@ -25,6 +27,7 @@ namespace LightReflectiveMirror public async Task MainAsync() { + WriteTitle(); if (!File.Exists("config.json")) { @@ -41,12 +44,15 @@ namespace LightReflectiveMirror Console.WriteLine(Directory.GetCurrentDirectory()); var asm = Assembly.LoadFile(Directory.GetCurrentDirectory() + @"\" + conf.TransportDLL); WriteLogMessage($"Loaded Assembly: {asm.FullName}", ConsoleColor.Green); - transport = (Transport)asm.CreateInstance(conf.TransportClass); + + transport = asm.CreateInstance(conf.TransportClass) as Transport; if (transport != null) { - WriteLogMessage($"Loaded Transport: {asm.GetType(conf.TransportClass).Name}! Loading Methods...", ConsoleColor.Green); - CheckMethods(asm.GetType(conf.TransportClass)); + var transportClass = asm.GetType(conf.TransportClass); + + WriteLogMessage($"Loaded Transport: {transportClass.Name}! Loading Methods...", ConsoleColor.Green); + CheckMethods(transportClass); if (awakeMethod != null) { @@ -152,5 +158,26 @@ namespace LightReflectiveMirror if (lateUpdateMethod != null) WriteLogMessage("'LateUpdate' Loaded!", ConsoleColor.Yellow); } + + void WriteTitle() + { + string t = @" + w c(..)o ( + _ _____ __ __ \__(-) __) + | | | __ \ | \/ | /\ ( + | | | |__) || \ / | /(_)___) + | | | _ / | |\/| | w /| + | |____ | | \ \ | | | | | \ + |______||_| \_\|_| |_| m m copyright monkesoft 2021 + +"; + + string load = $"Chimp Event Listener Initializing... OK" + + "\nHarambe Memorial Initializing... OK" + + "\nBananas initializing... OK\n"; + + WriteLogMessage(t, ConsoleColor.Green); + WriteLogMessage(load, ConsoleColor.Cyan); + } } } diff --git a/ServerProject-DONT-IMPORT-INTO-UNITY/RelayHandler.cs b/ServerProject-DONT-IMPORT-INTO-UNITY/RelayHandler.cs index b44303d..57aca00 100644 --- a/ServerProject-DONT-IMPORT-INTO-UNITY/RelayHandler.cs +++ b/ServerProject-DONT-IMPORT-INTO-UNITY/RelayHandler.cs @@ -125,7 +125,7 @@ namespace LightReflectiveMirror 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].hostId); + buffer.WriteInt(ref pos, rooms[i].serverId); buffer.WriteInt(ref pos, rooms[i].maxPlayers); buffer.WriteInt(ref pos, rooms[i].clients.Count + 1); } @@ -193,7 +193,7 @@ namespace LightReflectiveMirror for(int i = 0; i < rooms.Count; i++) { - if(rooms[i].hostId == serverId) + if(rooms[i].serverId == serverId) { if(rooms[i].clients.Count < rooms[i].maxPlayers) { @@ -206,7 +206,7 @@ namespace LightReflectiveMirror sendJoinBuffer.WriteInt(ref sendJoinPos, clientId); Program.transport.ServerSend(clientId, 0, new ArraySegment(sendJoinBuffer, 0, sendJoinPos)); - Program.transport.ServerSend(serverId, 0, new ArraySegment(sendJoinBuffer, 0, sendJoinPos)); + Program.transport.ServerSend(rooms[i].hostId, 0, new ArraySegment(sendJoinBuffer, 0, sendJoinPos)); sendBuffers.Return(sendJoinBuffer); return; } @@ -235,6 +235,7 @@ namespace LightReflectiveMirror room.serverData = serverData; room.clients = new List(); + room.serverId = GetRandomServerID(); rooms.Add(room); int pos = 0; @@ -247,6 +248,28 @@ namespace LightReflectiveMirror sendBuffers.Return(sendBuffer); } + int GetRandomServerID() + { + Random rand = new Random(); + int temp = rand.Next(int.MinValue, int.MaxValue); + + while (DoesServerIdExist(temp)) + temp = rand.Next(int.MinValue, int.MaxValue); + + return temp; + } + + bool DoesServerIdExist(int 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++) diff --git a/ServerProject-DONT-IMPORT-INTO-UNITY/Room.cs b/ServerProject-DONT-IMPORT-INTO-UNITY/Room.cs index 06386e4..a284c10 100644 --- a/ServerProject-DONT-IMPORT-INTO-UNITY/Room.cs +++ b/ServerProject-DONT-IMPORT-INTO-UNITY/Room.cs @@ -6,6 +6,7 @@ namespace LightReflectiveMirror { class Room { + public int serverId; public int hostId; public string serverName; public string serverData;