Exemplo n.º 1
0
 def _send_message(self, text, chat_id):
     request = ChatRequest()
     request.command_type = ChatRequest.MSG
     request.message.chat_id = chat_id
     request.message.text = text
     request.successful = True
     qt_send_message(self.server_socket, request.SerializeToString())
Exemplo n.º 2
0
 def _logging(self):
     request = ChatRequest()
     request.command_type = ChatRequest.SIGN_IN
     request.sign.login = self.user_login
     request.sign.passwd = self.user_passwd
     request.sign.hidden = self.user_hidden
     request.successful = True
     qt_send_message(self.server_socket, request.SerializeToString())
Exemplo n.º 3
0
    def sign_up(self):
        request = ChatRequest()
        request.command_type = ChatRequest.SIGN_UP
        request.sign.login = self.line_login.text()
        request.sign.passwd = self.line_passwd.text()
        request.sign.hidden = False
        request.successful = True

        qt_send_message(self.server_socket, request.SerializeToString())
        self.user_login = request.sign.login
        self.user_passwd = request.sign.passwd
        self.user_hidden = self.btn_hide.isChecked()

        log_info("Sended sing_up package")
Exemplo n.º 4
0
    def _input_loop(self):
        while True:
            socks_to_read = list(map(lambda x: x.sock, self.connected_clients))

            # Linux epoll magic
            socks_ready_to_read, _, _ = select.select(
                [self.server_sock] + socks_to_read, [], [])

            for sock in socks_ready_to_read:
                if sock == self.server_sock:
                    sock, addr = self.server_sock.accept()
                    new_client = Client(sock=sock, addr=addr)
                    self._register_client(new_client)

                    log_info("{} connected".format(str(new_client)))
                else:
                    client = self._get_client_by_sock(sock)
                    data = recv_until_end_messages(client.sock)
                    if not data:
                        self._unregister_and_close_client(client)
                        log_info(
                            "{} is offline (initiated by the client)".format(
                                str(client)))
                        continue

                    log_info(
                        "recieved {len} bytes from {client}: {data}".format(
                            len=len(data), client=client, data=data))

                    request = ChatRequest()
                    request.ParseFromString(data)
                    if self._input_for_logging(client, request):
                        continue
                    if client.id is not None:
                        self._input_with_logged_user(client, request)
                    elif client.id is None:
                        log_info("Client {client}: did something wrong".format(
                            client=client,
                        ))
                    else:
                        log_info("shit")
                        exit(0)
Exemplo n.º 5
0
 def _send_delete_msg(self, msg_id):
     request = ChatRequest()
     request.command_type = ChatRequest.DELETE_MSG
     request.info_text = msg_id
     request.successful = True
     qt_send_message(self.server_socket, request.SerializeToString())
Exemplo n.º 6
0
 def _get_chats_and_users(self):
     request = ChatRequest()
     request.command_type = ChatRequest.GET_CHATS_AND_MESSAGES
     request.info_text = '5'
     request.successful = True
     qt_send_message(self.server_socket, request.SerializeToString())
Exemplo n.º 7
0
 def _add_users_to_chat(self, args):
     request = ChatRequest()
     request.command_type = ChatRequest.ADD_USERS_TO_CHAT
     request.successful = True
     request.info_text = args
     qt_send_message(self.server_socket, request.SerializeToString())
Exemplo n.º 8
0
 def _add_chat(self, chat_name):
     request = ChatRequest()
     request.command_type = ChatRequest.ADD_CHAT
     request.successful = True
     request.info_text = chat_name
     qt_send_message(self.server_socket, request.SerializeToString())