Core/Housing: stage 26 add initiative persistence handlers

This commit is contained in:
Gexo91
2026-09-12 16:46:21 +03:00
parent cd3954d8b9
commit f2e58b0290
@@ -0,0 +1,91 @@
/*
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
*/
#include "HousingInitiativeSession.h"
#include "DatabaseEnv.h"
#include "HousingDefines.h"
#include "HousingMgr.h"
#include "HousingPackets.h"
#include "Log.h"
#include "Player.h"
#include "WorldSession.h"
namespace Housing
{
namespace
{
bool LoadOwnedNeighborhood(WorldSession* session, ObjectGuid const& neighborhoodGuid, HouseState& house)
{
house = {};
if (!session || !IsNeighborhoodGuid(neighborhoodGuid))
return false;
Player* player = session->GetPlayer();
if (!player)
return false;
if (sHousingMgr.LoadOwnedHouse(player, ObjectGuid::Empty, house) != Result::Success)
return false;
return house.NeighborhoodGuid == neighborhoodGuid;
}
void EnsureInitiativePersistence(HouseState const& house)
{
CharacterDatabase.PExecute(
"INSERT INTO housing_neighborhood_initiative "
"(NeighborhoodGuid, InitiativeID, State, Progress, RewardTier, StartedAt, EndsAt) "
"VALUES ('{}', 0, 0, 0, 0, NULL, NULL) "
"ON DUPLICATE KEY UPDATE NeighborhoodGuid = VALUES(NeighborhoodGuid)",
house.NeighborhoodGuid.ToString());
}
}
void HandleInitiativeServiceStatus(WorldSession* session,
WorldPackets::Housing::NeighborhoodInitiativeServiceStatusCheck& /*packet*/)
{
if (!session)
return;
WorldPackets::Housing::InitiativeServiceStatus response;
response.Available = true;
session->SendPacket(response.Write());
}
void HandleInitiativeActivityLog(WorldSession* session,
WorldPackets::Housing::GetInitiativeActivityLogRequest& packet)
{
if (!session)
return;
WorldPackets::Housing::GetInitiativeActivityLogResult response;
response.NeighborhoodGUID = packet.NeighborhoodGUID;
response.EntryCount = 0;
HouseState house;
if (!LoadOwnedNeighborhood(session, packet.NeighborhoodGUID, house))
{
session->SendPacket(response.Write());
return;
}
EnsureInitiativePersistence(house);
QueryResult persistedEntries = CharacterDatabase.PQuery(
"SELECT COUNT(*) FROM housing_initiative_activity_log "
"WHERE NeighborhoodGuid = '{}'",
packet.NeighborhoodGUID.ToString());
uint64 const persistedEntryCount = persistedEntries ? persistedEntries->Fetch()[0].GetUInt64() : 0;
if (persistedEntryCount != 0)
{
// The non-empty build 69587 activity-log record layout is not yet verified.
// Keep persisted progress server-side instead of advertising a count whose
// corresponding records cannot be serialized safely to the retail client.
TC_LOG_DEBUG("housing", "Neighborhood {} has {} persisted Initiative log entries; wire publication is deferred",
packet.NeighborhoodGUID.ToString(), persistedEntryCount);
}
session->SendPacket(response.Write());
}
}