Browse Source

History tab inside house now functioning for Paid Upkeep

Fixes issue #125
Image 3 years ago
parent
commit
4f1005b647

+ 10 - 0
DB/updates/character_house_history.sql

@@ -0,0 +1,10 @@
+CREATE TABLE `character_house_history` (
+  `timestamp` int(10) unsigned NOT NULL DEFAULT 0,
+  `house_id` int(10) unsigned NOT NULL DEFAULT 0,
+  `instance_id` int(10) unsigned NOT NULL DEFAULT 0,
+  `name` varchar(64) not null default '',
+  `reason` varchar(64) not null default '',
+  `amount` bigint unsigned NOT NULL DEFAULT 0,
+  `status` int(10) unsigned NOT NULL DEFAULT 0,
+  `pos_flag` tinyint(1) unsigned NOT NULL DEFAULT 0
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;

+ 45 - 1
EQ2/source/WorldServer/Housing/HousingDB.cpp

@@ -62,7 +62,7 @@ void WorldDatabase::LoadDeposits(PlayerHouse* ph)
 
 	Query query;
 	MYSQL_ROW row;
-	MYSQL_RES* result = query.RunQuery2(Q_SELECT, "select timestamp, amount, last_amount, status, last_status, name from character_house_deposits where house_id = %u and instance_id = %u order by timestamp asc", ph->house_id, ph->instance_id);
+	MYSQL_RES* result = query.RunQuery2(Q_SELECT, "select timestamp, amount, last_amount, status, last_status, name from character_house_deposits where house_id = %u and instance_id = %u order by timestamp asc limit 255", ph->house_id, ph->instance_id);
 
 	if (result && mysql_num_rows(result) > 0) {
 		while ((row = mysql_fetch_row(result))) {
@@ -84,4 +84,48 @@ void WorldDatabase::LoadDeposits(PlayerHouse* ph)
 			ph->depositsMap.insert(make_pair(d.name, d));
 		}
 	}
+}
+
+void WorldDatabase::LoadHistory(PlayerHouse* ph)
+{
+	if (!ph)
+		return;
+	ph->history.clear();
+
+	Query query;
+	MYSQL_ROW row;
+	MYSQL_RES* result = query.RunQuery2(Q_SELECT, "select timestamp, amount, status, reason, name, pos_flag from character_house_history where house_id = %u and instance_id = %u order by timestamp asc limit 255", ph->house_id, ph->instance_id);
+
+	if (result && mysql_num_rows(result) > 0) {
+		while ((row = mysql_fetch_row(result))) {
+			HouseHistory h;
+			h.timestamp = atoul(row[0]);
+
+			int64 outVal = strtoull(row[1], NULL, 0);
+			h.amount = outVal;
+
+			h.status = atoul(row[2]);
+
+			h.reason = string(row[3]);
+			h.name = string(row[4]);
+
+			h.pos_flag = atoul(row[5]);
+
+			ph->history.push_back(h);
+		}
+	}
+}
+
+
+void WorldDatabase::AddHistory(PlayerHouse* house, char* name, char* reason, int32 timestamp, int64 amount, int32 status, int8 pos_flag)
+{
+	if (!house)
+		return;
+
+	HouseHistory h(Timer::GetUnixTimeStamp(), amount, string(name), string(reason), status, pos_flag);
+	house->history.push_back(h);
+
+	Query query;
+	string insert = string("INSERT INTO character_house_history (timestamp, house_id, instance_id, name, amount, status, reason, pos_flag) VALUES (%u, %u, %u, '%s', %I64u, %u, '%s', %u) ");
+	query.RunQuery2(Q_INSERT, insert.c_str(), timestamp, house->house_id, house->instance_id, name, amount, status, reason, pos_flag);
 }

+ 17 - 2
EQ2/source/WorldServer/Housing/HousingPackets.cpp

@@ -146,8 +146,8 @@ void ClientPacketFunctions::SendBaseHouseWindow(Client* client, HouseZone* hz, P
 			packet->setDataByName("public_access_level", 1);
 			packet->setDataByName("num_history", 0);
 
-			// allows deposits to be seen
-			packet->setDataByName("unknown3", ph->deposits.size() ? 1 : 0);
+			// allows deposits/history to be seen -- at this point seems plausible supposed to be 'inside_house'..?
+			packet->setDataByName("unknown3", (ph->deposits.size() || ph->history.size()) ? 1 : 0);
 
 			packet->setArrayLengthByName("num_deposit", ph->deposits.size());
 			list<Deposit>::iterator itr;
@@ -162,6 +162,21 @@ void ClientPacketFunctions::SendBaseHouseWindow(Client* client, HouseZone* hz, P
 				packet->setArrayDataByName("deposit_last_status", itr->last_status, d);
 				d++;
 			}
+
+
+			packet->setArrayLengthByName("num_history", ph->history.size());
+			list<HouseHistory>::iterator hitr;
+			d = 0;
+			for (hitr = ph->history.begin(); hitr != ph->history.end(); hitr++)
+			{
+				packet->setArrayDataByName("history_name", hitr->name.c_str(), d);
+				packet->setArrayDataByName("history_coins", hitr->amount, d);
+				packet->setArrayDataByName("history_status", hitr->status, d);
+				packet->setArrayDataByName("history_time_stamp", hitr->timestamp, d);
+				packet->setArrayDataByName("history_reason", hitr->reason.c_str(), d);
+				packet->setArrayDataByName("history_add_flag", hitr->pos_flag, d);
+				d++;
+			}
 		}
 
 		client->QueuePacket(packet->serialize());

