Merge pull request #5 from cxxpxr/main

fixed dead lobby joining and added monke branding
This commit is contained in:
Derek S 2021-03-27 10:12:04 -05:00 committed by GitHub
commit 862ae51f9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 7 deletions

View file

@ -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<int> _currentConnections = new List<int>();
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);
}
}
}

View file

@ -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<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);
return;
}
@ -235,6 +235,7 @@ namespace LightReflectiveMirror
room.serverData = serverData;
room.clients = new List<int>();
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++)

View file

@ -6,6 +6,7 @@ namespace LightReflectiveMirror
{
class Room
{
public int serverId;
public int hostId;
public string serverName;
public string serverData;