diff --git a/rcon/hooks.py b/rcon/hooks.py index 903d365ed..17b7bf6f3 100644 --- a/rcon/hooks.py +++ b/rcon/hooks.py @@ -41,7 +41,7 @@ from rcon.steam_utils import get_player_bans, get_steam_profile, update_db_player_info from rcon.types import PlayerFlagType, SteamBansType, VACGameBansConfigType from rcon.user_config import CameraConfig, RealVipConfig -from rcon.utils import LOG_MAP_NAMES_TO_MAP, MapsHistory, get_server_number +from rcon.utils import LOG_MAP_NAMES_TO_MAP, MapsHistory, get_server_number, UNKNOWN_MAP_NAME from rcon.vote_map import VoteMap from rcon.workers import record_stats_worker, temporary_broadcast, temporary_welcome @@ -90,7 +90,7 @@ def handle_new_match_start(rcon: Rcon, struct_log): logger.error("Unable to get current map") map_name_to_save = LOG_MAP_NAMES_TO_MAP.get( - struct_log["sub_content"], "foy_warfare_night" + struct_log["sub_content"], UNKNOWN_MAP_NAME ) guessed = True log_map_name = struct_log["sub_content"].rsplit(" ")[0] @@ -104,6 +104,9 @@ def handle_new_match_start(rcon: Rcon, struct_log): ): map_name_to_save = current_map guessed = False + elif map_name_to_save == UNKNOWN_MAP_NAME: + map_name_to_save = current_map + guessed = True else: logger.warning( "Got recent match start but map don't match %s != %s", @@ -146,7 +149,7 @@ def record_map_end(rcon: Rcon, struct_log): current_map = "bla_" logger.error("Unable to get current map") - map_name = LOG_MAP_NAMES_TO_MAP.get(struct_log["sub_content"], "foy_warfare_night") + map_name = LOG_MAP_NAMES_TO_MAP.get(struct_log["sub_content"], UNKNOWN_MAP_NAME) log_time = datetime.fromtimestamp(struct_log["timestamp_ms"] / 1000) if (datetime.utcnow() - log_time).total_seconds() < 60: diff --git a/rcon/scorebot.py b/rcon/scorebot.py index 9ca2b06ce..6c5f3b059 100644 --- a/rcon/scorebot.py +++ b/rcon/scorebot.py @@ -15,6 +15,7 @@ from discord.embeds import Embed from discord.errors import HTTPException, NotFound from rcon.config import get_config +from rcon.utils import UNKNOWN_MAP_NAME class _PublicInfoCurrentMapType(TypedDict): @@ -130,26 +131,50 @@ class PublicInfoType(TypedDict): map_to_pict = { "carentan": "maps/carentan.webp", + "carentan_night": "maps/carentan-night.webp", "driel": "maps/driel.webp", + "driel_night": "maps/driel-night.webp", "elalamein": "maps/elalamein.webp", + "elalamein_night": "maps/elalamein-night.webp", "foy": "maps/foy.webp", + "foy_night": "maps/foy-night.webp", "hill400": "maps/hill400.webp", + "hill400_night": "maps/hill400-night.webp", "hurtgenforest": "maps/hurtgen.webp", + "hurtgenforest_night": "maps/hurtgen-night.webp", "kharkov": "maps/kharkov.webp", + "kharkov_night": "maps/kharkov-night.webp", "kursk": "maps/kursk.webp", + "kursk_night": "maps/kursk-night.webp", "omahabeach": "maps/omaha.webp", + "omahabeach_night": "maps/omaha-night.webp", "purpleheartlane": "maps/phl.webp", + "purpleheartlane_night": "maps/phl-night.webp", "stalingrad": "maps/stalingrad.webp", + "stalingrad_night": "maps/stalingrad-night.webp", "stmariedumont": "maps/smdm.webp", + "stmariedumont_night": "maps/smdm-night.webp", "stmereeglise": "maps/sme.webp", + "stmereeglise_night": "maps/sme-night.webp", "utahbeach": "maps/utah.webp", + "utahbeach_night": "maps/utah-night.webp", + UNKNOWN_MAP_NAME: "maps/unknown.webp", } def get_map_image(server_info): - img = map_to_pict.get( - server_info["current_map"]["just_name"], server_info["current_map"]["just_name"] - ) + map_name: str = server_info["current_map"]["name"] + + try: + base_map_name, _ = map_name.split("_", maxsplit=1) + except ValueError: + base_map_name = map_name + + if "night" in map_name.lower(): + base_map_name = base_map_name + "_night" + + + img = map_to_pict.get(base_map_name, UNKNOWN_MAP_NAME) url = urljoin(SCOREBOARD_BASE_PATH, img) return url diff --git a/rcon/utils.py b/rcon/utils.py index df9018f80..7bc8e413a 100644 --- a/rcon/utils.py +++ b/rcon/utils.py @@ -12,6 +12,8 @@ logger = logging.getLogger("rcon") +UNKNOWN_MAP_NAME = 'unknown' + ALL_MAPS = ( "carentan_offensive_ger", "carentan_offensive_us", @@ -289,7 +291,7 @@ def get_map_side(map_): "stmereeglise_warfare": "SME", "utahbeach_offensive_ger": "Utah Off. (GER)", "utahbeach_offensive_us": "Utah Off. (US)", - "utahbeach_warfare_night" : "Utah (Night)", + "utahbeach_warfare_night": "Utah (Night)", "utahbeach_warfare": "Utah", } diff --git a/rcongui/public/maps/carentan-night.webp b/rcongui/public/maps/carentan-night.webp new file mode 100644 index 000000000..666977f91 Binary files /dev/null and b/rcongui/public/maps/carentan-night.webp differ diff --git a/rcongui/public/maps/driel.webp b/rcongui/public/maps/driel.webp index e033b6d79..b066bb236 100644 Binary files a/rcongui/public/maps/driel.webp and b/rcongui/public/maps/driel.webp differ diff --git a/rcongui/public/maps/elalamein.webp b/rcongui/public/maps/elalamein.webp index b3ad966b3..2cc9a9b32 100644 Binary files a/rcongui/public/maps/elalamein.webp and b/rcongui/public/maps/elalamein.webp differ diff --git a/rcongui/public/maps/foy-night.webp b/rcongui/public/maps/foy-night.webp new file mode 100644 index 000000000..ea2ce1d2b Binary files /dev/null and b/rcongui/public/maps/foy-night.webp differ diff --git a/rcongui/public/maps/hill400-night.webp b/rcongui/public/maps/hill400-night.webp new file mode 100644 index 000000000..976a3f89b Binary files /dev/null and b/rcongui/public/maps/hill400-night.webp differ diff --git a/rcongui/public/maps/hurtgen-night.webp b/rcongui/public/maps/hurtgen-night.webp new file mode 100644 index 000000000..ded554360 Binary files /dev/null and b/rcongui/public/maps/hurtgen-night.webp differ diff --git a/rcongui/public/maps/kharkov.webp b/rcongui/public/maps/kharkov.webp index 2567e9221..d2e9f328d 100644 Binary files a/rcongui/public/maps/kharkov.webp and b/rcongui/public/maps/kharkov.webp differ diff --git a/rcongui/public/maps/kursk-night.webp b/rcongui/public/maps/kursk-night.webp new file mode 100644 index 000000000..ea40a73e1 Binary files /dev/null and b/rcongui/public/maps/kursk-night.webp differ diff --git a/rcongui/public/maps/kursk.webp b/rcongui/public/maps/kursk.webp old mode 100755 new mode 100644 index bd80aa34a..ba142d5bb Binary files a/rcongui/public/maps/kursk.webp and b/rcongui/public/maps/kursk.webp differ diff --git a/rcongui/public/maps/omaha-night.webp b/rcongui/public/maps/omaha-night.webp new file mode 100644 index 000000000..34c274544 Binary files /dev/null and b/rcongui/public/maps/omaha-night.webp differ diff --git a/rcongui/public/maps/phl-night.webp b/rcongui/public/maps/phl-night.webp new file mode 100644 index 000000000..6c460b3ab Binary files /dev/null and b/rcongui/public/maps/phl-night.webp differ diff --git a/rcongui/public/maps/remagen-night.webp b/rcongui/public/maps/remagen-night.webp new file mode 100644 index 000000000..31d125958 Binary files /dev/null and b/rcongui/public/maps/remagen-night.webp differ diff --git a/rcongui/public/maps/sme-night.webp b/rcongui/public/maps/sme-night.webp new file mode 100644 index 000000000..ff68c35a2 Binary files /dev/null and b/rcongui/public/maps/sme-night.webp differ diff --git a/rcongui/public/maps/unknown.webp b/rcongui/public/maps/unknown.webp new file mode 100644 index 000000000..0819e2b4e Binary files /dev/null and b/rcongui/public/maps/unknown.webp differ diff --git a/rcongui/public/maps/utah-night.webp b/rcongui/public/maps/utah-night.webp new file mode 100644 index 000000000..73dc41713 Binary files /dev/null and b/rcongui/public/maps/utah-night.webp differ diff --git a/rcongui/src/components/Embeds/ServerInfo.js b/rcongui/src/components/Embeds/ServerInfo.js index c034e8dec..f75fceb97 100644 --- a/rcongui/src/components/Embeds/ServerInfo.js +++ b/rcongui/src/components/Embeds/ServerInfo.js @@ -15,7 +15,7 @@ import { import { fade } from "@material-ui/core/styles/colorManipulator"; import { get, handle_http_errors, showResponse } from "../../utils/fetchUtils"; import { List as iList, Map, fromJS } from "immutable"; -import map_to_pict from "../Scoreboard/utils"; +import { getMapImageUrl } from "../Scoreboard/utils"; const useStyles = makeStyles((theme) => ({ padRight: { @@ -72,6 +72,7 @@ const ServerInfo = ({ classes }) => { const [serverState, setServerState] = React.useState(new Map()); const [isLoading, setIsLoading] = React.useState(true); const isXs = useMediaQuery(theme.breakpoints.down("sm")); + const [mapName, setMapName] = React.useState("") const getData = () => { setIsLoading(true); @@ -90,11 +91,17 @@ const ServerInfo = ({ classes }) => { return () => clearInterval(interval); }, []); + React.useEffect(() => { + if (serverState.get('current_map') !== undefined) { + setMapName(serverState.get('current_map').get('name')) + } + }, [serverState]) + let started = serverState.get("current_map", new Map()).get("start"); started = started ? new Date(Date.now() - new Date(started * 1000)) - .toISOString() - .substr(11, 8) + .toISOString() + .substr(11, 8) : "N/A"; const nextMapString = React.useMemo(() => { @@ -116,11 +123,7 @@ const ServerInfo = ({ classes }) => { Map {serverList.map((s) => { - let link = `${window.location.protocol}//${ - window.location.hostname - }:${s.get("port")}${window.location.pathname}${ - window.location.hash - }`; - if (s.get("link")) { - link = `${s.get("link")}${window.location.pathname}${ - window.location.hash + let link = `${window.location.protocol}//${window.location.hostname + }:${s.get("port")}${window.location.pathname}${window.location.hash }`; + if (s.get("link")) { + link = `${s.get("link")}${window.location.pathname}${window.location.hash + }`; } return ( @@ -146,11 +143,11 @@ class ServerStatus extends React.Component { .then((response) => showResponse(response, "get_status", false)) .then((data) => { this.setState({ - name: data.result.name, - map: data.result.map, + name: data?.result.name, + map: data?.result.map, nbPlayers: data.result.nb_players, }); - document.title = `(${data.result.player_count}) ${data.result.short_name}`; + document.title = `(${data?.result.player_count}) ${data?.result.short_name}`; }) .catch(handle_http_errors); } diff --git a/rcongui/src/components/MapManager/DraggableListItem.js b/rcongui/src/components/MapManager/DraggableListItem.js index 8fefc05e3..6cf8943bf 100644 --- a/rcongui/src/components/MapManager/DraggableListItem.js +++ b/rcongui/src/components/MapManager/DraggableListItem.js @@ -13,7 +13,7 @@ import { } from "@material-ui/core"; import Avatar from "@material-ui/core/Avatar"; import DeleteIcon from "@material-ui/icons/Delete"; -import map_to_pict from "../Scoreboard/utils"; +import { getMapName, getMapImageUrl } from "../Scoreboard/utils"; const useStyles = makeStyles({ draggingListItem: { @@ -25,13 +25,6 @@ const useStyles = makeStyles({ }); const DraggableListItem = ({ item, index, onRemove }) => { - const getMapName = (fullName) => { - const parts = fullName.split("_"); - if (parts && parts.length > 0) { - return parts[0]; - } - return "foy"; - }; const getLabels = (fullName) => { const labels = []; @@ -87,7 +80,7 @@ const DraggableListItem = ({ item, index, onRemove }) => { } > - + { setMapsPageSize(data.result.page_size); setMapsTotal(data.result.total); setMaps(fromJS(data.result.maps)); - if (data.result.maps && !slug) { + if (data.result.maps.length > 0 && !slug) { window.location.hash = `#/gamescoreboard/${data.result.maps[0].id}`; } }) @@ -186,8 +186,8 @@ const GamesScore = ({ classes }) => { let started = serverState.get("current_map", new Map()).get("start"); started = started ? new Date(Date.now() - new Date(started * 1000)) - .toISOString() - .substr(11, 8) + .toISOString() + .substr(11, 8) : "N/A"; return ( @@ -221,12 +221,12 @@ const GamesScore = ({ classes }) => { xl ? Math.min(maps.size, 8.5) : lg - ? Math.min(maps.size, 5.5) - : md - ? Math.min(maps.size, 3.5) - : sm - ? Math.min(maps.size, 2.5) - : Math.min(maps.size, 1.5) + ? Math.min(maps.size, 5.5) + : md + ? Math.min(maps.size, 3.5) + : sm + ? Math.min(maps.size, 2.5) + : Math.min(maps.size, 1.5) } className={styles.gridList} > @@ -243,7 +243,7 @@ const GamesScore = ({ classes }) => { onClick={() => doSelectMap(m.get("id"))} key={`${m.get("name")}${m.get("start")}${m.get("end")}`} > - Map + Map { let started = serverState.get("current_map", new Map()).get("start"); started = started ? new Date(Date.now() - new Date(started * 1000)) - .toISOString() - .substr(11, 8) + .toISOString() + .substr(11, 8) : "N/A"; return ( @@ -325,13 +325,7 @@ const LiveHeader = ({ Map { + if (mapName === undefined) { + return UNKNOWN_MAP_NAME; + } + + const parts = mapName.split("_"); + if (parts && parts.length > 0) { + if (parts.at(-1).toLowerCase() == "night") { + return parts[0] + "_night" + } else { + + + return parts[0]; + } + } + return UNKNOWN_MAP_NAME; }; -export default map_to_pict; +export const getMapImageUrl = (mapName) => { + console.log(`mapName=${mapName}`) + const imageName = map_to_pict.get(getMapName(mapName)) + + if (imageName === undefined) { + return map_to_pict.get(UNKNOWN_MAP_NAME) + } else { + return imageName + } +} \ No newline at end of file