def login(self): #сохраним имя пользователя в переменную self.polzovatel = self.line_login.text() auth = Authenticate(self.polzovatel) user = auth.create_authenticate() msg_pack = PackMessage(user) self.s.send(msg_pack.pack())
def login(self): self.polzovatel = self.window.in_login.text() auth = Authenticate(self.polzovatel) dic = auth.create_authenticate() msg_pack = PackMessage(dic) self.s.send(msg_pack.pack()) #self.set_text_viev() self.slush()
def init_connection(self, user_name): #создаём сокет s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #выводим запрос на ввод ip foreingn_ip = input('Введите IP-адрес в формате (0.0.0.0): ') #подключаемся к нужному адресу s.connect((foreingn_ip, 8888)) #выводим запрос на ввод логина account_name = user_name #подготавливаем presence сообщение press = CreatePresence('presence', time.strftime('%H:%M:%S'), 'status', account_name, 'I\'m here') #запаковываем сообщение jmsg = PackMessage(press.create_presence()) #отправляем presence сообщение s.send(jmsg.pack())
def history_messagess(self): userto = '' list = self.contact_view.selectedItems() for lst in list: userto = lst.text() history_dict = CreateHistory(self.polzovatel, userto).create_history() print(history_dict) b_history_dict = PackMessage(history_dict).pack() self.s.send(b_history_dict) print('Запрос истории отправлен')
def verification(self): #проверка аутентификации if self._dict['action'] == 'authenticate': user = VerificationUsers(self._dict['user']['account_name']) if user.ver_users(): self._user = self._dict['user']['account_name'] return self._user #проверка ответа на аутентификацию if self._dict['action'] == 'back_authenticate': pass #проверка пресенс собщения if self._dict['action'] == 'presence': print('Имя пользователя: {}'.format( self._dict['user']['account_name'])) user = VerificationUsers(self._dict['user']['account_name']) if user.ver_users(): probe = CreateProbe('probe', time.strftime('%H:%M:%S')) pack_probe = PackMessage(probe.create_probe()) print('Пользователь есть') return pack_probe.pack() elif not user.ver_users(): resp = CreateResponse(404, time.strftime('%H:%M:%S'), 'Такого пользователя не существует.') pack_resp = PackMessage(resp.create_response()) print('Пользователя нет') return pack_resp.pack() #проверка запроса истории if self._dict['action'] == 'history': print('Пришло сообщение на запрос истории') history = RetrievHistory(self._dict['userfrom'], self._dict['userto']).retriev_history() for h in history: print('Сообщение: {}. от: {}'.format(h.message, h.p_user_from.name)) dict_history = CreateBackHistory(history).back_history() print(dict_history) return dict_history #проверка сообщения if self._dict['action'] == 'msg': pass
#создаём сокет s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #выводим запрос на ввод ip foreingn_ip = input('Введите IP-адрес в формате (0.0.0.0): ') #подключаемся к нужному адресу s.connect((foreingn_ip, 8888)) #выводим запрос на ввод логина account_name = input('Введите свой логин: ') #подготавливаем presence сообщение press = CreatePresence('presence', time.strftime('%H:%M:%S'), 'status', account_name, 'I\'m here') #запаковываем сообщение jmsg = PackMessage(press.create_presence()) #отправляем presence сообщение s.send(jmsg.pack()) print('Переход в режим слушателя.') def read_client(): while True: clmsg = ReceiveMessage() msg = clmsg.receive_message(s) if msg['action'] == 'probe': print('Сервер получил сообщение в: {}'.format(msg['time'])) if msg['action'] == 'response': print(msg['error']) vopros = input('Создать нового пользователя? (y/n) ')