First Server Test | Next Update: Change Commands to Attributes

This commit is contained in:
SnapixLP | Tim G.
2025-06-05 08:27:40 +02:00
parent 67bfce265c
commit 4be4ee34cb
12 changed files with 148 additions and 26 deletions

View File

@@ -1,5 +1,6 @@
using System.Net.Sockets;
using System.Reflection;
using System.Text.Json;
using DX86;
using Server.Commands;
@@ -32,15 +33,22 @@ public class CommandManager
}
}
public void ExecuteCommand(string executor, TcpClient? client = null, TcpServer? clientSocket = null, params string[] args)
public void ExecuteCommand(string executor, TcpClient? client = null, TcpServer? clientSocket = null, string cid = "", params string[] args)
{
if (_commands.TryGetValue(executor, out var command))
{
command.Exec(args:args, client:client, clientSocket:clientSocket);
JsonMessage returnMessage = new JsonMessage();
returnMessage.cid = cid;
returnMessage.cmd = command.Exec(args:args, client:client, clientSocket:clientSocket);
string sendClientMessage = JsonSerializer.Serialize(returnMessage);
clientSocket.SendMessageAsync(client:client, message:sendClientMessage+"\n");
//clientSocket.SendMessageAsync(client:client, message:command.Exec(args:args, client:client, clientSocket:clientSocket));
}
else
{
Console.WriteLine($"Command '{executor}' not found.");
Program.messageSender.Log($"[COMMANDMANAGER] Command '{executor}' not found.");
}
}
}