Set all the required information on server when auth.

This commit is contained in:
derek.holloway committed 2026-08-04 08:26:27 -07:00
1 parent d446464f2a
commit 007f87f986
5 files changed
+27 -15

No files matched your search

+13 -7
View File
@@ -21,18 +21,24 @@ namespace Mistox.Server {
private readonly ServerListener Listener; // The Connection Listener singleton
public MistoxServer(IPEndPoint ListenerAddress, string serverName) {
Listener = new ServerListener(ListenerAddress, this);
Connections = new ConcurrentDictionary<string, ServerConnection>();
ServerName = serverName;
Listener = new ServerListener(ListenerAddress, this);
Console.WriteLine( "The Server is initilized and waiting for clients to connect at port : " + ListenerAddress.Port );
}
async Task ProcessAuthRequest(UserAuthPacket packet) {
// Need to set the connection userName via this packet
string user = packet.UserName;
async Task ProcessAuthRequest(ServerConnection user, UserAuthPacket packet) {
packet.ServerName = ServerName;
packet.AuthSuccessful = packet.ConnectionKey == ConnectionKey ? 1 : 0;
if (packet.ConnectionKey == ConnectionKey) {
packet.AuthSuccessful = 1;
Connections.TryRemove(user.UserName, out _);
user.UserName = packet.UserName;
Connections[packet.UserName] = user;
user.IsAuthenticated = true;
} else {
packet.AuthSuccessful = -1;
}
await SendClient(packet.UserName, packet);
}
@@ -44,12 +50,12 @@ namespace Mistox.Server {
}
public event Action<dynamic> onDataReceived;
public void InvokeDataReceived( dynamic data ){
public void InvokeDataReceived( ServerConnection user, dynamic data ){
switch (data as object) {
case UserAuthPacket packet:
Task.Run(async () => {
try {
await ProcessAuthRequest(packet);
await ProcessAuthRequest(user, packet);
} catch {}
});
break;