Esempio n. 1
0
    def _move_ship(self, connection, location):
        """
        Generate packet that moves ship.

        :param connection: Player being moved.
        :param location: The intended destination of the player.
        :return: Null.
        :raise: NotImplementedError when POI does not exist.
        """
        if location not in self.storage["pois"]:
            send_message(connection, "That POI does not exist!")
            raise NotImplementedError
        else:
            location = self.storage["pois"][location]
            destination = data_parser.FlyShip.build(
                dict(world_x=location.x,
                     world_y=location.y,
                     world_z=location.z,
                     location=dict(type=SystemLocationType.COORDINATE,
                                   world_x=location.x,
                                   world_y=location.y,
                                   world_z=location.z,
                                   world_planet=location.planet,
                                   world_satellite=location.satellite)))
            flyship_packet = pparser.build_packet(packets.packets["fly_ship"],
                                                  destination)
            yield from connection.client_raw_write(flyship_packet)
Esempio n. 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)
Esempio n. 3
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)
Esempio n. 4
0
    def _move_ship(self, connection):
        """
        Generate packet that moves ship.

        :param connection: Player being moved to spawn.
        :return: Null.
        :raise: NotImplementedError when spawn planet not yet set.
        """
        if "spawn_location" not in self.storage["spawn"]:
            send_message(connection, "Spawn planet not currently set.")
            raise NotImplementedError
        else:
            spawn_location = self.storage["spawn"]["spawn_location"]
            destination = data_parser.FlyShip.build(dict(
                world_x=spawn_location.x,
                world_y=spawn_location.y,
                world_z=spawn_location.z,
                location=dict(
                    type=SystemLocationType.COORDINATE,
                    world_x=spawn_location.x,
                    world_y=spawn_location.y,
                    world_z=spawn_location.z,
                    world_planet=spawn_location.planet,
                    world_satellite=spawn_location.satellite
                )
            ))
            flyship_packet = pparser.build_packet(packets.packets["fly_ship"],
                                                  destination)
            yield from connection.client_raw_write(flyship_packet)
Esempio n. 5
0
    def _move_ship(self, connection):
        """
        Generate packet that moves ship.

        :param connection: Player being moved to spawn.
        :return: Null.
        :raise: NotImplementedError when spawn planet not yet set.
        """
        if "spawn_location" not in self.storage["spawn"]:
            send_message(connection, "Spawn planet not currently set.")
            raise NotImplementedError
        else:
            spawn_location = self.storage["spawn"]["spawn_location"]
            destination = data_parser.FlyShip.build(
                dict(world_x=spawn_location.x,
                     world_y=spawn_location.y,
                     world_z=spawn_location.z,
                     location=dict(type=SystemLocationType.COORDINATE,
                                   world_x=spawn_location.x,
                                   world_y=spawn_location.y,
                                   world_z=spawn_location.z,
                                   world_planet=spawn_location.planet,
                                   world_satellite=spawn_location.satellite)))
            flyship_packet = pparser.build_packet(packets.packets["fly_ship"],
                                                  destination)
            yield from connection.client_raw_write(flyship_packet)
Esempio n. 6
0
    def _move_ship(self, connection, location):
        """
        Generate packet that moves ship.

        :param connection: Player being moved.
        :param location: The intended destination of the player.
        :return: Null.
        :raise: NotImplementedError when POI does not exist.
        """
        if location not in self.storage["pois"]:
            send_message(connection, "That POI does not exist!")
            raise NotImplementedError
        else:
            location = self.storage["pois"][location]
            destination = data_parser.FlyShip.build(dict(
                world_x=location.x,
                world_y=location.y,
                world_z=location.z,
                location=dict(
                    type=SystemLocationType.COORDINATE,
                    world_x=location.x,
                    world_y=location.y,
                    world_z=location.z,
                    world_planet=location.planet,
                    world_satellite=location.satellite
                )
            ))
            flyship_packet = pparser.build_packet(packets.packets["fly_ship"],
                                                  destination)
            yield from connection.client_raw_write(flyship_packet)
