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