From e3f5e5ea0290ef5db3838ef3eef0b2b8c7ccbdf7 Mon Sep 17 00:00:00 2001 From: Vortrex <3858226+VortrexFTW@users.noreply.github.com> Date: Fri, 8 Jan 2021 00:15:10 -0600 Subject: [PATCH] Use new logging util --- scripts/client/gui.js | 133 ++++++++++++++----------------- scripts/client/main.js | 18 +++-- scripts/server/account.js | 84 +++++++++---------- scripts/server/anticheat.js | 16 ++-- scripts/server/ban.js | 10 +-- scripts/server/business.js | 28 ++++--- scripts/server/chat.js | 4 +- scripts/server/clan.js | 10 +-- scripts/server/client.js | 10 +-- scripts/server/developer.js | 4 +- scripts/server/event.js | 12 +-- scripts/server/house.js | 14 ++-- scripts/server/keybind.js | 6 +- scripts/server/messaging.js | 16 ++-- scripts/server/misc.js | 10 +-- scripts/server/startup.js | 4 +- scripts/server/subaccount.js | 12 +-- scripts/server/timers.js | 4 +- scripts/server/translate.js | 2 +- scripts/server/utilities.js | 4 +- scripts/server/vehicle.js | 16 ++-- scripts/shared/native.js | 18 +++++ third-party/mexui/Core/Native.js | 52 ++++++------ 23 files changed, 251 insertions(+), 236 deletions(-) diff --git a/scripts/client/gui.js b/scripts/client/gui.js index 9ad221d6..e3231f8c 100644 --- a/scripts/client/gui.js +++ b/scripts/client/gui.js @@ -1081,9 +1081,9 @@ let currentCharacter = 0; app.init = function() { - console.log(`[Asshat.GUI] Initializing GUI ...`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Initializing GUI ...`); - console.log(`[Asshat.GUI] Creating login GUI ...`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Creating login GUI ...`); login.window = mexui.window(game.width/2-150, game.height/2-129, 300, 258, 'LOGIN', { main: { backgroundColour: toColour(0, 0, 0, windowAlpha), @@ -1158,11 +1158,11 @@ app.init = function() }, }, checkLogin); - console.log(`[Asshat.GUI] Created login GUI`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Created login GUI`); // ------------------------------------------------------------------------------ - console.log(`[Asshat.GUI] Creating two factor auth GUI ...`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Creating two factor auth GUI ...`); twoFactorAuth.window = mexui.window(game.width/2-150, game.height/2-129, 300, 258, 'LOGIN', { main: { backgroundColour: toColour(0, 0, 0, windowAlpha), @@ -1236,11 +1236,11 @@ app.init = function() }, }, checkTwoFactorAuth); - console.log(`[Asshat.GUI] Created two factor auth GUI`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Created two factor auth GUI`); // ------------------------------------------------------------------------------ - console.log(`[Asshat.GUI] Creating new character GUI ...`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Creating new character GUI ...`); newCharacter.window = mexui.window(game.width/2-215, game.height/2-83, 430, 166, 'New Character', { main: { @@ -1442,13 +1442,11 @@ app.init = function() borderColour: toColour(primaryColour[0], primaryColour[1], primaryColour[2], buttonAlpha), }, }, checkNewCharacter); - - console.log(`[Asshat.GUI] Created new character GUI`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Created new character GUI`); // ------------------------------------------------------------------------------ - console.log(`[Asshat.GUI] Creating register GUI ...`); - + logToConsole(LOG_DEBUG, `[Asshat.GUI] Creating register GUI ...`); register.window = mexui.window(game.width/2-130, game.height/2-115, 300, 230, 'Register', { main: { backgroundColour: toColour(0, 0, 0, windowAlpha), @@ -1557,13 +1555,11 @@ app.init = function() borderColour: toColour(primaryColour[0], primaryColour[1], primaryColour[2], buttonAlpha), }, }, checkRegistration); - - console.log(`[Asshat.GUI] Created register GUI`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Created register GUI`); // ------------------------------------------------------------------------------ - console.log(`[Asshat.GUI] Creating error GUI ...`); - + logToConsole(LOG_DEBUG, `[Asshat.GUI] Creating error GUI ...`); errorDialog.window = mexui.window(game.width/2-200, game.height/2-70, 400, 140, 'ERROR', { main: { backgroundColour: toColour(0, 0, 0, windowAlpha), @@ -1599,13 +1595,11 @@ app.init = function() textAlign: 0.5, }, }, closeErrorDialog); - - console.log(`[Asshat.GUI] Created error GUI ...`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Created error GUI ...`); // ------------------------------------------------------------------------------ - console.log(`[Asshat.GUI] Created prompt GUI ...`); - + logToConsole(LOG_DEBUG, `[Asshat.GUI] Created prompt GUI ...`); yesNoDialog.window = mexui.window(game.width/2-200, game.height/2-70, 400, 140, 'Question', { main: { backgroundColour: toColour(0, 0, 0, windowAlpha), @@ -1651,13 +1645,11 @@ app.init = function() textAlign: 0.5, }, }, yesNoDialogAnswerNo); - - console.log(`[Asshat.GUI] Created prompt GUI`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Created prompt GUI`); // ------------------------------------------------------------------------------ - console.log(`[Asshat.GUI] Creating info dialog GUI ...`); - + logToConsole(LOG_DEBUG, `[Asshat.GUI] Creating info dialog GUI ...`); infoDialog.window = mexui.window(game.width/2-200, game.height/2-70, 400, 140, 'Information', { main: { backgroundColour: toColour(0, 0, 0, windowAlpha), @@ -1692,13 +1684,11 @@ app.init = function() textAlign: 0.5, }, }, closeInfoDialog); - - console.log(`[Asshat.GUI] Created info dialog GUI`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Created info dialog GUI`); // ------------------------------------------------------------------------------ - console.log(`[Asshat.GUI] Creating character select GUI ...`); - + logToConsole(LOG_DEBUG, `[Asshat.GUI] Creating character select GUI ...`); characterSelect.window = mexui.window(game.width/2-215, game.height/2-83, 430, 166, 'Select Character', { main: { backgroundColour: toColour(0, 0, 0, windowAlpha), @@ -1808,26 +1798,25 @@ app.init = function() borderColour: toColour(0, 0, 0, 0), } }); - - console.log(`[Asshat.GUI] Created character select GUI`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Created character select GUI`); // --------------------------------------------------------------------------- - console.log(`[Asshat.GUI] All GUI created successfully!`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] All GUI created successfully!`); closeAllWindows(); }; // --------------------------------------------------------------------------- let checkLogin = function() { - console.log(`[Asshat.GUI] Checking login with server ...`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Checking login with server ...`); triggerNetworkEvent("ag.checkLogin", login.passwordInput.lines[0]); } // --------------------------------------------------------------------------- let loginFailed = function(errorMessage) { - console.log(`[Asshat.GUI] Server reports login failed`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Server reports login failed`); login.messageLabel.text = errorMessage; login.messageLabel.styles.main.textColour = toColour(180, 32, 32, 255); login.passwordInput.text = ""; @@ -1836,21 +1825,21 @@ let loginFailed = function(errorMessage) { // --------------------------------------------------------------------------- let loginSuccess = function() { - console.log(`[Asshat.GUI] Server reports login was successful`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Server reports login was successful`); closeAllWindows(); } // --------------------------------------------------------------------------- let checkRegistration = function() { - console.log(`[Asshat.GUI] Checking registration with server ...`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Checking registration with server ...`); triggerNetworkEvent("ag.checkRegistration", register.passwordInput.lines[0], register.confirmPasswordInput.lines[0], register.emailInput.lines[0]); } // --------------------------------------------------------------------------- let checkNewCharacter = function() { - console.log(`[Asshat.GUI] Checking new character with server ...`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Checking new character with server ...`); let skinId = false; if(newCharacter.firstNameInput.lines[0].length < 2) { @@ -1881,7 +1870,7 @@ let checkNewCharacter = function() { // --------------------------------------------------------------------------- let registrationFailed = function(errorMessage) { - console.log(`[Asshat.GUI] Server reports registration failed. Reason: ${errorMessage}`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Server reports registration failed. Reason: ${errorMessage}`); register.messageLabel.text = errorMessage; register.messageLabel.styles.main.textColour = toColour(180, 32, 32, 255); register.passwordInput.text = ""; @@ -1892,14 +1881,14 @@ let registrationFailed = function(errorMessage) { // --------------------------------------------------------------------------- let registrationSuccess = function() { - console.log(`[Asshat.GUI] Server reports registration was successful`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Server reports registration was successful`); closeAllWindows(); } // --------------------------------------------------------------------------- let twoFactorAuthFailed = function(errorMessage) { - console.log(`[Asshat.GUI] Server reports two-factor authentication failed. Reason: ${errorMessage}`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Server reports two-factor authentication failed. Reason: ${errorMessage}`); login.messageLabel.text = errorMessage; login.messageLabel.styles.main.textColour = toColour(180, 32, 32, 255); login.passwordInput.text = ""; @@ -1908,28 +1897,28 @@ let twoFactorAuthFailed = function(errorMessage) { // --------------------------------------------------------------------------- let twoFactorAuthSuccess = function() { - console.log(`[Asshat.GUI] Server reports two-factor authentication was successful`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Server reports two-factor authentication was successful`); closeAllWindows(); } // --------------------------------------------------------------------------- let checkTwoFactorAuth = function() { - console.log(`[Asshat.GUI] Checking two-factor authentication with server ...`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Checking two-factor authentication with server ...`); triggerNetworkEvent("ag.checkTwoFactorAuth", twoFactorAuth.codeInput.lines[0]); } // --------------------------------------------------------------------------- let characterSelectSuccess = function() { - console.log(`[Asshat.GUI] Server reports character selection was successful`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Server reports character selection was successful`); closeAllWindows(); } // --------------------------------------------------------------------------- let closeErrorDialog = function() { - console.log(`[Asshat.GUI] Closing error dialog`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Closing error dialog`); errorDialog.window.shown = false; mexui.setInput(false); } @@ -1937,7 +1926,7 @@ let closeErrorDialog = function() { // --------------------------------------------------------------------------- let closeInfoDialog = function() { - console.log(`[Asshat.GUI] Closing info dialog`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Closing info dialog`); infoDialog.window.shown = false; mexui.setInput(false); } @@ -1945,7 +1934,7 @@ let closeInfoDialog = function() { // --------------------------------------------------------------------------- let closeAllWindows = function() { - console.log(`[Asshat.GUI] Closing all GUI windows`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Closing all GUI windows`); infoDialog.window.shown = false; errorDialog.window.shown = false; yesNoDialog.window.shown = false; @@ -1961,21 +1950,21 @@ let closeAllWindows = function() { // --------------------------------------------------------------------------- let yesNoDialogAnswerNo = function() { - console.log(`[Asshat.GUI] Responding with answer NO to server prompt`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Responding with answer NO to server prompt`); triggerNetworkEvent("ag.promptAnswerNo"); } // --------------------------------------------------------------------------- let yesNoDialogAnswerYes = function() { - console.log(`[Asshat.GUI] Responding with answer YES to server prompt`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Responding with answer YES to server prompt`); triggerNetworkEvent("ag.promptAnswerYes"); } // --------------------------------------------------------------------------- let showRegistration = function() { - console.log(`[Asshat.GUI] Showing registration window`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Showing registration window`); closeAllWindows(); setChatWindowEnabled(false); mexui.setInput(true); @@ -1986,7 +1975,7 @@ let showRegistration = function() { let showLogin = function() { closeAllWindows(); - console.log(`[Asshat.GUI] Showing login window`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Showing login window`); setChatWindowEnabled(false); mexui.setInput(true); login.window.shown = true; @@ -1996,7 +1985,7 @@ let showLogin = function() { let showTwoFactorAuth = function() { closeAllWindows(); - console.log(`[Asshat.GUI] Showing two-factor authentication window`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Showing two-factor authentication window`); setChatWindowEnabled(false); mexui.setInput(true); twoFactorAuth.window.shown = true; @@ -2006,7 +1995,7 @@ let showTwoFactorAuth = function() { let showCharacterSelect = function(firstName, lastName, placeOfOrigin, dateOfBirth, skinId) { closeAllWindows(); - console.log(`[Asshat.GUI] Showing character selection window`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Showing character selection window`); setChatWindowEnabled(false); mexui.setInput(true); characterSelect.nameText.text = lastName + ", " + firstName; @@ -2020,7 +2009,7 @@ let showCharacterSelect = function(firstName, lastName, placeOfOrigin, dateOfBir let showError = function(errorMessage, errorTitle) { closeAllWindows(); - console.log(`[Asshat.GUI] Showing error window. Error: ${errorTitle} - ${errorMessage}`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Showing error window. Error: ${errorTitle} - ${errorMessage}`); setChatWindowEnabled(false); mexui.setInput(true); errorDialog.messageLabel.text = errorMessage; @@ -2031,7 +2020,7 @@ let showError = function(errorMessage, errorTitle) { let showYesNo = function(promptMessage, promptTitle) { closeAllWindows(); - console.log(`[Asshat.GUI] Showing prompt window. Prompt: ${promptTitle} - ${promptMessage}`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Showing prompt window. Prompt: ${promptTitle} - ${promptMessage}`); mexui.setInput(true); yesNoDialog.messageLabel.text = promptMessage; yesNoDialog.window.shown = true; @@ -2041,7 +2030,7 @@ let showYesNo = function(promptMessage, promptTitle) { let showInfo = function(infoMessage, infoTitle) { closeAllWindows(); - console.log(`[Asshat.GUI] Showing info dialog window. Info: ${infoTitle} - ${infoMessage}`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Showing info dialog window. Info: ${infoTitle} - ${infoMessage}`); mexui.setInput(true); infoDialog.messageLabel.text = infoMessage; infoDialog.window.shown = true; @@ -2051,7 +2040,7 @@ let showInfo = function(infoMessage, infoTitle) { let showNewCharacter = function() { closeAllWindows(); - console.log(`[Asshat.GUI] Showing info dialog window`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Showing info dialog window`); setChatWindowEnabled(false); mexui.setInput(true); newCharacter.window.shown = true; @@ -2060,28 +2049,28 @@ let showNewCharacter = function() { // --------------------------------------------------------------------------- let selectNextCharacter = function() { - console.log(`[Asshat.GUI] Requesting next character info from server for character select window`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Requesting next character info from server for character select window`); triggerNetworkEvent("ag.nextCharacter"); } // --------------------------------------------------------------------------- let selectPreviousCharacter = function() { - console.log(`[Asshat.GUI] Requesting previous character info from server for character select window`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Requesting previous character info from server for character select window`); triggerNetworkEvent("ag.previousCharacter"); } // --------------------------------------------------------------------------- let selectThisCharacter = function() { - console.log(`[Asshat.GUI] Tell server the current shown character was selected in character select window`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Tell server the current shown character was selected in character select window`); triggerNetworkEvent("ag.selectCharacter"); } // --------------------------------------------------------------------------- let switchCharacterSelect = function(firstName, lastName, placeOfOrigin, dateOfBirth, skinId) { - console.log(`[Asshat.GUI] Updating character info with data from server`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Updating character info with data from server`); setChatWindowEnabled(false); characterSelect.window.shown = false; characterSelect.nameText.text = lastName + ", " + firstName; @@ -2094,70 +2083,70 @@ let switchCharacterSelect = function(firstName, lastName, placeOfOrigin, dateOfB // --------------------------------------------------------------------------- addNetworkHandler("ag.showLogin", function() { - console.log(`[Asshat.GUI] Received request from server to show login window`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Received request from server to show login window`); showLogin(); }); // --------------------------------------------------------------------------- addNetworkHandler("ag.showRegistration", function() { - console.log(`[Asshat.GUI] Received request from server to show registration window`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Received request from server to show registration window`); showRegistration(); }); // --------------------------------------------------------------------------- addNetworkHandler("ag.showNewCharacter", function() { - console.log(`[Asshat.GUI] Received request from server to show new character window`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Received request from server to show new character window`); showNewCharacter(); }); // --------------------------------------------------------------------------- addNetworkHandler("ag.showCharacterSelect", function(firstName, lastName, placeOfOrigin, dateOfBirth, skinId) { - console.log(`[Asshat.GUI] Received request from server to show character selection window`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Received request from server to show character selection window`); showCharacterSelect(firstName, lastName, placeOfOrigin, dateOfBirth, skinId); }); // --------------------------------------------------------------------------- addNetworkHandler("ag.switchCharacterSelect", function(firstName, lastName, placeOfOrigin, dateOfBirth, skinId) { - console.log(`[Asshat.GUI] Received request from server to update character selection window with new info`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Received request from server to update character selection window with new info`); switchCharacterSelect(firstName, lastName, placeOfOrigin, dateOfBirth, skinId); }); // --------------------------------------------------------------------------- addNetworkHandler("ag.showError", function(errorMessage, errorTitle) { - console.log(`[Asshat.GUI] Received request from server to show error window`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Received request from server to show error window`); showError(errorMessage, errorTitle); }); // --------------------------------------------------------------------------- addNetworkHandler("ag.showPrompt", function(promptMessage, promptTitle) { - console.log(`[Asshat.GUI] Received request from server to show prompt window`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Received request from server to show prompt window`); showYesNo(promptMessage, promptTitle); }); // --------------------------------------------------------------------------- addNetworkHandler("ag.showInfo", function(infoMessage) { - console.log(`[Asshat.GUI] Received request from server to show info dialog`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Received request from server to show info dialog`); showInfo(infoMessage); }); // --------------------------------------------------------------------------- addNetworkHandler("ag.loginSuccess", function() { - console.log(`[Asshat.GUI] Received signal of successful login from server`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Received signal of successful login from server`); loginSuccess(); }); // --------------------------------------------------------------------------- addNetworkHandler("ag.characterSelectSuccess", function() { - console.log(`[Asshat.GUI] Received signal of successful character selection from server`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Received signal of successful character selection from server`); characterSelectSuccess(); setChatWindowEnabled(true); }); @@ -2165,32 +2154,32 @@ addNetworkHandler("ag.characterSelectSuccess", function() { // --------------------------------------------------------------------------- addNetworkHandler("ag.loginFailed", function(remainingAttempts) { - console.log(`[Asshat.GUI] Received signal of failed login from server`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Received signal of failed login from server`); loginFailed(remainingAttempts); }); // --------------------------------------------------------------------------- addNetworkHandler("ag.registrationSuccess", function() { - console.log(`[Asshat.GUI] Received signal of successful registration from server`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Received signal of successful registration from server`); registrationSuccess(); }); // --------------------------------------------------------------------------- addNetworkHandler("ag.registrationFailed", function(errorMessage) { - console.log(`[Asshat.GUI] Received signal of failed registration from server`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Received signal of failed registration from server`); registrationFailed(errorMessage); }); // --------------------------------------------------------------------------- addNetworkHandler("ag.guiColour", function(red, green, blue) { - console.log(`[Asshat.GUI] Received new GUI colours from server`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Received new GUI colours from server`); primaryColour = [red, green, blue]; focusedColour = [red+focusedColourOffset, green+focusedColourOffset, blue+focusedColourOffset]; - console.log(`[Asshat.GUI] Initializing MexUI app`); + logToConsole(LOG_DEBUG, `[Asshat.GUI] Initializing MexUI app`); app.init(); triggerNetworkEvent("ag.guiReady", true); }); diff --git a/scripts/client/main.js b/scripts/client/main.js index 469f2cfe..e78b8bd1 100644 --- a/scripts/client/main.js +++ b/scripts/client/main.js @@ -45,6 +45,8 @@ let renderLogo = false; let renderSmallGameMessage = false; let renderScoreboard = false; +let logLevel = LOG_DEBUG | LOG_INFO | LOG_ERROR | LOG_WARN | LOG_VERBOSE; + // --------------------------------------------------------------------------- addEvent("OnLocalPlayerEnterSphere", 1); @@ -99,29 +101,29 @@ addNetworkHandler("ag.connectCamera", function(cameraPosition, cameraLookat) { // --------------------------------------------------------------------------- addNetworkHandler("ag.restoreCamera", function() { - console.log(`[Asshat.Main] Camera restored`); + logToConsole(LOG_DEBUG, `[Asshat.Main] Camera restored`); gta.restoreCamera(true); }); // --------------------------------------------------------------------------- addNetworkHandler("ag.clearPeds", function() { - console.log(`[Asshat.Main] Clearing all self-owned peds ...`); + logToConsole(LOG_DEBUG, `[Asshat.Main] Clearing all self-owned peds ...`); clearSelfOwnedPeds(); - console.log(`[Asshat.Main] All self-owned peds cleared`); + logToConsole(LOG_DEBUG, `[Asshat.Main] All self-owned peds cleared`); }); // --------------------------------------------------------------------------- addNetworkHandler("ag.logo", function(state) { - console.log(`[Asshat.Main] Server logo ${(state) ? "enabled" : "disabled"}`); + logToConsole(LOG_DEBUG, `[Asshat.Main] Server logo ${(state) ? "enabled" : "disabled"}`); renderLogo = state; }); // --------------------------------------------------------------------------- addNetworkHandler("ag.ambience", function(state) { - console.log(`[Asshat.Main] Ambient civilians and traffic ${(state) ? "enabled" : "disabled"}`); + logToConsole(LOG_DEBUG, `[Asshat.Main] Ambient civilians and traffic ${(state) ? "enabled" : "disabled"}`); gta.setTrafficEnabled(state); gta.setGenerateCarsAroundCamera(state); if(gta.game != GAME_GTA_SA) { @@ -163,14 +165,14 @@ function getClosestVehicle(pos) { // ------------------------------------------------------------------------- addNetworkHandler("ag.clearWeapons", function() { - console.log(`[Asshat.Main] Clearing weapons`); + logToConsole(LOG_DEBUG, `[Asshat.Main] Clearing weapons`); localPlayer.clearWeapons(); }); // --------------------------------------------------------------------------- addNetworkHandler("ag.giveWeapon", function(weaponId, ammo, active) { - console.log(`[Asshat.Main] Giving weapon ${weaponId} with ${ammo} ammo`); + logToConsole(LOG_DEBUG, `[Asshat.Main] Giving weapon ${weaponId} with ${ammo} ammo`); localPlayer.giveWeapon(weaponId, ammo, active); }); @@ -515,7 +517,7 @@ addNetworkHandler("ag.money", function(amount) { // --------------------------------------------------------------------------- addNetworkHandler("ag.removeWorldObject", function(model, position, range) { - console.log(`Removing world object ${model} at X: ${position.x}, Y: ${position.x}, Z: ${position.x} with range of ${range}`); + logToConsole(LOG_DEBUG, `Removing world object ${model} at X: ${position.x}, Y: ${position.x}, Z: ${position.x} with range of ${range}`); gta.removeWorldObject(model, position, range); }); diff --git a/scripts/server/account.js b/scripts/server/account.js index 411fbebe..8bb18822 100644 --- a/scripts/server/account.js +++ b/scripts/server/account.js @@ -9,8 +9,8 @@ // =========================================================================== function initAccountScript() { - console.log("[Asshat.Account]: Initializing account script ..."); - console.log("[Asshat.Account]: Account script initialized!"); + logToConsole(LOG_DEBUG, "[Asshat.Account]: Initializing account script ..."); + logToConsole(LOG_DEBUG, "[Asshat.Account]: Account script initialized!"); } // --------------------------------------------------------------------------- @@ -68,29 +68,29 @@ function toggleAccountGUICommand(command, params, client) { if(!doesPlayerHaveGUIEnabled(client)) { getPlayerData(client).accountData.settings = getPlayerData(client).accountData.settings & ~flagValue; messagePlayerNormal(client, `⚙️ You will now be shown GUI (if enabled on current server)`); - console.log(`[Asshat.Account] ${getPlayerDisplayForConsole(client)} has toggled GUI for their account ON.`); + logToConsole(LOG_DEBUG, `[Asshat.Account] ${getPlayerDisplayForConsole(client)} has toggled GUI for their account ON.`); } else { getPlayerData(client).accountData.settings = getPlayerData(client).accountData.settings | flagValue; messagePlayerNormal(client, `⚙️ You will not be shown GUI anymore. Any GUI stuff will be shown as messages in the chatbox instead.`); - console.log(`[Asshat.Account] ${getPlayerDisplayForConsole(client)} has toggled GUI for their account OFF.`); + logToConsole(LOG_DEBUG, `[Asshat.Account] ${getPlayerDisplayForConsole(client)} has toggled GUI for their account OFF.`); } if(!isPlayerLoggedIn(client)) { if(getPlayerData().accountData.databaseId != 0) { if(getServerConfig().useGUI && doesPlayerHaveGUIEnabled(client)) { showPlayerLoginGUI(client); - console.log(`[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the login GUI`); + logToConsole(LOG_DEBUG, `[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the login GUI`); } else { messageClient(`👋 Welcome back to Asshat Gaming RP, ${client.name}! Please /login to continue.`, client, getColourByName("softGreen")); - console.log(`[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the login message (GUI disabled)`); + logToConsole(LOG_DEBUG, `[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the login message (GUI disabled)`); } } else { if(getServerConfig().useGUI && doesPlayerHaveGUIEnabled(client)) { showPlayerRegistrationGUI(client); - console.log(`[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the register GUI`); + logToConsole(LOG_DEBUG, `[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the register GUI`); } else { messageClient(`👋 Welcome to Asshat Gaming RP, ${client.name}! Please /register to continue.`, client, getColourByName("softGreen")); - console.log(`[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the register message (GUI disabled)`); + logToConsole(LOG_DEBUG, `[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the register message (GUI disabled)`); } } } @@ -105,13 +105,13 @@ function toggleAccountServerLogoCommand(command, params, client) { if(!doesPlayerHaveLogoEnabled(client)) { getPlayerData(client).accountData.settings = getPlayerData(client).accountData.settings & ~flagValue; messagePlayerNormal(client, `⚙️ You will ${getBoolRedGreenInlineColour(true)}now [#FFFFFF]be shown the server logo (if enabled on current server)`); - console.log(`[Asshat.Account] ${getPlayerDisplayForConsole(client)} has toggled the server logo ON for their account`); + logToConsole(LOG_DEBUG, `[Asshat.Account] ${getPlayerDisplayForConsole(client)} has toggled the server logo ON for their account`); updatePlayerShowLogoState(client); updatePlayerShowLogoState(client, false); } else { getPlayerData(client).accountData.settings = getPlayerData(client).accountData.settings | flagValue; messagePlayerNormal(client, `⚙️ You will ${getBoolRedGreenInlineColour(false)}not [#FFFFFF]be shown the server logo.`); - console.log(`[Asshat.Account] ${getPlayerDisplayForConsole(client)} has toggled the server logo OFF for their account`); + logToConsole(LOG_DEBUG, `[Asshat.Account] ${getPlayerDisplayForConsole(client)} has toggled the server logo OFF for their account`); updatePlayerShowLogoState(client, false); } @@ -140,11 +140,11 @@ function toggleAccountTwoFactorAuthCommand(command, params, client) { if(!doesPlayerHaveTwoFactorAuthEnabled(client)) { getPlayerData(client).accountData.settings = getPlayerData(client).accountData.settings & ~flagValue; messagePlayerSuccess(client, `[#FFFFFF]Use this code to add your account into your authenticator app: [#AAAAAA]${addtoAuthenticatorCode}`); - console.log(`[Asshat.Account] ${getPlayerDisplayForConsole(client)} has toggled two-factor authentication ON for their account`); + logToConsole(LOG_DEBUG, `[Asshat.Account] ${getPlayerDisplayForConsole(client)} has toggled two-factor authentication ON for their account`); } else { getPlayerData(client).accountData.settings = getPlayerData(client).accountData.settings | flagValue; messagePlayerSuccess(client, `You have turned ${getBoolRedGreenInlineColour(false)}OFF [#FFFFFF]two-factor authentication for login.`); - console.log(`[Asshat.Account] ${getPlayerDisplayForConsole(client)} has toggled two-factor authentication OFF for their account`); + logToConsole(LOG_DEBUG, `[Asshat.Account] ${getPlayerDisplayForConsole(client)} has toggled two-factor authentication OFF for their account`); } return true; } @@ -411,7 +411,7 @@ function saltAccountInfo(name, password) { // --------------------------------------------------------------------------- function loginSuccess(client) { - console.log(`[Asshat.Account] ${getPlayerDisplayForConsole(client)} successfully logged in.`); + logToConsole(LOG_DEBUG, `[Asshat.Account] ${getPlayerDisplayForConsole(client)} successfully logged in.`); getPlayerData(client).loggedIn = true; if(doesPlayerHaveStaffPermission(client, "developer") || doesPlayerHaveStaffPermission(client, "manageServer")) { @@ -423,10 +423,10 @@ function loginSuccess(client) { if(getServerConfig().useGUI && doesPlayerHaveGUIEnabled(client)) { triggerNetworkEvent("ag.showPrompt", client, "You have no characters. Would you like to make one?", "No characters"); setEntityData(client, "ag.prompt", AG_PROMPT_CREATEFIRSTCHAR, false); - console.log(`[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the no characters prompt GUI`); + logToConsole(LOG_DEBUG, `[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the no characters prompt GUI`); } else { messagePlayerAlert(client, `You have no characters. Use /newchar to make one.`); - console.log(`[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the no characters message (GUI disabled)`); + logToConsole(LOG_DEBUG, `[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the no characters message (GUI disabled)`); } } else { showCharacterSelectToClient(client); @@ -559,10 +559,10 @@ function checkLogin(client, password) { console.warn(`[Asshat.Account] ${getPlayerDisplayForConsole(client)} attempted to login but is not registered`); if(getServerConfig().useGUI && doesPlayerHaveGUIEnabled(client)) { triggerNetworkEvent("ag.showRegistration", client); - console.log(`[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the register GUI`); + logToConsole(LOG_DEBUG, `[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the register GUI`); } else { messagePlayerError(client, "Your name is not registered! Use /register to make an account."); - console.log(`[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the register message (GUI disabled)`); + logToConsole(LOG_DEBUG, `[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the register message (GUI disabled)`); } return false; } @@ -571,10 +571,10 @@ function checkLogin(client, password) { console.warn(`[Asshat.Account] ${getPlayerDisplayForConsole(client)} attempted to login but failed (empty password). ${loginAttemptsRemaining} login attempts remaining`); if(getServerConfig().useGUI && doesPlayerHaveGUIEnabled(client)) { triggerNetworkEvent("ag.loginFailed", client, `Invalid password! ${loginAttemptsRemaining} tries remaining.`); - console.log(`[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the login GUI with ${loginAttemptsRemaining} login attempts remaining alert.`); + logToConsole(LOG_DEBUG, `[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the login GUI with ${loginAttemptsRemaining} login attempts remaining alert.`); } else { messagePlayerError(client, `You must enter a password! ${loginAttemptsRemaining} tries remaining.`); - console.log(`[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the login message (GUI disabled) with ${loginAttemptsRemaining} login attempts remaining alert.`); + logToConsole(LOG_DEBUG, `[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the login message (GUI disabled) with ${loginAttemptsRemaining} login attempts remaining alert.`); } return false; } @@ -583,10 +583,10 @@ function checkLogin(client, password) { console.warn(`[Asshat.Account] ${getPlayerDisplayForConsole(client)} attempted to login but failed (wrong password). ${loginAttemptsRemaining} login attempts remaining`); if(getServerConfig().useGUI && doesPlayerHaveGUIEnabled(client)) { triggerNetworkEvent("ag.loginFailed", client, `Invalid password! ${loginAttemptsRemaining} tries remaining.`); - console.log(`[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the login GUI with ${loginAttemptsRemaining} login attempts remaining alert.`); + logToConsole(LOG_DEBUG, `[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the login GUI with ${loginAttemptsRemaining} login attempts remaining alert.`); } else { messagePlayerError(client, `Invalid password! ${loginAttemptsRemaining} tries remaining.`); - console.log(`[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the login message (GUI disabled) with ${loginAttemptsRemaining} login attempts remaining alert.`); + logToConsole(LOG_DEBUG, `[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the login message (GUI disabled) with ${loginAttemptsRemaining} login attempts remaining alert.`); } return false; } @@ -602,7 +602,7 @@ addNetworkHandler("ag.checkLogin", checkLogin); // --------------------------------------------------------------------------- function checkRegistration(client, password, confirmPassword = "", emailAddress = "") { - console.log("[Asshat.Account]: Checking registration for " + toString(client.name)); + logToConsole(LOG_DEBUG, "[Asshat.Account]: Checking registration for " + toString(client.name)); if(isPlayerRegistered(client)) { if(getServerConfig().useGUI && doesPlayerHaveGUIEnabled(client)) { @@ -706,11 +706,11 @@ function isValidEmailAddress(emailAddress) { // --------------------------------------------------------------------------- function saveAllClientsToDatabase() { - console.log("[Asshat.Account]: Saving all clients to database ..."); + logToConsole(LOG_DEBUG, "[Asshat.Account]: Saving all clients to database ..."); getClients().forEach(function(client) { savePlayerToDatabase(client); }); - console.log("[Asshat.Account]: All clients saved to database successfully!"); + logToConsole(LOG_DEBUG, "[Asshat.Account]: All clients saved to database successfully!"); } // --------------------------------------------------------------------------- @@ -724,7 +724,7 @@ function savePlayerToDatabase(client) { return false; } - console.log(`[Asshat.Account]: Saving client ${client.name} to database ...`); + logToConsole(LOG_DEBUG, `[Asshat.Account]: Saving client ${client.name} to database ...`); saveAccountToDatabase(getPlayerData(client).accountData); if(getPlayerData(client).currentSubAccount != -1) { @@ -739,7 +739,7 @@ function savePlayerToDatabase(client) { saveSubAccountToDatabase(subAccountData); } - console.log(`[Asshat.Account]: Saved client ${getPlayerDisplayForConsole(client)} to database successfully!`); + logToConsole(LOG_DEBUG, `[Asshat.Account]: Saved client ${getPlayerDisplayForConsole(client)} to database successfully!`); return true; } @@ -776,19 +776,19 @@ function initClient(client) { loginSuccess(client); } else { if(getServerConfig().useGUI && doesPlayerHaveGUIEnabled(client)) { - console.log(`[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the login GUI.`); + logToConsole(LOG_DEBUG, `[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the login GUI.`); triggerNetworkEvent("ag.showLogin", client); } else { - console.log(`[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the login message (GUI disabled).`); + logToConsole(LOG_DEBUG, `[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the login message (GUI disabled).`); messageClient(`Welcome back to Asshat Gaming RP, ${client.name}! Please /login to continue.`, client, getColourByName("softGreen")); } } } else { if(getServerConfig().useGUI && doesPlayerHaveGUIEnabled(client)) { - console.log(`[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the register GUI.`); + logToConsole(LOG_DEBUG, `[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the register GUI.`); triggerNetworkEvent("ag.showRegistration", client); } else { - console.log(`[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the register message (GUI disabled).`); + logToConsole(LOG_DEBUG, `[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the register message (GUI disabled).`); messageClient(`Welcome to Asshat Gaming RP, ${client.name}! Please /register to continue.`, client, getColourByName("softGreen")); } } @@ -815,7 +815,7 @@ function createDefaultKeybindsForAccount(accountDatabaseId) { // --------------------------------------------------------------------------- function loadAccountKeybindsFromDatabase(accountDatabaseID) { - console.log(`[Asshat.Account]: Loading account keybinds for account ${accountDatabaseID} from database ...`); + logToConsole(LOG_DEBUG, `[Asshat.Account]: Loading account keybinds for account ${accountDatabaseID} from database ...`); let tempAccountKeybinds = []; let dbConnection = connectToDatabase(); @@ -829,7 +829,7 @@ function loadAccountKeybindsFromDatabase(accountDatabaseID) { while(dbAssoc = fetchQueryAssoc(dbQuery)) { let tempAccountKeyBindData = new serverClasses.keyBindData(dbAssoc); tempAccountKeybinds.push(tempAccountKeyBindData); - console.log(`[Asshat.Account]: Account keybind '${tempAccountKeyBindData.databaseId}' (Key ${tempAccountKeyBindData.key} '${sdl.getKeyName(tempAccountKeyBindData.key)}') loaded from database successfully!`); + logToConsole(LOG_DEBUG, `[Asshat.Account]: Account keybind '${tempAccountKeyBindData.databaseId}' (Key ${tempAccountKeyBindData.key} '${sdl.getKeyName(tempAccountKeyBindData.key)}') loaded from database successfully!`); } } freeDatabaseQuery(dbQuery); @@ -837,14 +837,14 @@ function loadAccountKeybindsFromDatabase(accountDatabaseID) { disconnectFromDatabase(dbConnection); } - console.log(`[Asshat.Account]: ${tempAccountKeybinds.length} account keybinds for account ${accountDatabaseID} loaded from database successfully!`); + logToConsole(LOG_DEBUG, `[Asshat.Account]: ${tempAccountKeybinds.length} account keybinds for account ${accountDatabaseID} loaded from database successfully!`); return tempAccountKeybinds; } // --------------------------------------------------------------------------- function loadAccountStaffNotesFromDatabase(accountDatabaseID) { - console.log(`[Asshat.Account]: Loading account staff notes for account ${accountDatabaseID} from database ...`); + logToConsole(LOG_DEBUG, `[Asshat.Account]: Loading account staff notes for account ${accountDatabaseID} from database ...`); let tempAccountStaffNotes = []; let dbConnection = connectToDatabase(); @@ -858,7 +858,7 @@ function loadAccountStaffNotesFromDatabase(accountDatabaseID) { while(dbAssoc = fetchQueryAssoc(dbQuery)) { let tempAccountStaffNoteData = new serverClasses.accountStaffNoteData(dbAssoc); tempAccountStaffNotes.push(tempAccountStaffNoteData); - console.log(`[Asshat.Account]: Account staff note '${tempAccountStaffNoteData.databaseId}' loaded from database successfully!`); + logToConsole(LOG_DEBUG, `[Asshat.Account]: Account staff note '${tempAccountStaffNoteData.databaseId}' loaded from database successfully!`); } } freeDatabaseQuery(dbQuery); @@ -866,14 +866,14 @@ function loadAccountStaffNotesFromDatabase(accountDatabaseID) { disconnectFromDatabase(dbConnection); } - console.log(`[Asshat.Account]: ${tempAccountStaffNotes.length} account staff notes for account ${accountDatabaseID} loaded from database successfully!`); + logToConsole(LOG_DEBUG, `[Asshat.Account]: ${tempAccountStaffNotes.length} account staff notes for account ${accountDatabaseID} loaded from database successfully!`); return tempAccountStaffNotes; } // --------------------------------------------------------------------------- function loadAccountContactsFromDatabase(accountDatabaseID) { - console.log(`[Asshat.Account]: Loading account contacts for account ${accountDatabaseID} from database ...`); + logToConsole(LOG_DEBUG, `[Asshat.Account]: Loading account contacts for account ${accountDatabaseID} from database ...`); let tempAccountContacts = []; let dbConnection = connectToDatabase(); @@ -887,7 +887,7 @@ function loadAccountContactsFromDatabase(accountDatabaseID) { while(dbAssoc = fetchQueryAssoc(dbQuery)) { let tempAccountContactData = new serverClasses.accountContactData(dbAssoc); tempAccountContacts.push(tempAccountContactData); - console.log(`[Asshat.Account]: Account contact '${tempAccountContactData.databaseId}' loaded from database successfully!`); + logToConsole(LOG_DEBUG, `[Asshat.Account]: Account contact '${tempAccountContactData.databaseId}' loaded from database successfully!`); } } freeDatabaseQuery(dbQuery); @@ -895,14 +895,14 @@ function loadAccountContactsFromDatabase(accountDatabaseID) { disconnectFromDatabase(dbConnection); } - console.log(`[Asshat.Account]: ${tempAccountContacts.length} account contacts for account ${accountDatabaseID} loaded from database successfully!`); + logToConsole(LOG_DEBUG, `[Asshat.Account]: ${tempAccountContacts.length} account contacts for account ${accountDatabaseID} loaded from database successfully!`); return tempAccountContacts; } // --------------------------------------------------------------------------- function loadAccountMessagesFromDatabase(accountDatabaseID) { - console.log(`[Asshat.Account]: Loading account messages for account ${accountDatabaseID} from database ...`); + logToConsole(LOG_DEBUG, `[Asshat.Account]: Loading account messages for account ${accountDatabaseID} from database ...`); let tempAccountMessages = []; let dbConnection = connectToDatabase(); @@ -916,7 +916,7 @@ function loadAccountMessagesFromDatabase(accountDatabaseID) { while(dbAssoc = fetchQueryAssoc(dbQuery)) { let tempAccountMessageData = new serverClasses.accountContactData(dbAssoc); tempAccountMessages.push(tempAccountMessageData); - console.log(`[Asshat.Account]: Account contact '${tempAccountMessageData.databaseId}' loaded from database successfully!`); + logToConsole(LOG_DEBUG, `[Asshat.Account]: Account contact '${tempAccountMessageData.databaseId}' loaded from database successfully!`); } } freeDatabaseQuery(dbQuery); @@ -924,7 +924,7 @@ function loadAccountMessagesFromDatabase(accountDatabaseID) { disconnectFromDatabase(dbConnection); } - console.log(`[Asshat.Account]: ${tempAccountMessages.length} account messages for account ${accountDatabaseID} loaded from database successfully!`); + logToConsole(LOG_DEBUG, `[Asshat.Account]: ${tempAccountMessages.length} account messages for account ${accountDatabaseID} loaded from database successfully!`); return tempAccountMessages; } diff --git a/scripts/server/anticheat.js b/scripts/server/anticheat.js index 9cf91bf2..84e57049 100644 --- a/scripts/server/anticheat.js +++ b/scripts/server/anticheat.js @@ -9,15 +9,15 @@ // =========================================================================== function initAntiCheatScript() { - console.log("[Asshat.AntiCheat]: Initializing anticheat script ..."); + logToConsole(LOG_DEBUG, "[Asshat.AntiCheat]: Initializing anticheat script ..."); getServerData().antiCheat.whiteListedGameScripts = loadAntiCheatGameScriptWhiteListFromDatabase(); getServerData().antiCheat.blackListedGameScripts = loadAntiCheatGameScriptBlackListFromDatabase(); - console.log("[Asshat.AntiCheat]: Anticheat script initialized!"); + logToConsole(LOG_DEBUG, "[Asshat.AntiCheat]: Anticheat script initialized!"); } // --------------------------------------------------------------------------- function loadAntiCheatGameScriptWhiteListFromDatabase() { - console.log(`[Asshat.AntiCheat] Loading whitelisted game scripts ...`); + logToConsole(LOG_DEBUG, `[Asshat.AntiCheat] Loading whitelisted game scripts ...`); let dbConnection = connectToDatabase(); let tempWhiteListedGameScripts = []; @@ -29,19 +29,19 @@ function loadAntiCheatGameScriptWhiteListFromDatabase() { let dbAssoc = fetchQueryAssoc(dbQuery); let tempWhiteListedGameScriptData = new serverClasses.whiteListedGameScriptData(dbAssoc); tempWhiteListedGameScripts.push(tempWhiteListedGameScriptData); - console.log(`[Asshat.AntiCheat] Whitelisted game script '${tempWhiteListedGameScriptData.scriptName}' loaded successfully!`); + logToConsole(LOG_DEBUG, `[Asshat.AntiCheat] Whitelisted game script '${tempWhiteListedGameScriptData.scriptName}' loaded successfully!`); } } disconnectFromDatabase(dbConnection); } - console.log(`[Asshat.AntiCheat] ${tempWhiteListedGameScripts.length} whitelisted game scripts loaded!`); + logToConsole(LOG_DEBUG, `[Asshat.AntiCheat] ${tempWhiteListedGameScripts.length} whitelisted game scripts loaded!`); return tempWhiteListedGameScripts; } // --------------------------------------------------------------------------- function loadAntiCheatGameScriptBlackListFromDatabase() { - console.log(`[Asshat.AntiCheat] Loading blacklisted game scripts ...`); + logToConsole(LOG_DEBUG, `[Asshat.AntiCheat] Loading blacklisted game scripts ...`); let dbConnection = connectToDatabase(); let tempBlackListedGameScripts = []; @@ -53,12 +53,12 @@ function loadAntiCheatGameScriptBlackListFromDatabase() { let dbAssoc = fetchQueryAssoc(dbQuery); let tempBlackListedGameScriptData = new serverClasses.blackListedGameScriptData(dbAssoc); tempBlackListedGameScripts.push(tempBlackListedGameScriptData); - console.log(`[Asshat.AntiCheat] Blacklisted game script '${tempBlackListedGameScriptData.scriptName}' loaded successfully!`); + logToConsole(LOG_DEBUG, `[Asshat.AntiCheat] Blacklisted game script '${tempBlackListedGameScriptData.scriptName}' loaded successfully!`); } } disconnectFromDatabase(dbConnection); } - console.log(`[Asshat.AntiCheat] ${tempBlackListedGameScripts.length} blacklisted game scripts loaded!`); + logToConsole(LOG_DEBUG, `[Asshat.AntiCheat] ${tempBlackListedGameScripts.length} blacklisted game scripts loaded!`); return tempBlackListedGameScripts; } diff --git a/scripts/server/ban.js b/scripts/server/ban.js index ebf93416..a88fb750 100644 --- a/scripts/server/ban.js +++ b/scripts/server/ban.js @@ -19,13 +19,13 @@ const banType = { // --------------------------------------------------------------------------- function initBanScript() { - console.log("[Asshat.Ban]: Initializing ban script ..."); - console.log("[Asshat.Ban]: Ban script initialized!"); + logToConsole(LOG_DEBUG, "[Asshat.Ban]: Initializing ban script ..."); + logToConsole(LOG_DEBUG, "[Asshat.Ban]: Ban script initialized!"); } // --------------------------------------------------------------------------- -function accountBanCommand(command, params, client, fromDiscord) { +function accountBanCommand(command, params, client) { if(areParamsEmpty(params)) { messagePlayerSyntax(client, getCommandSyntaxText(command)); return false; @@ -39,7 +39,7 @@ function accountBanCommand(command, params, client, fromDiscord) { messageAdminAction(`${getPlayerData(targetClient).accountData.name} has been banned from the server (account ban).`); banAccount(getPlayerData(targetClient).accountData.databaseId, getPlayerData(client).accountData.databaseId, ""); - targetClient.disconnect(); + disconnectPlayer(client); } // --------------------------------------------------------------------------- @@ -62,7 +62,7 @@ function subAccountBanCommand(command, params, client, fromDiscord) { messageAdminAction(`${getPlayerData(targetClient).currentSubAccountData.name} has been banned from the server (character ban).`); banSubAccount(getPlayerData(targetClient).currentSubAccountData.databaseId, getPlayerData(client).accountData.databaseId, reason); - targetClient.disconnect(); + disconnectPlayer(client); } // --------------------------------------------------------------------------- diff --git a/scripts/server/business.js b/scripts/server/business.js index c5c740db..9bdb0d70 100644 --- a/scripts/server/business.js +++ b/scripts/server/business.js @@ -9,12 +9,12 @@ // =========================================================================== function initBusinessScript() { - console.log("[Asshat.Business]: Initializing business script ..."); + logToConsole(LOG_DEBUG, "[Asshat.Business]: Initializing business script ..."); getServerData().businesses = loadBusinessesFromDatabase(); createAllBusinessPickups(); createAllBusinessBlips(); setAllBusinessIndexes(); - console.log("[Asshat.Business]: Business script initialized successfully!"); + logToConsole(LOG_DEBUG, "[Asshat.Business]: Business script initialized successfully!"); return true; } @@ -39,7 +39,7 @@ function loadBusinessFromId(businessId) { // --------------------------------------------------------------------------- function loadBusinessesFromDatabase() { - console.log("[Asshat.Business]: Loading businesses from database ..."); + logToConsole(LOG_DEBUG, "[Asshat.Business]: Loading businesses from database ..."); let tempBusinesses = []; let dbConnection = connectToDatabase(); @@ -54,7 +54,7 @@ function loadBusinessesFromDatabase() { let tempBusinessData = new serverClasses.businessData(dbAssoc); tempBusinessData.locations = loadBusinessLocationsFromDatabase(tempBusinessData.databaseId); tempBusinesses.push(tempBusinessData); - console.log(`[Asshat.Business]: Business '${tempBusinessData.name}' (ID ${tempBusinessData.databaseId}) loaded from database successfully!`); + logToConsole(LOG_DEBUG, `[Asshat.Business]: Business '${tempBusinessData.name}' (ID ${tempBusinessData.databaseId}) loaded from database successfully!`); } } freeDatabaseQuery(dbQuery); @@ -62,14 +62,14 @@ function loadBusinessesFromDatabase() { disconnectFromDatabase(dbConnection); } - console.log(`[Asshat.Business]: ${tempBusinesses.length} businesses loaded from database successfully!`); + logToConsole(LOG_DEBUG, `[Asshat.Business]: ${tempBusinesses.length} businesses loaded from database successfully!`); return tempBusinesses; } // --------------------------------------------------------------------------- function loadBusinessLocationsFromDatabase(businessId) { - //console.log("[Asshat.Business]: Loading locations from database ..."); + //logToConsole(LOG_DEBUG, "[Asshat.Business]: Loading locations from database ..."); let tempBusinessLocations = []; let dbConnection = connectToDatabase(); @@ -83,7 +83,7 @@ function loadBusinessLocationsFromDatabase(businessId) { while(dbAssoc = fetchQueryAssoc(dbQuery)) { let tempBusinessLocationData = new serverClasses.businessLocationData(dbAssoc); tempBusinessLocations.push(tempBusinessLocationData); - //console.log(`[Asshat.Business]: Location '${tempBusinessLocationData.name}' loaded from database successfully!`); + //logToConsole(LOG_DEBUG, `[Asshat.Business]: Location '${tempBusinessLocationData.name}' loaded from database successfully!`); } } freeDatabaseQuery(dbQuery); @@ -91,7 +91,7 @@ function loadBusinessLocationsFromDatabase(businessId) { disconnectFromDatabase(dbConnection); } - //console.log(`[Asshat.Business]: ${tempBusinessLocations.length} location for business ${businessId} loaded from database successfully!`); + //logToConsole(LOG_DEBUG, `[Asshat.Business]: ${tempBusinessLocations.length} location for business ${businessId} loaded from database successfully!`); return tempBusinessLocations; } @@ -666,7 +666,7 @@ function buySkinFromBusinessCommand(command, params, client) { return false; } - if(getBusinessData(businessId).type == AG_BIZTYPE_CLOTHES) { + if(getBusinessData(businessId).type == getGlobalConfig().buySkinPrice) { messagePlayerError(client, `This business doesn't sell clothes (skins)!`); return false; } @@ -734,7 +734,7 @@ function saveAllBusinessesToDatabase() { function saveBusinessToDatabase(businessId) { let tempBusinessData = getServerData().businesses[businessId] - console.log(`[Asshat.Business]: Saving business '${tempBusinessData.name}' to database ...`); + logToConsole(LOG_DEBUG, `[Asshat.Business]: Saving business '${tempBusinessData.name}' to database ...`); let dbConnection = connectToDatabase(); if(dbConnection) { let safeBusinessName = escapeDatabaseString(dbConnection, tempBusinessData.name); @@ -749,7 +749,7 @@ function saveBusinessToDatabase(businessId) { disconnectFromDatabase(dbConnection); return true; } - console.log(`[Asshat.Business]: Saved business '${tempBusinessData.name}' to database!`); + logToConsole(LOG_DEBUG, `[Asshat.Business]: Saved business '${tempBusinessData.name}' to database!`); return false; } @@ -1053,4 +1053,10 @@ function addToBusinessInventory(businessId, itemType, amount, buyPrice) { getServerData().items[index].index = index; } +// --------------------------------------------------------------------------- + +function buyFromBusinessCommand(command, params, client) { + +} + // --------------------------------------------------------------------------- \ No newline at end of file diff --git a/scripts/server/chat.js b/scripts/server/chat.js index 788dd6ea..2669140d 100644 --- a/scripts/server/chat.js +++ b/scripts/server/chat.js @@ -9,8 +9,8 @@ // =========================================================================== function initChatScript() { - console.log("[Asshat.Chat]: Initializing chat script ..."); - console.log("[Asshat.Chat]: Chat script initialized successfully!"); + logToConsole(LOG_DEBUG, "[Asshat.Chat]: Initializing chat script ..."); + logToConsole(LOG_DEBUG, "[Asshat.Chat]: Chat script initialized successfully!"); return true; } diff --git a/scripts/server/clan.js b/scripts/server/clan.js index de3196b9..0b450811 100644 --- a/scripts/server/clan.js +++ b/scripts/server/clan.js @@ -9,17 +9,17 @@ // =========================================================================== function initClanScript() { - console.log("[Asshat.Clan]: Initializing clans script ..."); + logToConsole(LOG_DEBUG, "[Asshat.Clan]: Initializing clans script ..."); getServerData().clans = loadClansFromDatabase(); setAllClanDataIndexes(); - console.log("[Asshat.Clan]: Clan script initialized successfully!"); + logToConsole(LOG_DEBUG, "[Asshat.Clan]: Clan script initialized successfully!"); return true; } // --------------------------------------------------------------------------- function loadClansFromDatabase() { - console.log("[Asshat.Clan]: Loading clans from database ..."); + logToConsole(LOG_DEBUG, "[Asshat.Clan]: Loading clans from database ..."); let tempClans = []; let dbConnection = connectToDatabase(); @@ -34,7 +34,7 @@ function loadClansFromDatabase() { tempClanData.members = loadClanMembersFromDatabase(tempClanData.databaseId); tempClanData.ranks = loadClanRanksFromDatabase(tempClanData.databaseId); tempClans.push(tempClanData); - console.log(`[Asshat.Clan]: Clan '${tempClanData.name}' loaded from database successfully!`); + logToConsole(LOG_DEBUG, `[Asshat.Clan]: Clan '${tempClanData.name}' loaded from database successfully!`); } } freeDatabaseQuery(dbQuery); @@ -42,7 +42,7 @@ function loadClansFromDatabase() { disconnectFromDatabase(dbConnection); } - console.log(`[Asshat.Clan]: ${tempClans.length} clans loaded from database successfully!`); + logToConsole(LOG_DEBUG, `[Asshat.Clan]: ${tempClans.length} clans loaded from database successfully!`); return tempClans; } diff --git a/scripts/server/client.js b/scripts/server/client.js index 0226976f..31804db3 100644 --- a/scripts/server/client.js +++ b/scripts/server/client.js @@ -94,7 +94,7 @@ function updatePlayerPing(client) { // --------------------------------------------------------------------------- addNetworkHandler("ag.arrivedAtBusStop", function(client) { - console.log(client); + logToConsole(LOG_DEBUG, client); arrivedAtBusStop(client); }); @@ -102,7 +102,7 @@ addNetworkHandler("ag.arrivedAtBusStop", function(client) { addNetworkHandler("ag.clientReady", function(client) { client.setData("ag.isReady", true, false); - console.log(`${getPlayerDisplayForConsole(client)}'s client resources are downloaded and ready!`); + logToConsole(LOG_DEBUG, `${getPlayerDisplayForConsole(client)}'s client resources are downloaded and ready!`); if(client.getData("ag.isStarted") == true) { initClient(client); } @@ -112,14 +112,14 @@ addNetworkHandler("ag.clientReady", function(client) { addNetworkHandler("ag.guiReady", function(client) { client.setData("ag.guiReady", true, false); - console.log(`${getPlayerDisplayForConsole(client)}'s client GUI is initialized and ready!`); + logToConsole(LOG_DEBUG, `${getPlayerDisplayForConsole(client)}'s client GUI is initialized and ready!`); }); // --------------------------------------------------------------------------- addNetworkHandler("ag.clientStarted", function(client) { client.setData("ag.isStarted", true, false); - console.log(`${getPlayerDisplayForConsole(client)}'s client resources are started and running!`); + logToConsole(LOG_DEBUG, `${getPlayerDisplayForConsole(client)}'s client resources are started and running!`); if(client.getData("ag.isReady") == true) { initClient(client); } @@ -146,7 +146,7 @@ function disableCityAmbienceForPlayer(client) { // --------------------------------------------------------------------------- function clearPlayerOwnedPeds(client) { - console.log(`[Asshat.Utilities] Clearing peds owned by ${getPlayerDisplayForConsole(client)}`); + logToConsole(LOG_DEBUG, `[Asshat.Utilities] Clearing peds owned by ${getPlayerDisplayForConsole(client)}`); triggerNetworkEvent("ag.clearPeds", client); } diff --git a/scripts/server/developer.js b/scripts/server/developer.js index d9866850..608a4dfa 100644 --- a/scripts/server/developer.js +++ b/scripts/server/developer.js @@ -9,7 +9,7 @@ // =========================================================================== function initDeveloperScript() { - console.log("[Asshat.Developer]: Initializing developer script ..."); + logToConsole(LOG_DEBUG, "[Asshat.Developer]: Initializing developer script ..."); // Use GTAC command handlers for these since they need to be available on console addCommandHandler("sc", executeServerCodeCommand); @@ -17,7 +17,7 @@ function initDeveloperScript() { addCommandHandler("docmd", simulateCommandForPlayer); addCommandHandler("allcmd", simulateCommandForAllPlayers); - console.log("[Asshat.Developer]: Developer script initialized successfully!"); + logToConsole(LOG_DEBUG, "[Asshat.Developer]: Developer script initialized successfully!"); return true; } diff --git a/scripts/server/event.js b/scripts/server/event.js index 660bb55f..23f6d954 100644 --- a/scripts/server/event.js +++ b/scripts/server/event.js @@ -11,16 +11,16 @@ // --------------------------------------------------------------------------- function initEventScript() { - console.log("[Asshat.Event]: Initializing event script ..."); + logToConsole(LOG_DEBUG, "[Asshat.Event]: Initializing event script ..."); addNetworkHandler("ag.onPlayerEnterVehicle", playerEnteredVehicle); addNetworkHandler("ag.onPlayerExitVehicle", playerExitedVehicle); - console.log("[Asshat.Event]: Event script initialized!"); + logToConsole(LOG_DEBUG, "[Asshat.Event]: Event script initialized!"); } // --------------------------------------------------------------------------- addEventHandler("OnPlayerConnect", function(event, ipAddress, port) { - console.log(`[Asshat.Event] Client connecting (IP: ${ipAddress})`); + logToConsole(LOG_DEBUG, `[Asshat.Event] Client connecting (IP: ${ipAddress})`); if(isIpAddressBanned(ipAddress)) { messagePlayerError(client, "You are banned from this server!"); return false; @@ -42,7 +42,7 @@ addEventHandler("OnPlayerJoined", function(event, client) { // --------------------------------------------------------------------------- addEventHandler("OnPlayerQuit", function(event, client, quitReasonId) { - console.log(`[Asshat.Event] ${getPlayerDisplayForConsole(client)} disconnected (${disconnectReasons[quitReasonId]}[${quitReasonId}])`); + logToConsole(LOG_DEBUG, `[Asshat.Event] ${getPlayerDisplayForConsole(client)} disconnected (${disconnectReasons[quitReasonId]}[${quitReasonId}])`); //savePlayerToDatabase(client); resetClientStuff(client); @@ -157,7 +157,7 @@ async function playerEnteredVehicle(client) { return false; } - console.log(`[Asshat.Event] ${getPlayerDisplayForConsole(client)} entered a ${getVehicleName(vehicle)} (ID: ${vehicle.getData("ag.dataSlot")}, Database ID: ${getVehicleData(vehicle).databaseId})`); + logToConsole(LOG_DEBUG, `[Asshat.Event] ${getPlayerDisplayForConsole(client)} entered a ${getVehicleName(vehicle)} (ID: ${vehicle.getData("ag.dataSlot")}, Database ID: ${getVehicleData(vehicle).databaseId})`); getPlayerData(client).lastVehicle = vehicle; @@ -213,7 +213,7 @@ function playerExitedVehicle(client) { return false; } - console.log(`[Asshat.Event] ${getPlayerDisplayForConsole(client)} exited a ${getVehicleName(vehicle)} (ID: ${vehicle.getData("ag.dataSlot")}, Database ID: ${getVehicleData(vehicle).databaseId})`); + logToConsole(LOG_DEBUG, `[Asshat.Event] ${getPlayerDisplayForConsole(client)} exited a ${getVehicleName(vehicle)} (ID: ${vehicle.getData("ag.dataSlot")}, Database ID: ${getVehicleData(vehicle).databaseId})`); if(isPlayerWorking(client)) { if(isPlayerOnJobRoute(client)) { diff --git a/scripts/server/house.js b/scripts/server/house.js index 042d1229..af6619ae 100644 --- a/scripts/server/house.js +++ b/scripts/server/house.js @@ -9,19 +9,19 @@ // =========================================================================== function initHouseScript() { - console.log("[Asshat.House]: Initializing house script ..."); + logToConsole(LOG_DEBUG, "[Asshat.House]: Initializing house script ..."); getServerData().houses = loadHousesFromDatabase(); createAllHousePickups(); createAllHouseBlips(); setAllHouseIndexes(); - console.log("[Asshat.House]: House script initialized successfully!"); + logToConsole(LOG_DEBUG, "[Asshat.House]: House script initialized successfully!"); return true; } // --------------------------------------------------------------------------- function loadHousesFromDatabase() { - console.log("[Asshat.House]: Loading houses from database ..."); + logToConsole(LOG_DEBUG, "[Asshat.House]: Loading houses from database ..."); let tempHouses = []; let dbConnection = connectToDatabase(); let dbAssoc; @@ -33,14 +33,14 @@ function loadHousesFromDatabase() { while(dbAssoc = fetchQueryAssoc(dbQuery)) { let tempHouseData = new serverClasses.houseData(dbAssoc); tempHouses.push(tempHouseData); - console.log(`[Asshat.House]: House '${tempHouseData.description}' (ID ${tempHouseData.databaseId}) loaded!`); + logToConsole(LOG_DEBUG, `[Asshat.House]: House '${tempHouseData.description}' (ID ${tempHouseData.databaseId}) loaded!`); } } freeDatabaseQuery(dbQuery); } disconnectFromDatabase(dbConnection); } - console.log(`[Asshat.House]: ${tempHouses.length} houses loaded from database successfully!`); + logToConsole(LOG_DEBUG, `[Asshat.House]: ${tempHouses.length} houses loaded from database successfully!`); return tempHouses; } @@ -417,7 +417,7 @@ function saveAllHousesToDatabase() { function saveHouseToDatabase(houseId) { let tempHouseData = getServerData().houses[houseId]; - console.log(`[Asshat.House]: Saving house '${tempHouseData.databaseId}' to database ...`); + logToConsole(LOG_DEBUG, `[Asshat.House]: Saving house '${tempHouseData.databaseId}' to database ...`); let dbConnection = connectToDatabase(); if(dbConnection) { let safeHouseDescription = escapeDatabaseString(dbConnection, tempHouseData.description); @@ -432,7 +432,7 @@ function saveHouseToDatabase(houseId) { disconnectFromDatabase(dbConnection); return true; } - console.log(`[Asshat.house]: Saved house '${tempHouseData.description}' to database!`); + logToConsole(LOG_DEBUG, `[Asshat.house]: Saved house '${tempHouseData.description}' to database!`); return false; } diff --git a/scripts/server/keybind.js b/scripts/server/keybind.js index 8e16c985..e0b27fff 100644 --- a/scripts/server/keybind.js +++ b/scripts/server/keybind.js @@ -129,8 +129,8 @@ let bindableKeys = { // --------------------------------------------------------------------------- function initKeyBindScript() { - console.log("[Asshat.KeyBind]: Initializing key bind script ..."); - console.log("[Asshat.KeyBind]: Key bind script initialized!"); + logToConsole(LOG_DEBUG, "[Asshat.KeyBind]: Initializing key bind script ..."); + logToConsole(LOG_DEBUG, "[Asshat.KeyBind]: Key bind script initialized!"); } // --------------------------------------------------------------------------- @@ -265,7 +265,7 @@ function playerUsedKeyBind(client, key) { return false; } - console.log(`[Asshat.KeyBind] ${getPlayerDisplayForConsole(client)} used keybind ${sdl.getKeyName(key)} (${key})`); + logToConsole(LOG_DEBUG, `[Asshat.KeyBind] ${getPlayerDisplayForConsole(client)} used keybind ${sdl.getKeyName(key)} (${key})`); if(doesPlayerHaveKeyBindForKey(client, key)) { let keyBindData = getPlayerKeyBindForKey(client, key); if(keyBindData.enabled) { diff --git a/scripts/server/messaging.js b/scripts/server/messaging.js index 40580225..14452970 100644 --- a/scripts/server/messaging.js +++ b/scripts/server/messaging.js @@ -21,7 +21,7 @@ function messageAdminAction(messageText) { function messagePlayerNormal(client, messageText, colour = COLOUR_WHITE) { if(isConsole(client)) { - console.log(`[Asshat.Messaging] ${messageText}`); + logToConsole(LOG_DEBUG, `[Asshat.Messaging] ${messageText}`); return true; } @@ -38,7 +38,7 @@ function messageAdmins(messageText, colour = COLOUR_WHITE) { let clients = getClients(); for(let i in clients) { if(clients[i].console) { - console.log(`[Asshat.Messaging] 🛡️ ${messageText}`); + logToConsole(LOG_DEBUG, `[Asshat.Messaging] 🛡️ ${messageText}`); } else { if(doesPlayerHaveStaffPermission(clients[i], getStaffFlagValue("basicModeration"))) { messageClient(`🛡️ ${messageText}`, clients[i], getColourByName("softRed")); @@ -52,7 +52,7 @@ function messageAdmins(messageText, colour = COLOUR_WHITE) { function messagePlayerError(client, messageText) { if(isConsole(client)) { - console.log(`[Asshat.Messaging] ERROR: ${messageText}`); + logToConsole(LOG_DEBUG, `[Asshat.Messaging] ERROR: ${messageText}`); return true; } @@ -67,7 +67,7 @@ function messagePlayerError(client, messageText) { function messagePlayerSyntax(client, messageText) { if(isConsole(client)) { - console.log(`[Asshat.Messaging] USAGE: ${messageText}`); + logToConsole(LOG_DEBUG, `[Asshat.Messaging] USAGE: ${messageText}`); return true; } @@ -82,7 +82,7 @@ function messagePlayerSyntax(client, messageText) { function messagePlayerAlert(client, messageText) { if(isConsole(client)) { - console.log(`[Asshat.Messaging] ALERT: ${messageText}`); + logToConsole(LOG_DEBUG, `[Asshat.Messaging] ALERT: ${messageText}`); return true; } @@ -97,7 +97,7 @@ function messagePlayerAlert(client, messageText) { function messagePlayerSuccess(client, messageText) { if(isConsole(client)) { - console.log(`[Asshat.Messaging] SUCCESS: ${messageText}`); + logToConsole(LOG_DEBUG, `[Asshat.Messaging] SUCCESS: ${messageText}`); return true; } @@ -112,7 +112,7 @@ function messagePlayerSuccess(client, messageText) { function messagePlayerInfo(client, messageText) { if(isConsole(client)) { - console.log(`[INFO] ${messageText}`); + logToConsole(LOG_DEBUG, `[INFO] ${messageText}`); return true; } @@ -127,7 +127,7 @@ function messagePlayerInfo(client, messageText) { function messagePlayerTip(client, messageText) { if(isConsole(client)) { - console.log(`[TIP] ${messageText}`); + logToConsole(LOG_DEBUG, `[TIP] ${messageText}`); return true; } diff --git a/scripts/server/misc.js b/scripts/server/misc.js index 3cb03e59..54947f1c 100644 --- a/scripts/server/misc.js +++ b/scripts/server/misc.js @@ -11,8 +11,8 @@ // --------------------------------------------------------------------------- function initMiscScript() { - console.log("[Asshat.Misc]: Initializing misc script ..."); - console.log("[Asshat.Misc]: Misc script initialized successfully!"); + logToConsole(LOG_DEBUG, "[Asshat.Misc]: Initializing misc script ..."); + logToConsole(LOG_DEBUG, "[Asshat.Misc]: Misc script initialized successfully!"); return true; } @@ -22,7 +22,7 @@ function getPositionCommand(command, params, client) { let position = client.player.position; messagePlayerNormal(client, `Your position is: ${position.x.toFixed(2)}, ${position.y.toFixed(2)}, ${position.z.toFixed(2)}`); - console.log(`${getPlayerDisplayForConsole(client)}'s position is: ${position.x.toFixed(2)}, ${position.y.toFixed(2)}, ${position.z.toFixed(2)}`); + logToConsole(LOG_DEBUG, `${getPlayerDisplayForConsole(client)}'s position is: ${position.x.toFixed(2)}, ${position.y.toFixed(2)}, ${position.z.toFixed(2)}`); return true; } @@ -172,7 +172,7 @@ function enterExitPropertyCommand(command, params, client) { }, 1000); }, 1100); removeEntityData(client, "ag.inBusiness"); - console.log(`[Asshat.Misc] ${getPlayerDisplayForConsole(client)} entered business ${inBusiness.name}[${inBusiness.index}/${inBusiness.databaseId}]`); + logToConsole(LOG_DEBUG, `[Asshat.Misc] ${getPlayerDisplayForConsole(client)} entered business ${inBusiness.name}[${inBusiness.index}/${inBusiness.databaseId}]`); } return true; } @@ -253,7 +253,7 @@ function enterExitPropertyCommand(command, params, client) { function sendRemovedWorldObjectsToPlayer(client) { for(let i in getGameConfig().removedWorldObjects[getServerGame()]) { - console.log(`[Asshat.Misc] Sending removed world object ${i} (${getGameConfig().removedWorldObjects[getServerGame()][i].model}) to ${client.name}`); + logToConsole(LOG_DEBUG, `[Asshat.Misc] Sending removed world object ${i} (${getGameConfig().removedWorldObjects[getServerGame()][i].model}) to ${client.name}`); triggerNetworkEvent("ag.removeWorldObject", client, getGameConfig().removedWorldObjects[getServerGame()][i].model, getGameConfig().removedWorldObjects[getServerGame()][i].position, getGameConfig().removedWorldObjects[getServerGame()][i].range); } return true; diff --git a/scripts/server/startup.js b/scripts/server/startup.js index 4684e8f3..e8190d3f 100644 --- a/scripts/server/startup.js +++ b/scripts/server/startup.js @@ -68,7 +68,7 @@ function checkForMySQLModule() { // --------------------------------------------------------------------------- function checkForAllRequiredModules() { - console.log("[Asshat.Startup]: Checking for required modules ..."); + logToConsole(LOG_DEBUG, "[Asshat.Startup]: Checking for required modules ..."); if(!checkForHashingModule()) { console.warn("[Asshat.Startup]: Hashing module is not loaded!"); @@ -82,7 +82,7 @@ function checkForAllRequiredModules() { thisResource.stop(); } - console.log("[Asshat.Startup]: All required modules loaded!"); + logToConsole(LOG_DEBUG, "[Asshat.Startup]: All required modules loaded!"); return true; } diff --git a/scripts/server/subaccount.js b/scripts/server/subaccount.js index 764c6bd3..e804cdf5 100644 --- a/scripts/server/subaccount.js +++ b/scripts/server/subaccount.js @@ -9,8 +9,8 @@ // =========================================================================== function initSubAccountScript() { - console.log("[Asshat.SubAccount]: Initializing subaccount script ..."); - console.log("[Asshat.SubAccount]: SubAccount script initialized!"); + logToConsole(LOG_DEBUG, "[Asshat.SubAccount]: Initializing subaccount script ..."); + logToConsole(LOG_DEBUG, "[Asshat.SubAccount]: SubAccount script initialized!"); } // --------------------------------------------------------------------------- @@ -91,7 +91,7 @@ function saveSubAccountToDatabase(subAccountData) { // --------------------------------------------------------------------------- function createSubAccount(accountId, firstName, lastName, skinId, dateOfBirth, placeOfOrigin) { - console.log(`[Asshat.Account] Attempting to create subaccount ${firstName} ${lastName} in database`); + logToConsole(LOG_DEBUG, `[Asshat.Account] Attempting to create subaccount ${firstName} ${lastName} in database`); let dbConnection = connectToDatabase(); if(dbConnection) { @@ -127,7 +127,7 @@ function showCharacterSelectToClient(client) { getPlayerData(client).currentSubAccount = 0; let tempSubAccount = getPlayerData(client).subAccounts[0]; triggerNetworkEvent("ag.showCharacterSelect", client, tempSubAccount.firstName, tempSubAccount.lastName, tempSubAccount.placeOfOrigin, tempSubAccount.dateOfBirth, tempSubAccount.skin); - console.log(`[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the character select GUI`); + logToConsole(LOG_DEBUG, `[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the character select GUI`); } else { //let emojiNumbers = ["➊", "➋", "➌", "➍", "➎", "➏", "➐", "➑", "➒"]; //let emojiNumbers = ["①", "②", "③", "④", "⑤", "⑥", "⑦", "⑧", "⑨"]; @@ -136,7 +136,7 @@ function showCharacterSelectToClient(client) { getPlayerData(client).subAccounts.forEach(function(subAccount, index) { messagePlayerNormal(client, `${index+1} • [#AAAAAA]${subAccount.firstName} ${subAccount.lastName}`); }); - console.log(`[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the character select/list message (GUI disabled)`); + logToConsole(LOG_DEBUG, `[Asshat.Account] ${getPlayerDisplayForConsole(client)} is being shown the character select/list message (GUI disabled)`); } } @@ -230,7 +230,7 @@ function selectCharacter(client, characterId = -1) { getPlayerData(client).currentSubAccount = characterId; } - console.log(`[Asshat.SubAccount] Spawning ${getPlayerDisplayForConsole(client)} with skin ${getPlayerCurrentSubAccount(client).skin}`); + logToConsole(LOG_DEBUG, `[Asshat.SubAccount] Spawning ${getPlayerDisplayForConsole(client)} with skin ${getPlayerCurrentSubAccount(client).skin}`); spawnPlayer(client, getPlayerCurrentSubAccount(client).spawnPosition, getPlayerCurrentSubAccount(client).spawnHeading, getPlayerCurrentSubAccount(client).skin); getPlayerCurrentSubAccount(client).lastLogin = new Date().getTime(); diff --git a/scripts/server/timers.js b/scripts/server/timers.js index e98b8f2e..b74a73a3 100644 --- a/scripts/server/timers.js +++ b/scripts/server/timers.js @@ -19,14 +19,14 @@ function updateTimeRule() { // --------------------------------------------------------------------------- function saveAllServerDataToDatabase() { - console.log("[Asshat.Utilities]: Saving all server data to database ..."); + logToConsole(LOG_DEBUG, "[Asshat.Utilities]: Saving all server data to database ..."); saveAllClansToDatabase(); saveAllHousesToDatabase(); saveAllBusinessesToDatabase(); saveServerConfigToDatabase(getServerConfig()); saveAllVehiclesToDatabase(); saveAllClientsToDatabase(); - console.log("[Asshat.Utilities]: Saved all server data to database!"); + logToConsole(LOG_DEBUG, "[Asshat.Utilities]: Saved all server data to database!"); } // --------------------------------------------------------------------------- diff --git a/scripts/server/translate.js b/scripts/server/translate.js index 4713b665..de4f55ef 100644 --- a/scripts/server/translate.js +++ b/scripts/server/translate.js @@ -161,7 +161,7 @@ async function translateMessage(messageText, translateFrom = defaultLanguageId, return new Promise(resolve => { for(let i in translationCache[translateFrom][translateTo]) { if(translationCache[translateFrom][translateTo][0] == messageText) { - console.log(`[Translate]: Using existing translation for ${translationLanguages[translateFrom][0]} to ${translationLanguages[translateTo][0]} - (${messageText}), (${translationCache[translateFrom][translateTo][1]})`); + logToConsole(LOG_DEBUG, `[Translate]: Using existing translation for ${translationLanguages[translateFrom][0]} to ${translationLanguages[translateTo][0]} - (${messageText}), (${translationCache[translateFrom][translateTo][1]})`); resolve(translationCache[translateFrom][translateTo][1]); } } diff --git a/scripts/server/utilities.js b/scripts/server/utilities.js index c5cc088f..a2a92578 100644 --- a/scripts/server/utilities.js +++ b/scripts/server/utilities.js @@ -1856,7 +1856,7 @@ async function waitUntil(condition) { // ------------------------------------------------------------------------- function resetClientStuff(client) { - console.log(`[Asshat.Utilities] Resetting client data for ${getPlayerDisplayForConsole(client)}`); + logToConsole(LOG_DEBUG, `[Asshat.Utilities] Resetting client data for ${getPlayerDisplayForConsole(client)}`); if(!getPlayerData(client)) { return false; @@ -1873,4 +1873,4 @@ function resetClientStuff(client) { getPlayerData(client).lastVehicle = null; } -// ------------------------------------------------------------------------- +// ------------------------------------------------------------------------- \ No newline at end of file diff --git a/scripts/server/vehicle.js b/scripts/server/vehicle.js index 1c281202..58760023 100644 --- a/scripts/server/vehicle.js +++ b/scripts/server/vehicle.js @@ -9,17 +9,17 @@ // =========================================================================== function initVehicleScript() { - console.log("[Asshat.Vehicle]: Initializing vehicle script ..."); + logToConsole(LOG_DEBUG, "[Asshat.Vehicle]: Initializing vehicle script ..."); getServerData().vehicles = loadVehiclesFromDatabase(); spawnAllVehicles(); - console.log("[Asshat.Vehicle]: Vehicle script initialized successfully!"); + logToConsole(LOG_DEBUG, "[Asshat.Vehicle]: Vehicle script initialized successfully!"); return true; } // --------------------------------------------------------------------------- function loadVehiclesFromDatabase() { - console.log("[Asshat.Vehicle]: Loading vehicles from database ..."); + logToConsole(LOG_DEBUG, "[Asshat.Vehicle]: Loading vehicles from database ..."); let dbConnection = connectToDatabase(); let tempVehicles = []; let dbAssoc; @@ -36,19 +36,19 @@ function loadVehiclesFromDatabase() { disconnectFromDatabase(dbConnection); } - console.log(`[Asshat.Vehicle]: ${tempVehicles.length} vehicles loaded from database successfully!`); + logToConsole(LOG_DEBUG, `[Asshat.Vehicle]: ${tempVehicles.length} vehicles loaded from database successfully!`); return tempVehicles; } // --------------------------------------------------------------------------- function saveAllVehiclesToDatabase() { - console.log("[Asshat.Vehicle]: Saving all vehicles to database ..."); + logToConsole(LOG_DEBUG, "[Asshat.Vehicle]: Saving all vehicles to database ..."); let vehicles = getServerData().vehicles; for(let i in vehicles) { saveVehicleToDatabase(vehicles[i]); } - console.log("[Asshat.Vehicle]: Saved all vehicles to database!"); + logToConsole(LOG_DEBUG, "[Asshat.Vehicle]: Saved all vehicles to database!"); return true; } @@ -66,7 +66,7 @@ function saveVehicleToDatabase(vehicleData) { return false; } - console.log(`[Asshat.Vehicle]: Saving vehicle ${vehicleData.databaseId} to database ...`); + logToConsole(LOG_DEBUG, `[Asshat.Vehicle]: Saving vehicle ${vehicleData.databaseId} to database ...`); let dbConnection = connectToDatabase(); if(dbConnection) { if(!vehicleData.spawnLocked) { @@ -91,7 +91,7 @@ function saveVehicleToDatabase(vehicleData) { disconnectFromDatabase(dbConnection); return true; } - console.log(`[Asshat.Vehicle]: Saved vehicle ${vehicleData.vehicle.id} to database!`); + logToConsole(LOG_DEBUG, `[Asshat.Vehicle]: Saved vehicle ${vehicleData.vehicle.id} to database!`); return false; } diff --git a/scripts/shared/native.js b/scripts/shared/native.js index e8e8f2a7..f6e498ad 100644 --- a/scripts/shared/native.js +++ b/scripts/shared/native.js @@ -114,4 +114,22 @@ function isConsole(client) { return client.console; } +// --------------------------------------------------------------------------- + +function logToConsole(tempLogLevel, text) { + if(logLevel & tempLogLevel) { + if(tempLogLevel == LOG_ERROR) { + console.error(text); + } else if(tempLogLevel == LOG_WARN) { + console.warn(text); + } else { + console.log(text); + } + + return true; + } + + return false; +} + // --------------------------------------------------------------------------- \ No newline at end of file diff --git a/third-party/mexui/Core/Native.js b/third-party/mexui/Core/Native.js index 55c24764..e3a2a96e 100644 --- a/third-party/mexui/Core/Native.js +++ b/third-party/mexui/Core/Native.js @@ -6,10 +6,10 @@ mexui.native.loadImage = function(imageFilePath, imageName) var file = openFile(imageFilePath); if(!file) { - console.log('ERROR [IMAGE LOAD] - Opening File: '+imageFilePath); + logToConsole(LOG_DEBUG, 'ERROR [IMAGE LOAD] - Opening File: '+imageFilePath); return false; } - + var image = null; var parts = imageFilePath.split('.'); var ext = parts[parts.length - 1].toLowerCase(); @@ -19,22 +19,22 @@ mexui.native.loadImage = function(imageFilePath, imageName) image = graphics.loadBMP(file); else { - console.log('ERROR [IMAGE LOAD] - Unsupported image file path extension. Currently only supports PNG or BMP.'); + logToConsole(LOG_DEBUG, 'ERROR [IMAGE LOAD] - Unsupported image file path extension. Currently only supports PNG or BMP.'); return false; } - + if(!image) { file.close(); - console.log('ERROR [IMAGE LOAD] - Reading File: '+imageFilePath); + logToConsole(LOG_DEBUG, 'ERROR [IMAGE LOAD] - Reading File: '+imageFilePath); return false; } - + file.close(); - + if(imageName) mexui.images[imageName] = image; - + return image; }; @@ -42,17 +42,17 @@ mexui.native.loadImage = function(imageFilePath, imageName) mexui.native.getFont = function(textSize, textFont) { var textSizeStr = textSize + ''; - + if(!mexui.fonts[textSizeStr]) { mexui.fonts[textSizeStr] = {}; } - + if(!mexui.fonts[textSizeStr][textFont]) { mexui.fonts[textSizeStr][textFont] = lucasFont.createDefaultFont(textSize, textFont); } - + return mexui.fonts[textSizeStr][textFont]; }; @@ -61,12 +61,12 @@ mexui.native.getTextSize = function(text, styles, font) { if(!font) font = mexui.native.getFont(styles.textSize, styles.textFont); - + var size = font.measure(text + '', 10000, styles.textAlign, 0.0, styles.textSize, false, false); - + //if(text[text.length - 1] == ' ') // width += mexui.util.getStringCount(text, ' ') * spaceWidth; - + return size; }; @@ -92,7 +92,7 @@ mexui.native.drawRectangleBackground = function(position, size, styles) var backgroundColour = styles.backgroundColour != null ? styles.backgroundColour : styles.backgroundColor; if(backgroundColour == null || backgroundColour == 'none') return; - + graphics.drawRectangle(null, position, size, backgroundColour, backgroundColour, backgroundColour, backgroundColour); }; @@ -101,29 +101,29 @@ mexui.native.drawRectangleBorder = function(position, size, styles) var borderColour = styles.borderColour || styles.borderColor; if(borderColour == null || borderColour == 'none') return; - + var rightXPosition = position.x + size.x; var bottomYPosition = position.y + size.y; - + var topLeftPosition = new Vec2(position.x, position.y); var topRightPosition = new Vec2(rightXPosition, position.y); var bottomLeftPosition = new Vec2(position.x, bottomYPosition); var bottomRightPosition = new Vec2(rightXPosition, bottomYPosition); - + var original = styles.lineColour; - + styles.lineColour = styles.topBorderColour != null ? styles.topBorderColour : (styles.topBorderColor != null ? styles.topBorderColor : borderColour); mexui.native.drawAALine(topLeftPosition, topRightPosition, styles); - + styles.lineColour = styles.leftBorderColour != null ? styles.leftBorderColour : (styles.leftBorderColor != null ? styles.leftBorderColor : borderColour); mexui.native.drawAALine(topLeftPosition, bottomLeftPosition, styles); - + styles.lineColour = styles.bottomBorderColour != null ? styles.bottomBorderColour : (styles.bottomBorderColor != null ? styles.bottomBorderColor : borderColour); mexui.native.drawAALine(bottomLeftPosition, bottomRightPosition, styles); - + styles.lineColour = styles.rightBorderColour != null ? styles.rightBorderColour : (styles.rightBorderColor != null ? styles.rightBorderColor : borderColour); mexui.native.drawAALine(topRightPosition, bottomRightPosition, styles); - + styles.lineColour = original; }; @@ -132,18 +132,18 @@ mexui.native.drawAALine = function(point1, point2, styles) var lineColour = styles.lineColour != null ? styles.lineColour : styles.lineColor; if(lineColour == null || lineColour == 'none') return; - + graphics.drawRectangle(null, point1, new Vec2((point2.x - point1.x) + styles.lineWeight, (point2.y - point1.y) + styles.lineWeight), lineColour, lineColour, lineColour, lineColour); }; mexui.native.drawText = function(position, size, text, styles) { var font = mexui.native.getFont(styles.textSize, styles.textFont); - + var textHeight = mexui.native.getTextHeight(text, styles, font); var textIndent = styles.textAlign == 0.0 || styles.textAlign == 1.0 ? styles.textIndent : 0; var textPos = new Vec2(position.x + textIndent, position.y + ((size.y - textHeight) / 2.0)); - + font.render(text + '', textPos, size.x, styles.textAlign, 0.0, styles.textSize, styles.textColour != null ? styles.textColour : styles.textColor); };