Esempio n. 7
0
    def build_rejection(self, reason):
        """
        Function to build packet to reject connection for client.

        :param reason: String. Reason for rejection.
        :return: Rejection packet.
        """
        return build_packet(packets["connect_failure"],
                            ConnectFailure.build(dict(reason=reason)))
Esempio n. 8
0
 def _access_check(self, connection):
     yield from asyncio.sleep(.5)
     if str(connection.player.location) in self.storage["access"]:
         access = self.storage["access"][str(connection.player.location)]
         if connection.player.perm_check("planet_protect.bypass"):
             return
         elif connection.player.uuid in access["list"] and not \
                 access["whitelist"]:
             wp = PlayerWarp.build({"warp_action": {"warp_type": 3,
                                                    "alias_id": 2}})
             full = build_packet(packets.packets['player_warp'], wp)
             yield from connection.client_raw_write(full)
         elif connection.player.uuid not in access["list"] and \
                 access["whitelist"]:
             wp = PlayerWarp.build({"warp_action": {"warp_type": 3,
                                                    "alias_id": 2}})
             full = build_packet(packets.packets['player_warp'], wp)
             yield from connection.client_raw_write(full)
Esempio n. 9
0
 def on_connect_success(self, data, connection):
     if self.maintenance and "SuperAdmin" not in connection.player.roles:
         fail = data_parser.ConnectFailure.build(dict(
             reason=self.rejection_message))
         pkt = pparser.build_packet(packets.packets['connect_failure'],
                                    fail)
         yield from connection.raw_write(pkt)
         return False
     else:
         return True
Esempio n. 10
0
 def on_connect_success(self, data, connection):
     if self.maintenance and "SuperAdmin" not in connection.player.roles:
         fail = data_parser.ConnectFailure.build(dict(
             reason=self.rejection_message))
         pkt = pparser.build_packet(packets.packets['connect_failure'],
                                    fail)
         yield from connection.raw_write(pkt)
         return False
     else:
         return True
Esempio n. 11
0
    def build_rejection(self, reason):
        """
        Function to build packet to reject connection for client.

        :param reason: String. Reason for rejection.
        :return: Rejection packet.
        """
        return build_packet(packets["connect_failure"],
                            ConnectFailure.build(
                                dict(reason=reason)))
Esempio n. 12
0
 def on_connect_success(self, data, connection):
     if self.maintenance and not connection.player.perm_check(
             "general_commands.maintenance_bypass"):
         fail = data_parser.ConnectFailure.build(dict(
             reason=self.rejection_message))
         pkt = pparser.build_packet(packets.packets['connect_failure'],
                                    fail)
         yield from connection.raw_write(pkt)
         return False
     else:
         return True
Esempio n. 13
0
 def warp_player_to_player(self, from_player, to_player):
     """
     Warps a player to another player.
     :param from_player: Player: The player being warped.
     :param to_player: Player: The player being warped to.
     :return: None
     """
     wp = PlayerWarp.build(dict(warp_action=dict(warp_type=2,
                                                 player_id=to_player.uuid)))
     full = build_packet(packets.packets['player_warp'], wp)
     yield from from_player.connection.client_raw_write(full)
Esempio n. 14
0
 def warp_player_to_player(self, from_player, to_player):
     """
     Warps a player to another player.
     :param from_player: Player: The player being warped.
     :param to_player: Player: The player being warped to.
     :return: None
     """
     wp = PlayerWarp.build(dict(warp_action=dict(warp_type=2,
                                                 player_id=to_player.uuid)))
     full = build_packet(packets.packets['player_warp'], wp)
     yield from from_player.connection.client_raw_write(full)
Esempio n. 15
0
 def warp_player_to_ship(self, from_player, to_player):
     """
     Warps a player to another player's ship.
     :param from_player: Player: The player being warped.
     :param to_player: Player: The player whose ship is being warped to.
     :return: None
     """
     wp = PlayerWarp.build(dict(warp_action=dict(warp_type=1, world_id=2,
                                                 ship_id=to_player.uuid,
                                                 flag=0)))
     full = build_packet(packets.packets['player_warp'], wp)
     yield from from_player.connection.client_raw_write(full)
