From 00d4542404d78ad7d5b3e0d4d19cb91ce8f6b220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Mon, 26 Apr 2021 23:22:45 +0200 Subject: [PATCH] remove more redundant try --- server/netwrapper.py | 36 ++++++++++++++++-------------------- server/server.py | 1 - 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/server/netwrapper.py b/server/netwrapper.py index a572e31..b3504ba 100644 --- a/server/netwrapper.py +++ b/server/netwrapper.py @@ -111,27 +111,23 @@ class NetWrapper: self.cipherkey = (hasher.hexdigest()[:32]).encode('UTF-8') def login(self) -> bool: - try: - status, msg = self.network.receive_msg(blocking=True) - if not status: - raise Exception('Network error during connection.') - cleartext = self.recieveEncryptedMessage(msg, "AUT").decode('UTF-8') - if cleartext == "ERROR": - return False - else: - plaintext = cleartext.split(' ') - self.homeDirectory = self.authenticationInstance.login(plaintext[1], plaintext[2]) - linsuccess = (not (len(plaintext) != 3 or plaintext[0] != "LIN" or plaintext[ - 1] != self.currentUser)) and self.homeDirectory - if linsuccess: - message = "OK".encode('UTF-8') - else: - message = "ERROR".encode('UTF-8') - self.sendTypedMessage(message, "AUT") - return linsuccess - except Exception: - print("Login failed") + status, msg = self.network.receive_msg(blocking=True) + if not status: + raise Exception('Network error during connection.') + cleartext = self.recieveEncryptedMessage(msg, "AUT").decode('UTF-8') + if cleartext == "ERROR": return False + else: + plaintext = cleartext.split(' ') + self.homeDirectory = self.authenticationInstance.login(plaintext[1], plaintext[2]) + linsuccess = (not (len(plaintext) != 3 or plaintext[0] != "LIN" or plaintext[ + 1] != self.currentUser)) and self.homeDirectory + if linsuccess: + message = "OK".encode('UTF-8') + else: + message = "ERROR".encode('UTF-8') + self.sendTypedMessage(message, "AUT") + return linsuccess def initClientConnection(self, msg: bytes) -> bytes: print('A client is trying to connect') diff --git a/server/server.py b/server/server.py index 4eeecbf..9a96435 100644 --- a/server/server.py +++ b/server/server.py @@ -35,7 +35,6 @@ class Server: self.networkInstance.sendMessage("OK".encode('UTF-8')) return None elif command == "LINERROR": - self.networkInstance.sendMessage("ERROR".encode('UTF-8')) return None elif command == "ERROR": self.networkInstance.sendMessage("ERROR".encode('UTF-8'))