예제 #1
0
 def _send_control_message(self, player, message: Message):
     msg = a0070().set([
         m009e().set(MESSAGE_CONTROL),
         m02e6().set(message.to_string()),
         m034a().set(player.display_name),
         m0574(),
         m02fe().set('taserver'),
         m06de().set('bot')
     ])
     player.send(msg)
예제 #2
0
 def dispatch_client(self):
     try:
         while True:
             # Считать длинну сообщения
             message_length = yield self._stream.read_bytes(2)
             # Распоковать
             length = struct.unpack("!H", message_length)[0]
             # Считать сообщение
             message = yield self._stream.read_bytes(length)
             # Распоковать запрос
             request = Message.unpack(message=message)
             # Создать обработчик запросов
             handler = self._handler(request, self._id, self._storage)
             # Обработать запрос
             response = yield handler.process_request()
             # Вернуть ответ
             if response:
                 response = Message(response[0], kwargs=response[1])
                 yield self._stream.write(response.pack())
     except iostream.StreamClosedError:
         pass
예제 #3
0
파일: client.py 프로젝트: WolkoDav/TCP-Chat
 def _notification(self):
     while self._running:
         try:
             message_length = yield self._stream.read_bytes(2)
             length = struct.unpack("!H", message_length)[0]
             message = yield self._stream.read_bytes(length)
             request = Message.unpack(message)
             handler = self.notification_handler(request, self)
             handler.process_request()
         except OSError as e:
             print_(e)
             self.stop()
         except Exception as e:
             print_(e)
             self.stop()
예제 #4
0
 def test_pack(self):
     r = Message("LOGIN", kwargs={"username": "******"})
     packing = r.pack()
     self.assertIsInstance(packing, bytes)
예제 #5
0
 def test_unpack(self):
     message = b"LOGIN\ngAN9cQBYCAAAAHVzZXJuYW1lcQFYBAAAAHRlc3RxAnMu"
     r = Message.unpack(message)
     self.assertEqual(r.command, "LOGIN")
     self.assertIsInstance(r.kwargs, dict)
     self.assertDictEqual(r.kwargs, {'username': "******"})
예제 #6
0
 def write_msg(self, msg: m.Message):
     self.transport.write(msg.to_json().encode() + self.delimiter)
예제 #7
0
 def write_msg_no_print(self, msg: m.Message):
     line = msg.to_json().encode() + self.delimiter
     self.transport.write(line)
예제 #8
0
 def write_msg(self, msg: m.Message):
     line = msg.to_json().encode() + self.delimiter
     print(f"> gm server: Sending \"{line}\"")
     self.transport.write(line)