Esempio n. 16
0
 def warp_player_to_ship(self, from_player, to_player):
     """
     Warps a player to another player's ship.
     :param from_player: Player: The player being warped.
     :param to_player: Player: The player whose ship is being warped to.
     :return: None
     """
     wp = PlayerWarp.build(dict(warp_action=dict(warp_type=1, world_id=2,
                                                 ship_id=to_player.uuid,
                                                 flag=0)))
     full = build_packet(packets.packets['player_warp'], wp)
     yield from from_player.connection.client_raw_write(full)
Esempio n. 17
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)
Esempio n. 18
0
    def _give_item(self, data, connection):
        """
        Give item(s) to a player.

        :param data: The packet containing the command.
        :param connection: The connection from which the packet came.
        :return: Null.
        :raise: SyntaxWarning if too many arguments provided or item count
                cannot be properly converted. NameError if a target player
                cannot be resolved.
        """
        arg_count = len(data)
        target = self.plugins.player_manager.find_player(data[0])
        if arg_count == 1:
            target = connection.player
            item = data[0]
            count = 1
        elif arg_count == 2:
            if data[1].isdigit():
                target = connection.player
                item = data[0]
                count = int(data[1])
            else:
                item = data[1]
                count = 1
        elif arg_count == 3:
            item = data[1]
            if not data[2].isdigit():
                raise SyntaxWarning("Couldn't convert %s to an item count." %
                                    data[2])
            count = int(data[2])
        else:
            raise SyntaxWarning("Too many arguments")
        if target is None:
            raise NameError(target)
        target = target.connection
        if count > 10000 and item != "money":
            count = 10000
        item_base = data_parser.GiveItem.build(dict(name=item,
                                                    count=count,
                                                    variant_type=7,
                                                    description=""))
        item_packet = pparser.build_packet(packets.packets['give_item'],
                                           item_base)
        yield from target.raw_write(item_packet)
        send_message(connection,
                     "Gave {} (count: {}) to {}".format(
                         item,
                         count,
                         target.player.alias))
        send_message(target, "{} gave you {} (count: {})".format(
            connection.player.alias, item, count))
Esempio n. 19
0
 def warp_player_to_player(self, from_player, to_player):
     """
     Warps a player to another player's ship.
     :param from_player: Player
     :param to_player: Player
     :return: None
     """
     coords = dict(sector="", x=0, y=0, z=0, planet=0, satellite=0)
     wp = WarpCommand.build(dict(warp_type=3, coordinate=coords,
                                 player=to_player.name, sector="", x=0, y=0,
                                 z=0, planet=0, satellite=0))
     full = build_packet(id=packets.packets['warp_command'], data=wp)
     yield from from_player.protocol.client_raw_write(full)
Esempio n. 20
0
 def warp_player_to_player(self, from_player, to_player):
     """
     Warps a player to another player's ship.
     :param from_player: Player
     :param to_player: Player
     :return: None
     """
     coords = dict(x=0, y=0, z=0, planet=0, satellite=0)
     wp = PlayerWarp.build(dict(warp_type=3, coordinate=coords,
                                 player=to_player.name, x=0, y=0,
                                 z=0, planet=0, satellite=0))
     full = build_packet(id=packets.packets['player_warp'], data=wp)
     yield from from_player.connection.client_raw_write(full)
Esempio n. 21
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)
Esempio n. 22
0
 def on_client_connect(self, data, connection):
     if not self.enabled:
         return True
     species = data['parsed']['species']
     if species not in self.allowed_species:
         self.logger.warn("Aborting connection - player's species ({}) "
                 "is not in whitelist.".format(species))
         rejection_packet = build_packet(packets['connect_failure'],
                 ConnectFailure.build(dict(reason="^red;Connection "
                         "aborted!\n\n^orange;Your species ({}) is not "
                         "allowed on this server.\n^green;Please use a "
                         "different character.".format(species))))
         yield from connection.raw_write(rejection_packet)
         connection.die()
         return False
     return True
