mirror of
https://github.com/EQEmu/Server.git
synced 2026-03-23 06:32:28 +00:00
TryReward converted to QueryDatabase
This commit is contained in:
parent
fe1c67b8b4
commit
037df28b7c
166
zone/client.cpp
166
zone/client.cpp
@ -5270,8 +5270,7 @@ void Client::SendRewards()
|
|||||||
FastQueuePacket(&vetapp);
|
FastQueuePacket(&vetapp);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Client::TryReward(uint32 claim_id)
|
bool Client::TryReward(uint32 claim_id) {
|
||||||
{
|
|
||||||
//Make sure we have an open spot
|
//Make sure we have an open spot
|
||||||
//Make sure we have it in our acct and count > 0
|
//Make sure we have it in our acct and count > 0
|
||||||
//Make sure the entry was found
|
//Make sure the entry was found
|
||||||
@ -5281,143 +5280,90 @@ bool Client::TryReward(uint32 claim_id)
|
|||||||
//save
|
//save
|
||||||
uint32 free_slot = 0xFFFFFFFF;
|
uint32 free_slot = 0xFFFFFFFF;
|
||||||
|
|
||||||
for(int i = EmuConstants::GENERAL_BEGIN; i <= EmuConstants::GENERAL_END; ++i)
|
for(int i = EmuConstants::GENERAL_BEGIN; i <= EmuConstants::GENERAL_END; ++i) {
|
||||||
{
|
|
||||||
ItemInst *item = GetInv().GetItem(i);
|
ItemInst *item = GetInv().GetItem(i);
|
||||||
if(!item)
|
if(!item) {
|
||||||
{
|
|
||||||
free_slot = i;
|
free_slot = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(free_slot == 0xFFFFFFFF)
|
if(free_slot == 0xFFFFFFFF)
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
char errbuf[MYSQL_ERRMSG_SIZE];
|
||||||
char* query = 0;
|
std::string query = StringFormat("SELECT amount FROM account_rewards "
|
||||||
MYSQL_RES *result;
|
"WHERE account_id = %i AND reward_id = %i",
|
||||||
MYSQL_ROW row;
|
AccountID(), claim_id);
|
||||||
uint32 amt = 0;
|
auto results = database.QueryDatabase(query);
|
||||||
|
if (!results.Success()) {
|
||||||
if(database.RunQuery(query,MakeAnyLenString(&query,"SELECT amount FROM"
|
LogFile->write(EQEMuLog::Error, "Error in Client::TryReward(): %s (%s)", query.c_str(), results.ErrorMessage().c_str());
|
||||||
" account_rewards WHERE account_id=%i AND reward_id=%i", AccountID(), claim_id),
|
|
||||||
errbuf,&result))
|
|
||||||
{
|
|
||||||
row = mysql_fetch_row(result);
|
|
||||||
if(row)
|
|
||||||
{
|
|
||||||
amt = atoi(row[0]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mysql_free_result(result);
|
|
||||||
safe_delete_array(query);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
mysql_free_result(result);
|
|
||||||
safe_delete_array(query);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LogFile->write(EQEMuLog::Error, "Error in Client::TryReward(): %s (%s)", query, errbuf);
|
|
||||||
safe_delete_array(query);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (results.RowCount() == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
auto row = results.begin();
|
||||||
|
|
||||||
|
uint32 amt = atoi(row[0]);
|
||||||
if(amt == 0)
|
if(amt == 0)
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
std::list<InternalVeteranReward>::iterator iter = zone->VeteranRewards.begin();
|
std::list<InternalVeteranReward>::iterator iter = zone->VeteranRewards.begin();
|
||||||
while(iter != zone->VeteranRewards.end())
|
for (; iter != zone->VeteranRewards.end(); ++row)
|
||||||
{
|
|
||||||
if((*iter).claim_id == claim_id)
|
if((*iter).claim_id == claim_id)
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
++iter;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(iter == zone->VeteranRewards.end())
|
if(iter == zone->VeteranRewards.end())
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
if(amt == 1)
|
if(amt == 1) {
|
||||||
{
|
query = StringFormat("DELETE FROM account_rewards "
|
||||||
if(!database.RunQuery(query,MakeAnyLenString(&query,"DELETE FROM"
|
"WHERE account_id = %i AND reward_id = %i",
|
||||||
" account_rewards WHERE account_id=%i AND reward_id=%i", AccountID(), claim_id),
|
AccountID(), claim_id);
|
||||||
errbuf))
|
auto results = database.QueryDatabase(query);
|
||||||
{
|
if(!results.Success())
|
||||||
LogFile->write(EQEMuLog::Error, "Error in Client::TryReward(): %s (%s)", query, errbuf);
|
LogFile->write(EQEMuLog::Error, "Error in Client::TryReward(): %s (%s)", query.c_str(), results.ErrorMessage().c_str());
|
||||||
safe_delete_array(query);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
safe_delete_array(query);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
query = StringFormat("UPDATE account_rewards SET amount = (amount-1) "
|
||||||
if(!database.RunQuery(query,MakeAnyLenString(&query,"UPDATE account_rewards SET amount=(amount-1)"
|
"WHERE account_id = %i AND reward_id = %i",
|
||||||
" WHERE account_id=%i AND reward_id=%i", AccountID(), claim_id),
|
AccountID(), claim_id);
|
||||||
errbuf))
|
auto results = database.QueryDatabase(query);
|
||||||
{
|
if(!results.Success())
|
||||||
LogFile->write(EQEMuLog::Error, "Error in Client::TryReward(): %s (%s)", query, errbuf);
|
LogFile->write(EQEMuLog::Error, "Error in Client::TryReward(): %s (%s)", query.c_str(), results.ErrorMessage().c_str());
|
||||||
safe_delete_array(query);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
safe_delete_array(query);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
InternalVeteranReward ivr = (*iter);
|
InternalVeteranReward ivr = (*iter);
|
||||||
ItemInst *claim = database.CreateItem(ivr.items[0].item_id, ivr.items[0].charges);
|
ItemInst *claim = database.CreateItem(ivr.items[0].item_id, ivr.items[0].charges);
|
||||||
if(claim)
|
if(!claim) {
|
||||||
{
|
Save();
|
||||||
bool lore_conflict = false;
|
return true;
|
||||||
if(CheckLoreConflict(claim->GetItem()))
|
|
||||||
{
|
|
||||||
lore_conflict = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int y = 1; y < 8; y++)
|
|
||||||
{
|
|
||||||
if(ivr.items[y].item_id)
|
|
||||||
{
|
|
||||||
if(claim->GetItem()->ItemClass == 1)
|
|
||||||
{
|
|
||||||
ItemInst *item_temp = database.CreateItem(ivr.items[y].item_id, ivr.items[y].charges);
|
|
||||||
if(item_temp)
|
|
||||||
{
|
|
||||||
if(CheckLoreConflict(item_temp->GetItem()))
|
|
||||||
{
|
|
||||||
lore_conflict = true;
|
|
||||||
DuplicateLoreMessage(ivr.items[y].item_id);
|
|
||||||
}
|
|
||||||
claim->PutItem(y-1, *item_temp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(lore_conflict)
|
|
||||||
{
|
|
||||||
safe_delete(claim);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
PutItemInInventory(free_slot, *claim);
|
|
||||||
SendItemPacket(free_slot, claim, ItemPacketTrade);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool lore_conflict = CheckLoreConflict(claim->GetItem());
|
||||||
|
|
||||||
|
for(int y = 1; y < 8; y++)
|
||||||
|
if(ivr.items[y].item_id && claim->GetItem()->ItemClass == 1) {
|
||||||
|
ItemInst *item_temp = database.CreateItem(ivr.items[y].item_id, ivr.items[y].charges);
|
||||||
|
if(item_temp) {
|
||||||
|
if(CheckLoreConflict(item_temp->GetItem())) {
|
||||||
|
lore_conflict = true;
|
||||||
|
DuplicateLoreMessage(ivr.items[y].item_id);
|
||||||
|
}
|
||||||
|
claim->PutItem(y-1, *item_temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(lore_conflict) {
|
||||||
|
safe_delete(claim);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
PutItemInInventory(free_slot, *claim);
|
||||||
|
SendItemPacket(free_slot, claim, ItemPacketTrade);
|
||||||
|
|
||||||
Save();
|
Save();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user