From 1bbc55563d1394466aab1578c277181811b76398 Mon Sep 17 00:00:00 2001 From: Aelita4 Date: Sun, 3 Nov 2024 23:22:21 +0100 Subject: [PATCH] Change planetid cookie to currentPlanet --- src/components/ResourceBar.astro | 2 +- src/pages/game/buildings.astro | 2 +- src/pages/game/fleet.astro | 2 +- src/pages/game/index.astro | 2 +- src/pages/game/research.astro | 2 +- src/pages/game/ships.astro | 2 +- src/pages/game/systemManager/index.astro | 2 +- src/pages/login.astro | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/components/ResourceBar.astro b/src/components/ResourceBar.astro index 2836ae5..9712385 100644 --- a/src/components/ResourceBar.astro +++ b/src/components/ResourceBar.astro @@ -9,7 +9,7 @@ const resourceTypes = await getAllResources(); const lang = await getLocales(Astro.cookies.get('language')?.value ?? await getHighestWeightedLanguage(Astro.request.headers.get('accept-language'))); -const planetId = new ObjectId(Astro.cookies.get('planetid')?.value ?? ''); +const planetId = new ObjectId(Astro.cookies.get('currentPlanet')?.value ?? ''); const planet = locationManager.getPlanet(planetId); diff --git a/src/pages/game/buildings.astro b/src/pages/game/buildings.astro index 4c7f70e..a94a2d8 100644 --- a/src/pages/game/buildings.astro +++ b/src/pages/game/buildings.astro @@ -23,7 +23,7 @@ const locale = Astro.cookies.get('language')?.value ?? await getHighestWeightedL const lang = await getLocales(locale); -const planetId = Astro.cookies.get('planetid')?.value ?? ""; +const planetId = Astro.cookies.get('currentPlanet')?.value ?? ""; if(planetId === "") return "No planet selected"; const planet = locationManager.getPlanet(new ObjectId(planetId)); diff --git a/src/pages/game/fleet.astro b/src/pages/game/fleet.astro index e420f0e..52970c7 100644 --- a/src/pages/game/fleet.astro +++ b/src/pages/game/fleet.astro @@ -19,7 +19,7 @@ if(checkUser === null || checkUser.username !== username) return Astro.redirect( const user = locationManager.getUser(checkUser._id); if(!user) return Astro.redirect('/logout'); -const planetId = Astro.cookies.get('planetid')?.value ?? ""; +const planetId = Astro.cookies.get('currentPlanet')?.value ?? ""; if(planetId === "") return "No planet selected"; const planet = locationManager.getPlanet(new ObjectId(planetId)); diff --git a/src/pages/game/index.astro b/src/pages/game/index.astro index 6514e48..69265ea 100644 --- a/src/pages/game/index.astro +++ b/src/pages/game/index.astro @@ -13,8 +13,8 @@ if(loggedToken === null || username === "") return Astro.redirect('/logout'); const checkUser = await getUserByAccessToken(loggedToken); if(checkUser === null || checkUser.username !== username) return Astro.redirect('/logout'); -const currentPlanetId = Astro.cookies.get('planetid')?.value ?? null; if(currentPlanetId === null) return Astro.redirect('/game/logout'); +const currentPlanetId = Astro.cookies.get('currentPlanet')?.value ?? null; const currentPlanet = locationManager.getPlanet(new ObjectId(currentPlanetId)); if(currentPlanet === undefined) { Astro.cookies.delete('planetid'); diff --git a/src/pages/game/research.astro b/src/pages/game/research.astro index 143d8f1..c43ae61 100644 --- a/src/pages/game/research.astro +++ b/src/pages/game/research.astro @@ -16,7 +16,7 @@ if(loggedToken === null || username === "") return Astro.redirect('/logout'); const checkUser = await getUserByAccessToken(loggedToken); if(checkUser === null || checkUser.username !== username) return Astro.redirect('/logout'); -const planetId = Astro.cookies.get('planetid')?.value ?? ""; +const planetId = Astro.cookies.get('currentPlanet')?.value ?? ""; if(planetId === "") return Astro.redirect('/logout'); if(Astro.request.method === "POST") { diff --git a/src/pages/game/ships.astro b/src/pages/game/ships.astro index f943b08..a52bd90 100644 --- a/src/pages/game/ships.astro +++ b/src/pages/game/ships.astro @@ -18,7 +18,7 @@ if(checkUser === null || checkUser.username !== username) return Astro.redirect( const ships = await getAllShips(); -const planetId = Astro.cookies.get('planetid')?.value ?? ""; +const planetId = Astro.cookies.get('currentPlanet')?.value ?? ""; if(planetId === "") { console.error("No planet selected"); return Astro.redirect('/logout'); diff --git a/src/pages/game/systemManager/index.astro b/src/pages/game/systemManager/index.astro index 8f5ab58..898fa93 100644 --- a/src/pages/game/systemManager/index.astro +++ b/src/pages/game/systemManager/index.astro @@ -28,7 +28,7 @@ if(Astro.request.method === "POST") { const selectedPlanetId = (await Astro.request.formData()).get('planetId') as string | null; if(selectedPlanetId !== null) { - Astro.cookies.set('planetid', selectedPlanetId, { + Astro.cookies.set('currentPlanet', selectedPlanetId, { path: '/', expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7), sameSite: 'lax', diff --git a/src/pages/login.astro b/src/pages/login.astro index fb7947c..4460be1 100644 --- a/src/pages/login.astro +++ b/src/pages/login.astro @@ -71,7 +71,7 @@ if(Astro.request.method === "POST") { secure: true }); - Astro.cookies.set("planetid", user.mainPlanet._id, { + Astro.cookies.set("currentPlanet", user.mainPlanet._id, { path: "/", maxAge: sessionTime, sameSite: "lax",