Merge pull request #228 from addtheice/RunQueryToDatabaseQuery_zone_client_packet

Run query to database query zone client packet
This commit is contained in:
Alex 2014-08-26 17:35:51 -07:00
commit 0f321b3a69

View File

@ -3137,6 +3137,7 @@ void Client::Handle_OP_ItemLinkClick(const EQApplicationPacket *app)
DumpPacket(app); DumpPacket(app);
return; return;
} }
DumpPacket(app); DumpPacket(app);
ItemViewRequest_Struct* ivrs = (ItemViewRequest_Struct*)app->pBuffer; ItemViewRequest_Struct* ivrs = (ItemViewRequest_Struct*)app->pBuffer;
@ -3156,30 +3157,24 @@ void Client::Handle_OP_ItemLinkClick(const EQApplicationPacket *app)
silentsaylink = true; silentsaylink = true;
} }
if (sayid && sayid > 0) if (sayid > 0)
{ {
char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0;
MYSQL_RES *result;
MYSQL_ROW row;
std::string query = StringFormat("SELECT `phrase` FROM saylink WHERE `id` = '%i'", sayid);
auto results = database.QueryDatabase(query);
if (!results.Success()) {
Message(13, "Error: The saylink (%s) was not found in the database.", response.c_str());
return;
}
if(database.RunQuery(query,MakeAnyLenString(&query,"SELECT `phrase` FROM saylink WHERE `id` = '%i'", sayid),errbuf,&result)) if (results.RowCount() != 1) {
{ Message(13, "Error: The saylink (%s) was not found in the database.", response.c_str());
if (mysql_num_rows(result) == 1)
{
row = mysql_fetch_row(result);
response = row[0];
}
mysql_free_result(result);
}
else
{
Message(13, "Error: The saylink (%s) was not found in the database.",response.c_str());
safe_delete_array(query);
return; return;
} }
safe_delete_array(query);
auto row = results.begin();
response = row[0];
} }
if((response).size() > 0) if((response).size() > 0)
@ -4628,7 +4623,7 @@ void Client::Handle_OP_CastSpell(const EQApplicationPacket *app)
p_timers.Start(pTimerHarmTouch, HarmTouchReuseTime); p_timers.Start(pTimerHarmTouch, HarmTouchReuseTime);
} }
if (spell_to_cast > 0) // if we've matched LoH or HT, cast now if (spell_to_cast > 0) // if we've matched LoH or HT, cast now
CastSpell(spell_to_cast, castspell->target_id, castspell->slot); CastSpell(spell_to_cast, castspell->target_id, castspell->slot);
} }
@ -5899,9 +5894,9 @@ void Client::Handle_OP_ShopPlayerSell(const EQApplicationPacket *app)
else else
this->DeleteItemInInventory(mp->itemslot,mp->quantity,false); this->DeleteItemInInventory(mp->itemslot,mp->quantity,false);
//This forces the price to show up correctly for charged items. //This forces the price to show up correctly for charged items.
if(inst->IsCharged()) if(inst->IsCharged())
mp->quantity = 1; mp->quantity = 1;
EQApplicationPacket* outapp = new EQApplicationPacket(OP_ShopPlayerSell, sizeof(Merchant_Purchase_Struct)); EQApplicationPacket* outapp = new EQApplicationPacket(OP_ShopPlayerSell, sizeof(Merchant_Purchase_Struct));
Merchant_Purchase_Struct* mco=(Merchant_Purchase_Struct*)outapp->pBuffer; Merchant_Purchase_Struct* mco=(Merchant_Purchase_Struct*)outapp->pBuffer;
@ -7670,7 +7665,7 @@ void Client::Handle_OP_Mend(const EQApplicationPacket *app)
int mendhp = GetMaxHP() / 4; int mendhp = GetMaxHP() / 4;
int currenthp = GetHP(); int currenthp = GetHP();
if (MakeRandomInt(0, 199) < (int)GetSkill(SkillMend)) { if (MakeRandomInt(0, 199) < (int)GetSkill(SkillMend)) {
int criticalchance = spellbonuses.CriticalMend + itembonuses.CriticalMend + aabonuses.CriticalMend; int criticalchance = spellbonuses.CriticalMend + itembonuses.CriticalMend + aabonuses.CriticalMend;
if(MakeRandomInt(0,99) < criticalchance){ if(MakeRandomInt(0,99) < criticalchance){
@ -9567,7 +9562,7 @@ void Client::CompleteConnect() {
/* This sub event is for if a player logs in for the first time since entering world. */ /* This sub event is for if a player logs in for the first time since entering world. */
if (firstlogon == 1){ if (firstlogon == 1){
parse->EventPlayer(EVENT_CONNECT, this, "", 0); parse->EventPlayer(EVENT_CONNECT, this, "", 0);
/* QS: PlayerLogConnectDisconnect */ /* QS: PlayerLogConnectDisconnect */
if (RuleB(QueryServ, PlayerLogConnectDisconnect)){ if (RuleB(QueryServ, PlayerLogConnectDisconnect)){
std::string event_desc = StringFormat("Connect :: Logged into zoneid:%i instid:%i", this->GetZoneID(), this->GetInstanceID()); std::string event_desc = StringFormat("Connect :: Logged into zoneid:%i instid:%i", this->GetZoneID(), this->GetInstanceID());
@ -11445,92 +11440,68 @@ void Client::Handle_OP_SetStartCity(const EQApplicationPacket *app)
Message(15,"Your home city has already been set.", m_pp.binds[4].zoneId, database.GetZoneName(m_pp.binds[4].zoneId)); Message(15,"Your home city has already been set.", m_pp.binds[4].zoneId, database.GetZoneName(m_pp.binds[4].zoneId));
return; return;
} }
if (app->size < 1) { if (app->size < 1) {
LogFile->write(EQEMuLog::Error, "Wrong size: OP_SetStartCity, size=%i, expected %i", app->size, 1); LogFile->write(EQEMuLog::Error, "Wrong size: OP_SetStartCity, size=%i, expected %i", app->size, 1);
DumpPacket(app); DumpPacket(app);
return; return;
} }
char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0;
MYSQL_RES *result = nullptr;
MYSQL_ROW row = 0;
float x(0),y(0),z(0); float x(0),y(0),z(0);
uint32 zoneid = 0; uint32 zoneid = 0;
uint32 startCity = (uint32)strtol((const char*)app->pBuffer, nullptr, 10);
uint32 StartCity = (uint32)strtol((const char*)app->pBuffer, nullptr, 10); std::string query = StringFormat("SELECT zone_id, bind_id, x, y, z FROM start_zones "
bool ValidCity = false; "WHERE player_class=%i AND player_deity=%i AND player_race=%i",
database.RunQuery m_pp.class_, m_pp.deity, m_pp.race);
( auto results = database.QueryDatabase(query);
query, if(!results.Success()) {
MakeAnyLenString
(
&query,
"SELECT zone_id, bind_id, x, y, z FROM start_zones "
"WHERE player_class=%i AND player_deity=%i AND player_race=%i",
m_pp.class_,
m_pp.deity,
m_pp.race
),
errbuf,
&result
);
safe_delete_array(query);
if(!result) {
LogFile->write(EQEMuLog::Error, "No valid start zones found for /setstartcity"); LogFile->write(EQEMuLog::Error, "No valid start zones found for /setstartcity");
return; return;
} }
while(row = mysql_fetch_row(result)) { bool validCity = false;
for (auto row = results.begin(); row != results.end(); ++row) {
if(atoi(row[1]) != 0) if(atoi(row[1]) != 0)
zoneid = atoi(row[1]); zoneid = atoi(row[1]);
else else
zoneid = atoi(row[0]); zoneid = atoi(row[0]);
if(zoneid == StartCity) { if(zoneid != startCity)
ValidCity = true; continue;
x = atof(row[2]);
y = atof(row[3]); validCity = true;
z = atof(row[4]); x = atof(row[2]);
} y = atof(row[3]);
z = atof(row[4]);
} }
if(ValidCity) { if(validCity) {
Message(15,"Your home city has been set"); Message(15,"Your home city has been set");
SetStartZone(StartCity, x, y, z); SetStartZone(startCity, x, y, z);
} return;
else {
database.RunQuery
(
query,
MakeAnyLenString
(
&query,
"SELECT zone_id, bind_id FROM start_zones "
"WHERE player_class=%i AND player_deity=%i AND player_race=%i",
m_pp.class_,
m_pp.deity,
m_pp.race
),
errbuf,
&result
);
safe_delete_array(query);
Message(15,"Use \"/startcity #\" to choose a home city from the following list:");
char* name;
while(row = mysql_fetch_row(result)) {
if(atoi(row[1]) != 0)
zoneid = atoi(row[1]);
else
zoneid = atoi(row[0]);
database.GetZoneLongName(database.GetZoneName(zoneid),&name);
Message(15,"%d - %s", zoneid, name);
safe_delete_array(name);
}
} }
mysql_free_result(result); query = StringFormat("SELECT zone_id, bind_id FROM start_zones "
"WHERE player_class=%i AND player_deity=%i AND player_race=%i",
m_pp.class_, m_pp.deity, m_pp.race);
results = database.QueryDatabase(query);
if (!results.Success())
return;
Message(15,"Use \"/startcity #\" to choose a home city from the following list:");
for (auto row = results.begin(); row != results.end(); ++row) {
if(atoi(row[1]) != 0)
zoneid = atoi(row[1]);
else
zoneid = atoi(row[0]);
char* name;
database.GetZoneLongName(database.GetZoneName(zoneid), &name);
Message(15,"%d - %s", zoneid, name);
}
} }
void Client::Handle_OP_Report(const EQApplicationPacket *app) void Client::Handle_OP_Report(const EQApplicationPacket *app)
@ -11637,7 +11608,7 @@ void Client::Handle_OP_GMSearchCorpse(const EQApplicationPacket *app)
// Could make this into a rule, although there is a hard limit since we are using a popup, of 4096 bytes that can // Could make this into a rule, although there is a hard limit since we are using a popup, of 4096 bytes that can
// be displayed in the window, including all the HTML formatting tags. // be displayed in the window, including all the HTML formatting tags.
// //
const int MaxResults = 10; const int maxResults = 10;
if(app->size < sizeof(GMSearchCorpse_Struct)) if(app->size < sizeof(GMSearchCorpse_Struct))
{ {
@ -11650,85 +11621,62 @@ void Client::Handle_OP_GMSearchCorpse(const EQApplicationPacket *app)
GMSearchCorpse_Struct *gmscs = (GMSearchCorpse_Struct *)app->pBuffer; GMSearchCorpse_Struct *gmscs = (GMSearchCorpse_Struct *)app->pBuffer;
gmscs->Name[63] = '\0'; gmscs->Name[63] = '\0';
char errbuf[MYSQL_ERRMSG_SIZE]; char *escSearchString = new char[129];
char* Query = 0; database.DoEscapeString(escSearchString, gmscs->Name, strlen(gmscs->Name));
MYSQL_RES *Result;
MYSQL_ROW Row;
char *EscSearchString = new char[129]; std::string query = StringFormat("SELECT charname, zoneid, x, y, z, timeofdeath, rezzed, IsBurried "
"FROM player_corpses WheRE charname LIKE '%%%s%%' ORDER BY charname LIMIT %i",
escSearchString, maxResults);
safe_delete_array(escSearchString);
auto results = database.QueryDatabase(query);
if (!results.Success()) {
Message(0, "Query failed: %s.", results.ErrorMessage().c_str());
return;
}
database.DoEscapeString(EscSearchString, gmscs->Name, strlen(gmscs->Name)); if (results.RowCount() == 0)
return;
if (database.RunQuery(Query, MakeAnyLenString(&Query, "select charname, zoneid, x, y, z, timeofdeath, rezzed, IsBurried from " if(results.RowCount() == maxResults)
"player_corpses where charname like '%%%s%%' order by charname limit %i", Message(clientMessageError, "Your search found too many results; some are not displayed.");
EscSearchString, MaxResults), errbuf, &Result)) else
{ Message(clientMessageYellow, "There are %i corpse(s) that match the search string '%s'.", results.RowCount(), gmscs->Name);
int NumberOfRows = mysql_num_rows(Result); char charName[64], timeOfDeath[20];
if(NumberOfRows == MaxResults) std::string popupText = "<table><tr><td>Name</td><td>Zone</td><td>X</td><td>Y</td><td>Z</td><td>Date</td><td>"
Message(clientMessageError, "Your search found too many results; some are not displayed.");
else {
Message(clientMessageYellow, "There are %i corpse(s) that match the search string '%s'.",
NumberOfRows, gmscs->Name);
}
if(NumberOfRows == 0)
{
mysql_free_result(Result);
safe_delete_array(Query);
return;
}
char CharName[64], TimeOfDeath[20], Buffer[512];
std::string PopupText = "<table><tr><td>Name</td><td>Zone</td><td>X</td><td>Y</td><td>Z</td><td>Date</td><td>"
"Rezzed</td><td>Buried</td></tr><tr><td>&nbsp</td><td></td><td></td><td></td><td></td><td>" "Rezzed</td><td>Buried</td></tr><tr><td>&nbsp</td><td></td><td></td><td></td><td></td><td>"
"</td><td></td><td></td></tr>"; "</td><td></td><td></td></tr>";
for (auto row = results.begin(); row != results.end(); ++row) {
while ((Row = mysql_fetch_row(Result))) strn0cpy(charName, row[0], sizeof(charName));
{
strn0cpy(CharName, Row[0], sizeof(CharName)); uint32 ZoneID = atoi(row[1]);
float CorpseX = atof(row[2]);
float CorpseY = atof(row[3]);
float CorpseZ = atof(row[4]);
uint32 ZoneID = atoi(Row[1]); strn0cpy(timeOfDeath, row[5], sizeof(timeOfDeath));
float CorpseX = atof(Row[2]); bool corpseRezzed = atoi(row[6]);
float CorpseY = atof(Row[3]); bool corpseBuried = atoi(row[7]);
float CorpseZ = atof(Row[4]);
strn0cpy(TimeOfDeath, Row[5], sizeof(TimeOfDeath)); popupText += StringFormat("<tr><td>%s</td><td>%s</td><td>%8.0f</td><td>%8.0f</td><td>%8.0f</td><td>%s</td><td>%s</td><td>%s</td></tr>",
charName, StaticGetZoneName(ZoneID), CorpseX, CorpseY, CorpseZ, timeOfDeath,
corpseRezzed ? "Yes" : "No", corpseBuried ? "Yes" : "No");
bool CorpseRezzed = atoi(Row[6]); if(popupText.size() > 4000) {
bool CorpseBuried = atoi(Row[7]); Message(clientMessageError, "Unable to display all the results.");
break;
}
sprintf(Buffer, "<tr><td>%s</td><td>%s</td><td>%8.0f</td><td>%8.0f</td><td>%8.0f</td><td>%s</td><td>%s</td><td>%s</td></tr>", }
CharName, StaticGetZoneName(ZoneID), CorpseX, CorpseY, CorpseZ, TimeOfDeath,
CorpseRezzed ? "Yes" : "No", CorpseBuried ? "Yes" : "No");
PopupText += Buffer; popupText += "</table>";
if(PopupText.size() > 4000) SendPopupToClient("Corpses", popupText.c_str());
{
Message(clientMessageError, "Unable to display all the results.");
break;
}
}
PopupText += "</table>";
mysql_free_result(Result);
SendPopupToClient("Corpses", PopupText.c_str());
}
else{
Message(0, "Query failed: %s.", errbuf);
}
safe_delete_array(Query);
safe_delete_array(EscSearchString);
} }
void Client::Handle_OP_GuildBank(const EQApplicationPacket *app) void Client::Handle_OP_GuildBank(const EQApplicationPacket *app)
@ -12810,7 +12758,7 @@ void Client::Handle_OP_AltCurrencyReclaim(const EQApplicationPacket *app) {
QServ->PlayerLogEvent(Player_Log_Alternate_Currency_Transactions, this->CharacterID(), event_desc); QServ->PlayerLogEvent(Player_Log_Alternate_Currency_Transactions, this->CharacterID(), event_desc);
} }
} }
} }
/* Cursor to Item storage */ /* Cursor to Item storage */
else { else {
uint32 max_currency = GetAlternateCurrencyValue(reclaim->currency_id); uint32 max_currency = GetAlternateCurrencyValue(reclaim->currency_id);
@ -12819,7 +12767,7 @@ void Client::Handle_OP_AltCurrencyReclaim(const EQApplicationPacket *app) {
if(reclaim->count > max_currency) { if(reclaim->count > max_currency) {
SummonItem(item_id, max_currency); SummonItem(item_id, max_currency);
SetAlternateCurrencyValue(reclaim->currency_id, 0); SetAlternateCurrencyValue(reclaim->currency_id, 0);
} }
else { else {
SummonItem(item_id, reclaim->count, 0, 0, 0, 0, 0, false, MainCursor); SummonItem(item_id, reclaim->count, 0, 0, 0, 0, 0, false, MainCursor);
AddAlternateCurrencyValue(reclaim->currency_id, -((int32)reclaim->count)); AddAlternateCurrencyValue(reclaim->currency_id, -((int32)reclaim->count));
@ -12828,7 +12776,7 @@ void Client::Handle_OP_AltCurrencyReclaim(const EQApplicationPacket *app) {
if (RuleB(QueryServ, PlayerLogAlternateCurrencyTransactions)){ if (RuleB(QueryServ, PlayerLogAlternateCurrencyTransactions)){
std::string event_desc = StringFormat("Reclaim :: Cursor to Item :: alt_currency_id:%i amount:-%i in zoneid:%i instid:%i", reclaim->currency_id, reclaim->count, this->GetZoneID(), this->GetInstanceID()); std::string event_desc = StringFormat("Reclaim :: Cursor to Item :: alt_currency_id:%i amount:-%i in zoneid:%i instid:%i", reclaim->currency_id, reclaim->count, this->GetZoneID(), this->GetInstanceID());
QServ->PlayerLogEvent(Player_Log_Alternate_Currency_Transactions, this->CharacterID(), event_desc); QServ->PlayerLogEvent(Player_Log_Alternate_Currency_Transactions, this->CharacterID(), event_desc);
} }
} }
} }
@ -12920,8 +12868,8 @@ void Client::Handle_OP_AltCurrencySell(const EQApplicationPacket *app) {
/* QS: PlayerLogAlternateCurrencyTransactions :: Sold to Merchant*/ /* QS: PlayerLogAlternateCurrencyTransactions :: Sold to Merchant*/
if (RuleB(QueryServ, PlayerLogAlternateCurrencyTransactions)){ if (RuleB(QueryServ, PlayerLogAlternateCurrencyTransactions)){
std::string event_desc = StringFormat("Sold to Merchant :: itemid:%u npcid:%u alt_currency_id:%u cost:%u in zoneid:%u instid:%i", item->ID, npc_id, alt_cur_id, cost, this->GetZoneID(), this->GetInstanceID()); std::string event_desc = StringFormat("Sold to Merchant :: itemid:%u npcid:%u alt_currency_id:%u cost:%u in zoneid:%u instid:%i", item->ID, npc_id, alt_cur_id, cost, this->GetZoneID(), this->GetInstanceID());
QServ->PlayerLogEvent(Player_Log_Alternate_Currency_Transactions, this->CharacterID(), event_desc); QServ->PlayerLogEvent(Player_Log_Alternate_Currency_Transactions, this->CharacterID(), event_desc);
} }
FastQueuePacket(&outapp); FastQueuePacket(&outapp);
AddAlternateCurrencyValue(alt_cur_id, cost); AddAlternateCurrencyValue(alt_cur_id, cost);
@ -12982,7 +12930,7 @@ void Client::Handle_OP_LFGuild(const EQApplicationPacket *app)
switch(Command) switch(Command)
{ {
case 0: case 0:
{ {
VERIFY_PACKET_LENGTH(OP_LFGuild, app, LFGuild_PlayerToggle_Struct); VERIFY_PACKET_LENGTH(OP_LFGuild, app, LFGuild_PlayerToggle_Struct);
LFGuild_PlayerToggle_Struct *pts = (LFGuild_PlayerToggle_Struct *)app->pBuffer; LFGuild_PlayerToggle_Struct *pts = (LFGuild_PlayerToggle_Struct *)app->pBuffer;