[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.
This commit is contained in:
parent
a13b1d0ada
commit
ce640ff158
@ -31,6 +31,42 @@ function checkWebSocketAvailability() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a temporary cookie to detect whether cookies are allowed for the game website domain.
|
||||
*
|
||||
* <p>
|
||||
* This cookie, cookietest, with 1 as a value, is automatically deleted after being created.
|
||||
* </p>
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* <p>
|
||||
* If it is not available, an error message which prevents playing the game and requesting user to
|
||||
* enable website cookies is shown.
|
||||
* </p>
|
||||
*/
|
||||
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();
|
||||
checkWebSocketAvailability();
|
||||
checkCookiesAvailability();
|
||||
|
Loading…
Reference in New Issue
Block a user