示例#1
0
    def __init__(
            self, message, index=0, chat=False,
            color=(' \x01' if UserMessage.is_protobuf() else '\x01')):
        """Initialize the SayText instance."""
        super().__init__(message=message, index=index, chat=chat)

        super(AttrDict, self).__setattr__("color", color)
示例#2
0
    def _send(self, player_indexes, translated_kwargs):
        """Send the user message to the given players.

        :param iterable player_indexes: All players with the same language
            setting.
        :param AttrDict translated_kwargs: The translated arguments.
        """
        recipients = RecipientFilter(*player_indexes)
        recipients.reliable = self.reliable
        user_message = UserMessage(recipients, self.message_name)

        if user_message.is_protobuf():
            self.protobuf(user_message.buffer, translated_kwargs)
            user_message.send()
        else:
            try:
                self.bitbuf(user_message.buffer, translated_kwargs)
            except:
                # In case of an error during writing to the buffer (e. g. by using
                # the wrong data type for the write_* methods) reset the buffer
                # and send the message. This causes the engine to silently ignore
                # the user message and the server doesn't crash upon creating
                # another user message.
                # See also:
                # https://github.com/Source-Python-Dev-Team/Source.Python/issues/315
                user_message.buffer.reset()

                # Re-raise the exception to make the user aware of the problem
                raise
            finally:
                user_message.send()
示例#3
0
    def __init__(
            self, message, index=0, chat=False,
            param1='', param2='', param3='', param4='',
            color=(' \x01' if UserMessage.is_protobuf() else '\x01')):
        """Initialize the SayText2 instance."""
        super().__init__(
            message=message, index=index, chat=chat,
            param1=param1, param2=param2, param3=param3, param4=param4)

        super(AttrDict, self).__setattr__("color", color)
示例#4
0
 def send(self, *player_indexes):
     """Send the user message."""
     # We need to handle the ShowMenu user message with bitbuffers
     # differently, because the maximum size is 255. If the message exceeds
     # this length, we need to sent it in several parts.
     if UserMessage.is_protobuf():
         recipients = RecipientFilter(*player_indexes)
         user_message = UserMessage(recipients, self.message_name)
         self.protobuf(user_message.buffer, self)
         user_message.send()
     else:
         self.bitbuf(player_indexes, self)
示例#5
0
 def send(self, *player_indexes):
     """Send the user message."""
     # We need to handle the ShowMenu user message with bitbuffers
     # differently, because the maximum size is 255. If the message exceeds
     # this length, we need to sent it in several parts.
     if UserMessage.is_protobuf():
         recipients = RecipientFilter(*player_indexes)
         user_message = UserMessage(recipients, self.message_name)
         self.protobuf(user_message.buffer, self)
         user_message.send()
     else:
         self.bitbuf(player_indexes, self)
示例#6
0
    def _send(self, player_indexes, translated_kwargs):
        """Send the user message to the given players.

        :param iterable player_indexes: All players with the same language
            setting.
        :param AttrDict translated_kwargs: The translated arguments.
        """
        recipients = RecipientFilter(*player_indexes)
        user_message = UserMessage(recipients, self.message_name)

        if user_message.is_protobuf():
            self.protobuf(user_message.buffer, translated_kwargs)
        else:
            self.bitbuf(user_message.buffer, translated_kwargs)

        user_message.send()
示例#7
0
    def _send(self, player_indexes, translated_kwargs):
        """Send the user message to the given players.

        :param iterable player_indexes: All players with the same language
            setting.
        :param AttrDict translated_kwargs: The translated arguments.
        """
        recipients = RecipientFilter(*player_indexes)
        user_message = UserMessage(recipients, self.message_name)

        if user_message.is_protobuf():
            self.protobuf(user_message.buffer, translated_kwargs)
        else:
            self.bitbuf(user_message.buffer, translated_kwargs)

        user_message.send()