mirror of
https://git.battle-of-pip.de/root/vpr-mitarbeiterverwaltung.git
synced 2025-12-13 22:31:38 +01:00
updated CommandManager.cs to use attributes instead of Classes
This commit is contained in:
73
Server/CommandLibrary.cs
Normal file
73
Server/CommandLibrary.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
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 <username> <password>");
|
||||
|
||||
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
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user