diff --git a/client/client.py b/client/client.py index 494fc4a..e8cede5 100644 --- a/client/client.py +++ b/client/client.py @@ -11,6 +11,8 @@ from netwrapper import NetWrapper ABSOLUTE_PATH = os.path.abspath(os.path.dirname(sys.argv[0])) DOWNLOAD_LOCATION = ABSOLUTE_PATH + os.path.sep + 'download' + os.path.sep CONFIG_LOCATION = ABSOLUTE_PATH + os.path.sep + 'config' + os.path.sep + 'config.txt' +PASSPHRASE = '' +SERVER_ADDRESS = '' LOGGED_IN = False @@ -67,7 +69,7 @@ def printCommandsWihtoutLogin(): try: - opts, args = getopt.getopt(sys.argv[1:], 'hp:') + opts, args = getopt.getopt(sys.argv[1:], 'hp:s:') except getopt.GetoptError: print('Error: Unknown option detected.') sys.exit(1) @@ -76,10 +78,13 @@ for opt, arg in opts: if opt in '-p': PASSPHRASE = arg + if opt in '-s': + SERVER_ADDRESS = arg + if PASSPHRASE == '': print('Key required to start client!') print('Usage:') - print(' client.py -p ') + print(' client.py -p -s ') sys.exit(1) if not os.path.isfile(CONFIG_LOCATION) or os.stat(CONFIG_LOCATION).st_size == 0: @@ -91,6 +96,8 @@ CLIENT_PRIVATE_KEY = loadPrivateKey(PASSPHRASE) CLIENT_ADDRESS = loadAddress() LOGGED_IN = False +network = NetWrapper(CLIENT_PRIVATE_KEY, CLIENT_ADDRESS, SERVER_PUBLIC_KEY, serverAddr=SERVER_ADDRESS) + while True: command = input("Type a command:") separatedCommand = command.split(" ") @@ -102,7 +109,7 @@ while True: if not LOGGED_IN: if separatedCommand[0] == 'LIN' and len(separatedCommand) == 3: - network = NetWrapper(CLIENT_PRIVATE_KEY, CLIENT_ADDRESS, separatedCommand[1], SERVER_PUBLIC_KEY) + network.username = separatedCommand[1] try: network.connectToServer(separatedCommand[2]) response = network.recieveMessage().decode('UTF-8')