Esempio n. 1
0
    def execute(self, room, client, raw_command_string):
        command_match = command_pattern.match(raw_command_string)

        if command_match is None:
            raise GenericError("Invalid command input.")

        command_string = command_match.group('command_string')
        arg_string = command_match.group('arg_string') or ""

        if command_string is None:
            raise GenericError("Invalid command input.")

        command_handler = self._command_finder.find(room, client,
                                                    command_string)

        if command_handler is None:
            raise GenericError("Unknown command.")

        execute_functionality = command_handler.functionality

        if not client.allowed(execute_functionality):
            raise InsufficientPermissions(execute_functionality.denied_message)

        try:
            args = shlex.split(arg_string)
        except ValueError as e:
            raise GenericError("Invalid input: {error}", error=e.message)

        d = defer.maybeDeferred(command_handler.execute, self._spyd_server,
                                room, client, command_string, args, arg_string)
        d.addErrback(client.handle_exception)
Esempio n. 2
0
    def handle(room, client, map_name, mode_num):
        if not client.allowed(set_map_mode_functionality):
            raise InsufficientPermissions(
                set_map_mode_functionality.denied_message)

        mode_name = get_mode_name_from_num(mode_num)

        map_name = yield resolve_map_name(room, map_name)

        room.change_map_mode(map_name, mode_name)
Esempio n. 3
0
    def execute(cls, spyd_server, room, client, command_string, arguments, raw_args):
        if not client.allowed(set_map_mode_functionality):
            raise InsufficientPermissions(set_map_mode_functionality.denied_message)

        mode_name = command_string
        map_name = arguments[0]

        map_name = yield resolve_map_name(room, map_name)

        room.change_map_mode(map_name, mode_name)
Esempio n. 4
0
    def handle(room, client, target_pn, spectate):
        player = room.get_player(target_pn)
        if player is None:
            raise UnknownPlayer(cn=target_pn)

        if client.get_player() is player:
            if not client.allowed(set_spectator_functionality):
                raise InsufficientPermissions(
                    set_spectator_functionality.denied_message)
            if not spectate and not client.allowed(
                    set_room_not_spectator_locked_functionality):
                raise InsufficientPermissions(
                    set_room_not_spectator_locked_functionality.denied_message)
        else:
            if not client.allowed(set_other_spectator_functionality):
                raise InsufficientPermissions(
                    set_other_spectator_functionality.denied_message)

        room._set_player_spectator(player, spectate)
Esempio n. 5
0
    def handle(room, client, target_pn, team_name):
        if not client.allowed(set_others_teams_functionality):
            raise InsufficientPermissions(
                set_others_teams_functionality.denied_message)

        player = room.get_player(target_pn)
        if player is None:
            raise UnknownPlayer(cn=target_pn)

        room.gamemode.on_player_try_set_team(client.get_player(), player,
                                             player.team.name, team_name)
Esempio n. 6
0
    def _set_self_privilege(self, client, requested_privilege, password):
        room_classification = "temporary" if self.temporary else "permanent"

        if requested_privilege > privileges.PRIV_NONE:
            privilege_action = "claim"
            permission_involved = requested_privilege
        else:
            privilege_action = "relinquish"
            permission_involved = client.privilege

        functionality_category = Room.set_self_privilege_functionality_tree.get(room_classification, {}).get(privilege_action, {})

        functionality = functionality_category.get(permission_involved, None)

        if functionality is None:
            raise InsufficientPermissions("You do not have permissions to do that.")

        if client.allowed(functionality):
            self._client_change_privilege(client, client, requested_privilege)
        else:
            raise InsufficientPermissions(functionality.denied_message)
Esempio n. 7
0
    def execute(cls, spyd_server, room, client, command_string, arguments,
                raw_args):
        if len(arguments):
            if room.temporary:
                if not client.allowed(set_temporary_room_timeleft):
                    raise InsufficientPermissions(
                        set_temporary_room_timeleft.denied_message)
            else:
                if not client.allowed(set_permanent_room_timeleft):
                    raise InsufficientPermissions(
                        set_permanent_room_timeleft.denied_message)

            try:
                modifier, value = timestring.parseTimeString(raw_args)

                if modifier == '+':
                    new_timeleft = min(MAXTIMELEFT,
                                       max(0, room.timeleft + value))
                elif modifier == '-':
                    new_timeleft = min(MAXTIMELEFT,
                                       max(0, room.timeleft - value))
                elif modifier == '=':
                    new_timeleft = min(MAXTIMELEFT, max(0, value))

                timeleft = prettytime.createDurationString(new_timeleft)
                room._broadcaster.server_message(
                    info(timeleft_set_str, client=client, timeleft=timeleft))

                room.timeleft = new_timeleft

            except timestring.MalformedTimeString:
                raise GenericError("Invalid time string specified.")
        else:
            timeleft = prettytime.createDurationString(room.timeleft)
            client.send_server_message(
                info(timeleft_get_str, timeleft=timeleft))
Esempio n. 8
0
    def handle(room, client, pause):
        if not client.allowed(pause_resume_functionality):
            raise InsufficientPermissions(
                pause_resume_functionality.denied_message)

        if pause:
            if room.is_paused and not room.is_resuming:
                raise StateError('The game is already paused.')
            room.pause()
            room._broadcaster.server_message(
                info(f"{client.get_player().name} has paused the game."))
        elif not pause:
            if not room.is_paused:
                raise StateError('The game is already resumed.')
            room.resume()
            room._broadcaster.server_message(
                info(f"{client.get_player().name} has resumed the game."))