Example #1
0
    def send_chat_message(self, text, channel=0, world='', name=''):
        """
        Convenience function to send chat messages to the client. Note that this
        does *not* send messages to the server at large; broadcast should be
        used for messages to all clients, or manually constructed chat messages
        otherwise.

        :param text: Message text, may contain multiple lines.
        :param channel: The chat channel/context. 0 is global, 1 is planet.
        :param world: World
        :param name: The name to display before the message. Blank leaves no
        brackets, otherwise it will be displayed as `<name>`.
        :return: None
        """
        logger.debug("Sent chat message with text: %s", text)
        if '\n' in text:
            lines = text.split('\n')
            for line in lines:
                self.send_chat_message(line)
            return
        chat_data = packets.chat_received().build(Container(chat_channel=channel,
                                                            world=world,
                                                            client_id=0,
                                                            name=name,
                                                            message=text))
        chat_packet = build_packet(packets.Packets.CHAT_RECEIVED,
                                   chat_data)
        self.transport.write(chat_packet)
Example #2
0
    def send_chat_message(self, text, channel=0, world='', name=''):
        """
        Convenience function to send chat messages to the client. Note that this
        does *not* send messages to the server at large; broadcast should be
        used for messages to all clients, or manually constructed chat messages
        otherwise.

        :param text: Message text, may contain multiple lines.
        :param channel: The chat channel/context. 0 is global, 1 is planet.
        :param world: World
        :param name: The name to display before the message. Blank leaves no
        brackets, otherwise it will be displayed as `<name>`.
        :return: None
        """
        if '\n' in text:
            lines = text.split('\n')
            for line in lines:
                self.send_chat_message(line)
            return
        chat_data = packets.chat_received().build(
            Container(chat_channel=channel,
                      world=world,
                      client_id=0,
                      name=name,
                      message=text.encode("utf-8")))
        chat_packet = build_packet(packets.Packets.CHAT_RECEIVED, chat_data)
        self.transport.write(chat_packet)
Example #3
0
    def send_chat_message(self, text, mode='BROADCAST', channel='', name=''):
        """
        Convenience function to send chat messages to the client. Note that this
        does *not* send messages to the server at large; broadcast should be
        used for messages to all clients, or manually constructed chat messages
        otherwise.

        :param text: Message text, may contain multiple lines.
        :param channel: The chat channel/context.
        :param name: The name to display before the message. Blank leaves no
        brackets, otherwise it will be displayed as `<name>`.
        :return: None
        """
        if '\n' in text:
            lines = text.split('\n')
            for line in lines:
                self.send_chat_message(line)
            return
        if self.player is not None:
            logger.vdebug(('Calling send_chat_message from player %s on channel'
                          ' %s with mode %s with reported username of %s with'
                          ' message: %s'), self.player.name, channel, mode, name, text)
        chat_data = packets.chat_received().build(Container(mode=mode,
                                                            channel=channel,
                                                            client_id=0,
                                                            name=name,
                                                            message=text.encode("utf-8")))
        logger.vdebug("Built chat payload. Data: %s", chat_data.encode("hex"))
        chat_packet = build_packet(packets.Packets.CHAT_RECEIVED,
                                   chat_data)
        logger.vdebug("Built chat packet. Data: %s", chat_packet.encode("hex"))
        self.transport.write(chat_packet)
        logger.vdebug("Sent chat message with text: %s", text)
Example #4
0
    def send_chat_message(self, text, mode='BROADCAST', channel='', name=''):
        """
        Convenience function to send chat messages to the client. Note that this
        does *not* send messages to the server at large; broadcast should be
        used for messages to all clients, or manually constructed chat messages
        otherwise.

        :param text: Message text, may contain multiple lines.
        :param channel: The chat channel/context.
        :param name: The name to display before the message. Blank leaves no
        brackets, otherwise it will be displayed as `<name>`.
        :return: None
        """
        if '\n' in text:
            lines = text.split('\n')
            for line in lines:
                self.send_chat_message(line)
            return
        if self.player is not None:
            logger.vdebug(
                ('Calling send_chat_message from player %s on channel'
                 ' %s with mode %s with reported username of %s with'
                 ' message: %s'), self.player.name, channel, mode, name, text)
        chat_data = packets.chat_received().build(
            Container(mode=mode,
                      channel=channel,
                      client_id=0,
                      name=name,
                      message=text.encode("utf-8")))
        logger.vdebug("Built chat payload. Data: %s", chat_data.encode("hex"))
        chat_packet = build_packet(packets.Packets.CHAT_RECEIVED, chat_data)
        logger.vdebug("Built chat packet. Data: %s", chat_packet.encode("hex"))
        self.transport.write(chat_packet)
        logger.vdebug("Sent chat message with text: %s", text)