diff --git a/scripts/server/config.js b/scripts/server/config.js index eb78ecc9..d960ff46 100644 --- a/scripts/server/config.js +++ b/scripts/server/config.js @@ -87,39 +87,13 @@ let globalConfig = { function initConfigScript() { logToConsole(LOG_INFO, "[VRR.Config]: Initializing config script ..."); - logToConsole(LOG_DEBUG, "[VRR.Config]: Loading global config ..."); - loadGlobalConfig(); - - logToConsole(LOG_INFO, "[VRR.Config]: Loading server config ..."); - 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"))); - getServerConfig().showLogo = false; - getServerConfig().testerOnly = intToBool(toInteger(server.getCVar("vrr_testeronly"))); - getServerConfig().discordEnabled = false; - getServerConfig().createJobPickups = intToBool(toInteger(server.getCVar("vrr_jobpickups"))); - getServerConfig().createBusinessPickups = intToBool(toInteger(server.getCVar("vrr_businesspickups"))); - getServerConfig().createHousePickups = intToBool(toInteger(server.getCVar("vrr_housepickups"))); - getServerConfig().createJobBlips = intToBool(toInteger(server.getCVar("vrr_jobblips"))); - getServerConfig().createBusinessBlips = intToBool(toInteger(server.getCVar("vrr_businessblips"))); - getServerConfig().createHouseBlips = intToBool(toInteger(server.getCVar("vrr_houseblips"))); - getServerConfig().useRealTime = intToBool(toInteger(server.getCVar("vrr_realtime"))); - getServerConfig().antiCheat.enabled = intToBool(toInteger(server.getCVar("vrr_anticheat"))); - - applyConfigToServer(serverConfig); - logToConsole(LOG_DEBUG, "[VRR.Config]: Server config applied successfully!"); - logToConsole(LOG_INFO, "[VRR.Config]: Config script initialized!"); } - // =========================================================================== function loadGlobalConfig() { + getGlobalConfig().database = loadDatabaseConfig(); getGlobalConfig().economy = loadEconomyConfig(); getGlobalConfig().locale = loadLocaleConfig(); getGlobalConfig().accents = loadAccentConfig(); @@ -169,6 +143,24 @@ function loadServerConfigFromId(tempServerId) { // =========================================================================== function applyConfigToServer(tempServerConfig) { + 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"))); + getServerConfig().showLogo = false; + getServerConfig().testerOnly = intToBool(toInteger(server.getCVar("vrr_testeronly"))); + getServerConfig().discordEnabled = false; + getServerConfig().createJobPickups = intToBool(toInteger(server.getCVar("vrr_jobpickups"))); + getServerConfig().createBusinessPickups = intToBool(toInteger(server.getCVar("vrr_businesspickups"))); + getServerConfig().createHousePickups = intToBool(toInteger(server.getCVar("vrr_housepickups"))); + getServerConfig().createJobBlips = intToBool(toInteger(server.getCVar("vrr_jobblips"))); + getServerConfig().createBusinessBlips = intToBool(toInteger(server.getCVar("vrr_businessblips"))); + getServerConfig().createHouseBlips = intToBool(toInteger(server.getCVar("vrr_houseblips"))); + getServerConfig().useRealTime = intToBool(toInteger(server.getCVar("vrr_realtime"))); + getServerConfig().antiCheat.enabled = intToBool(toInteger(server.getCVar("vrr_anticheat"))); + logToConsole(LOG_DEBUG, "[VRR.Config]: Server config applied successfully!"); + if(isTimeSupported()) { logToConsole(LOG_DEBUG, `[VRR.Config]: Setting time to to ${tempServerConfig.hour}:${tempServerConfig.minute} with minute duration of ${tempServerConfig.minuteDuration}`); setGameTime(tempServerConfig.hour, tempServerConfig.minute, tempServerConfig.minuteDuration); @@ -707,16 +699,16 @@ function reloadEmailConfigurationCommand(command, params, client) { * */ function reloadDatabaseConfigurationCommand(command, params, client) { - if(databaseConfig.usePersistentConnection && isDatabaseConnected(persistentDatabaseConnection)) { + if(getDatabaseConfig().usePersistentConnection && isDatabaseConnected(persistentDatabaseConnection)) { console.warn(`[VRR.Database] Closing persistent database connection`); persistentDatabaseConnection.close(); persistentDatabaseConnection = null; } databaseEnabled = false; - databaseConfig = loadEmailConfig(); + getGlobalConfig().database = loadDatabaseConfig(); messagePlayerSuccess(client, `You reloaded the database configuration!`); databaseEnabled = true; - if(databaseConfig.usePersistentConnection) { + if(getDatabaseConfig().usePersistentConnection) { connectToDatabase(); } @@ -831,4 +823,17 @@ function doesServerHaveGroundSnowEnabled() { return getServerConfig().groundSnow; } +// =========================================================================== + +function loadDatabaseConfig() { + let databaseConfigFile = loadTextFile("config/database.json"); + return JSON.parse(databaseConfigFile); +} + +// =========================================================================== + +function getDatabaseConfig() { + return getGlobalConfig().database; +} + // =========================================================================== \ No newline at end of file diff --git a/scripts/server/core.js b/scripts/server/core.js index dced5f27..500175f3 100644 --- a/scripts/server/core.js +++ b/scripts/server/core.js @@ -40,8 +40,7 @@ let serverData = { // =========================================================================== -// Pre-cache allowed skins -let allowedSkins = getAllowedSkins(getGame()); +let allowedSkins = []; // =========================================================================== diff --git a/scripts/server/locale.js b/scripts/server/locale.js index a2768cb1..b876212f 100644 --- a/scripts/server/locale.js +++ b/scripts/server/locale.js @@ -7,22 +7,8 @@ // TYPE: Server (JavaScript) // =========================================================================== -let translateURL = "http://api.mymemory.translated.net/get?de={3}&q={0}&langpair={1}|{2}"; - -// =========================================================================== - function initLocaleScript() { logToConsole(LOG_INFO, "[VRR.Locale]: Initializing locale script ..."); - getServerData().localeStrings = loadAllLocaleStrings(); - - // Translation Cache - getServerData().cachedTranslations = new Array(getGlobalConfig().locale.locales.length); - getServerData().cachedTranslationFrom = new Array(getGlobalConfig().locale.locales.length); - getServerData().cachedTranslationFrom.fill([]); - getServerData().cachedTranslations.fill(getServerData().cachedTranslationFrom); - - getGlobalConfig().locale.defaultLanguageId = getLocaleFromParams(getGlobalConfig().locale.defaultLanguageId); - logToConsole(LOG_INFO, "[VRR.Locale]: Locale script initialized!"); } @@ -209,7 +195,7 @@ async function translateMessage(messageText, translateFrom = getGlobalConfig().l } } - let thisTranslationURL = translateURL.format(encodeURI(messageText), toUpperCase(getGlobalConfig().locale.locales[translateFrom].isoCode), toUpperCase(getGlobalConfig().locale.locales[translateTo].isoCode), getGlobalConfig().locale.apiEmail); + let thisTranslationURL = getGlobalConfig().locale.translateURL.format(encodeURI(messageText), toUpperCase(getGlobalConfig().locale.locales[translateFrom].isoCode), toUpperCase(getGlobalConfig().locale.locales[translateTo].isoCode), getGlobalConfig().locale.apiEmail); httpGet( thisTranslationURL, "", diff --git a/scripts/server/startup.js b/scripts/server/startup.js index 67220d84..6146477d 100644 --- a/scripts/server/startup.js +++ b/scripts/server/startup.js @@ -40,10 +40,16 @@ function initServerScripts() { initLocaleScript(); initCommandScript(); + // Load config, commands, and data + loadGlobalConfig(); + loadCommands(); loadServerDataFromDatabase(); + + // Set indexes and cache necessary data setAllServerDataIndexes(); createAllServerElements(); + applyConfigToServer(serverConfig); initAllClients(); initTimers(); @@ -108,8 +114,20 @@ function checkForAllRequiredModules() { // =========================================================================== function loadServerDataFromDatabase() { - getServerData().itemTypes = loadItemTypesFromDatabase(); + logToConsole(LOG_INFO, "[VRR.Config]: Loading server config ..."); + serverConfig = loadServerConfigFromGameAndPort(server.game, server.port, getMultiplayerMod()); + // Always load these regardless of "test server" status + getServerData().itemTypes = loadItemTypesFromDatabase(); + getServerData().localeStrings = loadAllLocaleStrings(); + + // Translation Cache + getServerData().cachedTranslations = new Array(getGlobalConfig().locale.locales.length); + getServerData().cachedTranslationFrom = new Array(getGlobalConfig().locale.locales.length); + getServerData().cachedTranslationFrom.fill([]); + getServerData().cachedTranslations.fill(getServerData().cachedTranslationFrom); + + // Only load these if the server isn't a testing/dev server if(!getServerConfig().devServer) { getServerData().items = loadItemsFromDatabase(); getServerData().businesses = loadBusinessesFromDatabase(); @@ -121,6 +139,9 @@ function loadServerDataFromDatabase() { getServerData().races = loadRacesFromDatabase(); getServerData().radioStations = loadRadioStationsFromDatabase(); } + + getServerData().commands = loadCommands(); + allowedSkins = getAllowedSkins(getGame()); } // =========================================================================== @@ -137,6 +158,7 @@ function setAllServerDataIndexes() { setAllRadioStationIndexes(); cacheAllGroundItems(); cacheAllBusinessItems(); + cacheAllCommandsAliases(); } // =========================================================================== @@ -151,6 +173,7 @@ function createAllServerElements() { createAllGroundItemObjects(); spawnAllVehicles(); spawnAllNPCs(); + addAllCommandHandlers(); } // ===========================================================================