Optimizations

This commit is contained in:
Vortrex
2022-05-10 17:54:53 -05:00
parent 37d09c025f
commit 8e643e376c
5 changed files with 27 additions and 49 deletions

View File

@@ -252,13 +252,9 @@ function unbanSubNet(ipAddressStart, ipAddressEnd, adminAccountId) {
// ===========================================================================
function isAccountBanned(accountId) {
let bans = getServerData().bans;
for(let i in bans) {
if(bans[i].type == VRR_BANTYPE_ACCOUNT) {
if(bans[i].detail == accountId) {
return true;
}
}
let bans = getServerData().bans.filter(ban => ban.type === VRR_BANTYPE_ACCOUNT && ban.detail === accountId);
if(bans.length > 0) {
return true;
}
return false;
@@ -267,13 +263,9 @@ function isAccountBanned(accountId) {
// ===========================================================================
function isSubAccountBanned(subAccountId) {
let bans = getServerData().bans;
for(let i in bans) {
if(bans[i].type == VRR_BANTYPE_SUBACCOUNT) {
if(bans[i].detail == subAccountId) {
return true;
}
}
let bans = getServerData().bans.filter(ban => ban.type === VRR_BANTYPE_SUBACCOUNT && ban.detail === subAccountId);
if(bans.length > 0) {
return true;
}
return false;
@@ -282,13 +274,9 @@ function isSubAccountBanned(subAccountId) {
// ===========================================================================
function isIpAddressBanned(ipAddress) {
let bans = getServerData().bans;
for(let i in bans) {
if(bans[i].type == VRR_BANTYPE_IPADDRESS) {
if(bans[i].detail == ipAddress) {
return true;
}
}
let bans = getServerData().bans.filter(ban => ban.type === VRR_BANTYPE_IPADDRESS && ban.detail === ipAddress);
if(bans.length > 0) {
return true;
}
return false;

View File

@@ -2394,26 +2394,14 @@ function stockItemOnBusinessFloorCommand(command, params, client) {
// Gets the first free slot in a business's storage items
function getBusinessStorageFirstFreeItemSlot(businessId) {
for(let i in getBusinessData(businessId).storageItemCache) {
if(getBusinessData(businessId).storageItemCache[i] == -1) {
return i;
}
}
return -1;
return getBusinessData(businessId).storageItemCache.findIndex(item => item == -1);
}
// ===========================================================================
// Gets the first free slot in a business's floor items
function getBusinessFloorFirstFreeItemSlot(businessId) {
for(let i in getBusinessData(businessId).floorItemCache) {
if(getBusinessData(businessId).floorItemCache[i] == -1) {
return i;
}
}
return -1;
return getBusinessData(businessId).floorItemCache.findIndex(item => item == -1);
}
// ===========================================================================
@@ -2449,13 +2437,7 @@ function cacheBusinessItems(businessId) {
// Gets a business's data index from a business's databaseId
function getBusinessIdFromDatabaseId(databaseId) {
for(let i in getServerData().businesses) {
if(getBusinessData(i).databaseId == databaseId) {
return i;
}
}
return false;
return getServerData().businesses.findIndex(business => business.databaseId == databaseId);
}
// ===========================================================================

View File

@@ -995,10 +995,10 @@ function playerUseItem(client, hotBarSlot) {
let clients = getClients();
for(let i in clients) {
if(getDistance(getPlayerPosition(client), getPlayerPosition(clients[i])) <= 7) {
messagePlayerInfo(client, `{clanOrange}== {jobYellow}Badge {clanOrange}====================================`);
messagePlayerNormal(client, `{clanOrange}Name: {MAINCOLOUR}${getCharacterFullName(client)}`);
messagePlayerNormal(client, `{clanOrange}Type: {MAINCOLOUR}${getJobData(getPlayerJob(client)).name}`);
messagePlayerNormal(client, `{clanOrange}Rank: {MAINCOLOUR}${getJobRankName(getPlayerJob(client), getPlayerJobRank(client))}`);
makeChatBoxSectionHeader(clients[i], getLocaleString(client, "Badge", getCharacterFullName(client)));
messagePlayerNormal(client, `{clanOrange}Type:{MAINCOLOUR} ${getJobData(getPlayerJob(client)).name}`);
messagePlayerNormal(client, `{clanOrange}ID:{MAINCOLOUR} ${addPrefixNumberFill(getPlayerCurrentSubAccount(client).databaseId, 5)}`);
messagePlayerNormal(client, `{clanOrange}Rank:{MAINCOLOUR} ${getJobRankName(getPlayerJob(client), getPlayerJobRank(client))}`);
}
}
break;

View File

@@ -509,3 +509,13 @@ function getPlayerConnectionsInLastMonthByName(name) {
}
// ===========================================================================
function addPrefixNumberFill(number, amount) {
let numberString = toString(number);
while(numberString.length < amount) {
numberString = toString(`0${numberString}`);
}
return toString(numberString);
}
// ===========================================================================

View File

@@ -1389,9 +1389,7 @@ function Enum(constantsList) {
// ===========================================================================
function clearArray(array) {
if(array != null) {
array.splice(0, array.length);
}
array.length = 0;
}
// ===========================================================================