mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-12-26 15:33:34 +00:00
Added negative checks
This commit is contained in:
parent
e66421d34f
commit
0561f60031
@ -192,31 +192,35 @@ void PropertyManagementComponent::UpdatePropertyDetails(std::string name, std::s
|
||||
OnQueryPropertyData(GetOwner(), UNASSIGNED_SYSTEM_ADDRESS);
|
||||
}
|
||||
|
||||
void PropertyManagementComponent::Claim(const LWOOBJID playerId)
|
||||
bool PropertyManagementComponent::Claim(const LWOOBJID playerId)
|
||||
{
|
||||
if (owner != LWOOBJID_EMPTY)
|
||||
{
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
SetOwnerId(playerId);
|
||||
|
||||
auto* zone = dZoneManager::Instance()->GetZone();
|
||||
|
||||
const auto& worldId = zone->GetZoneID();
|
||||
const auto zoneId = worldId.GetMapID();
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(playerId);
|
||||
|
||||
auto* user = entity->GetParentUser();
|
||||
|
||||
auto character = entity->GetCharacter();
|
||||
if (!character) return;
|
||||
if (!character) return false;
|
||||
|
||||
const auto cloneId = character->GetPropertyCloneID();
|
||||
auto* zone = dZoneManager::Instance()->GetZone();
|
||||
|
||||
const auto& worldId = zone->GetZoneID();
|
||||
const auto propertyZoneId = worldId.GetMapID();
|
||||
const auto propertyCloneId = worldId.GetCloneID();
|
||||
|
||||
const auto playerCloneId = character->GetPropertyCloneID();
|
||||
|
||||
// If we are not on our clone do not allow us to claim the property
|
||||
if (propertyCloneId != playerCloneId) return false;
|
||||
|
||||
SetOwnerId(playerId);
|
||||
|
||||
propertyId = ObjectIDManager::GenerateRandomObjectID();
|
||||
|
||||
|
||||
auto* insertion = Database::CreatePreppedStmt(
|
||||
"INSERT INTO properties"
|
||||
"(id, owner_id, template_id, clone_id, name, description, rent_amount, rent_due, privacy_option, last_updated, time_claimed, rejection_reason, reputation, zone_id, performance_cost)"
|
||||
@ -225,9 +229,9 @@ void PropertyManagementComponent::Claim(const LWOOBJID playerId)
|
||||
insertion->setUInt64(1, propertyId);
|
||||
insertion->setUInt64(2, (uint32_t) playerId);
|
||||
insertion->setUInt(3, templateId);
|
||||
insertion->setUInt64(4, cloneId);
|
||||
insertion->setUInt64(4, playerCloneId);
|
||||
insertion->setString(5, zone->GetZoneName().c_str());
|
||||
insertion->setInt(6, zoneId);
|
||||
insertion->setInt(6, propertyZoneId);
|
||||
|
||||
// Try and execute the query, print an error if it fails.
|
||||
try
|
||||
@ -239,12 +243,14 @@ void PropertyManagementComponent::Claim(const LWOOBJID playerId)
|
||||
Game::logger->Log("PropertyManagementComponent", "Failed to execute query: (%s)!\n", exception.what());
|
||||
|
||||
throw exception;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto* zoneControlObject = dZoneManager::Instance()->GetZoneControlObject();
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(zoneControlObject)) {
|
||||
script->OnZonePropertyRented(zoneControlObject, entity);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void PropertyManagementComponent::OnStartBuilding()
|
||||
|
@ -101,8 +101,10 @@ public:
|
||||
/**
|
||||
* Makes this property owned by the passed player ID, storing it in the database
|
||||
* @param playerId the ID of the entity that claimed the property
|
||||
*
|
||||
* @return If the claim is successful return true.
|
||||
*/
|
||||
void Claim(LWOOBJID playerId);
|
||||
bool Claim(LWOOBJID playerId);
|
||||
|
||||
/**
|
||||
* Event triggered when the owner of the property starts building, will kick other entities out
|
||||
|
@ -41,13 +41,16 @@ void PropertyVendorComponent::OnBuyFromVendor(Entity* originator, const bool con
|
||||
{
|
||||
if (PropertyManagementComponent::Instance() == nullptr) return;
|
||||
|
||||
if (PropertyManagementComponent::Instance()->Claim(originator->GetObjectID()) == false) {
|
||||
Game::logger->Log("PropertyVendorComponent", "FAILED TO CLAIM PROPERTY. PLAYER ID IS %llu\n", originator->GetObjectID());
|
||||
return;
|
||||
}
|
||||
|
||||
GameMessages::SendPropertyRentalResponse(m_Parent->GetObjectID(), 0, 0, 0, 0, originator->GetSystemAddress());
|
||||
|
||||
auto* controller = dZoneManager::Instance()->GetZoneControlObject();
|
||||
|
||||
controller->OnFireEventServerSide(m_Parent, "propertyRented");
|
||||
|
||||
PropertyManagementComponent::Instance()->Claim(originator->GetObjectID());
|
||||
|
||||
PropertyManagementComponent::Instance()->SetOwner(originator);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user