Esempio n. 23
0
    def _kick(self, data, connection):
        """
        Kick a play off the server. You must specify a name. You may also
        specify an optional reason.

        :param data: The packet containing the command.
        :param connection: The connection from which the packet came.
        :return: Null.
        """

        # FIXME: Kick is currently broken. Kicking someone will cause their
        # starbound client to crash (overkill).
        try:
            alias = data[0]
        except IndexError:
            raise SyntaxWarning("No target provided.")

        try:
            reason = " ".join(data[1:])
        except IndexError:
            reason = "No reason given."

        p = self.get_player_by_alias(alias)
        if p is None:
            send_message(connection,
                         "Couldn't find a player with name {}".format(alias))
        if not p.logged_in:
            send_message(connection,
                         "Player {} is not currently logged in.".format(alias))
        if p.client_id == -1 or p.connection is None:
            p.connection = None
            p.logged_in = False
            p.location = None
            self.players_online.remove(p.uuid)
            return
        kick_string = "You were kicked.\n Reason: {}".format(reason)
        kick_packet = build_packet(
            packets["server_disconnect"],
            ServerDisconnect.build(dict(reason=kick_string)))
        yield from p.connection.raw_write(kick_packet)
        p.connection = None
        p.logged_in = False
        p.location = None
        self.players_online.remove(p.uuid)
        broadcast(
            self, "^red;{} has been kicked for reason: "
            "{}^reset;".format(alias, reason))
Esempio n. 24
0
    def _kick(self, data, connection):
        """
        Kick a play off the server. You must specify a name. You may also
        specify an optional reason.

        :param data: The packet containing the command.
        :param connection: The connection from which the packet came.
        :return: Null.
        """

        # FIXME: Kick is currently broken. Kicking someone will cause their
        # starbound client to crash (overkill).
        try:
            alias = data[0]
        except IndexError:
            raise SyntaxWarning("No target provided.")

        try:
            reason = " ".join(data[1:])
        except IndexError:
            reason = "No reason given."

        p = self.get_player_by_alias(alias)
        if not p.logged_in:
            send_message(connection,
                         "Player {} is not currently logged in.".format(alias))
            return False
        if p is not None:
            if p.client_id == -1 or p.connection is None:
                p.connection = None
                p.logged_in = False
                p.location = None
                return
            kick_string = "You were kicked.\n Reason: {}".format(reason)
            kick_packet = build_packet(packets["server_disconnect"],
                                       ServerDisconnect.build(
                                           dict(reason=kick_string)))
            yield from p.connection.raw_write(kick_packet)
            p.connection = None
            p.logged_in = False
            p.location = None
            broadcast(self, "^red;{} has been kicked for reason: "
                            "{}^reset;".format(alias, reason))
        else:
            send_message(connection,
                         "Couldn't find a player with name {}".format(alias))
Esempio n. 25
0
    def kick(self, data, protocol):
        name = data[0]
        try:
            reason = " ".join(data[1:])
        except IndexError:
            reason = "No reason given."

        p = self.get_player_by_name(" ".join(data))
        if p is not None:
            kill_packet = build_packet(packets.packets['server_disconnect'],
                                       StarString.build("You were kicked."))
            yield from p.protocol.raw_write(kill_packet)
            yield from self.factory.broadcast(
                "%s has kicked %s. Reason: %s" %
                (protocol.player.name, p.name, reason))
        else:
            yield from protocol.send_message(
                "Couldn't find a player with name %s" % name)
Esempio n. 26
0
 def on_client_connect(self, data, connection):
     if not self.enabled:
         return True
     species = data['parsed']['species']
     if species not in self.allowed_species:
         self.logger.warn("Aborting connection - player's species ({}) "
                          "is not in whitelist.".format(species))
         rejection_packet = build_packet(
             packets['connect_failure'],
             ConnectFailure.build(
                 dict(reason="^red;Connection "
                      "aborted!\n\n^orange;Your species ({}) is not "
                      "allowed on this server.\n^green;Please use a "
                      "different character.".format(species))))
         yield from connection.raw_write(rejection_packet)
         connection.die()
         return False
     return True
