Add gate stuff (unfinished)
This commit is contained in:
@@ -117,4 +117,75 @@ function triggerGateCommand(command, params, client) {
|
|||||||
triggerGate(getGateData(closestGate).scriptName);
|
triggerGate(getGateData(closestGate).scriptName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ===========================================================================
|
||||||
|
|
||||||
|
function saveAllGatesToDatabase() {
|
||||||
|
if(getServerConfig().devServer) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(let i in getServerData().gates) {
|
||||||
|
saveGateToDatabase(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===========================================================================
|
||||||
|
|
||||||
|
function saveGateToDatabase(gateId) {
|
||||||
|
if(getGateData(gateId) == null) {
|
||||||
|
// Invalid gate data
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let tempGateData = getGateData(gateId);
|
||||||
|
|
||||||
|
if(tempGateData.databaseId == -1) {
|
||||||
|
// Temp gate, no need to save
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!tempGateData.needsSaved) {
|
||||||
|
// Gate hasn't changed. No need to save.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
logToConsole(LOG_VERBOSE, `[VRR.Gate]: Saving gate ${tempGateData.databaseId} to database ...`);
|
||||||
|
let dbConnection = connectToDatabase();
|
||||||
|
if(dbConnection) {
|
||||||
|
let safeGateName = escapeDatabaseString(tempGateData.name);
|
||||||
|
let safeGateScriptName = escapeDatabaseString(tempGateData.scriptName);
|
||||||
|
|
||||||
|
let data = [
|
||||||
|
["gate_server", getServerId()],
|
||||||
|
["gate_name", safeGateName],
|
||||||
|
["gate_script_name", safeGateScriptName],
|
||||||
|
["gate_owner_type", toInteger(tempGateData.ownerType)],
|
||||||
|
["gate_owner_id", toInteger(tempGateData.ownerId)],
|
||||||
|
["gate_pos_x", toFloat(tempGateData.position.x)],
|
||||||
|
["gate_pos_y", toFloat(tempGateData.position.y)],
|
||||||
|
["gate_pos_z", toFloat(tempGateData.position.z)],
|
||||||
|
["gate_radius", toFloat(tempGateData.radius)],
|
||||||
|
];
|
||||||
|
|
||||||
|
let dbQuery = null;
|
||||||
|
if(tempGateData.databaseId == 0) {
|
||||||
|
let queryString = createDatabaseInsertQuery("gate_main", data);
|
||||||
|
dbQuery = queryDatabase(dbConnection, queryString);
|
||||||
|
tempGateData.databaseId = getDatabaseInsertId(dbConnection);
|
||||||
|
tempGateData.needsSaved = false;
|
||||||
|
} else {
|
||||||
|
let queryString = createDatabaseUpdateQuery("gate_main", data, `gate_id=${tempGateData.databaseId}`);
|
||||||
|
dbQuery = queryDatabase(dbConnection, queryString);
|
||||||
|
tempGateData.needsSaved = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
freeDatabaseQuery(dbQuery);
|
||||||
|
disconnectFromDatabase(dbConnection);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
logToConsole(LOG_VERBOSE, `[VRR.Gate]: Saved gate ${gateDataId} to database!`);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// ===========================================================================
|
// ===========================================================================
|
||||||
Reference in New Issue
Block a user