This repository has been archived on 2025-01-04. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
NightTrainToBudapest/src/main/java/ch/unibas/dmi/dbis/cs108/NightTrainToBudapest.java
2022-04-18 22:11:56 +02:00

43 lines
1.5 KiB
Java

package ch.unibas.dmi.dbis.cs108;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.Client;
import ch.unibas.dmi.dbis.cs108.multiplayer.server.Server;
import java.net.InetAddress;
public class NightTrainToBudapest {
/**
* The main Method of the jar build of this project. calls either the main method of the server or
* the main method of the client
* @param args the arguments are either client {@code <hostadress>:<port> [<username>] or server <port>}
*/
public static void main(String[] args) {
try {
String clientOrServer = args[0];
if (clientOrServer.equalsIgnoreCase("client")) {
String addrString = args[1].substring(0, args[1].indexOf(":"));
InetAddress addr = InetAddress.getByName(addrString);
int port = Integer.parseInt(args[1].substring(args[1].indexOf(":") + 1));
String username = null;
if (args.length > 2) { //if the client provided a username
//StringBuilder usernamebuilder = new StringBuilder(); todo: support username with spaces.
username = args[2];
}
Client.main(addr, port, username);
} else if (clientOrServer.equalsIgnoreCase("server")) {
int port = Integer.parseInt(args[1]);
Server.main(port);
} else {
System.out.println("invalid arguments!");
}
} catch (Exception e) {
System.out.println("Please give more arguments.");
System.out.println("Syntax:");
System.out.println("client <hostadress>:<port> [<username>] | server <port>");
e.printStackTrace();
}
}
}