def get_user_nickname(): print_colored(colors.OKBLUE, "Entre com um nome de usuário para sua sessão atual") nickname_shell() nickname = input() return nickname
def _handle_first_interaction_response(self): try: response = read_response(self._sock) except SocketClosedError: print("Socket fechado, tente novamente") else: if response[protocol.status.ok]: logging.debug(f'Setting nickname as {response[protocol.nick]}') self._nick = response[protocol.nick] print_colored(colors.OKBLUE, "Nickname criado com sucesso!") else: print_colored(colors.FAIL, "Nickname já existente, tente novamente") self.first_interaction()
def send_command(self, open_connections, command, can_read_stdin): """ User sent a command via stdin, forward it to the server """ command_arguments = command.split() action = command_arguments[0] if action == protocol.action.LIST_CLIENTS: self._send_list_clients_request() elif action == protocol.action.CONNECT_CLIENT: try: nickname = command_arguments[1] except IndexError: print_colored(colors.WARNING, "Nenhum nickname fornecido, tente novamente") else: self._send_connect_client_request(open_connections, nickname, can_read_stdin) else: print_colored(colors.FAIL, "Comando inválido, tente novamente")
def interact_p2p(self, can_read_stdin): print_message_chat() can_read_stdin.clear() msg = input() while not msg: error = "Não é possível enviar uma mensagem vazia, digite alguma coisa" print_colored(colors.WARNING, error) msg = input() logging.debug(f"Sending {msg} from {self._nick}") payload = builder.build_message_payload(self._nick, msg) self._sock.sendall(payload, MSG_WAITALL) shell_print() can_read_stdin.set() self.close()
def nickname_shell(): print_colored(colors.OKBLUE, "@", end="")
def _handle_p2p_inactive_client(self, response): error = f'Cliente {response[protocol.nick]} não está ativo' print_colored(colors.FAIL, error)