Skip to content

Commit

Permalink
Add night map images, don't default recorded map names to Foy (#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
cemathey authored Nov 9, 2023
1 parent 917c230 commit 2410259
Show file tree
Hide file tree
Showing 24 changed files with 135 additions and 73 deletions.
9 changes: 6 additions & 3 deletions rcon/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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]
Expand All @@ -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",
Expand Down Expand Up @@ -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:
Expand Down
31 changes: 28 additions & 3 deletions rcon/scorebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion rcon/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

logger = logging.getLogger("rcon")

UNKNOWN_MAP_NAME = 'unknown'

ALL_MAPS = (
"carentan_offensive_ger",
"carentan_offensive_us",
Expand Down Expand Up @@ -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",
}

Expand Down
Binary file added rcongui/public/maps/carentan-night.webp
Binary file not shown.
Binary file modified rcongui/public/maps/driel.webp
Binary file not shown.
Binary file modified rcongui/public/maps/elalamein.webp
Binary file not shown.
Binary file added rcongui/public/maps/foy-night.webp
Binary file not shown.
Binary file added rcongui/public/maps/hill400-night.webp
Binary file not shown.
Binary file added rcongui/public/maps/hurtgen-night.webp
Binary file not shown.
Binary file modified rcongui/public/maps/kharkov.webp
Binary file not shown.
Binary file added rcongui/public/maps/kursk-night.webp
Binary file not shown.
Binary file modified rcongui/public/maps/kursk.webp
100755 → 100644
Binary file not shown.
Binary file added rcongui/public/maps/omaha-night.webp
Binary file not shown.
Binary file added rcongui/public/maps/phl-night.webp
Binary file not shown.
Binary file added rcongui/public/maps/remagen-night.webp
Binary file not shown.
Binary file added rcongui/public/maps/sme-night.webp
Binary file not shown.
Binary file added rcongui/public/maps/unknown.webp
Binary file not shown.
Binary file added rcongui/public/maps/utah-night.webp
Binary file not shown.
19 changes: 11 additions & 8 deletions rcongui/src/components/Embeds/ServerInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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);
Expand All @@ -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(() => {
Expand All @@ -116,11 +123,7 @@ const ServerInfo = ({ classes }) => {
<GridListTile>
<img
alt="Map"
src={
map_to_pict[
serverState.get("current_map", new Map()).get("just_name", "foy")
]
}
src={getMapImageUrl(mapName)}
/>
<GridListTileBar
className={styles.titleBarTop}
Expand Down
19 changes: 8 additions & 11 deletions rcongui/src/components/Header/serverStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,12 @@ const Status = ({
onClose={handleClose}
>
{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 (
<MenuItem onClick={handleClose}>
Expand Down Expand Up @@ -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);
}
Expand Down
11 changes: 2 additions & 9 deletions rcongui/src/components/MapManager/DraggableListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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 = [];
Expand Down Expand Up @@ -87,7 +80,7 @@ const DraggableListItem = ({ item, index, onRemove }) => {
}
>
<ListItemAvatar>
<Avatar src={map_to_pict[getMapName(item)]} />
<Avatar src={getMapImageUrl(item)} />
</ListItemAvatar>
<ListItemText
primary={
Expand Down
22 changes: 11 additions & 11 deletions rcongui/src/components/Scoreboard/GamesScore.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { List as iList, Map, fromJS, List } from "immutable";
import moment from "moment";
import { useTheme } from "@material-ui/core/styles";
import Scores from "./Scores";
import map_to_pict from "./utils";
import { getMapImageUrl } from "./utils";
import { fade } from "@material-ui/core/styles/colorManipulator";
import { CopyToClipboard } from "react-copy-to-clipboard";
import { useParams } from "react-router-dom";
Expand Down Expand Up @@ -155,7 +155,7 @@ const GamesScore = ({ classes }) => {
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}`;
}
})
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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}
>
Expand All @@ -243,7 +243,7 @@ const GamesScore = ({ classes }) => {
onClick={() => doSelectMap(m.get("id"))}
key={`${m.get("name")}${m.get("start")}${m.get("end")}`}
>
<img alt="Map" src={map_to_pict[m.get("just_name")]} />
<img alt="Map" src={getMapImageUrl(m.get('map_name'))} />

<GridListTileBar
className={isSelected(
Expand Down
14 changes: 4 additions & 10 deletions rcongui/src/components/Scoreboard/LiveScore.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import moment from "moment";
import useMediaQuery from "@material-ui/core/useMediaQuery";
import { useTheme } from "@material-ui/core/styles";
import Scores from "./Scores";
import map_to_pict from "./utils";
import { getMapImageUrl } from "./utils";
import { fade } from "@material-ui/core/styles/colorManipulator";
import { Link as RouterLink } from "react-router-dom";

Expand Down Expand Up @@ -176,8 +176,8 @@ const LiveScore = ({ classes, endpoint, explainText, title }) => {
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 (
Expand Down Expand Up @@ -325,13 +325,7 @@ const LiveHeader = ({
<GridListTile>
<img
alt="Map"
src={
map_to_pict[
serverState
.get("current_map", new Map())
.get("just_name", "foy")
]
}
src={getMapImageUrl(serverState.get('name'))}
/>
<GridListTileBar
className={styles.titleBarTop}
Expand Down
Loading

0 comments on commit 2410259

Please sign in to comment.