Esempio n. 27
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)
Esempio n. 28
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)
Esempio n. 29
0
    def on_chat_sent(self, data, connection):
        """
        Catch a chat packet as it goes by. If the first character in its
        string is the command_prefix, it is a command. Grab it and start
        interpreting its contents.

        :param data: Packet which is being transmitted.
        :param connection: Connection which sent the packet.
        :return: Boolean: True if the message is not a command (or not one we
                 know about), so that the packets keeps going. False if it is
                 a command we know, so that it stops here after it is
                 processed.
        """
        if data['parsed']['message'].startswith(
                self.plugin_config.command_prefix):
            if data['parsed']['message'].startswith("{}sb:".format(
                    self.plugin_config.command_prefix)):
                # Bypass StarryPy command processing and send to the
                # starbound server
                cmd = data['parsed']['message'].replace("sb:", "")
                pkt = ChatSent.build({
                    "message": cmd,
                    "send_mode": data['parsed']['send_mode']
                })
                full = build_packet(packets.packets['chat_sent'], pkt)
                yield from connection.client_raw_write(full)
                return False
            to_parse = data['parsed']['message'][len(self.plugin_config.
                                                     command_prefix):].split()

            try:
                command = to_parse[0]
            except IndexError:
                return True  # It's just a slash.

            if command not in self.commands:
                return True  # There's no command here that we know of.
            else:
                asyncio.ensure_future(
                    self.run_command(command, connection, to_parse[1:]))
                return False  # We're handling the command in the event loop.
        else:
            # Not a command, just text, so pass it along.
            return True
Esempio n. 30
0
    def on_chat_sent(self, data, connection):
        """
        Catch a chat packet as it goes by. If the first character in its
        string is the command_prefix, it is a command. Grab it and start
        interpreting its contents.

        :param data: Packet which is being transmitted.
        :param connection: Connection which sent the packet.
        :return: Boolean: True if the message is not a command (or not one we
                 know about), so that the packets keeps going. False if it is
                 a command we know, so that it stops here after it is
                 processed.
        """
        if data['parsed']['message'].startswith(
                self.plugin_config.command_prefix):
            if data['parsed']['message'].startswith("{}sb:".format(
                    self.plugin_config.command_prefix)):
                # Bypass StarryPy command processing and send to the
                # starbound server
                cmd = data['parsed']['message'].replace("sb:", "")
                pkt = ChatSent.build({"message": cmd, "send_mode": data[
                    'parsed']['send_mode']})
                full = build_packet(packets.packets['chat_sent'], pkt)
                yield from connection.client_raw_write(full)
                return False
            to_parse = data['parsed']['message'][len(
                self.plugin_config.command_prefix):].split()

            try:
                command = to_parse[0]
            except IndexError:
                return True  # It's just a slash.

            if command not in self.commands:
                return True  # There's no command here that we know of.
            else:
                asyncio.ensure_future(self.run_command(command,
                                                       connection,
                                                       to_parse[1:]))
                return False  # We're handling the command in the event loop.
        else:
            # Not a command, just text, so pass it along.
            return True
Esempio n. 31
0
    def kick(self, data, protocol):
        name = data[0]
        try:
            reason = " ".join(data[1:])
        except IndexError:
            reason = "No reason given."

        p = self.get_player_by_name(" ".join(data))
        if p is not None:
            kill_packet = build_packet(packets.packets['server_disconnect'],
                                       StarString.build("You were kicked."))
            yield from p.protocol.raw_write(kill_packet)
            yield from self.factory.broadcast("%s has kicked %s. Reason: %s" % (
                protocol.player.name,
                p.name,
                reason))
        else:
            yield from protocol.send_message(
                "Couldn't find a player with name %s" % name)
