Add check for invalid business ID
This commit is contained in:
@@ -27,8 +27,8 @@ class BusinessData {
|
||||
function receiveBusinessFromServer(businessId, name, entrancePosition, blipModel, pickupModel, hasInterior, hasItems) {
|
||||
logToConsole(LOG_DEBUG, `[VRR.Business] Received business ${businessId} (${name}) from server`);
|
||||
|
||||
if(!areServerElementsSupported()) {
|
||||
if(getBusinessData(businessId) != false) {
|
||||
if (!areServerElementsSupported()) {
|
||||
if (getBusinessData(businessId) != false) {
|
||||
let businessData = getBusinessData(businessId);
|
||||
businessData.name = name;
|
||||
businessData.entrancePosition = entrancePosition;
|
||||
@@ -38,10 +38,10 @@ function receiveBusinessFromServer(businessId, name, entrancePosition, blipModel
|
||||
businessData.hasItems = hasItems;
|
||||
|
||||
logToConsole(LOG_DEBUG, `[VRR.Business] Business ${businessId} already exists. Checking blip ...`);
|
||||
if(blipModel == -1) {
|
||||
if(businessData.blipId != -1) {
|
||||
if (blipModel == -1) {
|
||||
if (businessData.blipId != -1) {
|
||||
logToConsole(LOG_DEBUG, `[VRR.Business] Business ${businessId}'s blip has been removed by the server`);
|
||||
if(getGame() == VRR_GAME_GTA_IV) {
|
||||
if (getGame() == VRR_GAME_GTA_IV) {
|
||||
natives.removeBlipAndClearIndex(getBusinessData(businessId).blipId);
|
||||
} else {
|
||||
destroyElement(getElementFromId(blipId));
|
||||
@@ -53,18 +53,18 @@ function receiveBusinessFromServer(businessId, name, entrancePosition, blipModel
|
||||
logToConsole(LOG_DEBUG, `[VRR.Business] Business ${businessId}'s blip is unchanged`);
|
||||
}
|
||||
} else {
|
||||
if(businessData.blipId != -1) {
|
||||
if (businessData.blipId != -1) {
|
||||
logToConsole(LOG_DEBUG, `[VRR.Business] Business ${businessId}'s blip has been changed by the server`);
|
||||
if(getGame() == VRR_GAME_GTA_IV) {
|
||||
if (getGame() == VRR_GAME_GTA_IV) {
|
||||
natives.setBlipCoordinates(businessData.blipId, businessData.entrancePosition);
|
||||
natives.changeBlipSprite(businessData.blipId, businessData.blipModel);
|
||||
natives.setBlipMarkerLongDistance(businessData.blipId, false);
|
||||
natives.setBlipAsShortRange(tempBusinessData.blipId, true);
|
||||
natives.changeBlipNameFromAscii(businessData.blipId, `${businessData.name.substr(0, 24)}${(businessData.name.length > 24) ? " ...": ""}`);
|
||||
natives.changeBlipNameFromAscii(businessData.blipId, `${businessData.name.substr(0, 24)}${(businessData.name.length > 24) ? " ..." : ""}`);
|
||||
}
|
||||
} else {
|
||||
let blipId = createGameBlip(tempBusinessData.blipModel, tempBusinessData.entrancePosition, tempBusinessData.name);
|
||||
if(blipId != -1) {
|
||||
if (blipId != -1) {
|
||||
tempBusinessData.blipId = blipId;
|
||||
}
|
||||
logToConsole(LOG_DEBUG, `[VRR.Business] Business ${businessId}'s blip has been added by the server (Model ${blipModel}, ID ${blipId})`);
|
||||
@@ -73,9 +73,9 @@ function receiveBusinessFromServer(businessId, name, entrancePosition, blipModel
|
||||
} else {
|
||||
logToConsole(LOG_DEBUG, `[VRR.Business] Business ${businessId} doesn't exist. Adding ...`);
|
||||
let tempBusinessData = new BusinessData(businessId, name, entrancePosition, blipModel, pickupModel, hasInterior, hasItems);
|
||||
if(blipModel != -1) {
|
||||
if (blipModel != -1) {
|
||||
let blipId = createGameBlip(tempBusinessData.blipModel, tempBusinessData.entrancePosition, tempBusinessData.name);
|
||||
if(blipId != -1) {
|
||||
if (blipId != -1) {
|
||||
tempBusinessData.blipId = blipId;
|
||||
}
|
||||
logToConsole(LOG_DEBUG, `[VRR.Business] Business ${businessId}'s blip has been added by the server (Model ${blipModel}, ID ${blipId})`);
|
||||
@@ -100,8 +100,8 @@ function getBusinessData(businessId) {
|
||||
|
||||
let businesses = getServerData().businesses;
|
||||
|
||||
for(let i in businesses) {
|
||||
if(businesses[i].businessId == businessId) {
|
||||
for (let i in businesses) {
|
||||
if (businesses[i].businessId == businessId) {
|
||||
return businesses[i];
|
||||
}
|
||||
}
|
||||
@@ -112,7 +112,7 @@ function getBusinessData(businessId) {
|
||||
// ===========================================================================
|
||||
|
||||
function setAllBusinessDataIndexes() {
|
||||
for(let i in getServerData().businesses) {
|
||||
for (let i in getServerData().businesses) {
|
||||
getServerData().businesses[i].index = i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1724,7 +1724,11 @@ function moveBusinessExitCommand(command, params, client) {
|
||||
// ===========================================================================
|
||||
|
||||
function getBusinessDataFromDatabaseId(databaseId) {
|
||||
let matchingBusinesses = getServerData().businesses.filter(b => b.databaseId == businessId)
|
||||
if (databaseId <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let matchingBusinesses = getServerData().businesses.filter(b => b.databaseId == databaseId)
|
||||
if (matchingBusinesses.length == 1) {
|
||||
return matchingBusinesses[0];
|
||||
}
|
||||
@@ -2361,6 +2365,10 @@ function getBusinessOwnerTypeText(ownerType) {
|
||||
* @return {BusinessData} The business's data (class instance)
|
||||
*/
|
||||
function getBusinessData(businessId) {
|
||||
if (businessId == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (typeof getServerData().businesses[businessId] != null) {
|
||||
return getServerData().businesses[businessId];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user