Use new fetch assoc stuff
This commit is contained in:
@@ -715,20 +715,21 @@ function isAccountPasswordCorrect(accountData, password) {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadAccountFromName(accountName, fullLoad = false) {
|
||||
async function loadAccountFromName(accountName, fullLoad = false) {
|
||||
let dbConnection = connectToDatabase();
|
||||
let dbAssoc = [];
|
||||
if (dbConnection) {
|
||||
accountName = escapeDatabaseString(dbConnection, accountName);
|
||||
let dbQueryString = `SELECT acct_main.*, acct_svr.* FROM acct_main INNER JOIN acct_svr ON acct_svr.acct_svr_acct = acct_main.acct_id AND acct_svr.acct_svr_svr = ${getServerId()} WHERE acct_name = '${accountName}' LIMIT 1;`;
|
||||
let dbQuery = queryDatabase(dbConnection, dbQueryString);
|
||||
if (dbQuery) {
|
||||
if (dbQuery.numRows > 0) {
|
||||
let dbAssoc = fetchQueryAssoc(dbQuery);
|
||||
let tempAccountData = new AccountData(dbAssoc);
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
for (let i in dbAssoc) {
|
||||
let tempAccountData = new AccountData(dbAssoc[0]);
|
||||
if (fullLoad) {
|
||||
tempAccountData.messages = loadAccountMessagesFromDatabase(tempAccountData.databaseId);
|
||||
tempAccountData.notes = loadAccountStaffNotesFromDatabase(tempAccountData.databaseId);
|
||||
tempAccountData.contacts = loadAccountContactsFromDatabase(tempAccountData.databaseId);
|
||||
tempAccountData.messages = await loadAccountMessagesFromDatabase(tempAccountData.databaseId);
|
||||
tempAccountData.notes = await loadAccountStaffNotesFromDatabase(tempAccountData.databaseId);
|
||||
tempAccountData.contacts = await loadAccountContactsFromDatabase(tempAccountData.databaseId);
|
||||
}
|
||||
freeDatabaseQuery(dbQuery);
|
||||
return tempAccountData;
|
||||
@@ -742,19 +743,20 @@ function loadAccountFromName(accountName, fullLoad = false) {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadAccountFromId(accountId, fullLoad = false) {
|
||||
async function loadAccountFromId(accountId, fullLoad = false) {
|
||||
let dbConnection = connectToDatabase();
|
||||
let dbAssoc = [];
|
||||
if (dbConnection) {
|
||||
let dbQueryString = `SELECT acct_main.*, acct_svr.* FROM acct_main INNER JOIN acct_svr ON acct_svr.acct_svr_acct = acct_main.acct_id AND acct_svr.acct_svr_svr = ${getServerId()} WHERE acct_id = ${accountId} LIMIT 1;`;
|
||||
let dbQuery = queryDatabase(dbConnection, dbQueryString);
|
||||
if (dbQuery) {
|
||||
let dbAssoc = fetchQueryAssoc(dbQuery);
|
||||
let tempAccountData = new AccountData(dbAssoc);
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
let tempAccountData = new AccountData(dbAssoc[0]);
|
||||
freeDatabaseQuery(dbQuery);
|
||||
if (fullLoad) {
|
||||
tempAccountData.messages = loadAccountMessagesFromDatabase(tempAccountData.databaseId);
|
||||
tempAccountData.notes = loadAccountStaffNotesFromDatabase(tempAccountData.databaseId);
|
||||
tempAccountData.contacts = loadAccountContactsFromDatabase(tempAccountData.databaseId);
|
||||
tempAccountData.messages = await loadAccountMessagesFromDatabase(tempAccountData.databaseId);
|
||||
tempAccountData.notes = await loadAccountStaffNotesFromDatabase(tempAccountData.databaseId);
|
||||
tempAccountData.contacts = await loadAccountContactsFromDatabase(tempAccountData.databaseId);
|
||||
}
|
||||
|
||||
return tempAccountData;
|
||||
@@ -806,8 +808,8 @@ function getAccountHashingFunction() {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function isNameRegistered(name) {
|
||||
let accountData = loadAccountFromName(name, true);
|
||||
async function isNameRegistered(name) {
|
||||
let accountData = await loadAccountFromName(name, true);
|
||||
if (accountData.databaseId > 0) {
|
||||
return true;
|
||||
}
|
||||
@@ -1037,7 +1039,7 @@ function saveAccountContactsToDatabase(accountContactData) {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function createAccount(name, password, email = "") {
|
||||
async function createAccount(name, password, email = "") {
|
||||
let dbConnection = connectToDatabase();
|
||||
|
||||
if (dbConnection) {
|
||||
@@ -1049,11 +1051,11 @@ function createAccount(name, password, email = "") {
|
||||
if (getDatabaseInsertId(dbConnection) > 0) {
|
||||
let insertId = getDatabaseInsertId(dbConnection);
|
||||
createDefaultAccountServerData(insertId);
|
||||
let tempAccountData = loadAccountFromId(insertId, false);
|
||||
let tempAccountData = await loadAccountFromId(insertId, false);
|
||||
|
||||
tempAccountData.messages = loadAccountMessagesFromDatabase(tempAccountData.databaseId);
|
||||
tempAccountData.notes = loadAccountStaffNotesFromDatabase(tempAccountData.databaseId);
|
||||
tempAccountData.contacts = loadAccountContactsFromDatabase(tempAccountData.databaseId);
|
||||
tempAccountData.messages = await loadAccountMessagesFromDatabase(tempAccountData.databaseId);
|
||||
tempAccountData.notes = await loadAccountStaffNotesFromDatabase(tempAccountData.databaseId);
|
||||
tempAccountData.contacts = await loadAccountContactsFromDatabase(tempAccountData.databaseId);
|
||||
tempAccountData.flags.admin = 0;
|
||||
return tempAccountData;
|
||||
}
|
||||
@@ -1475,7 +1477,7 @@ function createDefaultAccountServerData(accountDatabaseId) {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadAccountKeybindsFromDatabase(accountDatabaseID) {
|
||||
async function loadAccountKeybindsFromDatabase(accountDatabaseID) {
|
||||
logToConsole(LOG_DEBUG, `[AGRP.Account]: Loading account keybinds for account ${accountDatabaseID} from database ...`);
|
||||
|
||||
let tempAccountKeybinds = [];
|
||||
@@ -1496,8 +1498,9 @@ function loadAccountKeybindsFromDatabase(accountDatabaseID) {
|
||||
if (dbConnection) {
|
||||
dbQuery = queryDatabase(dbConnection, `SELECT * FROM acct_hotkey WHERE acct_hotkey_enabled = 1 AND acct_hotkey_acct = ${accountDatabaseID} AND acct_hotkey_server = ${getServerId()}`);
|
||||
if (dbQuery) {
|
||||
if (dbQuery.numRows > 0) {
|
||||
while (dbAssoc = fetchQueryAssoc(dbQuery)) {
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
for (let i in dbAssoc) {
|
||||
let tempAccountKeyBindData = new KeyBindData(dbAssoc);
|
||||
tempAccountKeybinds.push(tempAccountKeyBindData);
|
||||
logToConsole(LOG_DEBUG, `[AGRP.Account]: Account keybind '${tempAccountKeyBindData.databaseId}' (Key ${tempAccountKeyBindData.key} '${toUpperCase(getKeyNameFromId(tempAccountKeyBindData.key))}') loaded from database successfully!`);
|
||||
@@ -1515,7 +1518,7 @@ function loadAccountKeybindsFromDatabase(accountDatabaseID) {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadAccountStaffNotesFromDatabase(accountDatabaseID) {
|
||||
async function loadAccountStaffNotesFromDatabase(accountDatabaseID) {
|
||||
logToConsole(LOG_DEBUG, `[AGRP.Account]: Loading account staff notes for account ${accountDatabaseID} from database ...`);
|
||||
|
||||
let tempAccountStaffNotes = [];
|
||||
@@ -1526,9 +1529,10 @@ function loadAccountStaffNotesFromDatabase(accountDatabaseID) {
|
||||
if (dbConnection) {
|
||||
dbQuery = queryDatabase(dbConnection, "SELECT * FROM `acct_note` WHERE `acct_note_deleted` = 0 AND `acct_note_acct` = " + toString(accountDatabaseID));
|
||||
if (dbQuery) {
|
||||
if (dbQuery.numRows > 0) {
|
||||
while (dbAssoc = fetchQueryAssoc(dbQuery)) {
|
||||
let tempAccountStaffNoteData = new AccountStaffNoteData(dbAssoc);
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
for (let i in dbAssoc) {
|
||||
let tempAccountStaffNoteData = new AccountStaffNoteData(dbAssoc[i]);
|
||||
tempAccountStaffNotes.push(tempAccountStaffNoteData);
|
||||
logToConsole(LOG_DEBUG, `[AGRP.Account]: Account staff note '${tempAccountStaffNoteData.databaseId}' loaded from database successfully!`);
|
||||
}
|
||||
@@ -1544,7 +1548,7 @@ function loadAccountStaffNotesFromDatabase(accountDatabaseID) {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadAccountContactsFromDatabase(accountDatabaseID) {
|
||||
async function loadAccountContactsFromDatabase(accountDatabaseID) {
|
||||
logToConsole(LOG_DEBUG, `[AGRP.Account]: Loading account contacts for account ${accountDatabaseID} from database ...`);
|
||||
|
||||
let tempAccountContacts = [];
|
||||
@@ -1555,9 +1559,10 @@ function loadAccountContactsFromDatabase(accountDatabaseID) {
|
||||
if (dbConnection) {
|
||||
dbQuery = queryDatabase(dbConnection, "SELECT * FROM `acct_contact` WHERE `acct_contact_deleted` = 0 AND `acct_contact_acct` = " + toString(accountDatabaseID));
|
||||
if (dbQuery) {
|
||||
if (dbQuery.numRows > 0) {
|
||||
while (dbAssoc = fetchQueryAssoc(dbQuery)) {
|
||||
let tempAccountContactData = new AccountContactData(dbAssoc);
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
for (let i in dbAssoc) {
|
||||
let tempAccountContactData = new AccountContactData(dbAssoc[i]);
|
||||
tempAccountContacts.push(tempAccountContactData);
|
||||
logToConsole(LOG_DEBUG, `[AGRP.Account]: Account contact '${tempAccountContactData.databaseId}' loaded from database successfully!`);
|
||||
}
|
||||
@@ -1573,7 +1578,7 @@ function loadAccountContactsFromDatabase(accountDatabaseID) {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadAccountMessagesFromDatabase(accountDatabaseID) {
|
||||
async function loadAccountMessagesFromDatabase(accountDatabaseID) {
|
||||
logToConsole(LOG_DEBUG, `[AGRP.Account]: Loading account messages for account ${accountDatabaseID} from database ...`);
|
||||
|
||||
let tempAccountMessages = [];
|
||||
@@ -1584,9 +1589,10 @@ function loadAccountMessagesFromDatabase(accountDatabaseID) {
|
||||
if (dbConnection) {
|
||||
dbQuery = queryDatabase(dbConnection, "SELECT * FROM `acct_msg` WHERE `acct_msg_deleted` = 0 AND `acct_msg_acct` = " + toString(accountDatabaseID));
|
||||
if (dbQuery) {
|
||||
if (dbQuery.numRows > 0) {
|
||||
while (dbAssoc = fetchQueryAssoc(dbQuery)) {
|
||||
let tempAccountMessageData = new AccountContactData(dbAssoc);
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
for (let i in dbAssoc) {
|
||||
let tempAccountMessageData = new AccountContactData(dbAssoc[i]);
|
||||
tempAccountMessages.push(tempAccountMessageData);
|
||||
logToConsole(LOG_DEBUG, `[AGRP.Account]: Account contact '${tempAccountMessageData.databaseId}' loaded from database successfully!`);
|
||||
}
|
||||
|
||||
@@ -196,13 +196,13 @@ function initBusinessScript() {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadBusinessFromId(businessId) {
|
||||
async function loadBusinessFromId(businessId) {
|
||||
let dbConnection = connectToDatabase();
|
||||
if (dbConnection) {
|
||||
let dbQueryString = `SELECT * FROM biz_main WHERE biz_id = ${businessId} LIMIT 1;`;
|
||||
let dbQuery = queryDatabase(dbConnection, dbQueryString);
|
||||
if (dbQuery) {
|
||||
let dbAssoc = fetchQueryAssoc(dbQuery);
|
||||
let dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
freeDatabaseQuery(dbQuery);
|
||||
return new BusinessData(dbAssoc);
|
||||
}
|
||||
@@ -214,20 +214,21 @@ function loadBusinessFromId(businessId) {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadBusinessesFromDatabase() {
|
||||
async function loadBusinessesFromDatabase() {
|
||||
logToConsole(LOG_INFO, "[AGRP.Business]: Loading businesses from database ...");
|
||||
|
||||
let tempBusinesses = [];
|
||||
let dbConnection = connectToDatabase();
|
||||
let dbQuery = null;
|
||||
let dbAssoc;
|
||||
let dbAssoc = [];
|
||||
|
||||
if (dbConnection) {
|
||||
dbQuery = queryDatabase(dbConnection, `SELECT * FROM biz_main WHERE biz_deleted = 0 AND biz_server = ${getServerId()}`);
|
||||
if (dbQuery) {
|
||||
if (dbQuery.numRows > 0) {
|
||||
while (dbAssoc = fetchQueryAssoc(dbQuery)) {
|
||||
let tempBusinessData = new BusinessData(dbAssoc);
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
for (let i in dbAssoc) {
|
||||
let tempBusinessData = new BusinessData(dbAssoc[i]);
|
||||
tempBusinessData.locations = loadBusinessLocationsFromDatabase(tempBusinessData.databaseId);
|
||||
//tempBusinessData.gameScripts = loadBusinessGameScriptsFromDatabase(tempBusinessData.databaseId);
|
||||
tempBusinesses.push(tempBusinessData);
|
||||
@@ -245,22 +246,23 @@ function loadBusinessesFromDatabase() {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadBusinessLocationsFromDatabase(businessId) {
|
||||
async function loadBusinessLocationsFromDatabase(businessId) {
|
||||
logToConsole(LOG_VERBOSE, `[AGRP.Business]: Loading business locations for business ${businessId} from database ...`);
|
||||
|
||||
let tempBusinessLocations = [];
|
||||
let dbConnection = connectToDatabase();
|
||||
let dbQuery = null;
|
||||
let dbAssoc;
|
||||
let dbAssoc = [];
|
||||
let dbQueryString = "";
|
||||
|
||||
if (dbConnection) {
|
||||
dbQueryString = `SELECT * FROM biz_loc WHERE biz_loc_biz = ${businessId}`;
|
||||
dbQuery = queryDatabase(dbConnection, dbQueryString);
|
||||
if (dbQuery) {
|
||||
if (dbQuery.numRows > 0) {
|
||||
while (dbAssoc = fetchQueryAssoc(dbQuery)) {
|
||||
let tempBusinessLocationData = new BusinessLocationData(dbAssoc);
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
for (let i in dbAssoc) {
|
||||
let tempBusinessLocationData = new BusinessLocationData(dbAssoc[i]);
|
||||
tempBusinessLocations.push(tempBusinessLocationData);
|
||||
logToConsole(LOG_VERBOSE, `[AGRP.Business]: Location '${tempBusinessLocationData.name}' loaded from database successfully!`);
|
||||
}
|
||||
@@ -277,22 +279,23 @@ function loadBusinessLocationsFromDatabase(businessId) {
|
||||
// ===========================================================================
|
||||
|
||||
/*
|
||||
function loadBusinessGameScriptsFromDatabase(businessId) {
|
||||
async function loadBusinessGameScriptsFromDatabase(businessId) {
|
||||
logToConsole(LOG_VERBOSE, `[AGRP.Business]: Loading business game scripts for business ${businessId} from database ...`);
|
||||
|
||||
let tempBusinessGameScripts = [];
|
||||
let dbConnection = connectToDatabase();
|
||||
let dbQuery = null;
|
||||
let dbAssoc;
|
||||
let dbAssoc = [];
|
||||
let dbQueryString = "";
|
||||
|
||||
if(dbConnection) {
|
||||
dbQueryString = `SELECT * FROM biz_script WHERE biz_script_biz = ${businessId}`;
|
||||
dbQuery = queryDatabase(dbConnection, dbQueryString);
|
||||
if(dbQuery) {
|
||||
if(dbQuery.numRows > 0) {
|
||||
while(dbAssoc = fetchQueryAssoc(dbQuery)) {
|
||||
let tempBusinessGameScriptData = new BusinessGameScriptData(dbAssoc);
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
for (let i in dbAssoc) {
|
||||
let tempBusinessGameScriptData = new BusinessGameScriptData(dbAssoc[i]);
|
||||
tempBusinessGameScripts.push(tempBusinessGameScriptData);
|
||||
logToConsole(LOG_VERBOSE, `[AGRP.Business]: Game script '${tempBusinessGameScriptData.name}' loaded from database successfully!`);
|
||||
}
|
||||
|
||||
@@ -117,19 +117,20 @@ function initClanScript() {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadClansFromDatabase() {
|
||||
async function loadClansFromDatabase() {
|
||||
logToConsole(LOG_INFO, "[AGRP.Clan]: Loading clans from database ...");
|
||||
|
||||
let tempClans = [];
|
||||
let dbConnection = connectToDatabase();
|
||||
let dbAssoc;
|
||||
let dbAssoc = [];
|
||||
|
||||
if (dbConnection) {
|
||||
let dbQuery = queryDatabase(dbConnection, `SELECT * FROM clan_main WHERE clan_deleted = 0 AND clan_server = ${getServerId()}`);
|
||||
if (dbQuery) {
|
||||
if (dbQuery.numRows > 0) {
|
||||
while (dbAssoc = fetchQueryAssoc(dbQuery)) {
|
||||
let tempClanData = new ClanData(dbAssoc);
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
for (let i in dbAssoc) {
|
||||
let tempClanData = new ClanData(dbAssoc[i]);
|
||||
//tempClanData.members = loadClanMembersFromDatabase(tempClanData.databaseId);
|
||||
tempClanData.ranks = loadClanRanksFromDatabase(tempClanData.databaseId);
|
||||
tempClans.push(tempClanData);
|
||||
@@ -147,7 +148,7 @@ function loadClansFromDatabase() {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadClanMembersFromDatabase() {
|
||||
async function loadClanMembersFromDatabase() {
|
||||
logToConsole(LOG_INFO, "[AGRP.Clan]: Loading clans from database ...");
|
||||
|
||||
let tempClans = [];
|
||||
@@ -157,9 +158,10 @@ function loadClanMembersFromDatabase() {
|
||||
if (dbConnection) {
|
||||
let dbQuery = queryDatabase(dbConnection, `SELECT * FROM clan_main WHERE clan_deleted = 0 AND clan_server = ${getServerId()}`);
|
||||
if (dbQuery) {
|
||||
if (dbQuery.numRows > 0) {
|
||||
while (dbAssoc = fetchQueryAssoc(dbQuery)) {
|
||||
let tempClanData = new ClanData(dbAssoc);
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
for (let i in dbAssoc) {
|
||||
let tempClanData = new ClanData(dbAssoc[i]);
|
||||
tempClans.push(tempClanData);
|
||||
logToConsole(LOG_VERBOSE, `[AGRP.Clan]: Clan '${tempClanData.name}' loaded from database successfully!`);
|
||||
}
|
||||
@@ -175,7 +177,7 @@ function loadClanMembersFromDatabase() {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadClanRanksFromDatabase(clanDatabaseId) {
|
||||
async function loadClanRanksFromDatabase(clanDatabaseId) {
|
||||
logToConsole(LOG_INFO, `[AGRP.Clan]: Loading ranks for clan ${clanDatabaseId} from database ...`);
|
||||
|
||||
let dbConnection = connectToDatabase();
|
||||
@@ -185,9 +187,10 @@ function loadClanRanksFromDatabase(clanDatabaseId) {
|
||||
if (dbConnection) {
|
||||
let dbQuery = queryDatabase(dbConnection, `SELECT * FROM clan_rank WHERE clan_rank_clan = ${clanDatabaseId}`);
|
||||
if (dbQuery) {
|
||||
if (dbQuery.numRows > 0) {
|
||||
while (dbAssoc = fetchQueryAssoc(dbQuery)) {
|
||||
let tempClanRankData = new ClanRankData(dbAssoc);
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
for (let i in dbAssoc) {
|
||||
let tempClanRankData = new ClanRankData(dbAssoc[i]);
|
||||
tempClanRanks.push(tempClanRankData);
|
||||
logToConsole(LOG_VERBOSE, `[AGRP.Clan]: Clan rank '${tempClanRankData.name}' loaded from database successfully!`);
|
||||
}
|
||||
|
||||
@@ -91,10 +91,10 @@ class ServerConfigData {
|
||||
this.databaseId = dbAssoc["svr_id"];
|
||||
this.newCharacter = {
|
||||
spawnPosition: toVector3(dbAssoc["svr_newchar_pos_x"], dbAssoc["svr_newchar_pos_y"], dbAssoc["svr_newchar_pos_z"]),
|
||||
spawnHeading: dbAssoc["svr_newchar_rot_z"],
|
||||
money: dbAssoc["svr_newchar_money"],
|
||||
bank: dbAssoc["svr_newchar_bank"],
|
||||
skin: dbAssoc["svr_newchar_skin"],
|
||||
spawnHeading: toFloat(dbAssoc["svr_newchar_rot_z"]),
|
||||
money: toInteger(dbAssoc["svr_newchar_money"]),
|
||||
bank: toInteger(dbAssoc["svr_newchar_bank"]),
|
||||
skin: toInteger(dbAssoc["svr_newchar_skin"]),
|
||||
};
|
||||
|
||||
this.connectCameraPosition = toVector3(dbAssoc["svr_connectcam_pos_x"], dbAssoc["svr_connectcam_pos_y"], dbAssoc["svr_connectcam_pos_z"]);
|
||||
@@ -318,10 +318,13 @@ async function loadServerConfigFromGameAndPort(gameId, port) {
|
||||
let dbConnection = connectToDatabase();
|
||||
if (dbConnection) {
|
||||
let dbQueryString = `SELECT * FROM svr_main WHERE svr_game = ${gameId} AND svr_port = ${port} LIMIT 1;`;
|
||||
let dbAssoc = await fetchQueryAssoc(dbConnection, dbQueryString);
|
||||
if (dbAssoc.length > 0) {
|
||||
let tempServerConfigData = new ServerConfigData(dbAssoc[0]);
|
||||
return tempServerConfigData;
|
||||
let dbQuery = queryDatabase(dbConnection, dbQueryString);
|
||||
if (dbQuery) {
|
||||
let dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
let tempServerConfigData = new ServerConfigData(dbAssoc[0]);
|
||||
return tempServerConfigData;
|
||||
}
|
||||
}
|
||||
disconnectFromDatabase(dbConnection);
|
||||
}
|
||||
@@ -334,13 +337,15 @@ async function loadServerConfigFromGame(gameId) {
|
||||
let dbConnection = connectToDatabase();
|
||||
if (dbConnection) {
|
||||
let dbQueryString = `SELECT * FROM svr_main WHERE svr_game = ${gameId} LIMIT 1;`;
|
||||
let dbAssocArray = await fetchQueryAssoc(dbConnection, dbQueryString);
|
||||
logToConsole(LOG_DEBUG | LOG_WARN, `${dbAssocArray[0]}`);
|
||||
if (dbAssocArray.length > 0) {
|
||||
let tempServerConfigData = new ServerConfigData(dbAssocArray[0]);
|
||||
return tempServerConfigData;
|
||||
let dbQuery = queryDatabase(dbConnection, dbQueryString);
|
||||
if (dbQuery) {
|
||||
let dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
let tempServerConfigData = new ServerConfigData(dbAssoc[0]);
|
||||
return tempServerConfigData;
|
||||
}
|
||||
disconnectFromDatabase(dbConnection);
|
||||
}
|
||||
disconnectFromDatabase(dbConnection);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -351,13 +356,17 @@ async function loadServerConfigFromId(tempServerId) {
|
||||
let dbConnection = connectToDatabase();
|
||||
if (dbConnection) {
|
||||
let dbQueryString = `SELECT * FROM svr_main WHERE svr_id = ${tempServerId} LIMIT 1;`;
|
||||
let dbAssoc = await fetchQueryAssoc(dbConnection, dbQueryString);
|
||||
if (dbAssoc.length > 0) {
|
||||
let tempServerConfigData = new ServerConfigData(dbAssoc[0]);
|
||||
return tempServerConfigData;
|
||||
let dbQuery = queryDatabase(dbConnection, dbQueryString);
|
||||
if (dbQuery) {
|
||||
let dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
let tempServerConfigData = new ServerConfigData(dbAssoc[0]);
|
||||
return tempServerConfigData;
|
||||
}
|
||||
}
|
||||
disconnectFromDatabase(dbConnection);
|
||||
}
|
||||
disconnectFromDatabase(dbConnection);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -883,8 +892,8 @@ function setServerRealWorldTimeZoneCommand(command, params, client) {
|
||||
* @return {bool} Whether or not the command was successful
|
||||
*
|
||||
*/
|
||||
function reloadServerConfigurationCommand(command, params, client) {
|
||||
serverConfig = loadServerConfigFromGameAndPort(server.game, server.port);
|
||||
async function reloadServerConfigurationCommand(command, params, client) {
|
||||
serverConfig = await loadServerConfigFromGameAndPort(server.game, server.port);
|
||||
applyConfigToServer(serverConfig);
|
||||
updateServerRules();
|
||||
|
||||
@@ -1116,18 +1125,18 @@ function getDatabaseConfig() {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadServerConfig() {
|
||||
async function loadServerConfig() {
|
||||
logToConsole(LOG_DEBUG, "[AGRP.Config] Loading server configuration");
|
||||
|
||||
if (toInteger(server.getCVar("agrp_devserver")) == 1) {
|
||||
serverConfig = loadServerConfigFromGame(getGame());
|
||||
serverConfig = await loadServerConfigFromGame(getGame());
|
||||
|
||||
if (serverConfig == false) {
|
||||
logToConsole(LOG_ERROR, `[AGRP.Config] Could not load server configuration for game ${getGame()}`);
|
||||
server.shutdown();
|
||||
}
|
||||
} else {
|
||||
serverConfig = loadServerConfigFromGameAndPort(getGame(), getServerPort());
|
||||
serverConfig = await loadServerConfigFromGameAndPort(getGame(), getServerPort());
|
||||
|
||||
if (serverConfig == false) {
|
||||
logToConsole(LOG_ERROR, `[AGRP.Config] Could not load server configuration for game ${getGame()} and port ${getServerPort()}`);
|
||||
|
||||
@@ -549,37 +549,36 @@ function isDevelopmentServer() {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function migrateSubAccountsToPerServerData() {
|
||||
async function migrateSubAccountsToPerServerData() {
|
||||
let dbConnection = connectToDatabase();
|
||||
let dbQuery = false;
|
||||
let dbAssoc = false;
|
||||
if (dbConnection) {
|
||||
dbQuery = queryDatabase(dbConnection, `SELECT * FROM sacct_main`);
|
||||
if (dbQuery) {
|
||||
while (dbAssoc = fetchQueryAssoc(dbQuery)) {
|
||||
createDefaultSubAccountServerData(dbAssoc["sacct_id"]);
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
createDefaultSubAccountServerData(dbAssoc[0]["sacct_id"]);
|
||||
|
||||
let dbQuery2 = queryDatabase(dbConnection, `UPDATE sacct_svr SET sacct_svr_skin = ${dbAssoc["sacct_skin"]}, sacct_svr_job = ${dbAssoc["sacct_job"]} WHERE sacct_svr_sacct=${dbAssoc["sacct_id"]} AND sacct_svr_server=${dbAssoc["sacct_server"]}`);
|
||||
if (dbQuery2) {
|
||||
freeDatabaseQuery(dbQuery2);
|
||||
}
|
||||
let dbQuery2 = queryDatabase(dbConnection, `UPDATE sacct_svr SET sacct_svr_skin = ${dbAssoc["sacct_skin"]}, sacct_svr_job = ${dbAssoc["sacct_job"]} WHERE sacct_svr_sacct=${dbAssoc["sacct_id"]} AND sacct_svr_server=${dbAssoc["sacct_server"]}`);
|
||||
if (dbQuery2) {
|
||||
freeDatabaseQuery(dbQuery2);
|
||||
}
|
||||
freeDatabaseQuery(dbQuery);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function resetAllAccountsHotkeysToDefault() {
|
||||
async function resetAllAccountsHotkeysToDefault() {
|
||||
let dbConnection = connectToDatabase();
|
||||
let dbQuery = false;
|
||||
let dbAssoc = false;
|
||||
if (dbConnection) {
|
||||
dbQuery = queryDatabase(dbConnection, `SELECT acct_id FROM acct_main`);
|
||||
if (dbQuery) {
|
||||
while (dbAssoc = fetchQueryAssoc(dbQuery)) {
|
||||
createDefaultKeybindsForAccount(dbAssoc["acct_id"]);
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
createDefaultKeybindsForAccount(dbAssoc[0]["acct_id"]);
|
||||
}
|
||||
freeDatabaseQuery(dbQuery);
|
||||
}
|
||||
|
||||
@@ -235,19 +235,20 @@ function saveGateToDatabase(gateId) {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadGatesFromDatabase() {
|
||||
async function loadGatesFromDatabase() {
|
||||
logToConsole(LOG_INFO, "[AGRP.Gate]: Loading gates from database ...");
|
||||
|
||||
let tempGates = [];
|
||||
let dbConnection = connectToDatabase();
|
||||
let dbAssoc;
|
||||
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);
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
for (let i in dbAssoc) {
|
||||
let tempGateData = new GateData(dbAssoc[i]);
|
||||
tempGates.push(tempGateData);
|
||||
logToConsole(LOG_DEBUG, `[AGRP.Gate]: Gate '${tempGateData.name}' loaded from database successfully!`);
|
||||
}
|
||||
|
||||
@@ -175,18 +175,19 @@ function initHouseScript() {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadHousesFromDatabase() {
|
||||
async function loadHousesFromDatabase() {
|
||||
logToConsole(LOG_INFO, "[AGRP.House]: Loading houses from database ...");
|
||||
let tempHouses = [];
|
||||
let dbConnection = connectToDatabase();
|
||||
let dbAssoc;
|
||||
let dbAssoc = [];
|
||||
|
||||
if (dbConnection) {
|
||||
let dbQuery = queryDatabase(dbConnection, `SELECT * FROM house_main WHERE house_deleted = 0 AND house_server = ${getServerId()}`);
|
||||
if (dbQuery) {
|
||||
if (dbQuery.numRows > 0) {
|
||||
while (dbAssoc = fetchQueryAssoc(dbQuery)) {
|
||||
let tempHouseData = new HouseData(dbAssoc);
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
for (let i in dbAssoc) {
|
||||
let tempHouseData = new HouseData(dbAssoc[i]);
|
||||
tempHouses.push(tempHouseData);
|
||||
logToConsole(LOG_VERBOSE, `[AGRP.House]: House '${tempHouseData.description}' (ID ${tempHouseData.databaseId}) loaded!`);
|
||||
}
|
||||
|
||||
@@ -288,17 +288,18 @@ function initItemScript() {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadItemsFromDatabase() {
|
||||
async function loadItemsFromDatabase() {
|
||||
logToConsole(LOG_DEBUG, `[AGRP.Item]: Loading items from database ...`);
|
||||
let tempItems = [];
|
||||
let dbConnection = connectToDatabase();
|
||||
let dbFetchAssoc;
|
||||
let dbAssoc;
|
||||
if (dbConnection) {
|
||||
let dbQuery = queryDatabase(dbConnection, `SELECT * FROM item_main WHERE item_deleted = 0 AND item_server = ${getServerId()}`);
|
||||
if (dbQuery) {
|
||||
if (dbQuery.numRows > 0) {
|
||||
while (dbFetchAssoc = fetchQueryAssoc(dbQuery)) {
|
||||
let tempItemData = new ItemData(dbFetchAssoc);
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
for (let i in dbAssoc) {
|
||||
let tempItemData = new ItemData(dbAssoc[i]);
|
||||
tempItems.push(tempItemData);
|
||||
logToConsole(LOG_VERBOSE, `[AGRP.Item]: Loaded item ${tempItemData.databaseId} (type ${tempItemData.itemType})} from database`);
|
||||
}
|
||||
@@ -313,17 +314,18 @@ function loadItemsFromDatabase() {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadItemTypesFromDatabase() {
|
||||
async function loadItemTypesFromDatabase() {
|
||||
logToConsole(LOG_DEBUG, `[AGRP.Item]: Loading item types from database ...`);
|
||||
let tempItemTypes = [];
|
||||
let dbConnection = connectToDatabase();
|
||||
let dbFetchAssoc;
|
||||
let dbAssoc;
|
||||
if (dbConnection) {
|
||||
let dbQuery = queryDatabase(dbConnection, `SELECT * FROM item_type WHERE item_type_deleted = 0 AND item_type_enabled = 1 AND item_type_server = ${getServerId()}`);
|
||||
if (dbQuery) {
|
||||
if (getQueryNumRows(dbQuery) > 0) {
|
||||
while (dbFetchAssoc = fetchQueryAssoc(dbQuery)) {
|
||||
let tempItemTypeData = new ItemTypeData(dbFetchAssoc);
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
for (let i in dbAssoc) {
|
||||
let tempItemTypeData = new ItemTypeData(dbAssoc[i]);
|
||||
tempItemTypes.push(tempItemTypeData);
|
||||
logToConsole(LOG_VERBOSE, `[AGRP.Item]: Loaded item type ${tempItemTypeData.name} (id ${tempItemTypeData.databaseId}} from database`);
|
||||
}
|
||||
|
||||
@@ -479,7 +479,7 @@ function initJobScript() {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadJobsFromDatabase() {
|
||||
async function loadJobsFromDatabase() {
|
||||
logToConsole(LOG_DEBUG, "[AGRP.Job]: Loading jobs from database ...");
|
||||
|
||||
let tempJobs = [];
|
||||
@@ -490,9 +490,10 @@ function loadJobsFromDatabase() {
|
||||
if (dbConnection) {
|
||||
dbQuery = queryDatabase(dbConnection, `SELECT * FROM job_main WHERE job_deleted = 0 AND job_enabled = 1 AND job_server = ${getServerId()}`);
|
||||
if (dbQuery) {
|
||||
if (dbQuery.numRows > 0) {
|
||||
while (dbAssoc = fetchQueryAssoc(dbQuery)) {
|
||||
let tempJobData = new JobData(dbAssoc);
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
for (let i in dbAssoc) {
|
||||
let tempJobData = new JobData(dbAssoc[i]);
|
||||
tempJobData.locations = loadJobLocationsFromDatabase(tempJobData.databaseId);
|
||||
tempJobData.equipment = loadJobEquipmentsFromDatabase(tempJobData.databaseId);
|
||||
tempJobData.uniforms = loadJobUniformsFromDatabase(tempJobData.databaseId);
|
||||
@@ -545,7 +546,7 @@ function loadAllJobLocationsFromDatabase() {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadJobRanksFromDatabase(jobDatabaseId) {
|
||||
async function loadJobRanksFromDatabase(jobDatabaseId) {
|
||||
logToConsole(LOG_DEBUG, `[AGRP.Job]: Loading ranks for job ${jobDatabaseId} from database ...`);
|
||||
|
||||
let tempJobRanks = [];
|
||||
@@ -556,9 +557,10 @@ function loadJobRanksFromDatabase(jobDatabaseId) {
|
||||
if (dbConnection) {
|
||||
dbQuery = queryDatabase(dbConnection, `SELECT * FROM job_rank WHERE job_rank_deleted = 0 AND job_rank_enabled = 1 AND job_rank_job = ${jobDatabaseId}`);
|
||||
if (dbQuery) {
|
||||
if (dbQuery.numRows > 0) {
|
||||
while (dbAssoc = fetchQueryAssoc(dbQuery)) {
|
||||
let tempJobRankData = new JobRankData(dbAssoc);
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
for (let i in dbAssoc) {
|
||||
let tempJobRankData = new JobRankData(dbAssoc[i]);
|
||||
tempJobRanks.push(tempJobRankData);
|
||||
logToConsole(LOG_VERBOSE, `[AGRP.Job]: Job rank '${tempJobRankData.name}' loaded from database successfully!`);
|
||||
}
|
||||
@@ -574,7 +576,7 @@ function loadJobRanksFromDatabase(jobDatabaseId) {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadJobRoutesFromDatabase(jobDatabaseId) {
|
||||
async function loadJobRoutesFromDatabase(jobDatabaseId) {
|
||||
logToConsole(LOG_DEBUG, `[AGRP.Job]: Loading job routes for job ${jobDatabaseId} from database ...`);
|
||||
|
||||
let tempJobRoutes = [];
|
||||
@@ -585,9 +587,10 @@ function loadJobRoutesFromDatabase(jobDatabaseId) {
|
||||
if (dbConnection) {
|
||||
dbQuery = queryDatabase(dbConnection, `SELECT * FROM job_route WHERE job_route_deleted = 0 AND job_route_enabled = 1 AND job_route_job = ${jobDatabaseId}`);
|
||||
if (dbQuery) {
|
||||
if (dbQuery.numRows > 0) {
|
||||
while (dbAssoc = fetchQueryAssoc(dbQuery)) {
|
||||
let tempJobRouteData = new JobRouteData(dbAssoc);
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
for (let i in dbAssoc) {
|
||||
let tempJobRouteData = new JobRouteData(dbAssoc[i]);
|
||||
tempJobRouteData.locations = loadJobRouteLocationsFromDatabase(tempJobRouteData.databaseId);
|
||||
tempJobRoutes.push(tempJobRouteData);
|
||||
logToConsole(LOG_VERBOSE, `[AGRP.Job]: Job route '${tempJobRouteData.name}' loaded from database successfully!`);
|
||||
@@ -604,7 +607,7 @@ function loadJobRoutesFromDatabase(jobDatabaseId) {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadJobRouteLocationsFromDatabase(jobRouteId) {
|
||||
async function loadJobRouteLocationsFromDatabase(jobRouteId) {
|
||||
logToConsole(LOG_DEBUG, `[AGRP.Job]: Loading locations for job route ${jobRouteId} from database ...`);
|
||||
|
||||
let tempJobRouteLocations = [];
|
||||
@@ -615,9 +618,10 @@ function loadJobRouteLocationsFromDatabase(jobRouteId) {
|
||||
if (dbConnection) {
|
||||
dbQuery = queryDatabase(dbConnection, `SELECT * FROM job_route_loc WHERE job_route_loc_deleted = 0 AND job_route_loc_enabled = 1 AND job_route_loc_route = ${jobRouteId}`);
|
||||
if (dbQuery) {
|
||||
if (dbQuery.numRows > 0) {
|
||||
while (dbAssoc = fetchQueryAssoc(dbQuery)) {
|
||||
let tempJobRouteLocationData = new JobRouteLocationData(dbAssoc);
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
for (let i in dbAssoc) {
|
||||
let tempJobRouteLocationData = new JobRouteLocationData(dbAssoc[i]);
|
||||
tempJobRouteLocations.push(tempJobRouteLocationData);
|
||||
logToConsole(LOG_VERBOSE, `[AGRP.Job]: Job route location '${tempJobRouteLocationData.databaseId}' loaded from database successfully!`);
|
||||
}
|
||||
@@ -633,7 +637,7 @@ function loadJobRouteLocationsFromDatabase(jobRouteId) {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadJobEquipmentsFromDatabase(jobDatabaseId) {
|
||||
async function loadJobEquipmentsFromDatabase(jobDatabaseId) {
|
||||
logToConsole(LOG_DEBUG, `[AGRP.Job]: Loading job equipments for job ${jobDatabaseId} from database ...`);
|
||||
|
||||
let tempJobEquipments = [];
|
||||
@@ -644,9 +648,10 @@ function loadJobEquipmentsFromDatabase(jobDatabaseId) {
|
||||
if (dbConnection) {
|
||||
dbQuery = queryDatabase(dbConnection, `SELECT * FROM job_equip WHERE job_equip_deleted = 0 AND job_equip_enabled = 1 AND job_equip_job = ${jobDatabaseId}`);
|
||||
if (dbQuery) {
|
||||
if (dbQuery.numRows > 0) {
|
||||
while (dbAssoc = fetchQueryAssoc(dbQuery)) {
|
||||
let tempJobEquipmentData = new JobEquipmentData(dbAssoc);
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
for (let i in dbAssoc) {
|
||||
let tempJobEquipmentData = new JobEquipmentData(dbAssoc[i]);
|
||||
tempJobEquipmentData.items = loadJobEquipmentItemsFromDatabase(tempJobEquipmentData.databaseId);
|
||||
tempJobEquipments.push(tempJobEquipmentData);
|
||||
logToConsole(LOG_VERBOSE, `[AGRP.Job]: Job equipment '${tempJobEquipmentData.name}' loaded from database successfully!`);
|
||||
@@ -663,7 +668,7 @@ function loadJobEquipmentsFromDatabase(jobDatabaseId) {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadJobLocationsFromDatabase(jobDatabaseId) {
|
||||
async function loadJobLocationsFromDatabase(jobDatabaseId) {
|
||||
logToConsole(LOG_DEBUG, `[AGRP.Job]: Loading job locations for job ${jobDatabaseId} from database ...`);
|
||||
|
||||
let tempJobLocations = [];
|
||||
@@ -674,9 +679,10 @@ function loadJobLocationsFromDatabase(jobDatabaseId) {
|
||||
if (dbConnection) {
|
||||
dbQuery = queryDatabase(dbConnection, `SELECT * FROM job_loc WHERE job_loc_deleted = 0 AND job_loc_enabled = 1 AND job_loc_job = ${jobDatabaseId}`);
|
||||
if (dbQuery) {
|
||||
if (dbQuery.numRows > 0) {
|
||||
while (dbAssoc = fetchQueryAssoc(dbQuery)) {
|
||||
let tempJobLocationData = new JobLocationData(dbAssoc);
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
for (let i in dbAssoc) {
|
||||
let tempJobLocationData = new JobLocationData(dbAssoc[i]);
|
||||
tempJobLocations.push(tempJobLocationData);
|
||||
logToConsole(LOG_VERBOSE, `[AGRP.Job]: Job location '${tempJobLocationData.databaseId}' loaded from database successfully!`);
|
||||
}
|
||||
@@ -692,7 +698,7 @@ function loadJobLocationsFromDatabase(jobDatabaseId) {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadJobUniformsFromDatabase(jobDatabaseId) {
|
||||
async function loadJobUniformsFromDatabase(jobDatabaseId) {
|
||||
logToConsole(LOG_DEBUG, `[AGRP.Job]: Loading job uniforms for job ${jobDatabaseId} from database ...`);
|
||||
|
||||
let tempJobUniforms = [];
|
||||
@@ -703,9 +709,10 @@ function loadJobUniformsFromDatabase(jobDatabaseId) {
|
||||
if (dbConnection) {
|
||||
dbQuery = queryDatabase(dbConnection, "SELECT * FROM `job_uniform` WHERE `job_uniform_enabled` = 1 AND `job_uniform_job` = " + toString(jobDatabaseId));
|
||||
if (dbQuery) {
|
||||
if (dbQuery.numRows > 0) {
|
||||
while (dbAssoc = fetchQueryAssoc(dbQuery)) {
|
||||
let tempJobUniformData = new JobUniformData(dbAssoc);
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
for (let i in dbAssoc) {
|
||||
let tempJobUniformData = new JobUniformData(dbAssoc[i]);
|
||||
tempJobUniforms.push(tempJobUniformData);
|
||||
logToConsole(LOG_VERBOSE, `[AGRP.Job]: Job uniform '${tempJobUniformData.databaseId}' loaded from database successfully!`);
|
||||
}
|
||||
@@ -721,7 +728,7 @@ function loadJobUniformsFromDatabase(jobDatabaseId) {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadJobEquipmentItemsFromDatabase(jobEquipmentDatabaseId) {
|
||||
async function loadJobEquipmentItemsFromDatabase(jobEquipmentDatabaseId) {
|
||||
logToConsole(LOG_DEBUG, `[AGRP.Job]: Loading job equipment items for job equipment ${jobEquipmentDatabaseId} from database ...`);
|
||||
|
||||
let tempJobEquipmentItems = [];
|
||||
@@ -732,9 +739,10 @@ function loadJobEquipmentItemsFromDatabase(jobEquipmentDatabaseId) {
|
||||
if (dbConnection) {
|
||||
dbQuery = queryDatabase(dbConnection, "SELECT * FROM `job_equip_item` WHERE `job_equip_item_enabled` = 1 AND `job_equip_item_equip` = " + toString(jobEquipmentDatabaseId));
|
||||
if (dbQuery) {
|
||||
if (dbQuery.numRows > 0) {
|
||||
while (dbAssoc = fetchQueryAssoc(dbQuery)) {
|
||||
let tempJobEquipmentItemData = new JobEquipmentItemData(dbAssoc);
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
for (let i in dbAssoc) {
|
||||
let tempJobEquipmentItemData = new JobEquipmentItemData(dbAssoc[i]);
|
||||
tempJobEquipmentItems.push(tempJobEquipmentItemData);
|
||||
logToConsole(LOG_VERBOSE, `[AGRP.Job]: Job equipment item '${tempJobEquipmentItemData.databaseId}' loaded from database successfully!`);
|
||||
}
|
||||
|
||||
@@ -917,9 +917,8 @@ function freeDatabaseQuery(dbQuery) {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
async function fetchQueryAssoc(dbConnection, dbQueryString) {
|
||||
async function fetchQueryAssoc(dbQuery) {
|
||||
//logToConsole(LOG_DEBUG, dbQueryString);
|
||||
let dbQuery = dbConnection.query(dbQueryString);
|
||||
let assocArray = [];
|
||||
let dbAssoc = null;
|
||||
|
||||
|
||||
@@ -246,22 +246,26 @@ function createNPCCommand(command, params, client) {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadNPCsFromDatabase() {
|
||||
async function loadNPCsFromDatabase() {
|
||||
logToConsole(LOG_DEBUG, `[AGRP.NPC]: Loading NPCs from database ...`);
|
||||
let dbConnection = connectToDatabase();
|
||||
let tempNPCs = [];
|
||||
let dbAssoc;
|
||||
let dbAssoc = [];
|
||||
if (dbConnection) {
|
||||
let dbQueryString = `SELECT * FROM npc_main WHERE npc_server = ${getServerId()} AND npc_enabled = 1`;
|
||||
let dbQuery = queryDatabase(dbConnection, dbQueryString);
|
||||
if (dbQuery) {
|
||||
while (dbAssoc = fetchQueryAssoc(dbQuery)) {
|
||||
let tempNPCData = new NPCData(dbAssoc);
|
||||
tempNPCData.triggers = loadNPCTriggersFromDatabase(tempNPCData.databaseId);
|
||||
tempNPCs.push(tempNPCData);
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
for (let i in dbAssoc) {
|
||||
let tempNPCData = new NPCData(dbAssoc[i]);
|
||||
tempNPCData.triggers = loadNPCTriggersFromDatabase(tempNPCData.databaseId);
|
||||
tempNPCs.push(tempNPCData);
|
||||
}
|
||||
}
|
||||
freeDatabaseQuery(dbQuery);
|
||||
}
|
||||
|
||||
disconnectFromDatabase(dbConnection);
|
||||
}
|
||||
|
||||
@@ -271,7 +275,7 @@ function loadNPCsFromDatabase() {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadNPCTriggersFromDatabase(npcDatabaseId) {
|
||||
async function loadNPCTriggersFromDatabase(npcDatabaseId) {
|
||||
logToConsole(LOG_DEBUG, `[AGRP.NPC]: Loading NPC triggers for NPC ${npcDatabaseId} from database ...`);
|
||||
let dbConnection = connectToDatabase();
|
||||
let tempNPCTriggers = [];
|
||||
@@ -279,9 +283,9 @@ function loadNPCTriggersFromDatabase(npcDatabaseId) {
|
||||
if (dbConnection) {
|
||||
let dbQueryString = `SELECT * FROM npc_trig WHERE npc_trig_npc = ${npcDatabaseId} AND npc_trig_enabled = 1`;
|
||||
let dbQuery = queryDatabase(dbConnection, dbQueryString);
|
||||
if (dbQuery) {
|
||||
while (dbAssoc = fetchQueryAssoc(dbQuery)) {
|
||||
let tempNPCTriggerData = new NPCTriggerData(dbAssoc);
|
||||
if (dbAssoc.length > 0) {
|
||||
for (let i in dbAssoc) {
|
||||
let tempNPCTriggerData = new NPCTriggerData(dbAssoc[i]);
|
||||
tempNPCTriggerData.conditions = loadNPCTriggerConditionsFromDatabase(tempNPCTriggerData.databaseId);
|
||||
tempNPCTriggerData.responses = loadNPCTriggerResponsesFromDatabase(tempNPCTriggerData.databaseId);
|
||||
tempNPCTriggers.push(tempNPCTriggerData);
|
||||
@@ -297,7 +301,7 @@ function loadNPCTriggersFromDatabase(npcDatabaseId) {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadNPCTriggerConditionsFromDatabase(npcTriggerDatabaseId) {
|
||||
async function loadNPCTriggerConditionsFromDatabase(npcTriggerDatabaseId) {
|
||||
logToConsole(LOG_DEBUG, `[AGRP.NPC]: Loading NPC trigger conditions for trigger ${npcTriggerDatabaseId} from database ...`);
|
||||
let dbConnection = connectToDatabase();
|
||||
let tempNPCTriggerConditions = [];
|
||||
@@ -306,13 +310,16 @@ function loadNPCTriggerConditionsFromDatabase(npcTriggerDatabaseId) {
|
||||
let dbQueryString = `SELECT * FROM npc_cond WHERE npc_cond_trig = ${npcTriggerDatabaseId} AND npc_cond_enabled = 1`;
|
||||
let dbQuery = queryDatabase(dbConnection, dbQueryString);
|
||||
if (dbQuery) {
|
||||
while (dbAssoc = fetchQueryAssoc(dbQuery)) {
|
||||
let tempNPCTriggerConditionData = new NPCTriggerConditionData(dbAssoc);
|
||||
tempNPCTriggerConditions.push(tempNPCTriggerConditionData);
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
for (let i in dbAssoc) {
|
||||
let tempNPCTriggerConditionData = new NPCTriggerConditionData(dbAssoc[i]);
|
||||
tempNPCTriggerConditions.push(tempNPCTriggerConditionData);
|
||||
}
|
||||
freeDatabaseQuery(dbQuery);
|
||||
}
|
||||
freeDatabaseQuery(dbQuery);
|
||||
disconnectFromDatabase(dbConnection);
|
||||
}
|
||||
disconnectFromDatabase(dbConnection);
|
||||
}
|
||||
|
||||
logToConsole(LOG_DEBUG, `[AGRP.NPC]: ${tempNPCTriggerConditions.length} conditions loaded for trigger ${npcTriggerDatabaseId} from database successfully!`);
|
||||
@@ -321,7 +328,7 @@ function loadNPCTriggerConditionsFromDatabase(npcTriggerDatabaseId) {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadNPCTriggerResponsesFromDatabase(npcTriggerDatabaseId) {
|
||||
async function loadNPCTriggerResponsesFromDatabase(npcTriggerDatabaseId) {
|
||||
logToConsole(LOG_DEBUG, `[AGRP.NPC]: Loading NPC trigger responses for trigger ${npcTriggerDatabaseId} from database ...`);
|
||||
let dbConnection = connectToDatabase();
|
||||
let tempNPCTriggerResponses = [];
|
||||
@@ -330,9 +337,11 @@ function loadNPCTriggerResponsesFromDatabase(npcTriggerDatabaseId) {
|
||||
let dbQueryString = `SELECT * FROM npc_resp WHERE npc_resp_trig = ${npcTriggerDatabaseId} AND npc_resp_enabled = 1`;
|
||||
let dbQuery = queryDatabase(dbConnection, dbQueryString);
|
||||
if (dbQuery) {
|
||||
while (dbAssoc = fetchQueryAssoc(dbQuery)) {
|
||||
let tempNPCTriggerResponseData = new NPCTriggerResponseData(dbAssoc);
|
||||
tempNPCTriggerResponses.push(tempNPCTriggerResponseData);
|
||||
if (dbAssoc.length > 0) {
|
||||
for (let i in dbAssoc) {
|
||||
let tempNPCTriggerResponseData = new NPCTriggerResponseData(dbAssoc[i]);
|
||||
tempNPCTriggerResponses.push(tempNPCTriggerResponseData);
|
||||
}
|
||||
}
|
||||
freeDatabaseQuery(dbQuery);
|
||||
}
|
||||
|
||||
@@ -159,13 +159,13 @@ function initPropertyScript() {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadPropertyFromId(propertyIndex) {
|
||||
async function loadPropertyFromId(propertyIndex) {
|
||||
let dbConnection = connectToDatabase();
|
||||
if (dbConnection) {
|
||||
let dbQueryString = `SELECT * FROM prop_main WHERE prop_id = ${propertyIndex} LIMIT 1;`;
|
||||
let dbQuery = queryDatabase(dbConnection, dbQueryString);
|
||||
if (dbQuery) {
|
||||
let dbAssoc = fetchQueryAssoc(dbQuery);
|
||||
let dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
freeDatabaseQuery(dbQuery);
|
||||
return new PropertyData(dbAssoc);
|
||||
}
|
||||
@@ -177,7 +177,7 @@ function loadPropertyFromId(propertyIndex) {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadPropertiesFromDatabase() {
|
||||
async function loadPropertiesFromDatabase() {
|
||||
logToConsole(LOG_INFO, "[AGRP.Property]: Loading properties from database ...");
|
||||
|
||||
let tempProperties = [];
|
||||
@@ -189,8 +189,8 @@ function loadPropertiesFromDatabase() {
|
||||
dbQuery = queryDatabase(dbConnection, `SELECT * FROM prop_main WHERE prop_deleted = 0 AND prop_server = ${getServerId()}`);
|
||||
if (dbQuery) {
|
||||
if (dbQuery.numRows > 0) {
|
||||
while (dbAssoc = fetchQueryAssoc(dbQuery)) {
|
||||
let tempPropertyData = new PropertyData(dbAssoc);
|
||||
while (dbAssoc = await fetchQueryAssoc(dbQuery)) {
|
||||
let tempPropertyData = new PropertyData(dbAssoc[i]);
|
||||
tempPropertyData.locations = loadPropertyLocationsFromDatabase(tempPropertyData.databaseId);
|
||||
tempProperties.push(tempPropertyData);
|
||||
logToConsole(LOG_VERBOSE, `[AGRP.Property]: Property '${tempPropertyData.name}' (ID ${tempPropertyData.databaseId}) loaded from database successfully!`);
|
||||
@@ -207,7 +207,7 @@ function loadPropertiesFromDatabase() {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadPropertyLocationsFromDatabase(propertyIndex) {
|
||||
async function loadPropertyLocationsFromDatabase(propertyIndex) {
|
||||
logToConsole(LOG_VERBOSE, `[AGRP.Property]: Loading property locations for property ${propertyIndex} from database ...`);
|
||||
|
||||
let tempPropertyLocations = [];
|
||||
@@ -220,9 +220,9 @@ function loadPropertyLocationsFromDatabase(propertyIndex) {
|
||||
dbQueryString = `SELECT * FROM prop_loc WHERE prop_loc_prop = ${propertyIndex}`;
|
||||
dbQuery = queryDatabase(dbConnection, dbQueryString);
|
||||
if (dbQuery) {
|
||||
if (dbQuery.numRows > 0) {
|
||||
while (dbAssoc = fetchQueryAssoc(dbQuery)) {
|
||||
let tempPropertyLocationData = new PropertyLocationData(dbAssoc);
|
||||
if (dbAssoc.length > 0) {
|
||||
for (let i in dbAssoc) {
|
||||
let tempPropertyLocationData = new PropertyLocationData(dbAssoc[i]);
|
||||
tempPropertyLocations.push(tempPropertyLocationData);
|
||||
logToConsole(LOG_VERBOSE, `[AGRP.Property]: Location '${tempPropertyLocationData.name}' loaded from database successfully!`);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ function initRadioScript() {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadRadioStationsFromDatabase() {
|
||||
async function loadRadioStationsFromDatabase() {
|
||||
logToConsole(LOG_INFO, "[AGRP.Radio]: Loading radio stations from database ...");
|
||||
let dbConnection = connectToDatabase();
|
||||
let tempRadioStations = [];
|
||||
@@ -45,9 +45,10 @@ function loadRadioStationsFromDatabase() {
|
||||
if (dbConnection) {
|
||||
let dbQueryString = `SELECT * FROM radio_main`;
|
||||
let dbQuery = queryDatabase(dbConnection, dbQueryString);
|
||||
if (dbQuery) {
|
||||
while (dbAssoc = fetchQueryAssoc(dbQuery)) {
|
||||
let tempRadioStationData = new RadioStationData(dbAssoc);
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
for (let i in dbAssoc) {
|
||||
let tempRadioStationData = new RadioStationData(dbAssoc[i]);
|
||||
tempRadioStations.push(tempRadioStationData);
|
||||
}
|
||||
freeDatabaseQuery(dbQuery);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
// TYPE: Server (JavaScript)
|
||||
// ===========================================================================
|
||||
|
||||
function initServerScripts() {
|
||||
async function initServerScripts() {
|
||||
checkForAllRequiredModules();
|
||||
|
||||
initDatabaseScript();
|
||||
@@ -42,7 +42,7 @@ function initServerScripts() {
|
||||
|
||||
// Load config and stuff
|
||||
loadGlobalConfig();
|
||||
loadServerConfig();
|
||||
await loadServerConfig();
|
||||
applyConfigToServer(getServerConfig());
|
||||
|
||||
// Load all the server data
|
||||
|
||||
@@ -129,35 +129,39 @@ function initSubAccountScript() {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadSubAccountFromName(firstName, lastName) {
|
||||
async function loadSubAccountFromName(firstName, lastName) {
|
||||
let dbConnection = connectToDatabase();
|
||||
let dbAssoc = [];
|
||||
if (dbConnection) {
|
||||
firstName = escapeDatabaseString(dbConnection, firstName);
|
||||
lastName = escapeDatabaseString(dbConnection, lastName);
|
||||
|
||||
let dbQueryString = `SELECT * FROM sacct_main INNER JOIN sacct_svr ON sacct_svr.sacct_svr_sacct=sacct_main.sacct_id AND sacct_svr.sacct_svr_server=${getServerId()} WHERE sacct_name_first = '${firstName}' AND sacct_name_last = '${lastName}' LIMIT 1;`;
|
||||
let dbQuery = queryDatabase(dbConnection, dbQueryString);
|
||||
if (dbQuery) {
|
||||
let dbAssoc = fetchQueryAssoc(dbQuery);
|
||||
freeDatabaseQuery(dbQuery);
|
||||
return new SubAccountData(dbAssoc);
|
||||
}
|
||||
disconnectFromDatabase(dbConnection);
|
||||
}
|
||||
|
||||
return false;
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
freeDatabaseQuery(dbQuery);
|
||||
return new SubAccountData(dbAssoc[0]);
|
||||
}
|
||||
|
||||
disconnectFromDatabase(dbConnection);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadSubAccountFromId(subAccountId) {
|
||||
async function loadSubAccountFromId(subAccountId) {
|
||||
let dbConnection = connectToDatabase();
|
||||
let dbAssoc = [];
|
||||
if (dbConnection) {
|
||||
let dbQueryString = `SELECT * FROM sacct_main INNER JOIN sacct_svr ON sacct_svr.sacct_svr_sacct=sacct_main.sacct_id AND sacct_svr.sacct_svr_server=${getServerId()} WHERE sacct_id = ${subAccountId} LIMIT 1;`;
|
||||
let dbQuery = queryDatabase(dbConnection, dbQueryString);
|
||||
if (dbQuery) {
|
||||
let dbAssoc = fetchQueryAssoc(dbQuery);
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
freeDatabaseQuery(dbQuery);
|
||||
return new SubAccountData(dbAssoc);
|
||||
return new SubAccountData(dbAssoc[0]);
|
||||
}
|
||||
disconnectFromDatabase(dbConnection);
|
||||
}
|
||||
@@ -167,7 +171,7 @@ function loadSubAccountFromId(subAccountId) {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadSubAccountsFromAccount(accountId) {
|
||||
async function loadSubAccountsFromAccount(accountId) {
|
||||
let tempSubAccounts = [];
|
||||
let dbAssoc = false;
|
||||
if (accountId > 0) {
|
||||
@@ -176,70 +180,73 @@ function loadSubAccountsFromAccount(accountId) {
|
||||
let dbQueryString = `SELECT * FROM sacct_main INNER JOIN sacct_svr ON sacct_svr.sacct_svr_sacct=sacct_main.sacct_id AND sacct_svr.sacct_svr_server=${getServerId()} WHERE sacct_acct = ${accountId} AND sacct_server = ${getServerId()}`;
|
||||
let dbQuery = queryDatabase(dbConnection, dbQueryString);
|
||||
if (dbQuery) {
|
||||
while (dbAssoc = fetchQueryAssoc(dbQuery)) {
|
||||
let tempSubAccount = new SubAccountData(dbAssoc);
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
for (let i in dbAssoc) {
|
||||
let tempSubAccount = new SubAccountData(dbAssoc[i]);
|
||||
|
||||
// Make sure skin is valid
|
||||
if (tempSubAccount.skin == -1) {
|
||||
tempSubAccount.skin = getServerConfig().newCharacter.skin;
|
||||
}
|
||||
|
||||
// Check if clan and rank are still valid
|
||||
if (tempSubAccount.clan != 0) {
|
||||
let clanIndex = getClanIndexFromDatabaseId(tempSubAccount.clan);
|
||||
if (!getClanData(clanIndex)) {
|
||||
tempSubAccount.clan = 0;
|
||||
tempSubAccount.clanRank = 0;
|
||||
tempSubAccount.clanIndex = -1;
|
||||
tempSubAccount.clanRankIndex = -1;
|
||||
tempSubAccount.clanTitle = "";
|
||||
tempSubAccount.clanFlags = 0;
|
||||
} else {
|
||||
let clanRankIndex = getClanRankIndexFromDatabaseId(clanIndex, tempSubAccount.clanRank);
|
||||
if (!getClanRankData(clanIndex, clanRankIndex)) {
|
||||
let newClanRankIndex = getLowestClanRank(clanIndex);
|
||||
tempSubAccount.clanRank = getClanRankData(clanIndex, newClanRankIndex).databaseId
|
||||
tempSubAccount.clanRankIndex = newClanRankIndex;
|
||||
} else {
|
||||
tempSubAccount.clanRankIndex = clanRankIndex;
|
||||
}
|
||||
|
||||
tempSubAccount.clanIndex = clanIndex;
|
||||
// Make sure skin is valid
|
||||
if (tempSubAccount.skin == -1) {
|
||||
tempSubAccount.skin = getServerConfig().newCharacter.skin;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if job and rank are still valid
|
||||
if (tempSubAccount.job != 0) {
|
||||
let jobIndex = getJobIndexFromDatabaseId(tempSubAccount.job);
|
||||
if (!getJobData(jobIndex)) {
|
||||
tempSubAccount.job = 0;
|
||||
tempSubAccount.jobRank = 0;
|
||||
tempSubAccount.jobIndex = -1;
|
||||
tempSubAccount.jobRankIndex = -1;
|
||||
} else {
|
||||
if (getJobData(jobIndex).ranks.length > 0) {
|
||||
let jobRankIndex = getJobRankIndexFromDatabaseId(jobIndex, tempSubAccount.jobRank);
|
||||
if (!getJobRankData(jobIndex, jobRankIndex)) {
|
||||
let newJobRankIndex = getLowestJobRank(jobIndex);
|
||||
console.log(`[AGRP.SubAccount]: Job ${jobIndex} has no rank ${tempSubAccount.jobRank}! Using lowest rank ${newJobRankIndex} instead.`);
|
||||
tempSubAccount.jobRank = getJobRankData(jobIndex, newJobRankIndex).databaseId;
|
||||
tempSubAccount.jobRankIndex = newJobRankIndex;
|
||||
// Check if clan and rank are still valid
|
||||
if (tempSubAccount.clan != 0) {
|
||||
let clanIndex = getClanIndexFromDatabaseId(tempSubAccount.clan);
|
||||
if (!getClanData(clanIndex)) {
|
||||
tempSubAccount.clan = 0;
|
||||
tempSubAccount.clanRank = 0;
|
||||
tempSubAccount.clanIndex = -1;
|
||||
tempSubAccount.clanRankIndex = -1;
|
||||
tempSubAccount.clanTitle = "";
|
||||
tempSubAccount.clanFlags = 0;
|
||||
} else {
|
||||
let clanRankIndex = getClanRankIndexFromDatabaseId(clanIndex, tempSubAccount.clanRank);
|
||||
if (!getClanRankData(clanIndex, clanRankIndex)) {
|
||||
let newClanRankIndex = getLowestClanRank(clanIndex);
|
||||
tempSubAccount.clanRank = getClanRankData(clanIndex, newClanRankIndex).databaseId
|
||||
tempSubAccount.clanRankIndex = newClanRankIndex;
|
||||
} else {
|
||||
tempSubAccount.jobRankIndex = jobRankIndex;
|
||||
tempSubAccount.clanRankIndex = clanRankIndex;
|
||||
}
|
||||
} else {
|
||||
tempSubAccount.jobRankIndex = -1;
|
||||
|
||||
tempSubAccount.clanIndex = clanIndex;
|
||||
}
|
||||
|
||||
tempSubAccount.jobIndex = jobIndex;
|
||||
}
|
||||
}
|
||||
|
||||
tempSubAccounts.push(tempSubAccount);
|
||||
// Check if job and rank are still valid
|
||||
if (tempSubAccount.job != 0) {
|
||||
let jobIndex = getJobIndexFromDatabaseId(tempSubAccount.job);
|
||||
if (!getJobData(jobIndex)) {
|
||||
tempSubAccount.job = 0;
|
||||
tempSubAccount.jobRank = 0;
|
||||
tempSubAccount.jobIndex = -1;
|
||||
tempSubAccount.jobRankIndex = -1;
|
||||
} else {
|
||||
if (getJobData(jobIndex).ranks.length > 0) {
|
||||
let jobRankIndex = getJobRankIndexFromDatabaseId(jobIndex, tempSubAccount.jobRank);
|
||||
if (!getJobRankData(jobIndex, jobRankIndex)) {
|
||||
let newJobRankIndex = getLowestJobRank(jobIndex);
|
||||
console.log(`[AGRP.SubAccount]: Job ${jobIndex} has no rank ${tempSubAccount.jobRank}! Using lowest rank ${newJobRankIndex} instead.`);
|
||||
tempSubAccount.jobRank = getJobRankData(jobIndex, newJobRankIndex).databaseId;
|
||||
tempSubAccount.jobRankIndex = newJobRankIndex;
|
||||
} else {
|
||||
tempSubAccount.jobRankIndex = jobRankIndex;
|
||||
}
|
||||
} else {
|
||||
tempSubAccount.jobRankIndex = -1;
|
||||
}
|
||||
|
||||
tempSubAccount.jobIndex = jobIndex;
|
||||
}
|
||||
}
|
||||
|
||||
tempSubAccounts.push(tempSubAccount);
|
||||
}
|
||||
freeDatabaseQuery(dbQuery);
|
||||
}
|
||||
freeDatabaseQuery(dbQuery);
|
||||
disconnectFromDatabase(dbConnection);
|
||||
}
|
||||
disconnectFromDatabase(dbConnection);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -177,7 +177,7 @@ function initVehicleScript() {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadVehiclesFromDatabase() {
|
||||
async function loadVehiclesFromDatabase() {
|
||||
logToConsole(LOG_INFO, "[AGRP.Vehicle]: Loading vehicles from database ...");
|
||||
let dbConnection = connectToDatabase();
|
||||
let tempVehicles = [];
|
||||
@@ -185,8 +185,9 @@ function loadVehiclesFromDatabase() {
|
||||
if (dbConnection) {
|
||||
let dbQueryString = `SELECT * FROM veh_main WHERE veh_server = ${getServerId()} AND veh_deleted = 0`;
|
||||
let dbQuery = queryDatabase(dbConnection, dbQueryString);
|
||||
if (dbQuery) {
|
||||
while (dbAssoc = fetchQueryAssoc(dbQuery)) {
|
||||
dbAssoc = await fetchQueryAssoc(dbQuery);
|
||||
if (dbAssoc.length > 0) {
|
||||
for (let i in dbAssoc) {
|
||||
let tempVehicleData = new VehicleData(dbAssoc);
|
||||
tempVehicles.push(tempVehicleData);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user