View Single Post
  #61  
Old 10-03-2015, 10:26 AM
AdrianD
Discordant
 
Join Date: Dec 2013
Posts: 297
Default

A little more progress on the pet thing.

The entire delete/save process (creating a new blank entry in table `character_pet_info`) for the DB in one spot. This eliminates running a couple unneeded queries from using the <SavePetInfo> function.

The pet window still appears on client. I don't know if this is avoidable by doing the norent check somewhere earlier in the process. It's not a big deal unless there is a cleaner/more efficient way to do this.

\client_process.cpp
Code:
	bool deletenorent = database.NoRentExpired(GetName());
	if (deletenorent) { //client was offline for more than 30 minutes, delete no rent items
		if (RuleB(Inventory, TransformSummonedBags))
			DisenchantSummonedBags(false);
		RemoveNoRent(false);

// added 9/30/15 no rent check (updated 10/3/15)
		if (!RuleB(Pets, PetLogPersistence))
		{
			SetPet(0);

			database.DeletePetInfo(this);
		}
	}
\zonedb.cpp
Code:
void ZoneDatabase::DeletePetInfo(Client *client)
{
	std::string query = StringFormat("DELETE FROM `character_pet_info` WHERE `char_id` = %u AND `pet` = 0", client->CharacterID());
	auto results = database.QueryDatabase(query);
	if (!results.Success())
		return;

	query = StringFormat("DELETE FROM `character_pet_buffs` WHERE `char_id` = %u AND `pet` = 0", client->CharacterID());
	results = database.QueryDatabase(query);
	if (!results.Success())
		return;

	query = StringFormat("DELETE FROM `character_pet_inventory` WHERE `char_id` = %u AND `pet` = 0", client->CharacterID());
	results = database.QueryDatabase(query);
	if (!results.Success())
		return;

	PetInfo *petinfo = client->GetPetInfo(0);

	memset(petinfo, 0, sizeof(struct PetInfo));

	int pet = 0;

	query = StringFormat("INSERT INTO `character_pet_info` "
		"(`char_id`, `pet`, `petname`, `petpower`, `spell_id`, `hp`, `mana`, `size`) "
		"VALUES (%u, %u, '%s', %i, %u, %u, %u, %f) "
		"ON DUPLICATE KEY UPDATE `petname` = '%s', `petpower` = %i, `spell_id` = %u, "
		"`hp` = %u, `mana` = %u, `size` = %f",
		client->CharacterID(), pet, petinfo->Name, petinfo->petpower, petinfo->SpellID,
		petinfo->HP, petinfo->Mana, petinfo->size, // and now the ON DUPLICATE ENTRIES
		petinfo->Name, petinfo->petpower, petinfo->SpellID, petinfo->HP, petinfo->Mana, petinfo->size);
	results = database.QueryDatabase(query);
	if (!results.Success())
		return;
	query.clear();
}
As an aside: While going through this process I noticed some queries are ran anywhere between 2-6 times from this maybe? <database.QueryDatabase(query);>

I understand my tinkering may have caused some of this but, I'm curious to know the purpose of this.

Thanks

EDIT:

Not sure if I mentioned this before. I had to add the line below when I created the item in \zonedb.cpp. Can't take it for granted.

\zonedb.h
Code:
	void DeletePetInfo(Client *c);
Reply With Quote