Example #1
0
    def send_message(self,
                     message,
                     *messages,
                     world="",
                     client_id=0,
                     name="",
                     channel=0):
        if messages:
            for m in messages:
                yield from self.send_message(m,
                                             world=world,
                                             client_id=client_id,
                                             name=name,
                                             channel=channel)
        if "\n" in message:
            for m in message.splitlines():
                yield from self.send_message(m,
                                             world=world,
                                             client_id=client_id,
                                             name=name,
                                             channel=channel)
            return

        if self.state == State.CONNECTED_WITH_HEARTBEAT:
            chat_packet = ChatReceived.build({
                "message": message,
                "world": world,
                "client_id": client_id,
                "name": name,
                "channel": channel
            })

            to_send = build_packet(4, chat_packet)
            yield from self.raw_write(to_send)
Example #2
0
    def send_message(self, message, *messages, world="", client_id=0, name="",
                     channel=0):
        if messages:
            for m in messages:
                yield from self.send_message(m,
                                             world=world,
                                             client_id=client_id,
                                             name=name,
                                             channel=channel)
        if "\n" in message:
            for m in message.splitlines():
                yield from self.send_message(m,
                                             world=world,
                                             client_id=client_id,
                                             name=name,
                                             channel=channel)
            return

        if self.state == State.CONNECTED_WITH_HEARTBEAT:
            chat_packet = ChatReceived.build(
                {"message": message,
                 "world": world,
                 "client_id": client_id,
                 "name": name,
                 "channel": channel})

            to_send = build_packet(4, chat_packet)
            yield from self.raw_write(to_send)
Example #3
0
    def send_message(self, message, *, world="", client_id=0, name="",
                     channel=0):
        if self.state == State.CONNECTED_WITH_HEARTBEAT:
            chat_packet = ChatReceived.build(
                {"message": message,
                 "world": world,
                 "client_id": client_id,
                 "name": name,
                 "channel": channel})

            to_send = build_packet(4, chat_packet)
            yield from self.raw_write(to_send)
Example #4
0
    def send_message(self,
                     message,
                     *messages,
                     mode=ChatReceiveMode.BROADCAST,
                     client_id=0,
                     name="",
                     channel=""):
        """
        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 message: message text
        :param messages: used if there are more that one message to be sent
        :param client_id: who sent the message
        :param name:
        :param channel:
        :param mode:
        :return:
        """
        header = {"mode": mode, "channel": channel, "client_id": client_id}
        try:
            if messages:
                for m in messages:
                    yield from self.send_message(m,
                                                 mode=mode,
                                                 client_id=client_id,
                                                 name=name,
                                                 channel=channel)
            if "\n" in message:
                for m in message.splitlines():
                    yield from self.send_message(m,
                                                 mode=mode,
                                                 client_id=client_id,
                                                 name=name,
                                                 channel=channel)
                return

            if self.state is not None and self.state >= State.CONNECTED:
                chat_packet = ChatReceived.build({
                    "message": message,
                    "name": name,
                    "junk": 0,
                    "header": header
                })
                to_send = build_packet(packets['chat_received'], chat_packet)
                yield from self.raw_write(to_send)
        except Exception as err:
            logger.exception("Error while trying to send message.")
            logger.exception(err)
Example #5
0
    def send_message(self,
                     message,
                     *,
                     world="",
                     client_id=0,
                     name="",
                     channel=0):
        if self.state == State.CONNECTED_WITH_HEARTBEAT:
            chat_packet = ChatReceived.build({
                "message": message,
                "world": world,
                "client_id": client_id,
                "name": name,
                "channel": channel
            })

            to_send = build_packet(4, chat_packet)
            yield from self.raw_write(to_send)
Example #6
0
    def send_message(self, message, *messages, mode=ChatReceiveMode.BROADCAST,
                     client_id=0, name="", channel=""):
        """
        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 message: message text
        :param messages: used if there are more that one message to be sent
        :param client_id: who sent the message
        :param name:
        :param channel:
        :param mode:
        :return:
        """
        header = {"mode": mode, "channel": channel, "client_id": client_id}
        try:
            if messages:
                for m in messages:
                    yield from self.send_message(m,
                                                 mode=mode,
                                                 client_id=client_id,
                                                 name=name,
                                                 channel=channel)
            if "\n" in message:
                for m in message.splitlines():
                    yield from self.send_message(m,
                                                 mode=mode,
                                                 client_id=client_id,
                                                 name=name,
                                                 channel=channel)
                return

            if self.state == State.CONNECTED_WITH_HEARTBEAT:
                chat_packet = ChatReceived.build({"message": message,
                                                  "name": name,
                                                  "junk": 0,
                                                  "header": header})
                to_send = build_packet(packets['chat_received'], chat_packet)
                yield from self.raw_write(to_send)
        except Exception as err:
            logger.exception("Error while trying to send message.")
            logger.exception(err)