Move game ID util to natives + use db config util

This commit is contained in:
Vortrex
2022-04-26 10:18:15 -05:00
parent 0e82417d8d
commit 0e3b30725f
2 changed files with 16 additions and 11 deletions

View File

@@ -748,10 +748,10 @@ function getPlayerWeapon(client) {
// ===========================================================================
function connectToDatabase() {
if(databaseConfig.usePersistentConnection) {
if(getDatabaseConfig().usePersistentConnection) {
if(persistentDatabaseConnection == null) {
logToConsole(LOG_DEBUG, "[VRR.Database] Initializing database connection ...");
persistentDatabaseConnection = module.mysql.connect(databaseConfig.host, databaseConfig.user, databaseConfig.pass, databaseConfig.name, databaseConfig.port);
persistentDatabaseConnection = module.mysql.connect(getDatabaseConfig().host, getDatabaseConfig().user, getDatabaseConfig().pass, getDatabaseConfig().name, getDatabaseConfig().port);
if(persistentDatabaseConnection.error) {
console.warn("[VRR.Database] Database connection error: " + toString(persistentDatabaseConnection.error));
persistentDatabaseConnection = null;
@@ -765,7 +765,7 @@ function connectToDatabase() {
return persistentDatabaseConnection;
}
} else {
let databaseConnection = module.mysql.connect(databaseConfig.host, databaseConfig.user, databaseConfig.pass, databaseConfig.name, databaseConfig.port);
let databaseConnection = module.mysql.connect(getDatabaseConfig().host, getDatabaseConfig().user, getDatabaseConfig().pass, getDatabaseConfig().name, getDatabaseConfig().port);
if(databaseConnection.error) {
console.warn("[VRR.Database] Database connection error: " + toString(persistentDatabaseConnection.error));
return false;
@@ -778,7 +778,7 @@ function connectToDatabase() {
// ===========================================================================
function disconnectFromDatabase(dbConnection) {
if(!databaseConfig.usePersistentConnection) {
if(!getDatabaseConfig().usePersistentConnection) {
try {
dbConnection.close();
logToConsole(LOG_DEBUG, `[VRR.Database] Database connection closed successfully`);
@@ -921,13 +921,6 @@ function setConstantsAsGlobalVariablesInDatabase() {
// ===========================================================================
function loadDatabaseConfiguration() {
let databaseConfigFile = loadTextFile("config/database.json");
return JSON.parse(databaseConfigFile);
}
// ===========================================================================
function createDatabaseInsertQuery(tableName, data) {
let fields = [];
let values = [];
@@ -1202,4 +1195,10 @@ function despawnPlayer(client) {
client.despawnPlayer();
}
// ===========================================================================
function getGame() {
return server.game;
}
// ===========================================================================