using System.Net.Sockets; using DX86; using Server.Commands; namespace Server; public class CommandLibrary { [Command("example")] public static string ExampleCommand(string[] args, TcpClient? client, TcpServer? socket) => $"Example command executed with arguments: {string.Join(", ", args)}"; #region Basic Commands [Command("help")] public static string HelpCommand() => "Available commands:\n" + "1. help - Show this help message\n" + "2. exit - Exit the server\n" + "3. user - User management\n" + "4. settings - Server settings\n" + "5. start - Start the server\n" + "6. stop - Stop the server\n"; #endregion #region Client Commands [Command("login")] public static string LoginCommand(string[] args, TcpClient? client, TcpServer? socket) { if (args.Length < 2) throw new CommandException("Missing arguments: usage is login "); string username = args[0]; string password = args[1]; if (username == "test" && password == "1234") { if (client != null) { socket?.LoggedInClients.Add(client, username); return "Login successful"; } throw new CommandException("No client connection detected."); } throw new CommandException("Invalid username or password."); } [Command("logout")] public static string LogoutCommand(TcpClient? client, TcpServer? socket) { if (client != null && socket?.LoggedInClients.ContainsKey(client) == true) { socket.LoggedInClients.Remove(client); return "Logout successful"; } throw new CommandException("No client provided or not logged in"); } #endregion #region Administration Commands [Command("get")] public static string GetCommand(string[] args, TcpClient? client, TcpServer? socket) => $"not implemented yet, args: {string.Join(", ", args)}"; #endregion }