Esempio n. 32
0
    def _new_player_gifter(self, connection):
        """
        Helper routine for giving items to new players.

        :param connection: The connection we're showing the message to.
        :return: Null.
        """
        yield from asyncio.sleep(2)
        for item, count in self.gifts.items():
            count = int(count)
            if count > 10000 and item != "money":
                count = 10000
            item_base = GiveItem.build(dict(name=item, count=count, variant_type=7, description=""))
            item_packet = pparser.build_packet(packets.packets["give_item"], item_base)
            yield from asyncio.sleep(0.1)
            yield from connection.raw_write(item_packet)
            send_message(
                connection, "You have been given {} {}".format(str(count), item), mode=ChatReceiveMode.COMMAND_RESULT
            )
        return
Esempio n. 33
0
 def warp_player_to_player(self, from_player, to_player):
     """
     Warps a player to another player's ship.
     :param from_player: Player
     :param to_player: Player
     :return: None
     """
     coords = dict(sector="", x=0, y=0, z=0, planet=0, satellite=0)
     wp = WarpCommand.build(
         dict(warp_type=3,
              coordinate=coords,
              player=to_player.name,
              sector="",
              x=0,
              y=0,
              z=0,
              planet=0,
              satellite=0))
     full = build_packet(id=packets.packets['warp_command'], data=wp)
     yield from from_player.protocol.client_raw_write(full)
Esempio n. 34
0
 def give_item(self, data, protocol):
     arg_count = len(data)
     if arg_count == 1:
         target = protocol.player
         item = data[0]
         count = 1
     elif arg_count == 2:
         if data[1].isdigit():
             target = protocol.player
             item = data[0]
             count = int(data[1])
         else:
             target = self.plugins.player_manager.get_player_by_name(data[0])
             item = data[1]
             count = 1
     elif arg_count == 3:
         target = self.plugins.player_manager.get_player_by_name(data[0])
         item = data[1]
         if not data[2].isdigit():
             raise SyntaxWarning("Couldn't convert %s to an item count." %
                                 data[2])
         count = int(data[2])
     else:
         raise SyntaxWarning("Too many arguments")
     if target is None:
         raise NameError(target)
     target = target.protocol
     if count > 1000 and item != "money":
         count = 1000
     count += 1
     item_base = data_parser.GiveItem.build(dict(name=item,
                                                 count=count,
                                                 variant_type=7,
                                                 extra=0))
     item_packet = pparser.build_packet(packets.packets['give_item'],
                                        item_base)
     yield from target.raw_write(item_packet)
     yield from protocol.send_message("Gave %s (count: %d) to %s" %
                                      (item, count - 1, target.player.name))
     yield from target.send_message("%s gave you %s (count: %d)" %
                                    (protocol.player.name, item, count - 1))
 def give_item(self, data, protocol):
     arg_count = len(data)
     target = self.plugins.player_manager.get_player_by_name(data[0])
     if arg_count == 1:
         target = protocol.player
         item = data[0]
         count = 1
     elif arg_count == 2:
         if data[1].isdigit():
             target = protocol.player
             item = data[0]
             count = int(data[1])
         else:
             item = data[1]
             count = 1
     elif arg_count == 3:
         item = data[1]
         if not data[2].isdigit():
             raise SyntaxWarning("Couldn't convert %s to an item count." %
                                 data[2])
         count = int(data[2])
     else:
         raise SyntaxWarning("Too many arguments")
     if target is None:
         raise NameError(target)
     target = target.protocol
     if count > 1000 and item != "money":
         count = 1000
     count += 1
     item_base = data_parser.GiveItem.build(dict(name=item,
                                                 count=count,
                                                 variant_type=7,
                                                 extra=0))
     item_packet = pparser.build_packet(packets.packets['give_item'],
                                        item_base)
     yield from target.raw_write(item_packet)
     send_message(protocol, "Gave %s (count: %d) to %s" %
                            (item, count - 1, target.player.name))
     send_message(target, "%s gave you %s (count: %d)" %
                          (protocol.player.name, item, count - 1))