+ 7 - 1
EQ2/source/WorldServer/World.cpp

@@ -1856,12 +1856,18 @@ void World::AddPlayerHouse(int32 char_id, int32 house_id, int64 unique_id, int32
 		ph->escrow_status = escrow_status;
 		ph->upkeep_due = upkeep_due;
 		ph->player_name = player_name;
-		database.LoadDeposits(ph);
+		ReloadHouseData(ph);
 		m_playerHouses[house_id][char_id] = ph;
 	}
 	MPlayerHouses.releasewritelock(__FUNCTION__, __LINE__);
 }
 
+void World::ReloadHouseData(PlayerHouse* ph)
+{
+	database.LoadDeposits(ph);
+	database.LoadHistory(ph);
+}
+
 PlayerHouse* World::GetPlayerHouseByHouseID(int32 char_id, int32 house_id) {
 	PlayerHouse* ret = 0;
 

+ 30 - 0
EQ2/source/WorldServer/World.h

@@ -200,6 +200,33 @@ struct Deposit {
 	string name;
 };
 
+struct HouseHistory {
+	HouseHistory()
+	{
+		timestamp = 0;
+		amount = 0;
+		name = string("");
+		reason = string("");
+		status = 0;
+		pos_flag = 0;
+	}
+	HouseHistory(int32 in_timestamp, int64 in_amount, string in_name, string in_reason, int32 in_status, int8 in_pos_flag)
+	{
+		timestamp = in_timestamp;
+		amount = in_amount;
+		name = in_name;
+		reason = in_reason;
+		status = in_status;
+		pos_flag = in_pos_flag;
+	}
+	int32 timestamp;
+	int64 amount;
+	string name;
+	string reason;
+	int32 status;
+	int8 pos_flag;
+};
+
 struct PlayerHouse {
 	int32 house_id;
 	int64 unique_id;
@@ -210,6 +237,7 @@ struct PlayerHouse {
 	string player_name;
 	list<Deposit> deposits;
 	map<string, Deposit> depositsMap;
+	list<HouseHistory> history;
 };
 
 // Constants for STATs counters
@@ -531,6 +559,8 @@ public:
 	vector<PlayerHouse*> GetAllPlayerHouses(int32 char_id);
 	vector<PlayerHouse*> GetAllPlayerHousesByHouseID(int32 house_id);
 
+	void ReloadHouseData(PlayerHouse* ph);
+
 	PlayerGroupManager* GetGroupManager() { return &m_playerGroupManager; }
 
 	bool CheckTempBugCRC(char* msg);

+ 2 - 0
EQ2/source/WorldServer/WorldDatabase.h

@@ -507,6 +507,8 @@ public:
 	void				UpdateHouseEscrow(int32 house_id, int32 instance_id, int64 amount);
 	void				LoadPlayerHouses();
 	void				LoadDeposits(PlayerHouse* house);
+	void				LoadHistory(PlayerHouse* house);
+	void				AddHistory(PlayerHouse* house, char* name, char* reason, int32 timestamp, int64 amount = 0, int32 status = 0, int8 pos_flag = 0);
 
 	/* World */
 	bool				CheckBannedIPs(const char* loginIP);

+ 3 - 0
EQ2/source/WorldServer/client.cpp

@@ -1903,8 +1903,11 @@ bool Client::HandlePacket(EQApplicationPacket* app) {
 				// TODO: Need support for upkeep_status, but alas status_points are not implemented!
 				if (!coinReq || coinReq && player->RemoveCoins(coinReq)) // TODO: Need option to take from bank if player does not have enough coin on them
 				{
+					database.AddHistory(ph, GetPlayer()->GetName(), "Paid Upkeep", Timer::GetUnixTimeStamp(), hz->upkeep_coin, 0, 0);
+
 					if (escrowChange)
 						database.UpdateHouseEscrow(ph->house_id, ph->instance_id, ph->escrow_coins);
+
 					ph->upkeep_due = upkeep_due;
 					database.SetHouseUpkeepDue(GetCharacterID(), ph->house_id, ph->instance_id, ph->upkeep_due);
 					//ClientPacketFunctions::SendHousingList(this);