Add logging

This commit is contained in:
Vortrex
2021-01-25 22:40:04 -06:00
parent 511b7a6960
commit edae8c4cc1

View File

@@ -446,12 +446,18 @@ function loginSuccess(client) {
function saveAccountToDatabase(accountData) {
let dbConnection = connectToDatabase();
if(dbConnection) {
logToConsole(LOG_VERBOSE, `Escaping account data for ${getPlayerDisplayForConsole(client)}`);
let safePassword = escapeDatabaseString(dbConnection, accountData.password);
//let safeStaffTitle = escapeDatabaseString(dbConnection, accountData.staffTitle);
//let safeEmailAddress = escapeDatabaseString(dbConnection, accountData.emailAddress);
//let safeIRCAccount = dbConnection.escapetoString(accountData.ircAccount);
logToConsole(LOG_VERBOSE, `${getPlayerDisplayForConsole(client)}'s password escaped successfully`);
let safeStaffTitle = escapeDatabaseString(dbConnection, accountData.staffTitle);
logToConsole(LOG_VERBOSE, `${getPlayerDisplayForConsole(client)}'s staff title escaped successfully`);
let safeEmailAddress = escapeDatabaseString(dbConnection, accountData.emailAddress);
logToConsole(LOG_VERBOSE, `${getPlayerDisplayForConsole(client)}'s email address escaped successfully`);
let safeIRCAccount = escapeDatabaseString(dbConnection, accountData.ircAccount);
logToConsole(LOG_VERBOSE, `${getPlayerDisplayForConsole(client)}'s irc account escaped successfully`);
let dbQueryString = `UPDATE acct_main SET acct_pass='${safePassword}', acct_settings=${accountData.settings}, acct_staff_flags=${accountData.flags.admin}, acct_mod_flags=${toString(accountData.flags.moderation)}, acct_discord=${toString(accountData.discordAccount)}, acct_ip=INET_ATON('${accountData.ipAddress}') WHERE acct_id=${accountData.databaseId}`;
let dbQueryString = `UPDATE acct_main SET acct_pass='${safePassword}', acct_settings=${accountData.settings}, acct_staff_flags=${accountData.flags.admin}, acct_mod_flags=${accountData.flags.moderation}, acct_discord=${accountData.discordAccount}, acct_ip=INET_ATON('${accountData.ipAddress}') WHERE acct_id=${accountData.databaseId}`;
logToConsole(LOG_VERBOSE, dbQueryString);
let dbQuery = queryDatabase(dbConnection, dbQueryString);
//freeDatabaseQuery(dbQuery);
disconnectFromDatabase(dbConnection);
@@ -463,7 +469,9 @@ function saveAccountToDatabase(accountData) {
function saveAccountKeyBindsDatabase(keyBindData) {
let dbConnection = connectToDatabase();
if(dbConnection) {
logToConsole(LOG_VERBOSE, `Escaping account keybinds data for ${getPlayerDisplayForConsole(client)}`);
let safeCommandString = escapeDatabaseString(dbConnection, keyBindData.commandString);
logToConsole(LOG_VERBOSE, `${getPlayerDisplayForConsole(client)}'s keybind command string escaped successfully`);
if(keyBindData.databaseId == 0) {
let dbQueryString = `INSERT INTO acct_hotkey (acct_hotkey_cmdstr, acct_hotkey_key, acct_hotkey_down, acct_hotkey_enabled) VALUES ('${safeCommandString}', ${keyBindData.key}, ${boolToInt(keyBindData.keyState)}, ${boolToInt(keyBindData.enabled)}, ${keyBindData.account}`;
keyBindData.databaseId = getDatabaseInsertId(dbConnection);
@@ -485,6 +493,7 @@ function saveAccountStaffNotesDatabase(staffNoteData) {
let dbConnection = connectToDatabase();
if(dbConnection) {
let safeNoteContent = escapeDatabaseString(dbConnection, staffNoteData.note);
logToConsole(LOG_VERBOSE, `${getPlayerDisplayForConsole(client)}'s staff note string escaped successfully`);
if(staffNoteData.databaseId == 0) {
let dbQueryString = `INSERT INTO acct_note (acct_note_message, acct_note_who_added, acct_note_when_added, acct_note_server, acct_note_acct) VALUES ('${safeNoteContent}', ${staffNoteData.whoAdded}, UNIX_TIMESTAMP(), ${getServerId()}, ${staffNoteData.account}`;
staffNoteData.databaseId = getDatabaseInsertId(dbConnection);
@@ -544,6 +553,9 @@ function createAccount(name, password, email = "") {
function checkLogin(client, password) {
getPlayerData(client).loginAttemptsRemaining = getPlayerData(client).loginAttemptsRemaining-1;
if(getPlayerData(client).loginAttemptsRemaining <= 0) {
client.disconnect();
}
if(isPlayerLoggedIn(client)) {
logToConsole(LOG_WARN, `[Asshat.Account] ${getPlayerDisplayForConsole(client)} attempted to login but is already logged in`);