Esempio n. 36
0
    def _new_player_gifter(self, connection):
        """
        Helper routine for giving items to new players.

        :param connection: The connection we're showing the message to.
        :return: Null.
        """
        yield from asyncio.sleep(2)
        for item, count in self.gifts.items():
            count = int(count)
            if count > 10000 and item != "money":
                count = 10000
            item_base = GiveItem.build(
                dict(name=item, count=count, variant_type=7, description=""))
            item_packet = pparser.build_packet(packets.packets['give_item'],
                                               item_base)
            yield from asyncio.sleep(.1)
            yield from connection.raw_write(item_packet)
            send_message(connection,
                         "You have been given {} {}".format(str(count), item),
                         mode=ChatReceiveMode.COMMAND_RESULT)
        return
Esempio n. 37
0
    def on_spawn_entity(self, data, connection):
        """
        Catch when a player tries spawning an object in the world.

        :param data: The packet containing the action.
        :param connection: The connection from which the packet came.
        :return: Boolean, Varied. If the server generates the packet,
                 let it pass. If planet is not protected, let it pass.
                 If player is an Admin, let it pass. If player is list of
                 builders, let it pass. Otherwise, block the packet from
                 reaching the server.
        """
        if not self.check_protection(connection.player.location):
            return True
        protection = self.get_protection(connection.player.location)
        if not protection.protected:
            return True
        if connection.player.check_role(Admin):
            return True
        elif protection.check_builder(connection.player):
            return True
        else:
            action = data["parsed"]["spawn_type"]
            if action not in [EntitySpawnType.OBJECT]:
                return True
        yield from self._protection_warn(data, connection)

        item_base = GiveItem.build(
            dict(name=data["parsed"]["payload"],
                 count=1,
                 variant_type=7,
                 description=""))
        item_packet = pparser.build_packet(packets.packets['give_item'],
                                           item_base)
        yield from asyncio.sleep(.1)
        yield from connection.raw_write(item_packet)
        return False
Esempio n. 38
0
    def on_spawn_entity(self, data, connection):
        """
        Catch when a player tries spawning an object in the world.

        :param data: The packet containing the action.
        :param connection: The connection from which the packet came.
        :return: Boolean, Varied. If the server generates the packet,
                 let it pass. If planet is not protected, let it pass.
                 If player is an Admin, let it pass. If player is list of
                 builders, let it pass. Otherwise, block the packet from
                 reaching the server.
        """
        if not self.check_protection(connection.player.location):
            return True
        protection = self.get_protection(connection.player.location)
        if not protection.protected:
            return True
        if connection.player.check_role(Admin):
            return True
        elif connection.player.alias in protection.get_builders():
            return True
        else:
            action = data["parsed"]["spawn_type"]
            if action not in [EntitySpawnType.OBJECT]:
                return True
        yield from self._protection_warn(data, connection)

        item_base = GiveItem.build(dict(name=data["parsed"]["payload"],
                                        count=1,
                                        variant_type=7,
                                        description=""))
        item_packet = pparser.build_packet(packets.packets['give_item'],
                                           item_base)
        yield from asyncio.sleep(.1)
        yield from connection.raw_write(item_packet)
        return False
Esempio n. 39
0
 def build_rejection(self, rejection_reason):
     return build_packet(
         packets.packets['connect_response'],
         ConnectResponse.build(
             dict(success=False, client_id=0, message=rejection_reason)) +
         self.unlocked_sector_magic)
Esempio n. 40
0
 def _send_to_server(self, message, mode, connection):
     msg_base = data_parser.ChatSent.build(dict(message=" ".join(message),
                                                send_mode=mode))
     msg_packet = pparser.build_packet(packets.packets['chat_sent'],
                                       msg_base)
     yield from connection.client_raw_write(msg_packet)
Esempio n. 41
0
 def build_rejection(self, rejection_reason):
     return build_packet(packets.packets['connect_response'],
                         ConnectResponse.build(
                             dict(success=False, client_id=0,
                                  message=rejection_reason)) +
                         self.unlocked_sector_magic)
Esempio n. 42
0
 def _send_to_server(self, message, mode, connection):
     msg_base = data_parser.ChatSent.build(dict(message="".join(message),
                                                send_mode=mode))
     msg_packet = pparser.build_packet(packets.packets['chat_sent'],
                                       msg_base)
     yield from connection.client_raw_write(msg_packet)