New assoc table usage

This commit is contained in:
Vortrex
2022-12-11 04:49:53 -06:00
parent b10118e1ab
commit a495f70239
16 changed files with 320 additions and 436 deletions

View File

@@ -137,9 +137,7 @@ async function loadSubAccountFromName(firstName, 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 dbQuery = queryDatabase(dbConnection, dbQueryString);
dbAssoc = await fetchQueryAssoc(dbQuery);
dbAssoc = await fetchQueryAssoc(dbConnection, dbQueryString);
if (dbAssoc.length > 0) {
freeDatabaseQuery(dbQuery);
return new SubAccountData(dbAssoc[0]);
@@ -157,10 +155,8 @@ async function loadSubAccountFromId(subAccountId) {
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) {
dbAssoc = await fetchQueryAssoc(dbQuery);
freeDatabaseQuery(dbQuery);
dbAssoc = await fetchQueryAssoc(dbConnection, dbQueryString);
if (dbAssoc.length > 0) {
return new SubAccountData(dbAssoc[0]);
}
disconnectFromDatabase(dbConnection);
@@ -178,75 +174,71 @@ async function loadSubAccountsFromAccount(accountId) {
let dbConnection = connectToDatabase();
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_acct = ${accountId} AND sacct_server = ${getServerId()}`;
let dbQuery = queryDatabase(dbConnection, dbQueryString);
if (dbQuery) {
dbAssoc = await fetchQueryAssoc(dbQuery);
if (dbAssoc.length > 0) {
for (let i in dbAssoc) {
let tempSubAccount = new SubAccountData(dbAssoc[i]);
dbAssoc = await fetchQueryAssoc(dbConnection, dbQueryString);
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;
}
}
// 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);
// Make sure skin is valid
if (tempSubAccount.skin == -1) {
tempSubAccount.skin = getServerConfig().newCharacter.skin;
}
freeDatabaseQuery(dbQuery);
// 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
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);
}
disconnectFromDatabase(dbConnection);
}
disconnectFromDatabase(dbConnection);
}
}