Move stuff to startup.js

This commit is contained in:
Vortrex
2022-04-26 10:20:50 -05:00
parent 940d37a9b4
commit 422baa01a3
4 changed files with 61 additions and 48 deletions

View File

@@ -87,39 +87,13 @@ let globalConfig = {
function initConfigScript() { function initConfigScript() {
logToConsole(LOG_INFO, "[VRR.Config]: Initializing config script ..."); 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!"); logToConsole(LOG_INFO, "[VRR.Config]: Config script initialized!");
} }
// =========================================================================== // ===========================================================================
function loadGlobalConfig() { function loadGlobalConfig() {
getGlobalConfig().database = loadDatabaseConfig();
getGlobalConfig().economy = loadEconomyConfig(); getGlobalConfig().economy = loadEconomyConfig();
getGlobalConfig().locale = loadLocaleConfig(); getGlobalConfig().locale = loadLocaleConfig();
getGlobalConfig().accents = loadAccentConfig(); getGlobalConfig().accents = loadAccentConfig();
@@ -169,6 +143,24 @@ function loadServerConfigFromId(tempServerId) {
// =========================================================================== // ===========================================================================
function applyConfigToServer(tempServerConfig) { 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()) { if(isTimeSupported()) {
logToConsole(LOG_DEBUG, `[VRR.Config]: Setting time to to ${tempServerConfig.hour}:${tempServerConfig.minute} with minute duration of ${tempServerConfig.minuteDuration}`); 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); setGameTime(tempServerConfig.hour, tempServerConfig.minute, tempServerConfig.minuteDuration);
@@ -707,16 +699,16 @@ function reloadEmailConfigurationCommand(command, params, client) {
* *
*/ */
function reloadDatabaseConfigurationCommand(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`); console.warn(`[VRR.Database] Closing persistent database connection`);
persistentDatabaseConnection.close(); persistentDatabaseConnection.close();
persistentDatabaseConnection = null; persistentDatabaseConnection = null;
} }
databaseEnabled = false; databaseEnabled = false;
databaseConfig = loadEmailConfig(); getGlobalConfig().database = loadDatabaseConfig();
messagePlayerSuccess(client, `You reloaded the database configuration!`); messagePlayerSuccess(client, `You reloaded the database configuration!`);
databaseEnabled = true; databaseEnabled = true;
if(databaseConfig.usePersistentConnection) { if(getDatabaseConfig().usePersistentConnection) {
connectToDatabase(); connectToDatabase();
} }
@@ -831,4 +823,17 @@ function doesServerHaveGroundSnowEnabled() {
return getServerConfig().groundSnow; return getServerConfig().groundSnow;
} }
// ===========================================================================
function loadDatabaseConfig() {
let databaseConfigFile = loadTextFile("config/database.json");
return JSON.parse(databaseConfigFile);
}
// ===========================================================================
function getDatabaseConfig() {
return getGlobalConfig().database;
}
// =========================================================================== // ===========================================================================

View File

@@ -40,8 +40,7 @@ let serverData = {
// =========================================================================== // ===========================================================================
// Pre-cache allowed skins let allowedSkins = [];
let allowedSkins = getAllowedSkins(getGame());
// =========================================================================== // ===========================================================================

View File

@@ -7,22 +7,8 @@
// TYPE: Server (JavaScript) // TYPE: Server (JavaScript)
// =========================================================================== // ===========================================================================
let translateURL = "http://api.mymemory.translated.net/get?de={3}&q={0}&langpair={1}|{2}";
// ===========================================================================
function initLocaleScript() { function initLocaleScript() {
logToConsole(LOG_INFO, "[VRR.Locale]: Initializing locale script ..."); 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!"); 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( httpGet(
thisTranslationURL, thisTranslationURL,
"", "",

View File

@@ -40,10 +40,16 @@ function initServerScripts() {
initLocaleScript(); initLocaleScript();
initCommandScript(); initCommandScript();
// Load config, commands, and data
loadGlobalConfig();
loadCommands();
loadServerDataFromDatabase(); loadServerDataFromDatabase();
// Set indexes and cache necessary data
setAllServerDataIndexes(); setAllServerDataIndexes();
createAllServerElements(); createAllServerElements();
applyConfigToServer(serverConfig);
initAllClients(); initAllClients();
initTimers(); initTimers();
@@ -108,8 +114,20 @@ function checkForAllRequiredModules() {
// =========================================================================== // ===========================================================================
function loadServerDataFromDatabase() { 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) { if(!getServerConfig().devServer) {
getServerData().items = loadItemsFromDatabase(); getServerData().items = loadItemsFromDatabase();
getServerData().businesses = loadBusinessesFromDatabase(); getServerData().businesses = loadBusinessesFromDatabase();
@@ -121,6 +139,9 @@ function loadServerDataFromDatabase() {
getServerData().races = loadRacesFromDatabase(); getServerData().races = loadRacesFromDatabase();
getServerData().radioStations = loadRadioStationsFromDatabase(); getServerData().radioStations = loadRadioStationsFromDatabase();
} }
getServerData().commands = loadCommands();
allowedSkins = getAllowedSkins(getGame());
} }
// =========================================================================== // ===========================================================================
@@ -137,6 +158,7 @@ function setAllServerDataIndexes() {
setAllRadioStationIndexes(); setAllRadioStationIndexes();
cacheAllGroundItems(); cacheAllGroundItems();
cacheAllBusinessItems(); cacheAllBusinessItems();
cacheAllCommandsAliases();
} }
// =========================================================================== // ===========================================================================
@@ -151,6 +173,7 @@ function createAllServerElements() {
createAllGroundItemObjects(); createAllGroundItemObjects();
spawnAllVehicles(); spawnAllVehicles();
spawnAllNPCs(); spawnAllNPCs();
addAllCommandHandlers();
} }
// =========================================================================== // ===========================================================================