Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
codergautam committed Dec 16, 2024
2 parents 99f599a + e869f8e commit c5e7f09
Show file tree
Hide file tree
Showing 8 changed files with 236 additions and 45 deletions.
8 changes: 8 additions & 0 deletions api/map/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ async function validateMap(name, data, description_short, description_long, edit
description_short = description_short.trim();
description_long = description_long.trim();

// name cannot include crazygamesdue to a url detection bug
if(name.toLowerCase().includes('crazygames')) {
return 'Name cannot include "CrazyGames"';
}

// validate name
if(typeof name !== 'string' || name.length < mapConst.MIN_NAME_LENGTH || name.length > mapConst.MAX_NAME_LENGTH) {
// return res.status(400).json({ message: `Name must be between ${mapConst.MIN_NAME_LENGTH} and ${mapConst.MAX_NAME_LENGTH} characters` });
Expand Down Expand Up @@ -74,6 +79,9 @@ async function validateMap(name, data, description_short, description_long, edit
// return res.status(400).json({ message: 'Please choose a different name' });
return 'Please choose a different name';
}
if(slug.toLowerCase().includes('crazygames') ) {
return 'Name cannot include "CrazyGames"';
}

// validate data
const locationsData = parseMapData(data);
Expand Down
15 changes: 12 additions & 3 deletions components/gameUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import HealthBar from "./duelHealthbar";

const MapWidget = dynamic(() => import("../components/Map"), { ssr: false });

export default function GameUI({ miniMapShown, setMiniMapShown, singlePlayerRound, setSinglePlayerRound, showDiscordModal, setShowDiscordModal, inCrazyGames, showPanoOnResult, setShowPanoOnResult, countryGuesserCorrect, setCountryGuesserCorrect, otherOptions, onboarding, setOnboarding, countryGuesser, options, timeOffset, ws, multiplayerState, backBtnPressed, setMultiplayerState, countryStreak, setCountryStreak, loading, setLoading, session, gameOptionsModalShown, setGameOptionsModalShown, latLong, streetViewShown, setStreetViewShown, loadLocation, gameOptions, setGameOptions, showAnswer, setShowAnswer, pinPoint, setPinPoint, hintShown, setHintShown, xpEarned, setXpEarned, showCountryButtons, setShowCountryButtons }) {
export default function GameUI({ inCoolMathGames, miniMapShown, setMiniMapShown, singlePlayerRound, setSinglePlayerRound, showDiscordModal, setShowDiscordModal, inCrazyGames, showPanoOnResult, setShowPanoOnResult, countryGuesserCorrect, setCountryGuesserCorrect, otherOptions, onboarding, setOnboarding, countryGuesser, options, timeOffset, ws, multiplayerState, backBtnPressed, setMultiplayerState, countryStreak, setCountryStreak, loading, setLoading, session, gameOptionsModalShown, setGameOptionsModalShown, latLong, streetViewShown, setStreetViewShown, loadLocation, gameOptions, setGameOptions, showAnswer, setShowAnswer, pinPoint, setPinPoint, hintShown, setHintShown, xpEarned, setXpEarned, showCountryButtons, setShowCountryButtons }) {
const { t: text } = useTranslation("common");
const [showStreakAdBanner, setShowStreakAdBanner] = useState(false);

Expand Down Expand Up @@ -101,6 +101,15 @@ export default function GameUI({ miniMapShown, setMiniMapShown, singlePlayerRoun
sendEvent('discord_modal_shown')
} else console.log("Not showing discord modal, waiting for "+(600000 - (Date.now() - loadTime))+"ms")
}
if(process.env.NEXT_PUBLIC_COOLMATH === "true") {
try {
console.log("Sending start event to CoolMathGames")
window.parent.postMessage({'cm_game_event': true, 'cm_game_evt' : 'start', 'cm_game_lvl':
"singleplayer"}, '*');
}catch(e) {
console.log("Failed sending start event to CoolMathGames", e)
}
}
// this is now disabled due to issues with afterAd() not being called / next round button not working
if(false && window.show_videoad && !session?.token?.supporter) {
window.show_videoad((state) =>{
Expand Down Expand Up @@ -382,7 +391,7 @@ export default function GameUI({ miniMapShown, setMiniMapShown, singlePlayerRoun
setLostCountryStreak(countryStreak);

// remove rewarded ads temporarily
if(countryStreak > 0 && window.adBreak && !inCrazyGames) {
if(countryStreak > 0 && window.adBreak && !inCrazyGames && !inCoolMathGames) {
console.log("requesting reward ad")
window.adBreak({
type: 'reward', // rewarded ad
Expand Down Expand Up @@ -445,7 +454,7 @@ export default function GameUI({ miniMapShown, setMiniMapShown, singlePlayerRoun
return (
<div className="gameUI">

{ !onboarding && !inCrazyGames && (!session?.token?.supporter) && (
{ !onboarding && !inCrazyGames && !inCoolMathGames && (!session?.token?.supporter) && (
<div className={`topAdFixed ${(multiplayerTimerShown || onboardingTimerShown || singlePlayerRound)?'moreDown':''}`}>
<Ad inCrazyGames={inCrazyGames} showAdvertisementText={false} screenH={height} types={[[728,90]]} centerOnOverflow={600} screenW={Math.max(400, width-450)} vertThresh={0.3} />
</div>
Expand Down
34 changes: 30 additions & 4 deletions components/headContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import Head from "next/head";
import Script from "next/script";
import { useEffect } from "react";

export default function HeadContent({text}) {
export default function HeadContent({text,inCoolMathGames}) {
useEffect(() => {
if (!window.location.search.includes("crazygames") && !process.env.NEXT_PUBLIC_POKI) {
if (!window.location.search.includes("crazygames") && !process.env.NEXT_PUBLIC_POKI &&
!process.env.NEXT_PUBLIC_COOLMATH) {
const script = document.createElement('script');
script.src = "https://api.adinplay.com/libs/aiptag/pub/SWT/worldguessr.com/tag.min.js";
script.async = true;
Expand Down Expand Up @@ -38,7 +39,31 @@ export default function HeadContent({text}) {
return () => {
document.body.removeChild(script);
}
} else if(process.env.NEXT_PUBLIC_POKI === "true") {
} else if(process.env.NEXT_PUBLIC_COOLMATH === "true") {
/*<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>
<script type="text/ja
vascript"
src="https://www.coolmathgames.com/sites/default/files/cmg
-
ads.js"></script>*/

const script = document.createElement('script');
script.src = "https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js";
script.async = false;
document.body.appendChild(script);

const script2 = document.createElement('script');
script2.src = "https://www.coolmathgames.com/sites/default/files/cmg-ads.js";
script2.async = false;
document.body.appendChild(script2);

return () => {
document.body.removeChild(script);
document.body.removeChild(script2);
}

}else if(process.env.NEXT_PUBLIC_POKI === "true") {
//
const script = document.createElement('script');
script.src = "https://game-cdn.poki.com/scripts/v2/poki-sdk.js";
Expand All @@ -57,7 +82,8 @@ export default function HeadContent({text}) {
return (
<Head>
<title>
{text("tabTitle")}
{ inCoolMathGames ? "WorldGuessr - Play it now at CoolmathGames.com" :
text("tabTitle") }
</title>
<meta property="og:title" content={text("fullTitle")}/>

Expand Down
114 changes: 107 additions & 7 deletions components/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,41 @@ statsRef.current = stats;
const [showDiscordModal, setShowDiscordModal] = useState(false);
const [singlePlayerRound, setSinglePlayerRound] = useState(null);
const [partyModalShown, setPartyModalShown] = useState(false);

const [inCoolMathGames, setInCoolMathGames] = useState(false);
const [coolmathSplash, setCoolmathSplash] = useState(null);

// check if ?coolmath=true
useEffect(() => {
if(process.env.NEXT_PUBLIC_COOLMATH === "true") {
setInCoolMathGames(true);
window.lastCoolmathAd =Date.now();

setCoolmathSplash(0);
let interval = setInterval(() => {
setCoolmathSplash((prev) => {
if(prev >= 1) {
clearInterval(interval);
interval = setInterval(() => {
setCoolmathSplash((prev) => {
if(prev <= 0) {
clearInterval(interval);
return null;
}
return prev - 0.1
})
}, 100)
}
return prev + 0.1
})
}, 100)

return () => {
clearInterval(interval);
}
}
}, [])

useEffect(() => {
if(screen === "singleplayer") {
// start the single player game
Expand Down Expand Up @@ -1022,7 +1057,7 @@ setShowCountryButtons(false)
}, 1000)
} else {
// create Party
handleMultiplayerAction("createPrivateGame")
// handleMultiplayerAction("createPrivateGame")
}

}
Expand Down Expand Up @@ -1485,7 +1520,29 @@ setShowCountryButtons(false)
adStarted: () => console.log("Start midgame ad"),
};
window.CrazyGames.SDK.ad.requestAd("midgame", callbacks);
} catch(e) {}
} catch(e) {
console.log("error requesting midgame ad", e)
adFinished()
}
} else if(process.env.NEXT_PUBLIC_COOLMATH === "true" && Date.now() - window.lastCoolmathAd > 120000) {
try {
window.lastCoolmathAd = Date.now();
function onEnd() {
adFinished()
console.log("End midgame ad")
document.removeEventListener("adBreakComplete", onEnd);
}
function onStart() {
console.log("Start midgame ad")
document.removeEventListener("adBreakStart", onStart);
}
window.cmgAdBreak();
document.addEventListener("adBreakStart", onStart);
document.addEventListener("adBreakComplete", onEnd);
} catch(e) {
console.log("error requesting midgame ad", e)
adFinished()
}
} else {
adFinished()
}
Expand Down Expand Up @@ -1792,7 +1849,7 @@ setShowCountryButtons(false)

return (
<>
<HeadContent text={text}/>
<HeadContent text={text} inCoolMathGames={inCoolMathGames} inCrazyGames={inCrazyGames} />

<AccountModal inCrazyGames={inCrazyGames} shown={accountModalOpen} session={session} setAccountModalOpen={setAccountModalOpen} />
<SetUsernameModal shown={session && session?.token?.secret && !session.token.username} session={session} />
Expand All @@ -1812,10 +1869,35 @@ setShowCountryButtons(false)
</div>
</div>

{ typeof coolmathSplash === "number" && (
// black background
<div style={{
position: 'fixed',
top: 0,
left: 0,
width: '100vw',
height: '100vh',
backgroundColor: 'rgb(36,36,36)',
zIndex: 100090,
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
color: 'white',
fontSize: '2em'
}}>
<div>
{/* image /coolmath-splash.png */}
<NextImage.default src={'/coolmath-splash.png'} draggable={false} fill alt="Coolmath Splash" style={{objectFit: "contain",userSelect:'none', opacity: coolmathSplash}} />

</div>
</div>

)}

{screen === "home" && !mapModal && !merchModal && !friendsModal && !accountModalOpen && !leagueModal && (
<div className="home__footer">
<div className="footer_btns">
{ !isApp && (
{ !isApp && !inCoolMathGames && (
<>
<Link target="_blank" href={"https://discord.gg/ubdJHjKtrC"}><button className="home__squarebtn gameBtn discord" aria-label="Discord"><FaDiscord className="home__squarebtnicon" /></button></Link>

Expand Down Expand Up @@ -1869,7 +1951,9 @@ setShowCountryButtons(false)
showRoadLabels={gameOptions?.showRoadName}
loading={loading}
setLoading={setLoading}
hidden={(!latLong || !latLong.lat || !latLong.long)|| loading}
hidden={((!latLong || !latLong.lat || !latLong.long)|| loading)||(
screen==="home"||(screen==="multiplayer" && (multiplayerState?.gameData?.state === "waiting"||multiplayerState?.enteringGameCode))
)}
onLoad={() => {
console.log("loaded")
setTimeout(() => {
Expand All @@ -1883,7 +1967,18 @@ setShowCountryButtons(false)



<Navbar 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} />
<Navbar
joinCodePress={() => {
setOnboarding(null)
setOnboardingCompleted(true)
gameStorage.setItem("onboarding", 'done')
setScreen("multiplayer")
setMultiplayerState((prev) => ({
...prev,
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} />
{/* ELO/League button */}
{screen === "home" && !mapModal && session && session?.token?.secret && (
<button className="gameBtn leagueBtn" onClick={()=>{setLeagueModal(true)}} style={{backgroundColor: eloData?.league?.color }}>
Expand Down Expand Up @@ -1957,7 +2052,7 @@ setShowCountryButtons(false)

<div style={{ marginTop: "20px" }}>
<center>
{ !loading && screen === "home" && !inCrazyGames &&(!session?.token?.supporter) && (
{ !loading && screen === "home" && !inCrazyGames && !inCoolMathGames &&(!session?.token?.supporter) && (
<Ad inCrazyGames={inCrazyGames} screenH={height} types={[[320,50],[728,90],[970,90],[970,250]]} screenW={width} />
)}
</center>
Expand Down Expand Up @@ -1990,12 +2085,15 @@ setShowCountryButtons(false)

{screen === "singleplayer" && <div className="home__singleplayer">
<GameUI
inCoolMathGames={inCoolMathGames}
miniMapShown={miniMapShown} setMiniMapShown={setMiniMapShown}
singlePlayerRound={singlePlayerRound} setSinglePlayerRound={setSinglePlayerRound} showDiscordModal={showDiscordModal} setShowDiscordModal={setShowDiscordModal} inCrazyGames={inCrazyGames} showPanoOnResult={showPanoOnResult} setShowPanoOnResult={setShowPanoOnResult} options={options} countryStreak={countryStreak} setCountryStreak={setCountryStreak} xpEarned={xpEarned} setXpEarned={setXpEarned} hintShown={hintShown} setHintShown={setHintShown} pinPoint={pinPoint} setPinPoint={setPinPoint} showAnswer={showAnswer} setShowAnswer={setShowAnswer} loading={loading} setLoading={setLoading} session={session} gameOptionsModalShown={gameOptionsModalShown} setGameOptionsModalShown={setGameOptionsModalShown} latLong={latLong} streetViewShown={streetViewShown} setStreetViewShown={setStreetViewShown} loadLocation={loadLocation} gameOptions={gameOptions} setGameOptions={setGameOptions} />
</div>}

{screen === "onboarding" && onboarding?.round && <div className="home__onboarding">
<GameUI
inCoolMathGames={inCoolMathGames}

miniMapShown={miniMapShown} setMiniMapShown={setMiniMapShown}
inCrazyGames={inCrazyGames} showPanoOnResult={showPanoOnResult} setShowPanoOnResult={setShowPanoOnResult} countryGuesserCorrect={countryGuesserCorrect} setCountryGuesserCorrect={setCountryGuesserCorrect} showCountryButtons={showCountryButtons} setShowCountryButtons={setShowCountryButtons} otherOptions={otherOptions} onboarding={onboarding} countryGuesser={false} setOnboarding={setOnboarding} options={options} countryStreak={countryStreak} setCountryStreak={setCountryStreak} xpEarned={xpEarned} setXpEarned={setXpEarned} hintShown={hintShown} setHintShown={setHintShown} pinPoint={pinPoint} setPinPoint={setPinPoint} showAnswer={showAnswer} setShowAnswer={setShowAnswer} loading={loading} setLoading={setLoading} session={session} gameOptionsModalShown={gameOptionsModalShown} setGameOptionsModalShown={setGameOptionsModalShown} latLong={latLong} streetViewShown={streetViewShown} setStreetViewShown={setStreetViewShown} loadLocation={loadLocation} gameOptions={gameOptions} setGameOptions={setGameOptions} />
</div>}
Expand Down Expand Up @@ -2057,6 +2155,8 @@ setShowCountryButtons(false)

{multiplayerState.inGame && ["guess", "getready", "end"].includes(multiplayerState.gameData?.state) && (
<GameUI
inCoolMathGames={inCoolMathGames}

miniMapShown={miniMapShown} setMiniMapShown={setMiniMapShown}
inCrazyGames={inCrazyGames} showPanoOnResult={showPanoOnResult} setShowPanoOnResult={setShowPanoOnResult} options={options} timeOffset={timeOffset} ws={ws} backBtnPressed={backBtnPressed} multiplayerChatOpen={multiplayerChatOpen} setMultiplayerChatOpen={setMultiplayerChatOpen} multiplayerState={multiplayerState} xpEarned={xpEarned} setXpEarned={setXpEarned} pinPoint={pinPoint} setPinPoint={setPinPoint} loading={loading} setLoading={setLoading} session={session} streetViewShown={streetViewShown} setStreetViewShown={setStreetViewShown} latLong={latLong} loadLocation={() => { }} gameOptions={{ location: "all", maxDist: 20000, extent: gameOptions?.extent ?? multiplayerState?.gameData?.extent,
nm: multiplayerState?.gameData?.nm,
Expand Down
11 changes: 9 additions & 2 deletions components/ui/navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useTranslation } from '@/components/useTranslations'
import WsIcon from "../wsIcon";
import { useState, useEffect } from "react";

export default function Navbar({ maintenance, inCrazyGames, inGame, openAccountModal, shown, backBtnPressed, reloadBtnPressed, setGameOptionsModalShown, onNavbarPress, onFriendsPress, gameOptions, session, screen, multiplayerState, loading }) {
export default function Navbar({ maintenance, joinCodePress, inCrazyGames, inCoolMathGames, inGame, openAccountModal, shown, backBtnPressed, reloadBtnPressed, setGameOptionsModalShown, onNavbarPress, onFriendsPress, gameOptions, session, screen, multiplayerState, loading }) {
const { t: text } = useTranslation("common");

const reloadBtn = (((multiplayerState?.inGame) || (screen === 'singleplayer'))) && (!loading);
Expand Down Expand Up @@ -69,7 +69,14 @@ export default function Navbar({ maintenance, inCrazyGames, inGame, openAccountM
<FaPencil size={20}/>
</button>
)}
{!inGame && showAccBtn && (<AccountBtn inCrazyGames={inCrazyGames} session={session} navbarMode={true} openAccountModal={openAccountModal} />)}

{screen === "onboarding" && (
<button className="gameBtn navBtn"
style={{backgroundColor: 'blue'}}
onClick={joinCodePress}>{text("joinGame")}</button>
)}

{!inGame && showAccBtn && !inCoolMathGames && (<AccountBtn inCrazyGames={inCrazyGames} session={session} navbarMode={true} openAccountModal={openAccountModal} />)}
</div>
</div>
</>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"type": "module",
"scripts": {
"dev": "node welcome.js && npx concurrently \"cross-env UWS_HTTP_MAX_HEADERS_SIZE=16384 nodemon ws/ws --exec \"node --no-warnings=ExperimentalWarning\" --watch ws/ws.js\" \"cross-env nodemon server.js --exec \"node --no-warnings=ExperimentalWarning\" --watch server.js\" \"cross-env nodemon cron.js --exec \"node --no-warnings=ExperimentalWarning\" --watch cron.js\" \"npx next dev\"",
"dev": "node welcome.js && npx concurrently \"cross-env NODE_OPTIONS='--no-warnings' UWS_HTTP_MAX_HEADERS_SIZE=16384 nodemon ws/ws --exec \"node --no-warnings=ExperimentalWarning\" --watch ws/ws.js\" \"cross-env NODE_OPTIONS='--no-warnings' nodemon server.js --exec \"node --no-warnings=ExperimentalWarning\" --watch server.js\" \"cross-env NODE_OPTIONS='--no-warnings' nodemon cron.js --exec \"node --no-warnings=ExperimentalWarning\" --watch cron.js\" \"npx next dev\"",
"build": "cross-env next build",
"start-api": "cross-env NODE_ENV=production node server.js",
"start-ws": "cross-env UWS_HTTP_MAX_HEADERS_SIZE=16384 NODE_ENV=production node ws/ws",
Expand Down
Loading

0 comments on commit c5e7f09

Please sign in to comment.