TradeskillSearchResults converted to QueryDatabase

This commit is contained in:
Arthur Ice 2014-10-08 14:38:38 -07:00
parent e2333e671b
commit d5955da08c

View File

@ -425,7 +425,7 @@ void Object::HandleAutoCombine(Client* user, const RecipeAutoCombine_Struct* rac
} }
//pull the list of components //pull the list of components
std::string query = StringFormat("SELECT tre.item_id,tre.componentcount " std::string query = StringFormat("SELECT tre.item_id, tre.componentcount "
"FROM tradeskill_recipe_entries AS tre " "FROM tradeskill_recipe_entries AS tre "
"WHERE tre.componentcount > 0 AND tre.recipe_id = %u", "WHERE tre.componentcount > 0 AND tre.recipe_id = %u",
rac->recipe_id); rac->recipe_id);
@ -638,32 +638,25 @@ SkillUseTypes Object::TypeToSkill(uint32 type)
void Client::TradeskillSearchResults(const char *query, unsigned long qlen, unsigned long objtype, unsigned long someid) { void Client::TradeskillSearchResults(const char *query, unsigned long qlen, unsigned long objtype, unsigned long someid) {
char errbuf[MYSQL_ERRMSG_SIZE]; std::string internalQuery(query);
MYSQL_RES *result; auto results = database.QueryDatabase(internalQuery);
MYSQL_ROW row; if (!results.Success()) {
LogFile->write(EQEMuLog::Error, "Error in TradeskillSearchResults query '%s': %s", internalQuery.c_str(), results.ErrorMessage().c_str());
if (!database.RunQuery(query, qlen, errbuf, &result)) {
LogFile->write(EQEMuLog::Error, "Error in TradeskillSearchResults query '%s': %s", query, errbuf);
return; return;
} }
uint8 qcount = 0; if(results.RowCount() < 1)
return; //search gave no results... not an error
qcount = mysql_num_rows(result); if(results.ColumnCount() != 6) {
if(qcount < 1) { LogFile->write(EQEMuLog::Error, "Error in TradeskillSearchResults query '%s': Invalid column count in result", internalQuery.c_str());
//search gave no results... not an error
return;
}
if(mysql_num_fields(result) != 6) {
LogFile->write(EQEMuLog::Error, "Error in TradeskillSearchResults query '%s': Invalid column count in result", query);
return; return;
} }
uint8 r; for(auto row = results.begin(); row != results.end(); ++row) {
for(r = 0; r < qcount; r++) {
row = mysql_fetch_row(result);
if(row == nullptr || row[0] == nullptr || row[1] == nullptr || row[2] == nullptr || row[3] == nullptr || row[5] == nullptr) if(row == nullptr || row[0] == nullptr || row[1] == nullptr || row[2] == nullptr || row[3] == nullptr || row[5] == nullptr)
continue; continue;
uint32 recipe = (uint32)atoi(row[0]); uint32 recipe = (uint32)atoi(row[0]);
const char *name = row[1]; const char *name = row[1];
uint32 trivial = (uint32) atoi(row[2]); uint32 trivial = (uint32) atoi(row[2]);
@ -673,14 +666,10 @@ void Client::TradeskillSearchResults(const char *query, unsigned long qlen, unsi
// Skip the recipes that exceed the threshold in skill difference // Skip the recipes that exceed the threshold in skill difference
// Recipes that have either been made before or were // Recipes that have either been made before or were
// explicitly learned are excempt from that limit // explicitly learned are excempt from that limit
if (RuleB(Skills, UseLimitTradeskillSearchSkillDiff)) { if (RuleB(Skills, UseLimitTradeskillSearchSkillDiff)
if (((int32)trivial - (int32)GetSkill((SkillUseTypes)tradeskill)) > RuleI(Skills, MaxTradeskillSearchSkillDiff) && ((int32)trivial - (int32)GetSkill((SkillUseTypes)tradeskill)) > RuleI(Skills, MaxTradeskillSearchSkillDiff)
&& row[4] == nullptr) && row[4] == nullptr)
{
continue; continue;
}
}
EQApplicationPacket* outapp = new EQApplicationPacket(OP_RecipeReply, sizeof(RecipeReply_Struct)); EQApplicationPacket* outapp = new EQApplicationPacket(OP_RecipeReply, sizeof(RecipeReply_Struct));
RecipeReply_Struct *reply = (RecipeReply_Struct *) outapp->pBuffer; RecipeReply_Struct *reply = (RecipeReply_Struct *) outapp->pBuffer;
@ -693,7 +682,7 @@ void Client::TradeskillSearchResults(const char *query, unsigned long qlen, unsi
strn0cpy(reply->recipe_name, name, sizeof(reply->recipe_name)); strn0cpy(reply->recipe_name, name, sizeof(reply->recipe_name));
FastQueuePacket(&outapp); FastQueuePacket(&outapp);
} }
mysql_free_result(result);
} }
void Client::SendTradeskillDetails(uint32 recipe_id) { void Client::SendTradeskillDetails(uint32 recipe_id) {