Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ then
python -m rcon.user_config.seed_db
# TODO: Temporarily handle converting users old scorebot URLs to the new format; remove in a few releases
SERVER_NUMBER=${SERVER_NUMBER} LOGGING_PATH=/logs/ LOGGING_FILENAME=api_${SERVER_NUMBER}.log python -m rcon.cli port_legacy_scorebot_urls
SERVER_NUMBER=${SERVER_NUMBER} LOGGING_PATH=/logs/ LOGGING_FILENAME=api_${SERVER_NUMBER}.log python -m rcon.cli remove_orphaned_map_ids
./manage.py register_api
cd rconweb
./manage.py collectstatic --noinput
Expand Down
3 changes: 1 addition & 2 deletions rcon/api_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,6 @@ def reset_votemap_state(self) -> list[VoteMapStatusType]:
def get_votemap_whitelist(self) -> list[str]:
v = VoteMap()

# TODO: update this when we return `Layer`s instead of strings
return [str(map) for map in v.get_map_whitelist()]

def add_map_to_votemap_whitelist(self, map_name: str):
Expand All @@ -703,7 +702,7 @@ def reset_map_votemap_whitelist(self):

def set_votemap_whitelist(self, map_names: Iterable[str]):
v = VoteMap()
v.set_map_whitelist(map_names=map_names)
v.set_map_whitelist(map_layers=set([maps.parse_layer(m) for m in map_names]))

def get_votemap_config(self) -> VoteMapUserConfig:
return VoteMapUserConfig.load_from_db()
Expand Down
20 changes: 19 additions & 1 deletion rcon/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import rcon.user_config
import rcon.user_config.utils
import rcon.watch_killrate
from rcon import auto_settings, broadcast, routines
from rcon import auto_settings, broadcast, routines, maps
from rcon.automods import automod
from rcon.blacklist import BlacklistCommandHandler
from rcon.cache_utils import RedisCached, get_redis_pool, invalidates
Expand All @@ -31,12 +31,14 @@
from rcon.user_config.legacy_scorebot import ScorebotUserConfig
from rcon.user_config.log_stream import LogStreamUserConfig
from rcon.user_config.scoreboard import ScoreboardUserConfig, _port_legacy_scorebot_urls
from rcon.user_config.vote_map import VoteMapUserConfig
from rcon.user_config.webhooks import (
BaseMentionWebhookUserConfig,
BaseUserConfig,
BaseWebhookUserConfig,
)
from rcon.utils import ApiKey
from rcon.vote_map import VoteMap

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -590,6 +592,22 @@ def convert_win_player_ids():
)
_merge_duplicate_player_ids(existing_ids=player_ids_to_merge)

@cli.command(name="remove_orphaned_map_ids")
def remove_orphaned_map_ids():
vm = VoteMap()
known_map_ids = [m.id for m in ctl.get_maps()]

res = set()
prev = vm.get_map_whitelist()
for m in prev:
if m.id in known_map_ids:
res.add(m)
else:
logger.info(f"Removed map {m.id} / {m.pretty_name} from VoteMap Whitelist as it does not exist in game server anymore")

if len(res) != len(prev):
vm.set_map_whitelist(res)


PREFIXES_TO_EXPOSE = ["get_", "set_", "do_"]
EXCLUDED: Set[str] = {"set_map_rotation", "connection_pool"}
Expand Down
17 changes: 12 additions & 5 deletions rcon/vote_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def _suggest_next_maps(
exclude_last_n,
[m.pretty_name for m in last_n_maps],
)
remaining_maps = [maps.parse_layer(m) for m in allowed_maps - last_n_maps]
remaining_maps = [m for m in allowed_maps - last_n_maps]
logger.info(
"Remaining maps to suggest from: %s", [m.pretty_name for m in remaining_maps]
)
Expand Down Expand Up @@ -639,9 +639,15 @@ def get_map_whitelist(self) -> set[maps.Layer]:
"""Return the set of map names on the whitelist or all possible game server maps if not configured"""
res = self.red.get(self.whitelist_key)
if res is not None:
return pickle.loads(res) # type: ignore
try:
l = pickle.loads(res)
# depending on the time the map was saved this is either a list of strings, a list of layers or
# a combination of both. Make sure we always return a list of layers
return set([maps.parse_layer(m) for m in l])
except ValueError:
pass

return set(maps.parse_layer(map_) for map_ in self.rcon.get_maps())
return set(self.rcon.get_maps())

def add_map_to_whitelist(self, map_name: str):
if map_name not in self.rcon.get_maps():
Expand Down Expand Up @@ -669,8 +675,9 @@ def remove_maps_from_whitelist(self, map_names):
def reset_map_whitelist(self):
self.set_map_whitelist(self.rcon.get_maps())

def set_map_whitelist(self, map_names) -> None:
self.red.set(self.whitelist_key, pickle.dumps(set(map_names)))
def set_map_whitelist(self, map_layers: set[maps.Layer]) -> None:
# No need to save the whole layer information, it can be resurrected with maps.parse_layer at read time
self.red.set(self.whitelist_key, pickle.dumps(set([m.id for m in map_layers])))

def gen_selection(self):
config = VoteMapUserConfig.load_from_db()
Expand Down