示例#1
0
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
示例#2
0
 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()
示例#3
0
 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")
示例#4
0
    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()
示例#5
0
def nickname_shell():
    print_colored(colors.OKBLUE, "@", end="")
示例#6
0
 def _handle_p2p_inactive_client(self, response):
     error = f'Cliente {response[protocol.nick]} não está ativo'
     print_colored(colors.FAIL, error)