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