diff --git a/components/Map.js b/components/Map.js index ea9d205..c662166 100644 --- a/components/Map.js +++ b/components/Map.js @@ -4,6 +4,7 @@ import { Circle, Marker, Polyline, Popup, Tooltip, useMapEvents } from "react-le import { useTranslation } from '@/components/useTranslations'; import 'leaflet/dist/leaflet.css'; import customPins from '../public/customPins.json' with { type: "module" }; +import guestNameString from "@/serverUtils/guestNameFromString"; const hintMul = 5000000 / 20000; //5000000 for all countries (20,000 km) // Dynamic import of react-leaflet components @@ -59,6 +60,8 @@ function MapPlugin({ pinPoint, setPinPoint, answerShown, dest, gameOptions, ws, if (!map || answerShown) return; setTimeout(() => { + try { + if (extent) { const bounds = L.latLngBounds([extent[1], extent[0]], [extent[3], extent[2]]); map.fitBounds(bounds); @@ -66,6 +69,7 @@ function MapPlugin({ pinPoint, setPinPoint, answerShown, dest, gameOptions, ws, // reset to default map.setView([30, 0], 2); } + }catch(e) {} }, 500); }, [gameOptions?.extent ? JSON.stringify(gameOptions.extent) : null, map, answerShown]); @@ -179,7 +183,7 @@ const MapComponent = ({ shown, options, ws, session, pinPoint, setPinPoint, answ if(!player.guess) return null; - const name = player.username; + const name = process.env.NEXT_PUBLIC_COOLMATH?guestNameString(player.username):player.username; const latLong = [player.guess[0], player.guess[1]]; const tIcon = customPins[name]==="polandball" ? polandballIcon : src2Icon; diff --git a/components/gameUI.js b/components/gameUI.js index 837e749..0322417 100644 --- a/components/gameUI.js +++ b/components/gameUI.js @@ -76,7 +76,7 @@ export default function GameUI({ inCoolMathGames, miniMapShown, setMiniMapShown, round: prev.round + 1 } }) - } else { + } else if(setSinglePlayerRound) { // reset to default setSinglePlayerRound({ round: 1, @@ -96,7 +96,7 @@ export default function GameUI({ inCoolMathGames, miniMapShown, setMiniMapShown, const loadTime = window.gameOpen; const lastDiscordShown = gameStorage.getItem("shownDiscordModal"); if(lastDiscordShown) return console.log("Discord modal already shown"); - if(Date.now() - loadTime > 600000) { + if(Date.now() - loadTime > 600000 && !process.env.NEXT_PUBLIC_COOLMATH) { setShowDiscordModal(true) sendEvent('discord_modal_shown') } else console.log("Not showing discord modal, waiting for "+(600000 - (Date.now() - loadTime))+"ms") @@ -454,14 +454,14 @@ export default function GameUI({ inCoolMathGames, miniMapShown, setMiniMapShown, return (
-{ !onboarding && !inCrazyGames && !inCoolMathGames && (!session?.token?.supporter) && ( +{ !onboarding && !inCrazyGames && !inCoolMathGames && (!session?.token?.supporter) && (width >700) && (
- +
)} -{ multiplayerState?.gameData?.public && ( +{ multiplayerState?.gameData?.duel && (
{ } }} /> )} - + {/* Round #{multiplayerState?.gameData?.curRound} / {multiplayerState?.gameData?.rounds} - {timeToNextMultiplayerEvt}s */} {text("roundTimer", {r:multiplayerState?.gameData?.curRound, mr: multiplayerState?.gameData?.rounds, t: timeToNextMultiplayerEvt})} @@ -651,21 +651,17 @@ button1Press={() =>{ ) } - {multiplayerState && multiplayerState.inGame && !multiplayerState?.gameData?.public && multiplayerState?.gameData?.state === 'getready' && multiplayerState?.gameData?.curRound === 1 && ( + {multiplayerState && multiplayerState.inGame && !multiplayerState?.gameData?.duel && multiplayerState?.gameData?.state === 'getready' && multiplayerState?.gameData?.curRound === 1 && ( )} - {multiplayerState && multiplayerState.inGame && !multiplayerState?.gameData?.public && ((multiplayerState?.gameData?.state === 'getready' && timeToNextMultiplayerEvt < 5 && multiplayerState?.gameData?.curRound !== 1 && multiplayerState?.gameData?.curRound <= multiplayerState?.gameData?.rounds)||(multiplayerState?.gameData?.state === "end")) && ( + {multiplayerState && multiplayerState.inGame && !multiplayerState?.gameData?.duel && ((multiplayerState?.gameData?.state === 'getready' && timeToNextMultiplayerEvt < 5 && multiplayerState?.gameData?.curRound !== 1 && multiplayerState?.gameData?.curRound <= multiplayerState?.gameData?.rounds)||(multiplayerState?.gameData?.state === "end")) && ( { - - - backBtnPressed(true) - + backBtnPressed(true, "unranked") }} backBtn={() => { - backBtnPressed() }} /> )} diff --git a/components/home.js b/components/home.js index bd29cf5..f55dbed 100644 --- a/components/home.js +++ b/components/home.js @@ -62,6 +62,7 @@ const initialMultiplayerState = { inGame: false, nextGameQueued: false, enteringGameCode: false, + nextGameType: null, createOptions: { rounds: 5, timePerRound: 30, @@ -183,7 +184,7 @@ statsRef.current = stats; }, onNonOAuthError: error => { console.log("login non oauth error", error); - toast.error("Login error, contact support if this persists (1)\n\nMake sure popups are enabled (needed for google window)") + toast.error("Login error, contact support if this persists (1)") }, flow: "auth-code", @@ -319,7 +320,11 @@ statsRef.current = stats; console.log("crazygames user not logged in") // user not logged in // verify with not_logged_in - window.verifyPayload = JSON.stringify({ type: "verify", secret: "not_logged_in", username: "not_logged_in" }); + let rc = gameStorage.getItem("rejoinCode"); + + window.verifyPayload = JSON.stringify({ type: "verify", secret: "not_logged_in", username: "not_logged_in", + rejoinCode: rc + }); setWs((prev) => { if(prev) { prev.send(window.verifyPayload) @@ -827,8 +832,14 @@ setShowCountryButtons(false) }, [multiplayerState?.joinOptions?.error]); + useEffect(() => { + if(multiplayerState?.connected && multiplayerError) { + setMultiplayerError(null) + } + }, [multiplayerState?.connected, multiplayerError]) function handleMultiplayerAction(action, ...args) { + console.log(action) if (!ws || !multiplayerState.connected || multiplayerState.gameQueued || multiplayerState.connecting) return; if (action === "publicDuel") { @@ -836,12 +847,26 @@ setShowCountryButtons(false) setMultiplayerState((prev) => ({ ...prev, gameQueued: "publicDuel", + nextGameType: undefined, nextGameQueued: false })) - sendEvent("multiplayer_request_duel") + sendEvent("multiplayer_request_ranked_duel") ws.send(JSON.stringify({ type: "publicDuel" })) } + if (action === "unrankedDuel") { + setScreen("multiplayer") + setMultiplayerState((prev) => ({ + ...prev, + gameQueued: "unrankedDuel", + nextGameType: undefined, + nextGameQueued: false, + publicDuelRange: null + })) + sendEvent("multiplayer_request_unranked_duel") + ws.send(JSON.stringify({ type: "unrankedDuel" })) + } + if (action === "joinPrivateGame") { if (args[0]) { @@ -947,7 +972,7 @@ setShowCountryButtons(false) connecting: true, shouldConnect: false })) - const ws = await initWebsocket(clientConfig().websocketUrl, null, 5000, 20) + const ws = await initWebsocket(clientConfig().websocketUrl, null, 5000, 50) if(ws && ws.readyState === 1) { setWs(ws) setMultiplayerState((prev)=>({ @@ -976,7 +1001,7 @@ setShowCountryButtons(false) if(secret !== "not_logged_in") { window.verified = true; } - ws.send(JSON.stringify({ type: "verify", secret, tz})) + ws.send(JSON.stringify({ type: "verify", secret, tz, rejoinCode: gameStorage.getItem("rejoinCode") })) } else if(window.verifyPayload) { console.log("sending verify from verifyPayload") ws.send(window.verifyPayload) @@ -1087,7 +1112,7 @@ setShowCountryButtons(false) useEffect(() => { - if (!multiplayerState?.inGame && multiplayerState?.gameData?.public) { + if (!multiplayerState?.inGame && multiplayerState?.gameData?.duel) { setMultiplayerChatEnabled(false) setMultiplayerChatOpen(false) @@ -1135,7 +1160,12 @@ setShowCountryButtons(false) connected: true, connecting: false, guestName: data.guestName - })) + })) + + if(data.rejoinCode) { + gameStorage.setItem("rejoinCode", data.rejoinCode) + } + } else if (data.type === "error") { setMultiplayerState((prev) => ({ ...prev, @@ -1163,7 +1193,7 @@ setShowCountryButtons(false) setScreen("multiplayer") setMultiplayerState((prev) => { - if(!data.public) { + if(!data.duel) { setMultiplayerChatEnabled(true) } @@ -1175,6 +1205,7 @@ setShowCountryButtons(false) } } catch(e) {} + // console.log('got game options', data) setGameOptions((prev) => ({ ...prev, nm: data.nm, @@ -1212,7 +1243,7 @@ setShowCountryButtons(false) if (didIguess) { setMultiplayerChatEnabled(true) } else { - if(multiplayerState?.gameData?.public) setMultiplayerChatEnabled(false) + // if(multiplayerState?.gameData?.public) setMultiplayerChatEnabled(false) } } @@ -1317,6 +1348,7 @@ setShowCountryButtons(false) ...initialMultiplayerState, connected: true, nextGameQueued: prev.nextGameQueued, + nextGameType: prev.nextGameType, playerCount: prev.playerCount, guestName: prev.guestName } @@ -1421,8 +1453,14 @@ setShowCountryButtons(false) setMultiplayerState((prev) => ({ ...initialMultiplayerState, })); - if(window.screen !== "home") + if(window.screen !== "home" && window.screen !== "singleplayer" && window.screen !== "onboarding") { setMultiplayerError(true) + setLoading(false) + + toast.info(text("connectionLostRecov")) + + setScreen("home") + } } @@ -1435,8 +1473,14 @@ setShowCountryButtons(false) setMultiplayerState((prev) => ({ ...initialMultiplayerState, })); - if(window.screen !== "home") + + if(window.screen !== "home" && window.screen !== "singleplayer" && window.screen !== "onboarding") { setMultiplayerError(true) + + toast.info(text("connectionLostRecov")) + setScreen("home") + } + } @@ -1451,7 +1495,12 @@ setShowCountryButtons(false) useEffect(() => { if (multiplayerState?.connected && !multiplayerState?.inGame && multiplayerState?.nextGameQueued) { - handleMultiplayerAction("publicDuel"); + // handleMultiplayerAction("publicDuel"); + if(multiplayerState?.nextGameType === "ranked") { + handleMultiplayerAction("publicDuel") + } else if(multiplayerState?.nextGameType === "unranked") { + handleMultiplayerAction("unrankedDuel") + } } }, [multiplayerState, timeOffset]) @@ -1553,9 +1602,7 @@ setShowCountryButtons(false) window.crazyMidgame = crazyMidgame; }, []); - function backBtnPressed(queueNextGame = false) { - - + function backBtnPressed(queueNextGame = false, nextGameType) { if (loading) setLoading(false); if(multiplayerError) setMultiplayerError(false) @@ -1591,10 +1638,12 @@ setShowCountryButtons(false) } catch(e) {} } + setMultiplayerState((prev) => { return { ...prev, - nextGameQueued: queueNextGame === true + nextGameQueued: queueNextGame === true, + nextGameType } }) setScreen("home") @@ -1676,10 +1725,11 @@ setShowCountryButtons(false) } function fetchMethod() { //gameOptions.countryMap && gameOptions.offical - console.log("fetching") - fetch(window.cConfig.apiUrl+((gameOptions.location==="all")?`/${window?.learnMode ? 'clue': 'all'}Countries.json`: + const url = window.cConfig.apiUrl+((gameOptions.location==="all")?`/${window?.learnMode ? 'clue': 'all'}Countries.json`: gameOptions.countryMap && gameOptions.official ? `/countryLocations/${gameOptions.countryMap}` : - `/mapLocations/${gameOptions.location}`)).then((res) => res.json()).then((data) => { + `/mapLocations/${gameOptions.location}`); + console.log("fetching", url) + fetch(url).then((res) => res.json()).then((data) => { if(data.ready) { // this uses long for lng for(let i = 0; i < data.locations.length; i++) { @@ -1689,12 +1739,17 @@ setShowCountryButtons(false) } } + // shuffle data.locations + data.locations = data.locations.sort(() => Math.random() - 0.5) + + console.log("got locations", data.locations) + setAllLocsArray(data.locations) if(gameOptions.location === "all") { const loc = data.locations[0] setLatLong(loc) - + console.log("setting latlong", loc) } else { let loc = data.locations[Math.floor(Math.random() * data.locations.length)]; @@ -1783,7 +1838,7 @@ setShowCountryButtons(false) } const ChatboxMemo = React.useMemo(() => setMultiplayerChatOpen(!multiplayerChatOpen)} enabled={ - session?.token?.secret && multiplayerChatEnabled + session?.token?.secret && multiplayerChatEnabled && !process.env.NEXT_PUBLIC_COOLMATH } isGuest={session?.token?.secret ? false : true} publicGame={multiplayerState?.gameData?.public} @@ -1858,7 +1913,7 @@ setShowCountryButtons(false) {/* setMerchModal(false)} session={session} /> */} setLeagueModal(false)} session={session} eloData={eloData} /> {ChatboxMemo} - +
@@ -1978,10 +2033,10 @@ setShowCountryButtons(false) enteringGameCode: true }))}} - inCoolMathGames={inCoolMathGames} maintenance={maintenance} inCrazyGames={inCrazyGames} loading={loading} onFriendsPress={()=>setFriendsModal(true)} loginQueued={loginQueued} setLoginQueued={setLoginQueued} inGame={multiplayerState?.inGame || screen === "singleplayer"} openAccountModal={() => setAccountModalOpen(true)} session={session} reloadBtnPressed={reloadBtnPressed} backBtnPressed={backBtnPressed} setGameOptionsModalShown={setGameOptionsModalShown} onNavbarPress={() => onNavbarLogoPress()} gameOptions={gameOptions} screen={screen} multiplayerState={multiplayerState} shown={!multiplayerState?.gameData?.public && !leagueModal} /> + inCoolMathGames={inCoolMathGames} maintenance={maintenance} inCrazyGames={inCrazyGames} loading={loading} onFriendsPress={()=>setFriendsModal(true)} loginQueued={loginQueued} setLoginQueued={setLoginQueued} inGame={multiplayerState?.inGame || screen === "singleplayer"} openAccountModal={() => setAccountModalOpen(true)} session={session} reloadBtnPressed={reloadBtnPressed} backBtnPressed={backBtnPressed} setGameOptionsModalShown={setGameOptionsModalShown} onNavbarPress={() => onNavbarLogoPress()} gameOptions={gameOptions} screen={screen} multiplayerState={multiplayerState} shown={!multiplayerState?.gameData?.duel && !leagueModal} /> {/* reload button for public game */} -{ multiplayerState?.gameData?.public && multiplayerState?.gameData?.state === "guess" && ( +{ multiplayerState?.gameData?.duel && multiplayerState?.gameData?.state === "guess" && (
@@ -2031,10 +2086,21 @@ setShowCountryButtons(false) }} >{text("singleplayer")} {/* {text("playOnline")} */} +
+ { session?.token?.secret && ( + disabled={!multiplayerState.connected || maintenance}>{text("rankedDuel")} + )} + +
{/* {text("playFriends")} */}
@@ -2052,7 +2118,8 @@ setShowCountryButtons(false) )} */} - + { !process.env.NEXT_PUBLIC_COOLMATH && + }
@@ -2144,16 +2211,12 @@ setShowCountryButtons(false)
{!map.countryMap && map.created_by_name && (
- by {highlightMatch(map.created_by_name, searchTerm)} + + +{!process.env.NEXT_PUBLIC_COOLMATH && ( + <> + {` by ${highlightMatch(map.created_by_name, searchTerm)}`} +  · + +)} + {map.accepted && ( -   · {formatNumber(map.locations, 3)} locations + {formatNumber(map.locations, 3)} locations )}
diff --git a/components/maps/mapView.js b/components/maps/mapView.js index c5da580..7d5a4b3 100644 --- a/components/maps/mapView.js +++ b/components/maps/mapView.js @@ -76,7 +76,7 @@ export default function MapView({ gameOptions, setGameOptions, showOptions, clos const handleSearch = useCallback( debounce((term) => { - if (term.length > 3) { + if (term.length > 3 && !process.env.NEXT_PUBLIC_COOLMATH) { fetch(window.cConfig.apiUrl+"/api/map/searchMap", { method: "POST", headers: { @@ -356,6 +356,7 @@ export default function MapView({ gameOptions, setGameOptions, showOptions, clos {hasResults ? ( Object.keys(mapHome) .filter((k) => k !== "message") + .filter((k) => !process.env.NEXT_PUBLIC_COOLMATH || k !== "recent") //coolmath doesnt want unmoderated maps .map((section, si) => { const mapsArray = section === "recent" && searchResults.length > 0 @@ -459,7 +460,13 @@ export default function MapView({ gameOptions, setGameOptions, showOptions, clos }) ) : ( // make sure not loading - !mapHome?.message && ( + (!mapHome?.message || + + (process.env.NEXT_PUBLIC_COOLMATH && + searchTerm.length > 0 && + (!hasResults || hasResults.filter((k) => k !== "recent").length === 0)) + ) && + (
{text("noResultsFound")}
) )} diff --git a/components/multiplayerHome.js b/components/multiplayerHome.js index 9571860..af7e2f3 100644 --- a/components/multiplayerHome.js +++ b/components/multiplayerHome.js @@ -31,6 +31,16 @@ export default function MultiplayerHome({ ws, setWs, multiplayerError, multiplay ) } + if(!((multiplayerState?.inGame) || (multiplayerState?.enteringGameCode) || + + (multiplayerState?.gameQueued) || (multiplayerState?.nextGameQueued))) { + return ( +
+ +
+ ) + } + return (
{/* */} @@ -51,7 +61,7 @@ export default function MultiplayerHome({ ws, setWs, multiplayerError, multiplay )} - diff --git a/components/playerList.js b/components/playerList.js index 181b6d2..3c744b5 100644 --- a/components/playerList.js +++ b/components/playerList.js @@ -1,4 +1,5 @@ import { useTranslation } from '@/components/useTranslations' +import guestNameString from '@/serverUtils/guestNameFromString'; import { useEffect } from 'react'; import { FaCopy } from 'react-icons/fa6'; import { toast } from 'react-toastify'; @@ -90,7 +91,9 @@ export default function PlayerList({ multiplayerState, playAgain, backBtn, start
- {player.username} + { + process.env.NEXT_PUBLIC_COOLMATH?guestNameString(player.username): + player.username} {player.supporter && {text("supporter")}} {player.host && ({text("host")})} @@ -98,7 +101,9 @@ export default function PlayerList({ multiplayerState, playAgain, backBtn, start ) : ( <> -
#{i + 1} - {player.username} +
#{i + 1} - { + process.env.NEXT_PUBLIC_COOLMATH?guestNameString(player.username): + player.username} {player.supporter && {text("supporter")}} diff --git a/components/roundOverScreen.js b/components/roundOverScreen.js index 19c9de6..6c91cbf 100644 --- a/components/roundOverScreen.js +++ b/components/roundOverScreen.js @@ -191,12 +191,17 @@ export default function RoundOverScreen({ {history && history.length > 0 && ( )}
diff --git a/components/streetview/svHandler.js b/components/streetview/svHandler.js index 02685a0..13442bd 100644 --- a/components/streetview/svHandler.js +++ b/components/streetview/svHandler.js @@ -2,7 +2,7 @@ import React, { useState, useEffect, useRef } from "react"; const SvEmbedIframe = (params) => { const iframeRef = useRef(null); - const [iframeSrc, setIframeSrc] = useState(`/svEmbed`); + const [iframeSrc, setIframeSrc] = useState(null); // Function to send updated params via postMessage to the iframe @@ -22,7 +22,7 @@ const SvEmbedIframe = (params) => { useEffect(() => { // reload iframe when lat or long changes - console.log("lat or long changed", params.lat, params.long); + // console.log("lat or long changed", params.lat, params.long); setIframeSrc(`/svEmbed?nm=${params.nm}&npz=${params.npz}&showRoadLabels=${params.showRoadLabels}&lat=${params.lat}&long=${params.long}&showAnswer=${params.showAnswer}&hidden=false`); }, [params?.lat, params?.long]); @@ -68,6 +68,10 @@ const SvEmbedIframe = (params) => { return null; } + if(!iframeSrc) { + return null; + } + return (