proper sessions, packet still not read as it should be

This commit is contained in:
rafi1212122
2023-05-26 10:21:53 +07:00
parent 6e87fc6ef2
commit 7a12c9ec55
6 changed files with 170 additions and 17 deletions

View File

@@ -8,27 +8,50 @@ namespace PemukulPaku.Gameserver
public class Server
{
public static readonly Logger c = new("TCP", ConsoleColor.Blue);
public readonly Dictionary<string, Session> Sessions = new();
private static Server? Instance;
public static void Start()
public static Server GetInstance() {
return Instance ??= new Server();
}
public Server()
{
Task.Run(Start);
}
public void Start()
{
TcpListener Listener = new(IPAddress.Parse("0.0.0.0"), (int)Global.config.Gameserver.Port);
try
while(true)
{
Listener.Start();
c.Log($"TCP server started on port {Global.config.Gameserver.Port}");
while (true)
try
{
TcpClient Client = Listener.AcceptTcpClient();
c.Warn($"{Client.Client.RemoteEndPoint} connected!");
NetworkStream stream = Client.GetStream();
Listener.Start();
c.Log($"TCP server started on port {Global.config.Gameserver.Port}");
while (true)
{
TcpClient Client = Listener.AcceptTcpClient();
string Id = Client.Client.RemoteEndPoint!.ToString()!;
c.Warn($"{Id} connected");
Sessions.Add(Id, new Session(Id, Client));
LogClients();
}
}
catch (Exception ex)
{
c.Error("TCP server error: " + ex.Message);
Thread.Sleep(3000);
}
}
catch (Exception ex)
{
c.Error("TCP server error: " + ex.Message);
}
}
public void LogClients()
{
c.Log($"Connected clients: {Sessions.Count}");
}
}
}