From a13b1d0adad6ccad8364e2264e60fb612c73c411 Mon Sep 17 00:00:00 2001 From: AudricV <74829229+AudricV@users.noreply.github.com> Date: Sun, 15 Jan 2023 11:39:35 +0100 Subject: [PATCH 1/3] [Client] Remove localStorage requirement As we use cookies for the game and that localStorage is only used to save the theme set on the start page, it isn't needed to use it, as the dark theme would be set as a fallback. In order to show a cookies requirement message if they are disabled, we need to remove the one of the localStorage, as when cookies access is disabled, localStorage cannot be accessed. --- truthseeker/static/js/game_start_page.js | 1 - 1 file changed, 1 deletion(-) diff --git a/truthseeker/static/js/game_start_page.js b/truthseeker/static/js/game_start_page.js index 11d58a0..9ef93e1 100644 --- a/truthseeker/static/js/game_start_page.js +++ b/truthseeker/static/js/game_start_page.js @@ -160,7 +160,6 @@ function setCurrentTheme() { } catch (e) { console.error("Unable to set theme from localStorage", e); htmlElement.classList.add("dark"); - showUnsupportedBrowserMessage("Votre navigateur ne semble pas supporter le localStorage. Certains navigateurs nécessitant l'autorisation d'utiliser des cookies pour utiliser le localStorage, vérifiez que les cookies sont autorisés pour le site du jeu dans le vôtre."); } } From ce640ff1580868c329d52d0e1a7ab2f77e1bcb96 Mon Sep 17 00:00:00 2001 From: AudricV <74829229+AudricV@users.noreply.github.com> Date: Sun, 15 Jan 2023 11:46:47 +0100 Subject: [PATCH 2/3] [Client] Add cookie availability check If cookies are not allowed, the game cannot be played. That's the reason why an alert error message is show in this case, in order to prevent the user to play the game. --- truthseeker/static/js/game_common.js | 39 +++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/truthseeker/static/js/game_common.js b/truthseeker/static/js/game_common.js index a0655e7..a200e69 100644 --- a/truthseeker/static/js/game_common.js +++ b/truthseeker/static/js/game_common.js @@ -31,6 +31,42 @@ function checkWebSocketAvailability() { } } +/** + * Create a temporary cookie to detect whether cookies are allowed for the game website domain. + * + *
+ * This cookie, cookietest, with 1 as a value, is automatically deleted after being created. + *
+ * + * @returns whether cookies are allowed for the website domain + */ +function createTemporaryCookieThenDeleteIt() { + try { + // Create a temporary cookie + document.cookie = "cookietest=1; path=/"; + let cookieTestResult = document.cookie.indexOf("cookietest=") !== -1; + // Delete the temporary cookie + document.cookie = "cookietest=1; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/"; + return cookieTestResult; + } catch (e) { + return false; + } +} + +/** + * Check the availability of cookies in the client. + * + *+ * If it is not available, an error message which prevents playing the game and requesting user to + * enable website cookies is shown. + *
+ */ +function checkCookiesAvailability() { + if (!createTemporaryCookieThenDeleteIt()) { + showUnsupportedBrowserMessage("Votre navigateur ne prend pas en charge les cookies, nécessaires au fonctionnement du jeu. Veuillez les activer dans les paramètres de votre navigateur."); + } +} + /** * Show the unsupported browser dialog, which disables ability to play the game, using the given * unsupported browser message text. @@ -67,4 +103,5 @@ function showAlertDialog(element) { // Execution of main functions detectIEBrowsers(); -checkWebSocketAvailability(); \ No newline at end of file +checkWebSocketAvailability(); +checkCookiesAvailability(); From fa9024167be77a3622456671f2b136f716c70536 Mon Sep 17 00:00:00 2001 From: AudricV <74829229+AudricV@users.noreply.github.com> Date: Sun, 15 Jan 2023 11:58:06 +0100 Subject: [PATCH 3/3] [Client] Add legal links on game pages when the game cannot be played --- truthseeker/templates/game.html | 10 ++++++++++ truthseeker/templates/index.html | 10 ++++++++++ truthseeker/templates/lobby.html | 10 ++++++++++ 3 files changed, 30 insertions(+) diff --git a/truthseeker/templates/game.html b/truthseeker/templates/game.html index 3b3eaeb..a6f5408 100644 --- a/truthseeker/templates/game.html +++ b/truthseeker/templates/game.html @@ -87,6 +87,11 @@