Пример #1
0
 def warp_player_to_player(self, from_string, to_string):
     self.logger.debug("Warp player-to-player command called by %s: %s to %s", self.protocol.player.name,
                       from_string, to_string)
     from_player = self.player_manager.get_logged_in_by_name(from_string)
     to_player = self.player_manager.get_logged_in_by_name(to_string)
     if from_player is not None:
         if to_player is not None:
             from_protocol = self.factory.protocols[from_player.protocol]
             if from_player is not to_player:
                 self.logger.debug("target:  %s", to_player.uuid)
                 warp_packet = build_packet(Packets.PLAYER_WARP,
                                            player_warp_toplayer_write(
                                                uuid=to_player.uuid
                                            ))
             else:
                 warp_packet = build_packet(Packets.PLAYER_WARP,
                                            player_warp_toalias_write(
                                                alias=WarpAliasType.SHIP
                                            ))
             from_protocol.client_protocol.transport.write(warp_packet)
             if from_string != to_string:
                 self.protocol.send_chat_message("Warped ^yellow;%s^green; to ^yellow;%s^green;." % (from_string, to_string))
             else:
                 self.protocol.send_chat_message("Warped to ^yellow;%s^green;." % to_string)
         else:
             self.protocol.send_chat_message("No player by the name ^yellow;%s^green; found." % to_string)
             self.protocol.send_chat_message(self.warp.__doc__)
             return
     else:
         self.protocol.send_chat_message("No player by the name ^yellow;%s^green; found." % from_string)
         self.protocol.send_chat_message(self.warp.__doc__)
Пример #2
0
    def teleport_to_player(self, data):
        """Teleports a player to another player's location. If no source player is provided, we assume you mean yourself.\nSyntax: /teleport [player] (destination player) [source player]"""
        usage = 'Syntax: /teleport [player] (destination player) [source player]'
        if not data:
            self.protocol.send_chat_message(self.teleport_to_player.__doc__)
            return

        destination, rest = extract_name(data)
        if not self._validate_player(destination):
            self.protocol.send_chat_message(usage)
            return
        destination = destination.lower()

        if not rest:
            source = self.protocol.player.name
            source = source.lower()
        else:
            source, rest = extract_name(rest)
            if not self._validate_player(source):
                self.protocol.send_chat_message(usage)
                return
            source = source.lower()

        if source == destination:
            self.logger.debug("Error: player is teleporting to self.")
            self.protocol.send_chat_message("Why are you trying to teleport to yourself? That seems illogical, captain.")
            return

        destination_player = self.player_manager.get_logged_in_by_name(destination)
        if destination_player is None:
            self.logger.debug("Error: Player %s is not logged in.", destination)
            self.protocol.send_chat_message("Error: Player %s is not logged in." % (destination, ))
            return

        source_player = self.player_manager.get_logged_in_by_name(source)
        if source_player is None:
            self.logger.debug("Error: Player %s is not logged in.", source)
            self.protocol.send_chat_message("Error: Player %s is not logged in." % (source, ))
            return

        source_protocol = self.factory.protocols[source_player.protocol]
        teleport_packet = build_packet(Packets.PLAYER_WARP, player_warp_toplayer_write(uuid=destination_player.uuid))

        source_protocol.client_protocol.transport.write(teleport_packet)

        self.logger.debug("Teleport command called by %s. Teleporting %s to %s", self.protocol.player.name, source, destination)
        self.protocol.send_chat_message("Teleported ^yellow;%s^green; to ^yellow;%s^green;." % (source, destination))
Пример #3
0
 def warp_player_to_player(self, from_string, to_string):
     self.logger.debug(
         'Warp player-to-player command called by %s: %s to %s',
         self.protocol.player.name, from_string, to_string)
     from_player = self.player_manager.get_logged_in_by_name(from_string)
     to_player = self.player_manager.get_logged_in_by_name(to_string)
     if from_player is not None:
         if to_player is not None:
             from_protocol = self.factory.protocols[from_player.protocol]
             if from_player is not to_player:
                 self.logger.debug('target:  %s', to_player.uuid)
                 warp_packet = build_packet(
                     Packets.PLAYER_WARP,
                     player_warp_toplayer_write(uuid=to_player.uuid))
             else:
                 warp_packet = build_packet(
                     Packets.PLAYER_WARP,
                     player_warp_toalias_write(alias=WarpAliasType.SHIP))
             from_protocol.client_protocol.transport.write(warp_packet)
             if from_string != to_string:
                 self.protocol.send_chat_message(
                     'Warped ^yellow;{}^green;'
                     ' to ^yellow;{}^green;.'.format(
                         from_string, to_string))
             else:
                 self.protocol.send_chat_message(
                     'Warped to ^yellow;{}^green;.'.format(to_string))
         else:
             self.protocol.send_chat_message(
                 'No player by the name ^yellow;{}^green; found.'.format(
                     to_string))
             self.protocol.send_chat_message(self.warp.__doc__)
             return
     else:
         self.protocol.send_chat_message(
             'No player by the name ^yellow;{}^green; found.'.format(
                 to_player))
         self.protocol.send_chat_message(self.warp.__doc__)
Пример #4
0
    def teleport_to_player(self, data):
        """
        Teleports a player to another player's location. If no source player
        is provided, we assume you mean yourself.
        Syntax: /teleport [player] (destination player) [source player]
        """
        usage = (
            'Syntax: /teleport [player] (destination player) [source player]'
        )
        if not data:
            self.protocol.send_chat_message(self.teleport_to_player.__doc__)
            return

        destination, rest = extract_name(data)
        if not self._validate_player(destination):
            self.protocol.send_chat_message(usage)
            return
        destination = destination.lower()

        if not rest:
            source = self.protocol.player.name
            source = source.lower()
        else:
            source, rest = extract_name(rest)
            if not self._validate_player(source):
                self.protocol.send_chat_message(usage)
                return
            source = source.lower()

        if source == destination:
            self.logger.debug('Error: player is teleporting to self.')
            self.protocol.send_chat_message(
                'Why are you trying to teleport to yourself? '
                'That seems illogical, captain.'
            )
            return

        destination_player = self.player_manager.get_logged_in_by_name(
            destination
        )
        if destination_player is None:
            self.logger.debug(
                'Error: Player %s is not logged in.', destination
            )
            self.protocol.send_chat_message(
                'Error: Player {} is not logged in.'.format(destination)
            )
            return

        source_player = self.player_manager.get_logged_in_by_name(source)
        if source_player is None:
            self.logger.debug('Error: Player %s is not logged in.', source)
            self.protocol.send_chat_message(
                'Error: Player {} is not logged in.'.format(source)
            )
            return

        source_protocol = self.factory.protocols[source_player.protocol]
        teleport_packet = build_packet(
            Packets.PLAYER_WARP,
            player_warp_toplayer_write(uuid=destination_player.uuid)
        )

        source_protocol.client_protocol.transport.write(teleport_packet)

        self.logger.debug(
            'Teleport command called by %s. Teleporting %s to %s',
            self.protocol.player.name, source, destination
        )
        self.protocol.send_chat_message(
            'Teleported ^yellow;{}^green; to ^yellow;{}^green;.'.format(
                source, destination
            )
        )