This commit is contained in:
parent
48fd34117d
commit
57af60ee07
@ -11,6 +11,8 @@ from netwrapper import NetWrapper
|
|||||||
ABSOLUTE_PATH = os.path.abspath(os.path.dirname(sys.argv[0]))
|
ABSOLUTE_PATH = os.path.abspath(os.path.dirname(sys.argv[0]))
|
||||||
DOWNLOAD_LOCATION = ABSOLUTE_PATH + os.path.sep + 'download' + os.path.sep
|
DOWNLOAD_LOCATION = ABSOLUTE_PATH + os.path.sep + 'download' + os.path.sep
|
||||||
CONFIG_LOCATION = ABSOLUTE_PATH + os.path.sep + 'config' + os.path.sep + 'config.txt'
|
CONFIG_LOCATION = ABSOLUTE_PATH + os.path.sep + 'config' + os.path.sep + 'config.txt'
|
||||||
|
PASSPHRASE = ''
|
||||||
|
SERVER_ADDRESS = ''
|
||||||
LOGGED_IN = False
|
LOGGED_IN = False
|
||||||
|
|
||||||
|
|
||||||
@ -67,7 +69,7 @@ def printCommandsWihtoutLogin():
|
|||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(sys.argv[1:], 'hp:')
|
opts, args = getopt.getopt(sys.argv[1:], 'hp:s:')
|
||||||
except getopt.GetoptError:
|
except getopt.GetoptError:
|
||||||
print('Error: Unknown option detected.')
|
print('Error: Unknown option detected.')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@ -76,10 +78,13 @@ for opt, arg in opts:
|
|||||||
if opt in '-p':
|
if opt in '-p':
|
||||||
PASSPHRASE = arg
|
PASSPHRASE = arg
|
||||||
|
|
||||||
|
if opt in '-s':
|
||||||
|
SERVER_ADDRESS = arg
|
||||||
|
|
||||||
if PASSPHRASE == '':
|
if PASSPHRASE == '':
|
||||||
print('Key required to start client!')
|
print('Key required to start client!')
|
||||||
print('Usage:')
|
print('Usage:')
|
||||||
print(' client.py -p <passphrase>')
|
print(' client.py -p <passphrase> -s <server_address>')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if not os.path.isfile(CONFIG_LOCATION) or os.stat(CONFIG_LOCATION).st_size == 0:
|
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()
|
CLIENT_ADDRESS = loadAddress()
|
||||||
LOGGED_IN = False
|
LOGGED_IN = False
|
||||||
|
|
||||||
|
network = NetWrapper(CLIENT_PRIVATE_KEY, CLIENT_ADDRESS, SERVER_PUBLIC_KEY, serverAddr=SERVER_ADDRESS)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
command = input("Type a command:")
|
command = input("Type a command:")
|
||||||
separatedCommand = command.split(" ")
|
separatedCommand = command.split(" ")
|
||||||
@ -102,7 +109,7 @@ while True:
|
|||||||
|
|
||||||
if not LOGGED_IN:
|
if not LOGGED_IN:
|
||||||
if separatedCommand[0] == 'LIN' and len(separatedCommand) == 3:
|
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:
|
try:
|
||||||
network.connectToServer(separatedCommand[2])
|
network.connectToServer(separatedCommand[2])
|
||||||
response = network.recieveMessage().decode('UTF-8')
|
response = network.recieveMessage().decode('UTF-8')
|
||||||
|
Loading…
Reference in New Issue
Block a user