From eb582a666d66aa12803563cdb4c1568351be89b4 Mon Sep 17 00:00:00 2001 From: Vortrex <3858226+VortrexFTW@users.noreply.github.com> Date: Thu, 7 Jul 2022 22:16:50 -0500 Subject: [PATCH] Add login timeout (60 seconds) --- scripts/server/account.js | 31 +++++++++++++++++++++++-------- scripts/server/client.js | 36 +++++++++++++++++++++++++++++++++++- scripts/server/config.js | 1 + scripts/server/event.js | 7 ++++++- 4 files changed, 65 insertions(+), 10 deletions(-) diff --git a/scripts/server/account.js b/scripts/server/account.js index 07907d16..2a2eeeca 100644 --- a/scripts/server/account.js +++ b/scripts/server/account.js @@ -782,6 +782,9 @@ function loginSuccess(client) { logToConsole(LOG_DEBUG, `[VRR.Account] ${getPlayerDisplayForConsole(client)} successfully logged in.`); getPlayerData(client).loggedIn = true; + clearTimeout(getPlayerData(client).loginTimeout); + getPlayerData(client).loginTimeout = null; + updateConnectionLogOnAuth(client, getPlayerData(client).accountData.databaseId); if (doesPlayerHaveStaffPermission(client, "Developer") || doesPlayerHaveStaffPermission(client, "ManageServer")) { @@ -1003,7 +1006,7 @@ function createAccount(name, password, email = "") { // =========================================================================== -async function checkLogin(client, password) { +function checkLogin(client, password) { getPlayerData(client).loginAttemptsRemaining = getPlayerData(client).loginAttemptsRemaining - 1; if (getPlayerData(client).loginAttemptsRemaining <= 0) { getPlayerData(client).customDisconnectReason = "Kicked - Failed to login"; @@ -1044,9 +1047,9 @@ async function checkLogin(client, password) { } // Disabling email login alerts for now. It hangs the server for a couple seconds. Need a way to thread it. - //if (isAccountEmailVerified(getPlayerData(client).accountData) && !isAccountSettingFlagEnabled(getPlayerData(client).accountData, getAccountSettingsFlagValue("AuthAttemptAlert"))) { - // await sendAccountLoginFailedNotification(getPlayerData(client).accountData.emailAddress, getPlayerName(client), getPlayerIP(client), getGame()); - //} + if (isAccountEmailVerified(getPlayerData(client).accountData) && !isAccountSettingFlagEnabled(getPlayerData(client).accountData, getAccountSettingsFlagValue("AuthAttemptAlert"))) { + sendAccountLoginFailedNotification(getPlayerData(client).accountData.emailAddress, getPlayerName(client), getPlayerIP(client), getGame()); + } return false; } @@ -1061,9 +1064,9 @@ async function checkLogin(client, password) { } // Disabling email login alerts for now. It hangs the server for a couple seconds. Need a way to thread it. - //if (isAccountEmailVerified(getPlayerData(client).accountData) && !isAccountSettingFlagEnabled(getPlayerData(client).accountData, getAccountSettingsFlagValue("AuthAttemptAlert"))) { - // await sendAccountLoginFailedNotification(getPlayerData(client).accountData.emailAddress, getPlayerName(client), getPlayerIP(client), getGame()); - //} + if (isAccountEmailVerified(getPlayerData(client).accountData) && !isAccountSettingFlagEnabled(getPlayerData(client).accountData, getAccountSettingsFlagValue("AuthAttemptAlert"))) { + sendAccountLoginFailedNotification(getPlayerData(client).accountData.emailAddress, getPlayerName(client), getPlayerIP(client), getGame()); + } return false; } @@ -1082,7 +1085,7 @@ async function checkLogin(client, password) { // Disabling email login alerts for now. It hangs the server for a couple seconds. Need a way to thread it. //if (isAccountEmailVerified(getPlayerData(client).accountData) && !isAccountSettingFlagEnabled(getPlayerData(client).accountData, getAccountSettingsFlagValue("AuthAttemptAlert"))) { - // await sendAccountLoginSuccessNotification(getPlayerData(client).accountData.emailAddress, getPlayerName(client), getPlayerIP(client), getGame()); + // sendAccountLoginSuccessNotification(getPlayerData(client).accountData.emailAddress, getPlayerName(client), getPlayerIP(client), getGame()); //} } @@ -1440,6 +1443,7 @@ function initClient(client) { //} //showGameMessage(client, getLocaleString(client, "LocaleOffer", `/lang ${getLocaleData(localeId)[2]}`), getColourByName("white"), 10000, "Roboto"); } + startLoginTimeoutForPlayer(client); playRadioStreamForPlayer(client, getServerIntroMusicURL(), true, getPlayerStreamingRadioVolume(client)); } } else { @@ -1798,4 +1802,15 @@ function sendAccountTwoFactorAuthCode(emailAddress, name, twoFactorAuthCode) { return true; } +// =========================================================================== + +function startLoginTimeoutForPlayer(client) { + getPlayerData(client).loginTimeout = setTimeout(function () { + //if (isPlayerLoggedIn(client) == false) { + getPlayerData(client).customDisconnectReason = "Kicked - Login timeout"; + disconnectPlayer(client); + //} + }, getGlobalConfig().loginTimeout); +} + // =========================================================================== \ No newline at end of file diff --git a/scripts/server/client.js b/scripts/server/client.js index c76ea40a..3d320921 100644 --- a/scripts/server/client.js +++ b/scripts/server/client.js @@ -32,7 +32,6 @@ class ClientData { this.index = -1; this.connectTime = 0; this.clientVersion = "0.0.0"; - this.loginAttemptsRemaining = 3; this.afk = false; this.spawned = false; this.sessionId = 0; @@ -42,6 +41,8 @@ class ClientData { this.passwordResetCode = ""; this.twoFactorAuthenticationState = AGRP_2FA_STATE_NONE; this.twoFactorAuthenticationCode = 0; + this.loginTimeout = null; + this.loginAttemptsRemaining = 3; // Job Stuff this.jobEquipmentCache = []; @@ -145,4 +146,37 @@ function initClientScript() { logToConsole(LOG_DEBUG, "[VRR.Client]: Client script initialized!"); } +// =========================================================================== + +function resetClientStuff(client) { + logToConsole(LOG_DEBUG, `[VRR.Utilities] Resetting client data for ${getPlayerDisplayForConsole(client)}`); + + if (!getPlayerData(client)) { + return false; + } + + if (isPlayerOnJobRoute(client)) { + stopJobRoute(client, false, false); + } + + if (getPlayerData(client).rentingVehicle) { + stopRentingVehicle(client); + } + + deleteJobItems(client); + deletePaintBallItems(client); + //deletePlayerTemporaryLockerItems(client); + + getPlayerData(client).lastVehicle = null; +} + +// =========================================================================== + +function kickAllClients() { + getClients().forEach((client) => { + getPlayerData(client).customDisconnectReason = `Kicked - All clients are being disconnected`; + disconnectPlayer(client); + }) +} + // =========================================================================== \ No newline at end of file diff --git a/scripts/server/config.js b/scripts/server/config.js index 5a365f15..e74907ae 100644 --- a/scripts/server/config.js +++ b/scripts/server/config.js @@ -235,6 +235,7 @@ let globalConfig = { vehicleTrunkDistance: 2.0, fishingSpotDistance: 10.0, atmDistance: 1.5, + loginTimeout: 60000, }; // =========================================================================== diff --git a/scripts/server/event.js b/scripts/server/event.js index ccd96a49..ec43f80e 100644 --- a/scripts/server/event.js +++ b/scripts/server/event.js @@ -125,13 +125,18 @@ function onPlayerQuit(event, client, quitReasonId) { if (isPlayerLoggedIn(client)) { savePlayerToDatabase(client); resetClientStuff(client); - getServerData().clients[getPlayerId(client)] = null; + } + + if (getPlayerData(client).loginTimeout != null) { + clearTimeout(getPlayerData(client).loginTimeout); } playerResourceReady[client.index] = false; playerResourceStarted[client.index] = false; playerInitialized[client.index] = false; playerGUIReady[client.index] = false; + + getServerData().clients[getPlayerId(client)] = null; } // ===========================================================================