1
0
Fork 0

Add own ip as cli arg and add examples to readme

This commit is contained in:
qvalentin 2022-04-12 12:47:26 +02:00
parent f60eaf1da6
commit c958cc6634
Signed by: qvalentin
GPG key ID: C979FA1EAFCABF1C
2 changed files with 68 additions and 19 deletions

View file

@ -11,6 +11,7 @@ if __name__ == "__main__":
"""
Getting the args
- own ip
- own port
Optional: A neighbour:
@ -22,22 +23,25 @@ if __name__ == "__main__":
args = sys.argv
print(args)
if len(args) >= 2:
own_port = int(args[1])
if len(args) >= 3:
own_ip = args[1]
own_port = int(args[2])
else:
print("using default ip 0.0.0.0")
print("using default port 8080")
own_ip = "0.0.0.0"
own_port = 8080
neighbours = Neighbours(own_process=Member("0.0.0.0", own_port))
neighbours = Neighbours(own_process=Member(own_ip, own_port))
game_state = GameState(neighbours)
server = Server(neighbours, game_state)
n_direction = Direction.LEFT
if len(args) > 4:
n_direction = args[4]
if len(args) >= 4:
n_ip = args[2]
n_port = int(args[3])
if len(args) > 5:
n_direction = args[5]
if len(args) >= 5:
n_ip = args[3]
n_port = int(args[4])
neighbours.connect(Direction[n_direction], n_ip, n_port)
serverThread = threading.Thread(target=server.start)