Merge pull request #5 from cxxpxr/main
fixed dead lobby joining and added monke branding
This commit is contained in:
commit
862ae51f9e
4 changed files with 58 additions and 7 deletions
BIN
ServerProject-DONT-IMPORT-INTO-UNITY/.vs/LRM-Server/v16/.suo
Normal file
BIN
ServerProject-DONT-IMPORT-INTO-UNITY/.vs/LRM-Server/v16/.suo
Normal file
Binary file not shown.
|
|
@ -10,13 +10,15 @@ namespace LightReflectiveMirror
|
||||||
{
|
{
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
|
public static Transport transport;
|
||||||
public static Config conf;
|
public static Config conf;
|
||||||
RelayHandler relay;
|
RelayHandler relay;
|
||||||
public static Transport transport;
|
|
||||||
MethodInfo awakeMethod;
|
MethodInfo awakeMethod;
|
||||||
MethodInfo startMethod;
|
MethodInfo startMethod;
|
||||||
MethodInfo updateMethod;
|
MethodInfo updateMethod;
|
||||||
MethodInfo lateUpdateMethod;
|
MethodInfo lateUpdateMethod;
|
||||||
|
|
||||||
List<int> _currentConnections = new List<int>();
|
List<int> _currentConnections = new List<int>();
|
||||||
int _currentHeartbeatTimer = 0;
|
int _currentHeartbeatTimer = 0;
|
||||||
|
|
||||||
|
|
@ -25,6 +27,7 @@ namespace LightReflectiveMirror
|
||||||
|
|
||||||
public async Task MainAsync()
|
public async Task MainAsync()
|
||||||
{
|
{
|
||||||
|
WriteTitle();
|
||||||
|
|
||||||
if (!File.Exists("config.json"))
|
if (!File.Exists("config.json"))
|
||||||
{
|
{
|
||||||
|
|
@ -41,12 +44,15 @@ namespace LightReflectiveMirror
|
||||||
Console.WriteLine(Directory.GetCurrentDirectory());
|
Console.WriteLine(Directory.GetCurrentDirectory());
|
||||||
var asm = Assembly.LoadFile(Directory.GetCurrentDirectory() + @"\" + conf.TransportDLL);
|
var asm = Assembly.LoadFile(Directory.GetCurrentDirectory() + @"\" + conf.TransportDLL);
|
||||||
WriteLogMessage($"Loaded Assembly: {asm.FullName}", ConsoleColor.Green);
|
WriteLogMessage($"Loaded Assembly: {asm.FullName}", ConsoleColor.Green);
|
||||||
transport = (Transport)asm.CreateInstance(conf.TransportClass);
|
|
||||||
|
transport = asm.CreateInstance(conf.TransportClass) as Transport;
|
||||||
|
|
||||||
if (transport != null)
|
if (transport != null)
|
||||||
{
|
{
|
||||||
WriteLogMessage($"Loaded Transport: {asm.GetType(conf.TransportClass).Name}! Loading Methods...", ConsoleColor.Green);
|
var transportClass = asm.GetType(conf.TransportClass);
|
||||||
CheckMethods(asm.GetType(conf.TransportClass));
|
|
||||||
|
WriteLogMessage($"Loaded Transport: {transportClass.Name}! Loading Methods...", ConsoleColor.Green);
|
||||||
|
CheckMethods(transportClass);
|
||||||
|
|
||||||
if (awakeMethod != null)
|
if (awakeMethod != null)
|
||||||
{
|
{
|
||||||
|
|
@ -152,5 +158,26 @@ namespace LightReflectiveMirror
|
||||||
if (lateUpdateMethod != null)
|
if (lateUpdateMethod != null)
|
||||||
WriteLogMessage("'LateUpdate' Loaded!", ConsoleColor.Yellow);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -125,7 +125,7 @@ namespace LightReflectiveMirror
|
||||||
buffer.WriteBool(ref pos, true);
|
buffer.WriteBool(ref pos, true);
|
||||||
buffer.WriteString(ref pos, rooms[i].serverName);
|
buffer.WriteString(ref pos, rooms[i].serverName);
|
||||||
buffer.WriteString(ref pos, rooms[i].serverData);
|
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].maxPlayers);
|
||||||
buffer.WriteInt(ref pos, rooms[i].clients.Count + 1);
|
buffer.WriteInt(ref pos, rooms[i].clients.Count + 1);
|
||||||
}
|
}
|
||||||
|
|
@ -193,7 +193,7 @@ namespace LightReflectiveMirror
|
||||||
|
|
||||||
for(int i = 0; i < rooms.Count; i++)
|
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)
|
if(rooms[i].clients.Count < rooms[i].maxPlayers)
|
||||||
{
|
{
|
||||||
|
|
@ -206,7 +206,7 @@ namespace LightReflectiveMirror
|
||||||
sendJoinBuffer.WriteInt(ref sendJoinPos, clientId);
|
sendJoinBuffer.WriteInt(ref sendJoinPos, clientId);
|
||||||
|
|
||||||
Program.transport.ServerSend(clientId, 0, new ArraySegment<byte>(sendJoinBuffer, 0, sendJoinPos));
|
Program.transport.ServerSend(clientId, 0, new ArraySegment<byte>(sendJoinBuffer, 0, sendJoinPos));
|
||||||
Program.transport.ServerSend(serverId, 0, new ArraySegment<byte>(sendJoinBuffer, 0, sendJoinPos));
|
Program.transport.ServerSend(rooms[i].hostId, 0, new ArraySegment<byte>(sendJoinBuffer, 0, sendJoinPos));
|
||||||
sendBuffers.Return(sendJoinBuffer);
|
sendBuffers.Return(sendJoinBuffer);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -235,6 +235,7 @@ namespace LightReflectiveMirror
|
||||||
room.serverData = serverData;
|
room.serverData = serverData;
|
||||||
room.clients = new List<int>();
|
room.clients = new List<int>();
|
||||||
|
|
||||||
|
room.serverId = GetRandomServerID();
|
||||||
rooms.Add(room);
|
rooms.Add(room);
|
||||||
|
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
|
@ -247,6 +248,28 @@ namespace LightReflectiveMirror
|
||||||
sendBuffers.Return(sendBuffer);
|
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)
|
void LeaveRoom(int clientId, int requiredHostId = -1)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < rooms.Count; i++)
|
for(int i = 0; i < rooms.Count; i++)
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ namespace LightReflectiveMirror
|
||||||
{
|
{
|
||||||
class Room
|
class Room
|
||||||
{
|
{
|
||||||
|
public int serverId;
|
||||||
public int hostId;
|
public int hostId;
|
||||||
public string serverName;
|
public string serverName;
|
||||||
public string serverData;
|
public string serverData;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue