Add login timeout (60 seconds)
This commit is contained in:
@@ -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 {
|
||||
@@ -1799,3 +1803,14 @@ function sendAccountTwoFactorAuthCode(emailAddress, name, twoFactorAuthCode) {
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function startLoginTimeoutForPlayer(client) {
|
||||
getPlayerData(client).loginTimeout = setTimeout(function () {
|
||||
//if (isPlayerLoggedIn(client) == false) {
|
||||
getPlayerData(client).customDisconnectReason = "Kicked - Login timeout";
|
||||
disconnectPlayer(client);
|
||||
//}
|
||||
}, getGlobalConfig().loginTimeout);
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
@@ -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 = [];
|
||||
@@ -146,3 +147,36 @@ function initClientScript() {
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
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);
|
||||
})
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
@@ -235,6 +235,7 @@ let globalConfig = {
|
||||
vehicleTrunkDistance: 2.0,
|
||||
fishingSpotDistance: 10.0,
|
||||
atmDistance: 1.5,
|
||||
loginTimeout: 60000,
|
||||
};
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
Reference in New Issue
Block a user