示例#1
0
def remove_player_from_blacklist(steam_id_64):
    with enter_session() as sess:
        player = get_player(sess, steam_id_64)
        if not player:
            raise CommandFailedError(f"Player with steam id {steam_id_64} not found")

        if not player.blacklist:
            raise CommandFailedError(f"Player {player} was not blacklisted")

        player.blacklist.is_blacklisted = False
        sess.commit()
示例#2
0
    def set_maprotation(self, rotation):
        if not rotation:
            raise CommandFailedError("Empty rotation")

        rotation = list(rotation)
        logger.info("Apply map rotation %s", rotation)

        current = self.get_map_rotation()
        if rotation == current:
            logger.debug("Map rotation is the same, nothing to do")
            return current
        with invalidates(Rcon.get_map_rotation):
            if len(current) == 1:
                logger.info("Current rotation is a single map")
                for idx, m in enumerate(rotation):
                    if m not in current:
                        self.do_add_map_to_rotation(m)
                    if m in current and idx != 0:
                        self.do_remove_map_from_rotation(m)
                        self.do_add_map_to_rotation(m)
                if current[0] not in rotation:
                    self.do_remove_map_from_rotation(m)
                return rotation

            first = rotation.pop(0)
            to_remove = set(current) - {first}
            if to_remove == set(current):
                self.do_add_map_to_rotation(first)

            self.do_remove_maps_from_rotation(to_remove)
            self.do_add_maps_to_rotation(rotation)

        return [first] + rotation
示例#3
0
    def get_map_rotation(self):
        l = super().get_map_rotation()

        for map_ in l:
            if not self.map_regexp.match(map_):
                raise CommandFailedError("Server return wrong data")
        return l
示例#4
0
def add_player_to_blacklist(steam_id_64, reason, name=None, by=None):
    # TODO save author of blacklist
    with enter_session() as sess:
        player = _get_set_player(sess, steam_id_64=steam_id_64, player_name=name)
        if not player:
            raise CommandFailedError(f"Player with steam id {steam_id_64} not found")

        if player.blacklist:
            if player.blacklist.is_blacklisted:
                logger.warning(
                    "Player %s was already blacklisted with %s, updating reason to %s",
                    str(player),
                    player.blacklist.reason,
                    reason,
                )
            player.blacklist.is_blacklisted = True
            player.blacklist.reason = reason
            player.blacklist.by = by
        else:
            logger.info("Player %s blacklisted for %s", str(player), reason)
            sess.add(
                BlacklistedPlayer(
                    steamid=player, is_blacklisted=True, reason=reason, by=by
                )
            )

        sess.commit()
示例#5
0
 def set_votekick_threshold(self, threshold_pairs):
     # Todo use proper data structure
     with invalidates(self.get_votekick_threshold):
         res = super().set_votekick_threshold(threshold_pairs)
         print(f"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! {res}")
         logger.error("Threshold res %s", res)
         if res.lower().startswith("error"):
             logger.error("Unable to set votekick threshold: %s", res)
             raise CommandFailedError(res)
示例#6
0
    def set_maprotation(self, rotation):
        if not rotation:
            raise CommandFailedError("Empty rotation")
        first = rotation.pop(0)

        with invalidates(self.get_map_rotation):
            current = set(self.get_map_rotation())
            self.do_remove_maps_from_rotation(current - set([first]))
            self.do_add_maps_to_rotation(rotation)

        return [first] + rotation
示例#7
0
    def set_messages(self, msg_type, messages):
        msgs = []

        for m in messages:
            m = m.replace("\\n", "\n")
            m = m.strip()
            if m:
                msgs.append(m)
        try:
            set_user_config(self.message_types[msg_type], msgs)
        except KeyError:
            raise CommandFailedError("{} is an invalid type".format(msg_type))
示例#8
0
def remove_flag(flag_id):
    with enter_session() as sess:
        exits = sess.query(PlayerFlag).filter(
            PlayerFlag.id == int(flag_id)).one_or_none()
        if not exits:
            logger.warning("Flag does not exists")
            raise CommandFailedError("Flag does not exists")
        player = exits.steamid.to_dict()
        flag = exits.to_dict()
        sess.delete(exits)
        sess.commit()

    return player, flag
示例#9
0
def add_flag_to_player(steam_id_64, flag, comment=None, player_name=None):
    with enter_session() as sess:
        player = _get_set_player(sess, player_name=player_name, steam_id_64=steam_id_64)
        exits = (
            sess.query(PlayerFlag)
            .filter(PlayerFlag.playersteamid_id == player.id, PlayerFlag.flag == flag)
            .all()
        )
        if exits:
            logger.warning("Flag already exists")
            raise CommandFailedError("Flag already exists")
        new = PlayerFlag(flag=flag, comment=comment, steamid=player)
        sess.add(new)
        sess.commit()
        res = player.to_dict()
        return res, new.to_dict()
示例#10
0
 def get_messages(self, msg_type):
     try:
         return get_user_config(self.message_types[msg_type])
     except KeyError:
         raise CommandFailedError("{} is an invalid type".format(msg_type))
示例#11
0
 def get_slots(self):
     res = super().get_slots()
     if not self.slots_regexp.match(res):
         raise CommandFailedError("Server returned crap")
     return res
示例#12
0
 def get_name(self):
     name = super().get_name()
     if len(name) > self.MAX_SERV_NAME_LEN:
         raise CommandFailedError("Server returned wrong data")
     return name
示例#13
0
 def get_map(self):
     current_map = super().get_map()
     if not self.map_regexp.match(current_map):
         raise CommandFailedError("Server returned wrong data")
     return current_map
示例#14
0
 def set_map(self, map_name):
     with invalidates(Rcon.get_map):
         res = super().set_map(map_name)
         if res != "SUCCESS":
             raise CommandFailedError(res)