def delegate_room_join_to_handler(self): is_nickname_valid = self.validate_nickname() is_room_code_valid = self.validate_room_code() if is_nickname_valid and is_room_code_valid: self.client_context['username'] = self.nickname_field.text() self.client_context['roomCode'] = self.room_code_field.text() self.connection_handler.send_join_room_req( self.client_context['username'], self.client_context['roomCode']) elif not is_nickname_valid: PopUpWindow('Nickname not valid!', 'ERROR') if not is_room_code_valid: PopUpWindow('Room code not valid!', 'ERROR')
def delegate_room_creation_to_handler(self): if self.validate_nickname(): self.client_context['username'] = self.nickname_field.text() self.connection_handler.send_create_room_req( self.client_context['username']) else: PopUpWindow('Nickname not valid!', 'ERROR')
def handle_CreateRoomResp(self, received_msg): if received_msg['status'] == 'OK': self.switch_window.emit(received_msg['room_code']) self.room_created_signal.emit(received_msg) else: PopUpWindow('Room could not be created!', 'ERROR') logging.debug( '[MESSAGE DISPATCHER] handling CreateRoomResp failed, STATUS NOK' ) logging.debug( '[MESSAGE DISPATCHER] handling CreateRoomResp Successful, STATUS OK' )
def room_list_element_clicked(self, item): fetched_room_code = item.text()[-8:] logging.debug('[ROOM LIST CLICKED] clicked: {},'.format( item.text()[-8:], fetched_room_code)) is_nickname_valid = self.validate_nickname() if is_nickname_valid: self.client_context['username'] = self.nickname_field.text() self.client_context['roomCode'] = fetched_room_code self.connection_handler.send_join_room_req( self.client_context['username'], self.client_context['roomCode']) else: PopUpWindow('Nickname not valid!', 'ERROR')
def handle_JoinRoomResp(self, received_msg): with GameWindow.thread_lock: if received_msg['status'] == 'OK': # TODO: enhance window switching self.switch_window.emit('Joining') self.room_joined_signal.emit(received_msg) else: PopUpWindow( 'Could not join to room!\n{}'.format(received_msg['info']), 'ERROR') logging.debug( '[MESSAGE DISPATCHER] handling JoinRoomResp failed, STATUS NOK' ) logging.debug( '[MESSAGE DISPATCHER] handling JoinRoomResp Successful, STATUS OK' )
def handle_StartGameResp(self, received_msg): logging.debug( '[MESSAGE DISPATCHER] handling StartGameResp, STATUS {}'.format( received_msg['status'])) if received_msg['status'] == 'NOT_OK': PopUpWindow(received_msg['info'], 'ERROR')
from Communication.ConnectionHandler import ConnectionHandler from Utils.PopUpWindow import PopUpWindow # for windows (PowerShell): # $env:PYTHONPATH = "." # for UT: # $env:PYTHONPATH = ".\Client\" if __name__ == '__main__': logging.basicConfig( format= '%(asctime)s,%(msecs)d %(levelname)-8s [%(filename)s:%(lineno)d](%(funcName)s) %(message)s', datefmt='%Y-%m-%d:%H:%M:%S', level=logging.DEBUG, ) logging.debug('[STARTING] Client is being loaded ...') app = QApplication([]) try: connHandler = ConnectionHandler() except: logging.debug('[SOCKET CONNECTION] Connection to server failed') PopUpWindow('Game server is unreachable!') exit() AppResourceManager = AppResourceManager(connHandler) logging.debug('[CLIENT STARTED]') AppResourceManager.show_start() app_return = app.exec_() connHandler.kill_receiver() sys.exit(app_return)