diff --git a/scripts/server/gate.js b/scripts/server/gate.js index 6df974e4..9e4afbe8 100644 --- a/scripts/server/gate.js +++ b/scripts/server/gate.js @@ -195,4 +195,32 @@ function saveGateToDatabase(gateId) { return true; } +// =========================================================================== + +function loadGatesFromDatabase() { + logToConsole(LOG_INFO, "[VRR.Gate]: Loading gates from database ..."); + + let tempGates = []; + let dbConnection = connectToDatabase(); + let dbAssoc; + + if(dbConnection) { + let dbQuery = queryDatabase(dbConnection, `SELECT * FROM gate_main WHERE gate_server = ${getServerId()}`); + if(dbQuery) { + if(dbQuery.numRows > 0) { + while(dbAssoc = fetchQueryAssoc(dbQuery)) { + let tempGateData = new GateData(dbAssoc); + tempGates.push(tempGateData); + logToConsole(LOG_DEBUG, `[VRR.Gate]: Gate '${tempGateData.name}' loaded from database successfully!`); + } + } + freeDatabaseQuery(dbQuery); + } + disconnectFromDatabase(dbConnection); + } + + logToConsole(LOG_INFO, `[VRR.Gate]: ${tempGates.length} gates loaded from database successfully!`); + return tempGates; +} + // =========================================================================== \ No newline at end of file