From 6999661bba408fe2b641ab283c81a545132a0578 Mon Sep 17 00:00:00 2001 From: Vortrex <3858226+VortrexFTW@users.noreply.github.com> Date: Wed, 20 Apr 2022 06:47:54 -0500 Subject: [PATCH] More native utils + move startup stuff into startup.js --- scripts/client/event.js | 16 ++-- scripts/client/native/connected.js | 24 ++++++ scripts/client/utilities.js | 2 +- scripts/server/accent.js | 6 +- scripts/server/account.js | 40 ++++----- scripts/server/ban.js | 18 ++-- scripts/server/business.js | 24 ++---- scripts/server/clan.js | 5 -- scripts/server/client.js | 10 +-- scripts/server/command.js | 2 +- scripts/server/config.js | 1 + scripts/server/core.js | 1 + scripts/server/developer.js | 6 +- scripts/server/discord.js | 2 +- scripts/server/economy.js | 6 +- scripts/server/event.js | 22 ++--- scripts/server/gui.js | 2 +- scripts/server/house.js | 23 ++---- scripts/server/index.js | 1 + scripts/server/item.js | 11 --- scripts/server/job.js | 7 -- scripts/server/locale.js | 2 +- scripts/server/misc.js | 128 +++++++++++++++++++++++------ scripts/server/native/connected.js | 42 +++++++++- scripts/server/npc.js | 14 ++-- scripts/server/race.js | 36 ++++++-- scripts/server/radio.js | 7 +- scripts/server/staff.js | 48 +++++------ scripts/server/startup.js | 56 ++++++++++++- scripts/server/utilities.js | 8 +- 30 files changed, 369 insertions(+), 201 deletions(-) diff --git a/scripts/client/event.js b/scripts/client/event.js index 851028a7..3562fbdb 100644 --- a/scripts/client/event.js +++ b/scripts/client/event.js @@ -163,13 +163,13 @@ function onLocalPlayerEnteredVehicle(event, vehicle, seat) { sendNetworkEventToServer("vrr.onPlayerEnterVehicle", getVehicleForNetworkEvent(vehicle), seat); - if(inVehicleSeat == 0) { - inVehicle.engine = false; - if(!inVehicle.engine) { - parkedVehiclePosition = inVehicle.position; - parkedVehicleHeading = inVehicle.heading; - } - } + //if(inVehicleSeat == 0) { + //setVehicleEngine(vehicle, false); + //if(!inVehicle.engine) { + // parkedVehiclePosition = inVehicle.position; + // parkedVehicleHeading = inVehicle.heading; + //} + //} } // =========================================================================== @@ -182,7 +182,7 @@ function onPedInflictDamage(event, damagedEntity, damagerEntity, weaponId, healt if(damagedEntity.isType(ELEMENT_PLAYER)) { if(damagedEntity == localPlayer) { //if(!weaponDamageEnabled[damagerEntity.name]) { - event.preventDefault(); + preventDefaultEventAction(event); sendNetworkEventToServer("vrr.weaponDamage", damagerEntity.name, weaponId, pedPiece, healthLoss); //} } diff --git a/scripts/client/native/connected.js b/scripts/client/native/connected.js index ba5c4ebc..a3a8c00f 100644 --- a/scripts/client/native/connected.js +++ b/scripts/client/native/connected.js @@ -188,4 +188,28 @@ function doesEntityDataExist(entity, dataName) { return null; } +// =========================================================================== + +function preventDefaultEventAction(event) { + event.preventDefault(); +} + +// =========================================================================== + +function getPlayerId(client) { + return client.index; +} + +// =========================================================================== + +function consolePrint(text) { + console.log(text); +} + +// =========================================================================== + +function getPlayerName(client) { + return client.name; +} + // =========================================================================== \ No newline at end of file diff --git a/scripts/client/utilities.js b/scripts/client/utilities.js index 9c105c4d..c1cbedf0 100644 --- a/scripts/client/utilities.js +++ b/scripts/client/utilities.js @@ -185,7 +185,7 @@ function setLocalPlayerControlState(controlState, cursorState = false) { logToConsole(LOG_DEBUG, `[VRR.Utilities] Setting control state to ${controlState} (Cursor: ${cursorState})`); controlsEnabled = controlState; if(getGame() == VRR_GAME_GTA_III || getGame() == VRR_GAME_GTA_VC) { - game.SET_PLAYER_CONTROL(localClient.index, boolToInt(controlState)); + game.SET_PLAYER_CONTROL(getPlayerId(localClient), boolToInt(controlState)); } if(getGame() != VRR_GAME_GTA_IV) { diff --git a/scripts/server/accent.js b/scripts/server/accent.js index 30697e45..bc78abb4 100644 --- a/scripts/server/accent.js +++ b/scripts/server/accent.js @@ -91,7 +91,7 @@ function getAccentFromParams(params) { function reloadAccentConfigurationCommand(command, params, client) { getGlobalConfig().accents = loadAccentConfig(); - messageAdmins(`${client.name} {MAINCOLOUR}has reloaded the accent list`); + messageAdmins(`{adminRed}${getPlayerName(client)} {MAINCOLOUR}has reloaded the accent list`); } // =========================================================================== @@ -111,7 +111,7 @@ function addAccentCommand(command, params, client) { getGlobalConfig().accents.push(newAccentName); saveAccentConfig(); - messageAdmins(`${client.name}{MAINCOLOUR} added a new accent: ${newAccentName}`); + messageAdmins(`{adminRed}${getPlayerName(client)}{MAINCOLOUR} added a new accent: {ALTCOLOUR}${newAccentName}{MAINCOLOUR}`); } // =========================================================================== @@ -131,7 +131,7 @@ function removeAccentCommand(command, params, client) { getGlobalConfig().accents.push(newAccentName); saveAccentConfig(); - messageAdmins(`${client.name}{MAINCOLOUR} added a new accent: ${newAccentName}`); + messageAdmins(`{adminRed}${getPlayerName(client)}{MAINCOLOUR} removed an accent: {ALTCOLOUR}${newAccentName}{MAINCOLOUR}`); } // =========================================================================== \ No newline at end of file diff --git a/scripts/server/account.js b/scripts/server/account.js index 97a117f2..d44c3b88 100644 --- a/scripts/server/account.js +++ b/scripts/server/account.js @@ -583,14 +583,14 @@ function loginSuccess(client) { if(doesPlayerHaveStaffPermission(client, "Developer") || doesPlayerHaveStaffPermission(client, "ManageServer")) { logToConsole(LOG_WARN, `[VRR.Account] ${getPlayerDisplayForConsole(client)} has needed permissions and is being given administrator access`); - client.administrator = true; + setPlayerAsNativeAdmin(client); } if(doesServerHaveTesterOnlyEnabled()) { if(!hasBitFlag(getPlayerData(client).accountData.flags.moderation, getModerationFlagValue("IsTester"))) { setTimeout(function() { getPlayerData(client).customDisconnectReason = "Kicked - Not a tester"; - client.disconnect(); + disconnectPlayer(); }, 3500); if(doesServerHaveGUIEnabled() && doesPlayerHaveGUIEnabled(client)) { @@ -618,7 +618,7 @@ function loginSuccess(client) { showCharacterSelectToClient(client); } - getPlayerData(client).accountData.ipAddress = client.ip; + getPlayerData(client).accountData.ipAddress = getPlayerIP(client); sendPlayerChatScrollLines(client, getPlayerData(client).accountData.chatScrollLines); messagePlayerNormal(null, `👋 ${getPlayerName(client)} has joined the server`, getColourByName("softYellow")); @@ -794,7 +794,7 @@ function createAccount(name, password, email = "") { function checkLogin(client, password) { getPlayerData(client).loginAttemptsRemaining = getPlayerData(client).loginAttemptsRemaining-1; if(getPlayerData(client).loginAttemptsRemaining <= 0) { - client.disconnect(); + disconnectPlayer(); } if(isPlayerLoggedIn(client)) { @@ -831,7 +831,7 @@ function checkLogin(client, password) { } if(isAccountEmailVerified(getPlayerData(client).accountData) && isAccountSettingFlagEnabled(getPlayerData(client).accountData, getAccountSettingsFlagValue("AuthAttemptAlert"))) { - sendAccountLoginFailedNotification(getPlayerData(client).accountData.emailAddress, client.name, client.ip, getServerGame()); + sendAccountLoginFailedNotification(getPlayerData(client).accountData.emailAddress, getPlayerName(client), getPlayerIP(client), getServerGame()); } return false; } @@ -847,7 +847,7 @@ function checkLogin(client, password) { } if(isAccountEmailVerified(getPlayerData(client).accountData) && isAccountSettingFlagEnabled(getPlayerData(client).accountData, getAccountSettingsFlagValue("AuthAttemptAlert"))) { - sendAccountLoginFailedNotification(getPlayerData(client).accountData.emailAddress, client.name, client.ip, getServerGame()); + sendAccountLoginFailedNotification(getPlayerData(client).accountData.emailAddress, getPlayerName(client), getPlayerIP(client), getServerGame()); } return false; } @@ -865,7 +865,7 @@ function checkLogin(client, password) { loginSuccess(client); if(isAccountEmailVerified(getPlayerData(client).accountData) && isAccountSettingFlagEnabled(getPlayerData(client).accountData, getAccountSettingsFlagValue("AuthAttemptAlert"))) { - sendAccountLoginSuccessNotification(getPlayerData(client).accountData.emailAddress, client.name, client.ip, getServerGame()); + sendAccountLoginSuccessNotification(getPlayerData(client).accountData.emailAddress, getPlayerName(client), getPlayerIP(client), getServerGame()); } } @@ -973,7 +973,7 @@ function checkRegistration(client, password, confirmPassword = "", emailAddress if(doesServerHaveTesterOnlyEnabled() && !isPlayerATester(client)) { setTimeout(function() { - client.disconnect(); + disconnectPlayer(); }, 5000); if(doesServerHaveGUIEnabled() && doesPlayerHaveGUIEnabled(client)) { @@ -1024,7 +1024,7 @@ function checkAccountResetPasswordRequest(client, inputText) { logToConsole(LOG_DEBUG, `${getPlayerDisplayForConsole(client)} entered the correct reset password verification code. Awaiting new password input ...`); } else { getPlayerData(client).passwordResetState = VRR_RESETPASS_STATE_NONE; - client.disconnect(); + disconnectPlayer(client); logToConsole(LOG_DEBUG|LOG_WARN, `${getPlayerDisplayForConsole(client)} failed to reset their password (verification code not correct)`); } } @@ -1038,7 +1038,7 @@ function checkAccountChangePassword(client, newPassword, confirmNewPassword) { if(!isPlayerLoggedIn(client)) { if(getPlayerData(client).passwordResetState != VRR_RESETPASS_STATE_SETPASS) { //getPlayerData(client).passwordResetState = VRR_RESETPASS_STATE_NONE; - //client.disconnect(); + //disconnectPlayer(client); logToConsole(LOG_DEBUG|LOG_WARN, `${getPlayerDisplayForConsole(client)} failed to change their password (not logged in or not using reset password)`); return false; } @@ -1141,11 +1141,11 @@ function initClient(client) { return false; } - if(client.getData("vrr.isInitialized") != null || client.getData("vrr.isInitialized") == true) { + if(doesEntityDataExist(client, "vrr.isInitialized") || getEntityData(client, "vrr.isInitialized") == true) { return false; } - client.setData("vrr.isInitialized", true, false); + setEntityData(client, "vrr.isInitialized", true, false); sendPlayerGUIColours(client); sendPlayerGUIInit(client); @@ -1162,14 +1162,14 @@ function initClient(client) { let tempAccountData = loadAccountFromName(getPlayerName(client), true); let tempSubAccounts = loadSubAccountsFromAccount(tempAccountData.databaseId); - getServerData().clients[client.index] = new ClientData(client, tempAccountData, tempSubAccounts); + getServerData().clients[getPlayerId(client)] = new ClientData(client, tempAccountData, tempSubAccounts); - getServerData().clients[client.index].sessionId = saveConnectionToDatabase(client); - getServerData().clients[client.index].connectTime = getCurrentUnixTimestamp(); + getServerData().clients[getPlayerId(client)].sessionId = saveConnectionToDatabase(client); + getServerData().clients[getPlayerId(client)].connectTime = getCurrentUnixTimestamp(); requestClientInfo(client); if(tempAccountData != false) { - if(isAccountAutoIPLoginEnabled(tempAccountData) && getPlayerData(client).accountData.ipAddress == client.ip) { + if(isAccountAutoIPLoginEnabled(tempAccountData) && getPlayerData(client).accountData.ipAddress == getPlayerIp(client)) { messagePlayerAlert(client, getLocaleString(client, "AutoLoggedInIP")); loginSuccess(client); playRadioStreamForPlayer(client, getServerIntroMusicURL(), true, getPlayerStreamingRadioVolume(client)); @@ -1182,7 +1182,7 @@ function initClient(client) { messagePlayerNormal(client, getLocaleString(client, "WelcomeBack", getServerName(), getPlayerName(client), "/login"),getColourByName("softGreen")); //if(checkForGeoIPModule()) { - // let iso = module.geoip.getCountryISO(client.ip); + // let iso = module.geoip.getCountryISO(getPlayerIp(client)); // let localeId = getLocaleFromCountryISO(iso); //} //showGameMessage(client, getLocaleString(client, "LocaleOffer", `/lang ${getLocaleData(localeId)[2]}`), getColourByName("white"), 10000, "Roboto"); @@ -1200,7 +1200,7 @@ function initClient(client) { playRadioStreamForPlayer(client, getServerIntroMusicURL(), true, getPlayerStreamingRadioVolume(client)); } - getServerData().clients[client.index].keyBinds = loadAccountKeybindsFromDatabase(getServerData().clients[client.index].accountData.databaseId); + getServerData().clients[getPlayerId(client)].keyBinds = loadAccountKeybindsFromDatabase(getServerData().clients[getPlayerId(client)].accountData.databaseId); sendAccountKeyBindsToClient(client); } }, 2500); @@ -1212,7 +1212,7 @@ function saveConnectionToDatabase(client) { let dbConnection = connectToDatabase(); if(dbConnection) { let safeName = escapeDatabaseString(dbConnection, getPlayerName(client)); - let dbQueryString = `INSERT INTO conn_main (conn_when_connect, conn_server, conn_script_version, conn_game_version, conn_client_version, conn_name, conn_ip) VALUES (NOW(), ${getServerConfig().databaseId}, '${scriptVersion}', '${client.gameVersion}', '0.0.0', '${safeName}', '${client.ip}')`; + let dbQueryString = `INSERT INTO conn_main (conn_when_connect, conn_server, conn_script_version, conn_game_version, conn_client_version, conn_name, conn_ip) VALUES (NOW(), ${getServerConfig().databaseId}, '${scriptVersion}', '${getPlayerGameVersion(client)}', '0.0.0', '${safeName}', '${getPlayerIP(client)}')`; queryDatabase(dbConnection, dbQueryString); return getDatabaseInsertId(dbConnection); } @@ -1520,7 +1520,7 @@ function checkPlayerTwoFactorAuthentication(client, authCode) { } } - client.disconnect(); + disconnectPlayer(client); return false; } diff --git a/scripts/server/ban.js b/scripts/server/ban.js index f95179c0..b54413da 100644 --- a/scripts/server/ban.js +++ b/scripts/server/ban.js @@ -39,7 +39,7 @@ function accountBanCommand(command, params, client) { logToConsole(LOG_WARN, `[VRR.Ban]: ${getPlayerDisplayForConsole(targetClient)} (${getPlayerData(targetClient).accountData.name}) account was banned by ${getPlayerDisplayForConsole(client)}. Reason: ${reason}`); - announceAdminAction(`PlayerAccountBanned`, `{ALTCOLOUR}${targetClient.name}{MAINCOLOUR}`); + announceAdminAction(`PlayerAccountBanned`, `{ALTCOLOUR}${getPlayerName(client)}{MAINCOLOUR}`); banAccount(getPlayerData(targetClient).accountData.databaseId, getPlayerData(client).accountData.databaseId, reason); disconnectPlayer(client); } @@ -69,7 +69,7 @@ function subAccountBanCommand(command, params, client, fromDiscord) { logToConsole(LOG_WARN, `[VRR.Ban]: ${getPlayerDisplayForConsole(targetClient)} (${getPlayerData(targetClient).accountData.name})'s subaccount was banned by ${getPlayerDisplayForConsole(client)}. Reason: ${reason}`); - announceAdminAction(`PlayerCharacterBanned`, `{ALTCOLOUR}${targetClient.name}{MAINCOLOUR}`); + announceAdminAction(`PlayerCharacterBanned`, `{ALTCOLOUR}${getPlayerName(client)}{MAINCOLOUR}`); banSubAccount(getPlayerData(targetClient).currentSubAccountData.databaseId, getPlayerData(client).accountData.databaseId, reason); disconnectPlayer(client); @@ -98,11 +98,11 @@ function ipBanCommand(command, params, client, fromDiscord) { return false; } - announceAdminAction(`PlayerIPBanned`, `{ALTCOLOUR}${targetClient.name}{MAINCOLOUR}`); - banIPAddress(targetClient.ip, getPlayerData(client).accountData.databaseId, reason); + announceAdminAction(`PlayerIPBanned`, `{ALTCOLOUR}${getPlayerName(targetClient)}{MAINCOLOUR}`); + banIPAddress(getPlayerIP(targetClient), getPlayerData(client).accountData.databaseId, reason); - server.banIP(targetClient.ip); - targetClient.disconnect(); + server.banIP(getPlayerIP(targetClient)); + disconnectPlayer(targetClient); } // =========================================================================== @@ -129,10 +129,10 @@ function subNetBanCommand(command, params, client, fromDiscord) { return false; } - announceAdminAction(`PlayerSubNetBanned`, `{ALTCOLOUR}${targetClient.name}{MAINCOLOUR}`); - banSubNet(targetClient.ip, getSubNet(targetClient.ip, octetAmount), getPlayerData(client).accountData.databaseId, reason); + announceAdminAction(`PlayerSubNetBanned`, `{ALTCOLOUR}${getPlayerName(client)}{MAINCOLOUR}`); + banSubNet(getPlayerIP(targetClient), getSubNet(getPlayerIP(targetClient), octetAmount), getPlayerData(client).accountData.databaseId, reason); - server.banIP(targetClient.ip); + server.banIP(getPlayerIP(targetClient)); } // =========================================================================== diff --git a/scripts/server/business.js b/scripts/server/business.js index fc21d4c0..ebbdcaae 100644 --- a/scripts/server/business.js +++ b/scripts/server/business.js @@ -9,15 +9,7 @@ function initBusinessScript() { logToConsole(LOG_INFO, "[VRR.Business]: Initializing business script ..."); - if(!getServerConfig().devServer) { - getServerData().businesses = loadBusinessesFromDatabase(); - } - createAllBusinessPickups(); - createAllBusinessBlips(); - - setAllBusinessIndexes(); - cacheAllBusinessItems(); logToConsole(LOG_INFO, "[VRR.Business]: Business script initialized successfully!"); return true; @@ -151,7 +143,7 @@ function createBusinessCommand(command, params, client) { let tempBusinessData = createBusiness(params, getPlayerPosition(client), toVector3(0.0, 0.0, 0.0), getGameConfig().pickupModels[getServerGame()].Business, getGameConfig().blipSprites[getServerGame()].Business, getPlayerInterior(client), getPlayerDimension(client), getPlayerData(client).interiorCutscene); tempBusinessData.needsSaved = true; let businessId = getServerData().businesses.push(tempBusinessData); - setAllBusinessIndexes(); + setBusinessDataIndexes(); saveBusinessesToDatabase(); @@ -2111,7 +2103,7 @@ function reloadAllBusinessesCommand(command, params, client) { getServerData().businesses = loadBusinessesFromDatabase(); createAllBusinessPickups(); createAllBusinessBlips(); - setAllBusinessIndexes(); + setBusinessDataIndexes(); cacheAllBusinessItems(); announceAdminAction(`AllBusinessesReloaded`); @@ -2124,7 +2116,7 @@ function reloadAllBusinessesCommand(command, params, client) { * * @returns {Boolean} Whether or not the exit blip of the business was deleted */ -function setAllBusinessIndexes() { +function setBusinessDataIndexes() { for(let i in getServerData().businesses) { getServerData().businesses[i].index = i; } @@ -2486,10 +2478,10 @@ function updateBusinessPickupLabelData(businessId) { } else if(getBusinessData(businessId).labelHelpType == VRR_PROPLABEL_INFO_REPAIR) { setEntityData(getBusinessData(businessId).entrancePickup, "vrr.label.help", VRR_PROPLABEL_INFO_REPAIR, true); } else { - if(getBusinessData(businessId).buyPrice > 0) { - setEntityData(getBusinessData(businessId).entrancePickup, "vrr.label.price", getBusinessData(businessId).buyPrice, true); - setEntityData(getBusinessData(businessId).entrancePickup, "vrr.label.help", VRR_PROPLABEL_INFO_BUYBIZ, true); - } else { + //if(getBusinessData(businessId).buyPrice > 0) { + // setEntityData(getBusinessData(businessId).entrancePickup, "vrr.label.price", getBusinessData(businessId).buyPrice, true); + // setEntityData(getBusinessData(businessId).entrancePickup, "vrr.label.help", VRR_PROPLABEL_INFO_BUYBIZ, true); + //} else { if(getBusinessData(businessId).hasInterior) { setEntityData(getBusinessData(businessId).entrancePickup, "vrr.label.help", VRR_PROPLABEL_INFO_ENTER, true); } else { @@ -2497,7 +2489,7 @@ function updateBusinessPickupLabelData(businessId) { setEntityData(getBusinessData(businessId).entrancePickup, "vrr.label.help", VRR_PROPLABEL_INFO_BUY, true); } } - } + //} } if(getBusinessData(businessId).buyPrice > 0) { diff --git a/scripts/server/clan.js b/scripts/server/clan.js index 2c35c30b..414476ed 100644 --- a/scripts/server/clan.js +++ b/scripts/server/clan.js @@ -9,11 +9,6 @@ function initClanScript() { logToConsole(LOG_INFO, "[VRR.Clan]: Initializing clans script ..."); - if(!getServerConfig().devServer) { - getServerData().clans = loadClansFromDatabase(); - } - - setAllClanDataIndexes(); logToConsole(LOG_INFO, "[VRR.Clan]: Clan script initialized successfully!"); return true; } diff --git a/scripts/server/client.js b/scripts/server/client.js index 774fe143..8623bbec 100644 --- a/scripts/server/client.js +++ b/scripts/server/client.js @@ -98,7 +98,7 @@ function updateAllPlayerNameTags() { function updatePlayerPing(client) { //logToConsole(LOG_DEBUG, `[VRR.Client] Sending ${getPlayerDisplayForConsole(client)}'s ping to all players`); - sendNetworkEventToPlayer("vrr.ping", null, getPlayerName(client), client.ping); + sendNetworkEventToPlayer("vrr.ping", null, getPlayerName(client), getPlayerPing(client)); } // =========================================================================== @@ -106,7 +106,7 @@ function updatePlayerPing(client) { function playerClientReady(client) { setEntityData(client, "vrr.isReady", true, false); logToConsole(LOG_DEBUG, `${getPlayerDisplayForConsole(client)}'s client resources are downloaded and ready!`); - if(client.getData("vrr.isStarted") == true) { + if(getEntityData(client, "vrr.isStarted") == true) { initClient(client); } } @@ -123,7 +123,7 @@ function playerGUIReady(client) { function playerClientStarted(client) { setEntityData(client, "vrr.isStarted", true, false); logToConsole(LOG_DEBUG, `${getPlayerDisplayForConsole(client)}'s client resources are started and running!`); - if(client.getData("vrr.isReady") == true) { + if(getEntityData(client, "vrr.isReady") == true) { initClient(client); } } @@ -132,7 +132,7 @@ function playerClientStarted(client) { function playerClientStopped(client) { logToConsole(LOG_DEBUG, `${getPlayerDisplayForConsole(client)}'s client resources have stopped (possibly error?). Kicking them from the server ...`); - client.disconnect(); + disconnectPlayer(client); } // =========================================================================== @@ -739,7 +739,7 @@ function forcePlayerIntoSkinSelect(client) { setPlayerPosition(client, getGameConfig().skinChangePosition[getServerGame()][0]); setPlayerHeading(client, getGameConfig().skinChangePosition[getServerGame()][1]); setPlayerInterior(client, getGameConfig().skinChangePosition[getServerGame()][2]); - setPlayerDimension(client, client.index+500); + setPlayerDimension(client, getPlayerId(client)+500); } sendNetworkEventToPlayer("vrr.skinSelect", client, true); diff --git a/scripts/server/command.js b/scripts/server/command.js index dc8ce87f..a85fa49f 100644 --- a/scripts/server/command.js +++ b/scripts/server/command.js @@ -756,7 +756,7 @@ function processPlayerCommand(command, params, client) { // } //} - if(!client.console) { + if(!isConsole(client)) { if(!doesPlayerHaveStaffPermission(client, getCommandRequiredPermissions(toLowerCase(command)))) { console.warn(`[VRR.Command] ${getPlayerDisplayForConsole(client)} attempted to use command, but failed (no permission): /${command} ${paramsDisplay}`); messagePlayerError(client, `You do not have permission to use the {ALTCOLOUR}/${toLowerCase(command)} {MAINCOLOUR}command!`); diff --git a/scripts/server/config.js b/scripts/server/config.js index 0ee31170..eb78ecc9 100644 --- a/scripts/server/config.js +++ b/scripts/server/config.js @@ -94,6 +94,7 @@ function initConfigScript() { serverConfig = loadServerConfigFromGameAndPort(server.game, server.port, getMultiplayerMod()); logToConsole(LOG_INFO, "[VRR.Config]: Applying server config ..."); + getServerConfig().devServer = intToBool(toInteger(server.getCVar("vrr_devserver"))); getServerConfig().fallingSnow = intToBool(toInteger(server.getCVar("vrr_fallingsnow"))); getServerConfig().groundSnow = intToBool(toInteger(server.getCVar("vrr_groundsnow"))); getServerConfig().useGUI = intToBool(toInteger(server.getCVar("vrr_gui"))); diff --git a/scripts/server/core.js b/scripts/server/core.js index eb7dda7b..dced5f27 100644 --- a/scripts/server/core.js +++ b/scripts/server/core.js @@ -35,6 +35,7 @@ let serverData = { npcs: [], locales: [], accents: [], + races: [], }; // =========================================================================== diff --git a/scripts/server/developer.js b/scripts/server/developer.js index 350e6f27..72a908f9 100644 --- a/scripts/server/developer.js +++ b/scripts/server/developer.js @@ -350,7 +350,7 @@ function executeClientCodeCommand(command, params, client) { return false; } - sendRunCodeToClient(client, targetClient, targetCode, client.index); + sendRunCodeToClient(client, targetClient, targetCode, getPlayerId(client)); messagePlayerSuccess(client, "Executing client code for " + toString(targetgetPlayerName(client)) + "!"); messagePlayerNormal(client, "Code: " + targetCode); @@ -380,7 +380,7 @@ function setPlayerTesterStatusCommand(command, params, client) { let enabled = hasBitFlag(getPlayerData(targetClient).accountData.flags.moderation, getModerationFlagValue("IsTester")); - messageAdmins(`{ALTCOLOUR}${client.name} ${getBoolRedGreenInlineColour(enabled)}${toUpperCase(getEnabledDisabledFromBool(enabled))} {ALTCOLOUR}${targetClient.name}'s {MAINCOLOUR}tester status`) + messageAdmins(`{ALTCOLOUR}${getPlayerName(client)} ${getBoolRedGreenInlineColour(enabled)}${toUpperCase(getEnabledDisabledFromBool(enabled))} {ALTCOLOUR}${getPlayerName(targetClient)}'s {MAINCOLOUR}tester status`) return true; } @@ -667,7 +667,7 @@ function resetAllServerAmbienceElementsCommand(command, params, client) { function reloadEconomyConfigurationCommand(command, params, client) { getGlobalConfig().economy = loadEconomyConfig(); - messageAdmins(`${client.name} {MAINCOLOUR}has reloaded the economy settings`); + messageAdmins(`{adminRed}${getPlayerName(client)} {MAINCOLOUR}has reloaded the economy settings`); } // =========================================================================== diff --git a/scripts/server/discord.js b/scripts/server/discord.js index d98264a6..5457f467 100644 --- a/scripts/server/discord.js +++ b/scripts/server/discord.js @@ -89,7 +89,7 @@ function getDiscordUserData(discordUserId) { // =========================================================================== function messageDiscordChatChannel(messageString) { - if(getServerConfig().devServer) { + if(getServerConfig().devServer == true) { return false; } diff --git a/scripts/server/economy.js b/scripts/server/economy.js index 67ae6e2a..2a052a00 100644 --- a/scripts/server/economy.js +++ b/scripts/server/economy.js @@ -111,7 +111,7 @@ function forcePlayerPayDayCommand(command, params, client) { return false; } - messageAdmins(`${client.name} gave ${targetClient.name} an instant payday`); + messageAdmins(`{adminRed}${getPlayerName(client)}{MAINCOLOUR} gave {ALTCOLOUR}${getPlayerName(targetClient)}{MAINCOLOUR} an instant payday`); playerPayDay(targetClient); } @@ -132,7 +132,7 @@ function setPayDayBonusMultiplier(command, params, client) { getGlobalConfig().economy.grossIncomeMultiplier = newMultiplier; - announceAdminAction(`PaydayBonusSet`, `{adminRed}${client.name}{MAINCOLOUR}`, `{ALTCOLOUR}${newMultiplier*100}%{MAINCOLOUR}`); + announceAdminAction(`PaydayBonusSet`, `{adminRed}${getPlayerName(client)}{MAINCOLOUR}`, `{ALTCOLOUR}${newMultiplier*100}%{MAINCOLOUR}`); } // =========================================================================== @@ -147,7 +147,7 @@ function taxInfoCommand(command, params, client) { function wealthInfoCommand(command, params, client) { let wealth = calculateWealth(client); - messagePlayerInfo(client, `Your wealth is: $${wealth}. Use {ALTCOLOUR}/help wealth {MAINCOLOUR}for more information.`); + messagePlayerInfo(client, `Your wealth is: {ALTCOLOUR}$${wealth}{MAINCOLOUR}. Use {ALTCOLOUR}/help wealth {MAINCOLOUR}for more information.`); } // =========================================================================== diff --git a/scripts/server/event.js b/scripts/server/event.js index 249211d2..e14074f4 100644 --- a/scripts/server/event.js +++ b/scripts/server/event.js @@ -54,13 +54,13 @@ function onPlayerConnect(event, ipAddress, port) { // =========================================================================== function onPlayerJoin(event, client) { - logToConsole(LOG_INFO, `[VRR.Event] Client ${client.name}[${client.index}] joining from ${client.ip}`); + logToConsole(LOG_INFO, `[VRR.Event] Client ${getPlayerName(client)}[${getPlayerId(client)}] joining from ${getPlayerIP(client)}`); if(isFadeCameraSupported()) { fadeCamera(client, true, 1.0); } - messageDiscordEventChannel(`👋 ${client.name} is connecting to the server ...`); + messageDiscordEventChannel(`👋 ${getPlayerName(client)} is connecting to the server ...`); //messageDiscordEventChannel(`👋 ${getPlayerDisplayForConsole(client)} has joined the server.`); } @@ -103,13 +103,13 @@ function onPlayerQuit(event, client, quitReasonId) { reasonText = getPlayerData(client).customDisconnectReason; } messagePlayerNormal(null, `👋 ${getPlayerName(client)} has left the server (${reasonText})`, getColourByName("softYellow")); - messageDiscordEventChannel(`👋 ${client.name} has left the server (${reasonText})`); + messageDiscordEventChannel(`👋 ${getPlayerName(client)} has left the server (${reasonText})`); savePlayerToDatabase(client); resetClientStuff(client); - getServerData().clients[client.index] = null; + getServerData().clients[getPlayerId(client)] = null; } else { - messageDiscordEventChannel(`👋 ${client.name} has left the server (${disconnectReasons[quitReasonId]}[${quitReasonId}])`); + messageDiscordEventChannel(`👋 ${getPlayerName(client)} has left the server (${disconnectReasons[quitReasonId]}[${quitReasonId}])`); } clearTemporaryVehicles(); @@ -395,7 +395,7 @@ function onPlayerDeath(client, position) { setTimeout(function() { if(getPlayerCurrentSubAccount(client).inJail) { let closestJail = getClosestPoliceStation(getPlayerPosition(client)); - client.despawnPlayer(); + despawnPlayer(client); getPlayerCurrentSubAccount(client).interior = closestJail.interior; getPlayerCurrentSubAccount(client).dimension = closestJail.dimension; @@ -417,7 +417,7 @@ function onPlayerDeath(client, position) { setPlayerControlState(client, true); } else { let closestHospital = getClosestHospital(getPlayerPosition(client)); - client.despawnPlayer(); + despawnPlayer(client); getPlayerCurrentSubAccount(client).interior = closestHospital.interior; getPlayerCurrentSubAccount(client).dimension = closestHospital.dimension; @@ -467,21 +467,21 @@ function onPlayerSpawn(client) { logToConsole(LOG_DEBUG, `[VRR.Event] Checking ${getPlayerDisplayForConsole(client)}'s player data`); if(!getPlayerData(client)) { logToConsole(LOG_DEBUG, `[VRR.Event] ${getPlayerDisplayForConsole(client)}'s player data is invalid. Kicking them from server.`); - client.disconnect(); + disconnectPlayer(client); return false; } logToConsole(LOG_DEBUG, `[VRR.Event] Checking ${getPlayerDisplayForConsole(client)}'s login status`); if(!isPlayerLoggedIn(client)) { logToConsole(LOG_DEBUG, `[VRR.Event] ${getPlayerDisplayForConsole(client)} is NOT logged in. Despawning their player.`); - client.disconnect(); + disconnectPlayer(client); return false; } logToConsole(LOG_DEBUG, `[VRR.Event] Checking ${getPlayerDisplayForConsole(client)}'s selected character status`); if(getPlayerData(client).currentSubAccount == -1) { logToConsole(LOG_DEBUG, `[VRR.Event] ${getPlayerDisplayForConsole(client)} has NOT selected a character. Despawning their player.`); - client.disconnect(); + disconnectPlayer(client); return false; } @@ -622,7 +622,7 @@ function onPlayerSpawn(client) { getPlayerData(client).payDayTickStart = sdl.ticks; - messageDiscordEventChannel(`🧍 ${client.name} spawned as ${getCharacterFullName(client)}`); + messageDiscordEventChannel(`🧍 ${getPlayerName(client)} spawned as ${getCharacterFullName(client)}`); } // =========================================================================== diff --git a/scripts/server/gui.js b/scripts/server/gui.js index 664c0873..6afae940 100644 --- a/scripts/server/gui.js +++ b/scripts/server/gui.js @@ -25,7 +25,7 @@ function playerPromptAnswerNo(client) { case VRR_PROMPT_CREATEFIRSTCHAR: logToConsole(LOG_DEBUG, `${getPlayerDisplayForConsole(client)} chose not to create a first character. Kicking them from the server ...`); showPlayerErrorGUI(client, "You don't have a character to play. Goodbye!", "No Characters"); - setTimeout(function() { client.disconnect(); }, 5000); + setTimeout(function() { disconnectPlayer(client); }, 5000); break; case VRR_PROMPT_BIZORDER: diff --git a/scripts/server/house.js b/scripts/server/house.js index 9ede4edc..44627b28 100644 --- a/scripts/server/house.js +++ b/scripts/server/house.js @@ -9,19 +9,6 @@ function initHouseScript() { logToConsole(LOG_INFO, "[VRR.House]: Initializing house script ..."); - if(!getServerConfig().devServer) { - getServerData().houses = loadHousesFromDatabase(); - } - - if(getServerConfig().createHousePickups) { - createAllHousePickups(); - } - - if(getServerConfig().createHouseBlips) { - createAllHouseBlips(); - } - - setAllHouseIndexes(); logToConsole(LOG_INFO, "[VRR.House]: House script initialized successfully!"); return true; } @@ -83,7 +70,7 @@ function createHouseCommand(command, params, client) { let houseId = getServerData().houses.push(tempHouseData); saveHouseToDatabase(houseId-1); - setAllHouseIndexes(); + setHouseDataIndexes(); createHouseEntrancePickup(houseId-1); createHouseExitPickup(houseId-1); @@ -333,7 +320,7 @@ function setHousePickupCommand(command, params, client) { getHouseData(houseId).needsSaved = true; - messageAdmins(`{adminRed}${client.name}{MAINCOLOUR} set house {houseGreen}${getHouseData(houseId).description}{MAINCOLOUR} pickup display to {ALTCOLOUR}${toLowerCase(typeParam)}`); + messageAdmins(`{adminRed}${getPlayerName(client)}{MAINCOLOUR} set house {houseGreen}${getHouseData(houseId).description}{MAINCOLOUR} pickup display to {ALTCOLOUR}${toLowerCase(typeParam)}`); } // =========================================================================== @@ -394,7 +381,7 @@ function setHouseInteriorTypeCommand(command, params, client) { getHouseData(houseId).needsSaved = true; - messageAdmins(`{adminRed}${client.name}{MAINCOLOUR} set house {houseGreen}${getHouseData(houseId).description}{MAINCOLOUR} interior type to {ALTCOLOUR}${toLowerCase(typeParam)}`); + messageAdmins(`{adminRed}${getPlayerName(client)}{MAINCOLOUR} set house {houseGreen}${getHouseData(houseId).description}{MAINCOLOUR} interior type to {ALTCOLOUR}${toLowerCase(typeParam)}`); } // =========================================================================== @@ -445,7 +432,7 @@ function setHouseBlipCommand(command, params, client) { resetHouseBlips(houseId); getHouseData(houseId).needsSaved = true; - messageAdmins(`{adminRed}${client.name}{MAINCOLOUR} set house {houseGreen}${getHouseData(houseId).description}{MAINCOLOUR} blip display to {ALTCOLOUR}${toLowerCase(typeParam)}`); + messageAdmins(`{adminRed}${getPlayerName(client)}{MAINCOLOUR} set house {houseGreen}${getHouseData(houseId).description}{MAINCOLOUR} blip display to {ALTCOLOUR}${toLowerCase(typeParam)}`); } // =========================================================================== @@ -1279,7 +1266,7 @@ function exitHouse(client) { // =========================================================================== -function setAllHouseIndexes() { +function setHouseDataIndexes() { for(let i in getServerData().houses) { getServerData().houses[i].index = i; diff --git a/scripts/server/index.js b/scripts/server/index.js index 462c1410..67fbcb04 100644 --- a/scripts/server/index.js +++ b/scripts/server/index.js @@ -38,6 +38,7 @@ require("scripts/server/messaging.js"); require("scripts/server/misc.js"); require("scripts/server/npc.js"); require("scripts/server/staff.js"); +require("scripts/server/race.js"); require("scripts/server/radio.js"); require("scripts/server/security.js"); require("scripts/server/subaccount.js"); diff --git a/scripts/server/item.js b/scripts/server/item.js index 085b7575..3b135a10 100644 --- a/scripts/server/item.js +++ b/scripts/server/item.js @@ -9,16 +9,6 @@ function initItemScript() { logToConsole(LOG_INFO, "[VRR.Item]: Initializing item script ..."); - getServerData().itemTypes = loadItemTypesFromDatabase(); - if(!getServerConfig().devServer) { - getServerData().items = loadItemsFromDatabase(); - } - - setItemTypeDataIndexes(); - setItemDataIndexes(); - - cacheAllGroundItems(); - createAllGroundItemObjects(); logToConsole(LOG_INFO, "[VRR.Item]: Item script initialized successfully!"); return true; } @@ -2327,7 +2317,6 @@ function createGroundPlant(itemId) { createGroundItem(getItemTypeData(itemId).useId, 1, position, dimension); groundPlantCache.push(itemId); groundItemCache.push(itemId); - } // =========================================================================== diff --git a/scripts/server/job.js b/scripts/server/job.js index f1bb18e9..b3ea1c95 100644 --- a/scripts/server/job.js +++ b/scripts/server/job.js @@ -9,13 +9,6 @@ function initJobScript() { logToConsole(LOG_INFO, "[VRR.Job]: Initializing job script ..."); - getServerData().jobs = loadJobsFromDatabase(); - - createAllJobPickups(); - createAllJobBlips(); - - setAllJobDataIndexes(); - logToConsole(LOG_INFO, "[VRR.Job]: Job script initialized successfully!"); return true; } diff --git a/scripts/server/locale.js b/scripts/server/locale.js index ed16c62e..a2768cb1 100644 --- a/scripts/server/locale.js +++ b/scripts/server/locale.js @@ -190,7 +190,7 @@ function reloadLocaleConfigurationCommand(command, params, client) { getGlobalConfig().locale.defaultLanguageId = getLocaleFromParams(getGlobalConfig().locale.defaultLanguage); - messageAdmins(`${client.name}{MAINCOLOUR} has reloaded the locale settings and texts`); + messageAdmins(`${getPlayerName(client)}{MAINCOLOUR} has reloaded the locale settings and texts`); } // =========================================================================== diff --git a/scripts/server/misc.js b/scripts/server/misc.js index 08b6214b..0761eccf 100644 --- a/scripts/server/misc.js +++ b/scripts/server/misc.js @@ -672,17 +672,9 @@ function lockCommand(command, params, client) { return false; } - if(isPlayerInAnyVehicle(client)) { - vehicle = getPlayerVehicle(client); - if(!isPlayerInFrontVehicleSeat(client)) { - messagePlayerError(client, getLocaleString(client, "MustBeInVehicleFrontSeat")); - return false; - } - } else { - if(!doesPlayerHaveVehicleKeys(client, vehicle)) { - messagePlayerError(client, getLocaleString(client, "DontHaveVehicleKey")); - return false; - } + if(!isPlayerInFrontVehicleSeat(client)) { + messagePlayerError(client, getLocaleString(client, "MustBeInVehicleFrontSeat")); + return false; } getVehicleData(vehicle).locked = !getVehicleData(vehicle).locked; @@ -728,17 +720,9 @@ function lockCommand(command, params, client) { return false; } - if(isPlayerInAnyVehicle(client)) { - vehicle = getPlayerVehicle(client); - if(!isPlayerInFrontVehicleSeat(client)) { - messagePlayerError(client, getLocaleString(client, "MustBeInVehicleFrontSeat")); - return false; - } - } else { - if(!doesPlayerHaveVehicleKeys(client, vehicle)) { - messagePlayerError(client, getLocaleString(client, "DontHaveVehicleKey")); - return false; - } + if(!doesPlayerHaveVehicleKeys(client, vehicle)) { + messagePlayerError(client, getLocaleString(client, "DontHaveVehicleKey")); + return false; } getVehicleData(vehicle).locked = !getVehicleData(vehicle).locked; @@ -752,4 +736,102 @@ function lockCommand(command, params, client) { } } -// =========================================================================== \ No newline at end of file +// =========================================================================== + +/** + * This is a command handler function. + * + * @param {string} command - The command name used by the player + * @param {string} params - The parameters/args string used with the command by the player + * @param {Client} client - The client/player that used the command + * @return {bool} Whether or not the command was successful + * + */ + function lightsCommand(command, params, client) { + if(isPlayerInAnyVehicle(client)) { + let vehicle = getPlayerVehicle(client); + + if(!getVehicleData(vehicle)) { + messagePlayerError(client, getLocaleString(client, "RandomVehicleCommandsDisabled")); + return false; + } + + if(!isPlayerInFrontVehicleSeat(client)) { + messagePlayerError(client, getLocaleString(client, "MustBeInVehicleFrontSeat")); + return false; + } + + getVehicleData(vehicle).lights = !getVehicleData(vehicle).lights; + setVehicleLights(vehicle, getVehicleData(vehicle).lights) + getVehicleData(vehicle).needsSaved = true; + + meActionToNearbyPlayers(client, `${toLowerCase(getLockedUnlockedFromBool(getVehicleData(vehicle).lights))} the ${getVehicleName(vehicle)}`); + } else { + let vehicle = getClosestVehicle(getPlayerPosition(client)); + if(vehicle != false) { + if(getDistance(getPlayerPosition(client), getVehiclePosition(vehicle) <= getGlobalConfig().vehicleLockDistance)) { + return false; + } + + if(!getVehicleData(vehicle)) { + messagePlayerError(client, getLocaleString(client, "RandomVehicleCommandsDisabled")); + return false; + } + + if(!doesPlayerHaveVehicleKeys(client, vehicle)) { + messagePlayerError(client, getLocaleString(client, "DontHaveVehicleKey")); + return false; + } + + getVehicleData(vehicle).locked = !getVehicleData(vehicle).locked; + vehicle.locked = getVehicleData(vehicle).locked; + getVehicleData(vehicle).needsSaved = true; + + meActionToNearbyPlayers(client, `${toLowerCase(getLockedUnlockedFromBool(getVehicleData(vehicle).locked))} the ${getVehicleName(vehicle)}`); + } + + let businessId = getPlayerBusiness(client); + if(businessId != false) { + if(!canPlayerManageBusiness(client, businessId)) { + messagePlayerError(client, getLocaleString(client, "CantModifyBusiness")); + return false; + } + + getBusinessData(businessId).interiorLights = !getBusinessData(businessId).interiorLights; + + let clients = getClients(); + for(let i in clients) { + if(getPlayerBusiness(client) == getPlayerBusiness(clients[i]) && getPlayerDimension(clients[i]) == getBusinessData(businessId).exitDimension) { + setPlayerInteriorLights(clients[i], getBusinessData(businessId).interiorLights); + } + } + + getBusinessData(businessId).needsSaved = true; + + meActionToNearbyPlayers(client, `turned ${getOnOffFromBool((getBusinessData(businessId).interiorLights))} on the business lights`); + return true; + } + + let houseId = getPlayerHouse(client); + if(houseId != false) { + if(!canPlayerManageHouse(client, houseId)) { + messagePlayerError(client, getLocaleString(client, "CantModifyHouse")); + return false; + } + + getHouseData(businessId).interiorLights = !getHouseData(houseId).interiorLights; + + let clients = getClients(); + for(let i in clients) { + if(getPlayerHouse(client) == getPlayerHouse(clients[i]) && getPlayerDimension(clients[i]) == getHouseData(houseId).exitDimension) { + setPlayerInteriorLights(clients[i], getHouseData(houseId).interiorLights); + } + } + + getHouseData(houseId).needsSaved = true; + + meActionToNearbyPlayers(client, `turned ${getOnOffFromBool((getHouseData(houseId).interiorLights))} on the house lights`); + return true; + } + } +} \ No newline at end of file diff --git a/scripts/server/native/connected.js b/scripts/server/native/connected.js index 2aaaf067..c5cb542e 100644 --- a/scripts/server/native/connected.js +++ b/scripts/server/native/connected.js @@ -261,7 +261,7 @@ function setPlayerHealth(client, health) { // =========================================================================== function getPlayerHealth(client) { - return getServerData(client).health; + return getPlayerData(client).health; } // =========================================================================== @@ -331,7 +331,7 @@ function takePlayerCash(client, amount) { function disconnectPlayer(client) { logToConsole(LOG_DEBUG, `Disconnecting (kicking) ${getPlayerDisplayForConsole(client)}`); - client.disconnect(); + disconnectPlayer(client); return false; } @@ -739,7 +739,7 @@ function givePlayerWeaponAmmo(client, ammo) { function getPlayerWeapon(client) { if(areServerElementsSupported(client)) { - return getPlayerPed(client).weapon;; + return getPlayerPed(client).weapon; } else { return getPlayerData(client).syncWeapon; } @@ -1166,4 +1166,40 @@ function doesEntityDataExist(entity, dataName) { return null; } +// =========================================================================== + +function disconnectPlayer(client) { + client.disconnect(); +} + +// =========================================================================== + +function getPlayerId(client) { + return client.index; +} + +// =========================================================================== + +function getPlayerIP(client) { + return client.ip; +} + +// =========================================================================== + +function getPlayerGameVersion(client) { + client.gameVersion; +} + +// =========================================================================== + +function setPlayerNativeAdminState(client, state) { + client.administrator = state; +} + +// =========================================================================== + +function despawnPlayer(client) { + client.despawnPlayer(); +} + // =========================================================================== \ No newline at end of file diff --git a/scripts/server/npc.js b/scripts/server/npc.js index b43d749b..78b2c33a 100644 --- a/scripts/server/npc.js +++ b/scripts/server/npc.js @@ -8,12 +8,8 @@ // =========================================================================== function initNPCScript() { - if(!getServerConfig().devServer) { - getServerData().npcs = loadNPCsFromDatabase(); - } - - setNPCDataIndexes(); - spawnNPCs(); + logToConsole(LOG_INFO, "[VRR.NPC]: Initializing NPC script ..."); + logToConsole(LOG_INFO, "[VRR.NPC]: NPC script initialized successfully!"); } // =========================================================================== @@ -47,7 +43,7 @@ function createNPCCommand(client, command, params) { let position = getPosInFrontOfPos(getPlayerPosition(client), getPlayerHeading(client), 3); let npcId = createNPC(skinId, position, getPlayerHeading(client)); - messageAdmins(`${client.name}{MAINCOLOUR} created a ${getSkinNameFromIndex(getNPCData(npcId).skin)} NPC!`); + messageAdmins(`${getPlayerName(client)}{MAINCOLOUR} created a ${getSkinNameFromIndex(getNPCData(npcId).skin)} NPC!`); } // =========================================================================== @@ -285,7 +281,7 @@ function spawnNPC(npcIndex) { // =========================================================================== -function spawnNPCs() { +function spawnAllNPCs() { for(let i in getServerData().npcs) { spawnNPC(npcIndex); } @@ -309,7 +305,7 @@ function deleteNPCCommand(command, params, client) { let npcName = getNPCData(closestNPC).name; deleteNPC(closestNPC); - messageAdmins(`${client.name}{MAINCOLOUR} deleted NPC {npcPink}${npcName}`); + messageAdmins(`${getPlayerName(client)}{MAINCOLOUR} deleted NPC {npcPink}${npcName}`); } // =========================================================================== diff --git a/scripts/server/race.js b/scripts/server/race.js index 3fcfc684..13e2166a 100644 --- a/scripts/server/race.js +++ b/scripts/server/race.js @@ -8,11 +8,8 @@ // =========================================================================== function initRaceScript() { - if(!getServerConfig().devServer) { - getServerData().races = loadRacesFromDatabase(); - } - - setRaceDataIndexes(); + logToConsole(LOG_INFO, "[VRR.Race]: Initializing race script ..."); + logToConsole(LOG_INFO, "[VRR.Race]: Race script initialized successfully!"); } // =========================================================================== @@ -28,4 +25,33 @@ function getRaceData(raceId) { return false; } +// =========================================================================== + +function setAllRaceDataIndexes() { + for(let i in getServerData().races) { + getServerData().races[i].index = i; + } +} + +// =========================================================================== + +function loadRacesFromDatabase() { + // To-do + return []; +} + +// =========================================================================== + +function saveRacesToDatabase() { + for(let i in getServerData().races) { + saveRaceToDatabase(getServerData().races[i]); + } +} + +// =========================================================================== + +function saveRaceToDatabase(raceData) { + return true; +} + // =========================================================================== \ No newline at end of file diff --git a/scripts/server/radio.js b/scripts/server/radio.js index 30390046..bda1b48e 100644 --- a/scripts/server/radio.js +++ b/scripts/server/radio.js @@ -9,11 +9,6 @@ function initRadioScript() { logToConsole(LOG_INFO, "[VRR.Radio]: Initializing radio script ..."); - if(!getServerConfig().devServer) { - getServerData().radioStations = loadRadioStationsFromDatabase(); - } - - setRadioStationIndexes(); logToConsole(LOG_INFO, "[VRR.Radio]: Radio script initialized successfully!"); return true; } @@ -229,7 +224,7 @@ function showRadioStationListCommand(command, params, client) { // =========================================================================== -function setRadioStationIndexes() { +function setAllRadioStationIndexes() { for(let i in getServerData().radioStations) { getServerData().radioStations[i].index = i; } diff --git a/scripts/server/staff.js b/scripts/server/staff.js index b3c4f03d..a5c2c8ab 100644 --- a/scripts/server/staff.js +++ b/scripts/server/staff.js @@ -45,7 +45,7 @@ function kickClientCommand(command, params, client) { //getPlayerData(targetClient).customDisconnectReason = reason; announceAdminAction(`PlayerKicked`, getPlayerName(targetClient)); - targetClient.disconnect(); + targetdisconnectPlayer(client); } // =========================================================================== @@ -83,9 +83,9 @@ function setStaffTitleCommand(command, params, client) { } getPlayerData(targetClient).accountData.staffTitle = staffTitle; - messageAdmins(`{adminRed}${client.name}{MAINCOLOUR} set {ALTCOLOUR}${getPlayerName(targetClient)}'s{MAINCOLOUR} staff title to ${staffTitle}`); + messageAdmins(`{adminRed}${getPlayerName(client)}{MAINCOLOUR} set {ALTCOLOUR}${getPlayerName(targetClient)}'s{MAINCOLOUR} staff title to ${staffTitle}`); messagePlayerAlert(client, `${getPlayerName(client)} set your staff title to ${staffTitle}`); - targetClient.disconnect(); + targetdisconnectPlayer(client); } // =========================================================================== @@ -119,7 +119,7 @@ function muteClientCommand(command, params, client) { } } - messageAdmins(`{adminRed}${targetClient.name}{MAINCOLOUR} has been muted by {adminRed}${client.name}`); + messageAdmins(`{adminRed}${targetgetPlayerName(client)}{MAINCOLOUR} has been muted by {adminRed}${getPlayerName(client)}`); getPlayerData(targetClient).muted = true; } @@ -154,7 +154,7 @@ function unMuteClientCommand(command, params, client) { } } - messageAdmins(`{adminRed}${targetClient.name}{MAINCOLOUR} has been un-muted by {adminRed}${client.name}`); + messageAdmins(`{adminRed}${targetgetPlayerName(client)}{MAINCOLOUR} has been un-muted by {adminRed}${getPlayerName(client)}`); getPlayerData(targetClient).muted = false; } @@ -189,7 +189,7 @@ function freezeClientCommand(command, params, client) { } } - messageAdmins(`{adminRed}${targetClient.name}{MAINCOLOUR} has been frozen by ${client.name}`); + messageAdmins(`{adminRed}${targetgetPlayerName(client)}{MAINCOLOUR} has been frozen by ${getPlayerName(client)}`); //setPlayerFrozenState(client, state); setPlayerControlState(client, false); } @@ -225,7 +225,7 @@ function unFreezeClientCommand(command, params, client) { } } - messageAdmins(`{adminRed}${targetClient.name}{MAINCOLOUR} has been un-frozen by ${client.name}`); + messageAdmins(`{adminRed}${targetgetPlayerName(client)}{MAINCOLOUR} has been un-frozen by ${getPlayerName(client)}`); //sendPlayerFrozenState(client, false); setPlayerControlState(client, true); } @@ -294,11 +294,11 @@ function getPlayerGeoIPInformationCommand(command, params, client) { return false; } - let countryName = module.geoip.getCountryName(getGlobalConfig().geoIPCountryDatabaseFilePath, targetClient.ip); - let subDivisionName = module.geoip.getSubdivisionName(getGlobalConfig().geoIPCityDatabaseFilePath, targetClient.ip); - let cityName = module.geoip.getCityName(getGlobalConfig().geoIPCityDatabaseFilePath, targetClient.ip); + let countryName = module.geoip.getCountryName(getGlobalConfig().geoIPCountryDatabaseFilePath, targetgetPlayerIP(client)); + let subDivisionName = module.geoip.getSubdivisionName(getGlobalConfig().geoIPCityDatabaseFilePath, targetgetPlayerIP(client)); + let cityName = module.geoip.getCityName(getGlobalConfig().geoIPCityDatabaseFilePath, targetgetPlayerIP(client)); - messagePlayerInfo(client, `{ALTCOLOUR}${targetClient.name} {MAINCOLOUR}is from {ALTCOLOUR}${cityName}, ${subDivisionName}, ${countryName}`); + messagePlayerInfo(client, `{ALTCOLOUR}${targetgetPlayerName(client)} {MAINCOLOUR}is from {ALTCOLOUR}${cityName}, ${subDivisionName}, ${countryName}`); } // =========================================================================== @@ -324,7 +324,7 @@ function getPlayerIPInformationCommand(command, params, client) { return false; } - messagePlayerInfo(client, `{ALTCOLOUR}${targetClient.name}'s{MAINCOLOUR} IP is ${targetClient.ip}`); + messagePlayerInfo(client, `{ALTCOLOUR}${targetgetPlayerName(client)}'s{MAINCOLOUR} IP is ${targetgetPlayerIP(client)}`); } // =========================================================================== @@ -393,7 +393,7 @@ function getVehicleCommand(command, params, client) { setElementInterior(vehicle, getPlayerInterior(client)); setElementDimension(vehicle, getPlayerDimension(client)); - messageAdmins(`{adminRed}${client.name}{MAINCOLOUR} teleported a {vehiclePurple}${getVehicleName(vehicle)}{ALTCOLOUR} (ID ${vehicle.id}){MAINCOLOUR} to their position`); + messageAdmins(`{adminRed}${getPlayerName(client)}{MAINCOLOUR} teleported a {vehiclePurple}${getVehicleName(vehicle)}{ALTCOLOUR} (ID ${vehicle.id}){MAINCOLOUR} to their position`); } // =========================================================================== @@ -814,7 +814,7 @@ function playerInteriorCommand(command, params, client) { let interiorId = getParam(params, " ", 2); setPlayerInterior(targetClient, Number(interiorId)); - messageAdmins(`{adminRed}${client.name}{MAINCOLOUR} set {ALTCOLOUR}${getPlayerName(targetClient)}'s{MAINCOLOUR} interior to {ALTCOLOUR}${interiorId}`); + messageAdmins(`{adminRed}${getPlayerName(client)}{MAINCOLOUR} set {ALTCOLOUR}${getPlayerName(targetClient)}'s{MAINCOLOUR} interior to {ALTCOLOUR}${interiorId}`); } // =========================================================================== @@ -847,7 +847,7 @@ function playerVirtualWorldCommand(command, params, client) { let dimensionId = getParam(params, " ", 2); setPlayerDimension(targetClient, Number(dimensionId)); - messageAdmins(`{adminRed}${client.name}{MAINCOLOUR} set {ALTCOLOUR}${getPlayerName(targetClient)}'s{MAINCOLOUR} virtual world to {ALTCOLOUR}${dimensionId}`); + messageAdmins(`{adminRed}${getPlayerName(client)}{MAINCOLOUR} set {ALTCOLOUR}${getPlayerName(targetClient)}'s{MAINCOLOUR} virtual world to {ALTCOLOUR}${dimensionId}`); } // =========================================================================== @@ -895,7 +895,7 @@ function getPlayerCommand(command, params, client) { setPlayerInterior(targetClient, getPlayerInterior(client)); setPlayerDimension(targetClient, getPlayerDimension(client)); - messageAdmins(`{adminRed}${client.name}{MAINCOLOUR} teleported {ALTCOLOUR}${getPlayerName(targetClient)}{MAINCOLOUR} to their position.`); + messageAdmins(`{adminRed}${getPlayerName(client)}{MAINCOLOUR} teleported {ALTCOLOUR}${getPlayerName(targetClient)}{MAINCOLOUR} to their position.`); messagePlayerAlert(targetClient, `An admin has teleported you to their location`); } @@ -942,7 +942,7 @@ function returnPlayerCommand(command, params, client) { getPlayerData(targetClient).returnToBusiness = null; getPlayerData(targetClient).returnToType = VRR_RETURNTO_TYPE_NONE; - messageAdmins(`{adminRed}${client.name}{MAINCOLOUR} returned {ALTCOLOUR}${getPlayerName(targetClient)}{MAINCOLOUR} to their previous position.`); + messageAdmins(`{adminRed}${getPlayerName(client)}{MAINCOLOUR} returned {ALTCOLOUR}${getPlayerName(targetClient)}{MAINCOLOUR} to their previous position.`); messagePlayerAlert(targetClient, `An admin has returned you to your previous location`); } @@ -985,7 +985,7 @@ function addPlayerStaffFlagCommand(command, params, client) { } givePlayerStaffFlag(targetClient, flagName); - messageAdmins(`{adminRed}${client.name}{MAINCOLOUR} has given {ALTCOLOUR}${getPlayerName(targetClient)}{MAINCOLOUR} the {ALTCOLOUR}${flagName}{MAINCOLOUR} staff flag`); + messageAdmins(`{adminRed}${getPlayerName(client)}{MAINCOLOUR} has given {ALTCOLOUR}${getPlayerName(targetClient)}{MAINCOLOUR} the {ALTCOLOUR}${flagName}{MAINCOLOUR} staff flag`); } // =========================================================================== @@ -1027,7 +1027,7 @@ function removePlayerStaffFlagCommand(command, params, client) { } takePlayerStaffFlag(targetClient, flagName); - messageAdmins(`{adminRed}${client.name}{MAINCOLOUR} has taken the {ALTCOLOUR}${flagName}{MAINCOLOUR} staff flag from {ALTCOLOUR}${getPlayerName(targetClient)}`); + messageAdmins(`{adminRed}${getPlayerName(client)}{MAINCOLOUR} has taken the {ALTCOLOUR}${flagName}{MAINCOLOUR} staff flag from {ALTCOLOUR}${getPlayerName(targetClient)}`); } // =========================================================================== @@ -1063,7 +1063,7 @@ function removePlayerStaffFlagsCommand(command, params, client) { } clearPlayerStaffFlags(targetClient); - messageAdmins(`{adminRed}${client.name}{MAINCOLOUR} removed all staff flags from {ALTCOLOUR}${getPlayerName(targetClient)}`); + messageAdmins(`{adminRed}${getPlayerName(client)}{MAINCOLOUR} removed all staff flags from {ALTCOLOUR}${getPlayerName(targetClient)}`); } // =========================================================================== @@ -1190,7 +1190,7 @@ function givePlayerMoneyCommand(command, params, client) { givePlayerCash(targetClient, toInteger(amount)); updatePlayerCash(targetClient); //messagePlayerSuccess(client, `You gave {ALTCOLOUR}$${amount} {MAINCOLOUR}to {ALTCOLOUR}${getCharacterFullName(targetClient)}`); - messageAdmins(`{adminRed}${client.name}{MAINCOLOUR} gave {ALTCOLOUR}$${amount}{MAINCOLOUR} to {ALTCOLOUR}${getCharacterFullName(targetClient)}`) + messageAdmins(`{adminRed}${getPlayerName(client)}{MAINCOLOUR} gave {ALTCOLOUR}$${amount}{MAINCOLOUR} to {ALTCOLOUR}${getCharacterFullName(targetClient)}`) messagePlayerAlert(targetClient, `An admin gave you {ALTCOLOUR}$${amount}`); } @@ -1227,11 +1227,11 @@ function setPlayerAccentCommand(command, params, client) { if(newAccent == "") { //messagePlayerSuccess(client, `You removed {ALTCOLOUR}${getCharacterFullName(targetClient)}'s {MAINCOLOUR}accent.`); - messageAdmins(`{adminRed}${client.name}{MAINCOLOUR} removed {ALTCOLOUR}${getCharacterFullName(targetClient)}'s{MAINCOLOUR} accent.`); + messageAdmins(`{adminRed}${getPlayerName(client)}{MAINCOLOUR} removed {ALTCOLOUR}${getCharacterFullName(targetClient)}'s{MAINCOLOUR} accent.`); messagePlayerAlert(client, `An admin removed your accent.`); } else { //messagePlayerSuccess(client, `You set {ALTCOLOUR}${getCharacterFullName(targetClient)}'s {MAINCOLOUR}accent to {ALTCOLOUR}${newAccent}`); - messageAdmins(`{adminRed}${client.name}{MAINCOLOUR} set {ALTCOLOUR}${getCharacterFullName(targetClient)}'s{MAINCOLOUR} accent to {ALTCOLOUR}${newAccent}`) + messageAdmins(`{adminRed}${getPlayerName(client)}{MAINCOLOUR} set {ALTCOLOUR}${getCharacterFullName(targetClient)}'s{MAINCOLOUR} accent to {ALTCOLOUR}${newAccent}`) messagePlayerAlert(client, `An admin set your accent to {ALTCOLOUR}${newAccent}`); } } @@ -1262,7 +1262,7 @@ function forceCharacterNameChangeCommand(command, params, client) { getPlayerData(targetClient).changingCharacterName = true; - messageAdmins(`{adminRed}${client.name}{MAINCOLOUR} forced {ALTCOLOUR}${getPlayerName(targetClient)} (${getCharacterFullName(targetClient)}){MAINCOLOUR} to change their character's name.`); + messageAdmins(`{adminRed}${getPlayerName(client)}{MAINCOLOUR} forced {ALTCOLOUR}${getPlayerName(targetClient)} (${getCharacterFullName(targetClient)}){MAINCOLOUR} to change their character's name.`); showPlayerNewCharacterFailedGUI(targetClient, getLocaleString(targetClient, "NonRPName")); } diff --git a/scripts/server/startup.js b/scripts/server/startup.js index 6f051d32..67220d84 100644 --- a/scripts/server/startup.js +++ b/scripts/server/startup.js @@ -38,14 +38,16 @@ function initServerScripts() { initEconomyScript(); initRadioScript(); initLocaleScript(); - initCommandScript(); - serverStartTime = getCurrentUnixTimestamp(); + loadServerDataFromDatabase(); + setAllServerDataIndexes(); + createAllServerElements(); initAllClients(); - initTimers(); + + serverStartTime = getCurrentUnixTimestamp(); } // =========================================================================== @@ -105,6 +107,54 @@ function checkForAllRequiredModules() { // =========================================================================== +function loadServerDataFromDatabase() { + getServerData().itemTypes = loadItemTypesFromDatabase(); + + if(!getServerConfig().devServer) { + getServerData().items = loadItemsFromDatabase(); + getServerData().businesses = loadBusinessesFromDatabase(); + getServerData().houses = loadHousesFromDatabase(); + getServerData().vehicles = loadVehiclesFromDatabase(); + getServerData().clans = loadClansFromDatabase(); + getServerData().jobs = loadJobsFromDatabase(); + getServerData().npcs = loadNPCsFromDatabase(); + getServerData().races = loadRacesFromDatabase(); + getServerData().radioStations = loadRadioStationsFromDatabase(); + } +} + +// =========================================================================== + +function setAllServerDataIndexes() { + setItemTypeDataIndexes(); + setItemDataIndexes(); + setBusinessDataIndexes(); + setHouseDataIndexes(); + setAllClanDataIndexes(); + setAllJobDataIndexes(); + setNPCDataIndexes(); + setAllRaceDataIndexes(); + setAllRadioStationIndexes(); + cacheAllGroundItems(); + cacheAllBusinessItems(); +} + +// =========================================================================== + +function createAllServerElements() { + createAllBusinessPickups(); + createAllBusinessBlips(); + createAllHousePickups(); + createAllHouseBlips(); + createAllJobPickups(); + createAllJobBlips(); + createAllGroundItemObjects(); + spawnAllVehicles(); + spawnAllNPCs(); +} + +// =========================================================================== + initServerScripts(); // =========================================================================== \ No newline at end of file diff --git a/scripts/server/utilities.js b/scripts/server/utilities.js index 32df26a5..ada357c0 100644 --- a/scripts/server/utilities.js +++ b/scripts/server/utilities.js @@ -64,7 +64,7 @@ function getGameAreas(gameId) { function getPlayerData(client) { if(client != null) { if(isClientInitialized(client)) { - return getServerData().clients[client.index]; + return getServerData().clients[getPlayerId(client)]; } } return false; @@ -178,7 +178,7 @@ function getPlayerDisplayForConsole(client) { if(isNull(client)) { return "(Unknown client)"; } - return `${getPlayerName(client)}[${client.index}]`; + return `${getPlayerName(client)}[${getPlayerId(client)}]`; } // =========================================================================== @@ -449,7 +449,7 @@ function clearTemporaryPeds() { function kickAllClients() { getClients().forEach((client) => { - client.disconnect(); + disconnectPlayer(client); }) } @@ -464,7 +464,7 @@ function updateTimeRule() { // =========================================================================== function isClientInitialized(client) { - return (typeof getServerData().clients[client.index] != "undefined"); + return (typeof getServerData().clients[getPlayerId(client)] != "undefined"); } // ===========================================================================