mirror of
https://git.battle-of-pip.de/root/vpr-mitarbeiterverwaltung.git
synced 2025-10-15 02:24:53 +02:00
First Server Test | Next Update: Change Commands to Attributes
This commit is contained in:
6
Server/Commands/ClockCommand.cs
Normal file
6
Server/Commands/ClockCommand.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Server.Commands;
|
||||
|
||||
public class ClockCommand
|
||||
{
|
||||
|
||||
}
|
6
Server/Commands/GetCommand.cs
Normal file
6
Server/Commands/GetCommand.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Server.Commands;
|
||||
|
||||
public class GetCommand
|
||||
{
|
||||
|
||||
}
|
@@ -6,19 +6,21 @@ namespace Server.Commands;
|
||||
public class HelpCommand : ICommand
|
||||
{
|
||||
public string Executor { get; }
|
||||
|
||||
public HelpCommand()
|
||||
{
|
||||
Executor = "help";
|
||||
}
|
||||
public void Exec(string[] args, TcpClient? client = null, TcpServer? clientSocket = null)
|
||||
public string Exec(string[] args, TcpClient? client = null, TcpServer? clientSocket = null)
|
||||
{
|
||||
clientSocket.SendMessageAsync(client, "" +
|
||||
return
|
||||
"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");
|
||||
"6. stop - Stop the server\n"
|
||||
;
|
||||
}
|
||||
}
|
@@ -6,5 +6,5 @@ namespace Server.Commands;
|
||||
public interface ICommand
|
||||
{
|
||||
string Executor { get; }
|
||||
public void Exec(string[] args, TcpClient? client = null, TcpServer? clientSocket = null);
|
||||
public string Exec(string[] args, TcpClient? client, TcpServer? clientSocket);
|
||||
}
|
34
Server/Commands/LoginCommand.cs
Normal file
34
Server/Commands/LoginCommand.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Net.Sockets;
|
||||
using DX86;
|
||||
using MySqlX.XDevAPI;
|
||||
|
||||
namespace Server.Commands;
|
||||
|
||||
public class LoginCommand : ICommand
|
||||
{
|
||||
public string Executor { get; }
|
||||
|
||||
public LoginCommand()
|
||||
{
|
||||
Executor = "login";
|
||||
}
|
||||
public string Exec(string[] args, TcpClient? client, TcpServer? clientSocket)
|
||||
{
|
||||
|
||||
if (args[0] == "test" && args[1] == "test")
|
||||
{
|
||||
if (client != null)
|
||||
{
|
||||
//clientSocket?.SendMessageAsync(client, "Login successful");
|
||||
clientSocket?.LoggedInClients.Add(client, "test");
|
||||
return "Login successful";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (client != null) return "Invalid credentials";
|
||||
}
|
||||
|
||||
return "No client provided or invalid credentials";
|
||||
}
|
||||
}
|
30
Server/Commands/LogoutCommand.cs
Normal file
30
Server/Commands/LogoutCommand.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System.Net.Sockets;
|
||||
using DX86;
|
||||
|
||||
namespace Server.Commands;
|
||||
|
||||
public class LogoutCommand : ICommand
|
||||
{
|
||||
public string Executor { get; }
|
||||
public LogoutCommand()
|
||||
{
|
||||
Executor = "logout";
|
||||
}
|
||||
public string Exec(string[] args, TcpClient? client = null, TcpServer? clientSocket = null)
|
||||
{
|
||||
if (clientSocket == null && client == null)
|
||||
return "Please provide a valid client or clientSocket.";
|
||||
|
||||
if (client != null && clientSocket != null && clientSocket.LoggedInClients.ContainsKey(client))
|
||||
{
|
||||
clientSocket.LoggedInClients.Remove(client);
|
||||
//clientSocket.SendMessageAsync(client, "Success");
|
||||
return "Logout successful.";
|
||||
}
|
||||
else
|
||||
{
|
||||
//clientSocket?.SendMessageAsync(client, "Logout failed. You are not logged in.");
|
||||
return "Logout failed. You are not logged in.";
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user