refactor: server

This commit is contained in:
2025-03-31 22:40:36 +02:00
parent f0ea538c21
commit 8599c14979
4 changed files with 72 additions and 47 deletions

View File

@@ -10,28 +10,48 @@ public class App {
}
public static void main(String[] args) {
if (args.length == 0) {
System.out.println(
"Please use --args='client' or --args='server'."
);
String mode = null;
// Parse arguments
for (String arg : args) {
switch (arg.toLowerCase()) {
case "--client":
mode = "client";
break;
case "--server":
mode = "server";
break;
default:
System.out.println("Unknown argument: " + arg);
printUsage();
return;
}
}
// Check if mode is specified
if (mode == null) {
System.out.println("No mode specified.");
printUsage();
return;
}
String mode = args[0];
switch (mode.toLowerCase()) {
// Execute based on mode
switch (mode) {
case "client":
// Run the client
System.out.println("Starting client...");
Client.main(new String[] {});
break;
case "server":
// Run the server
System.out.println("Starting server...");
Server.run();
break;
default:
System.out.println("Unknown mode: " + mode);
}
}
private static void printUsage() {
System.out.println("Usage: ./gradlew run --args='option'");
System.out.println("Options:");
System.out.println(" --client Run in client mode");
System.out.println(" --server Run in server mode");
}
}