mirror of
https://github.com/EQEmu/Server.git
synced 2026-04-04 14:22:24 +00:00
LearnRecipe converted to QueryDatabase
This commit is contained in:
parent
97c1c479f9
commit
5dac9a944b
@ -1418,73 +1418,54 @@ bool ZoneDatabase::GetTradeRecipe(uint32 recipe_id, uint8 c_type, uint32 some_id
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoneDatabase::UpdateRecipeMadecount(uint32 recipe_id, uint32 char_id, uint32 madecount)
|
void ZoneDatabase::UpdateRecipeMadecount(uint32 recipe_id, uint32 char_id, uint32 madeCount)
|
||||||
{
|
{
|
||||||
char *query = 0;
|
std::string query = StringFormat("INSERT INTO char_recipe_list "
|
||||||
uint32 qlen;
|
"SET recipe_id = %u, char_id = %u, madecount = %u "
|
||||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
"ON DUPLICATE KEY UPDATE madecount = %u;",
|
||||||
|
recipe_id, char_id, madeCount, madeCount);
|
||||||
qlen = MakeAnyLenString(&query, "INSERT INTO char_recipe_list "
|
auto results = QueryDatabase(query);
|
||||||
" SET recipe_id = %u, char_id = %u, madecount = %u "
|
if (!results.Success())
|
||||||
" ON DUPLICATE KEY UPDATE madecount = %u;"
|
LogFile->write(EQEMuLog::Error, "Error in UpdateRecipeMadecount query '%s': %s", query.c_str(), results.ErrorMessage().c_str());
|
||||||
, recipe_id, char_id, madecount, madecount);
|
|
||||||
|
|
||||||
if (!RunQuery(query, qlen, errbuf)) {
|
|
||||||
LogFile->write(EQEMuLog::Error, "Error in UpdateRecipeMadecount query '%s': %s", query, errbuf);
|
|
||||||
}
|
|
||||||
safe_delete_array(query);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::LearnRecipe(uint32 recipeID)
|
void Client::LearnRecipe(uint32 recipeID)
|
||||||
{
|
{
|
||||||
char *query = 0;
|
std::string query = StringFormat("SELECT tr.name, crl.madecount "
|
||||||
uint32 qlen;
|
"FROM tradeskill_recipe AS tr "
|
||||||
uint32 qcount = 0;
|
"LEFT JOIN (SELECT recipe_id, madecount "
|
||||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
"FROM char_recipe_list WHERE char_id = %u) AS crl "
|
||||||
MYSQL_RES *result;
|
"ON tr.id = crl.recipe_id "
|
||||||
MYSQL_ROW row;
|
"WHERE tr.id = %u ;", CharacterID(), recipeID);
|
||||||
|
auto results = database.QueryDatabase(query);
|
||||||
qlen = MakeAnyLenString(&query, "SELECT tr.name, crl.madecount "
|
if (!results.Success()) {
|
||||||
" FROM tradeskill_recipe as tr "
|
LogFile->write(EQEMuLog::Error, "Error in Client::LearnRecipe query '%s': %s", query.c_str(), results.ErrorMessage().c_str());
|
||||||
" LEFT JOIN (SELECT recipe_id, madecount FROM char_recipe_list WHERE char_id = %u) AS crl "
|
|
||||||
" ON tr.id = crl.recipe_id "
|
|
||||||
" WHERE tr.id = %u ;", CharacterID(), recipeID);
|
|
||||||
|
|
||||||
if (!database.RunQuery(query, qlen, errbuf, &result)) {
|
|
||||||
LogFile->write(EQEMuLog::Error, "Error in Client::LearnRecipe query '%s': %s", query, errbuf);
|
|
||||||
safe_delete_array(query);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
qcount = mysql_num_rows(result);
|
if (results.RowCount() != 1) {
|
||||||
if (qcount != 1) {
|
LogFile->write(EQEMuLog::Normal, "Client::LearnRecipe - RecipeID: %d had %d occurences.", recipeID, results.RowCount());
|
||||||
LogFile->write(EQEMuLog::Normal, "Client::LearnRecipe - RecipeID: %d had %d occurences.", recipeID, qcount);
|
|
||||||
mysql_free_result(result);
|
|
||||||
safe_delete_array(query);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
safe_delete_array(query);
|
|
||||||
|
|
||||||
row = mysql_fetch_row(result);
|
auto row = results.begin();
|
||||||
|
|
||||||
if (row != nullptr && row[0] != nullptr) {
|
if (row[0] == nullptr)
|
||||||
// Only give Learn message if character doesn't know the recipe
|
return;
|
||||||
if (row[1] == nullptr) {
|
|
||||||
Message_StringID(4, TRADESKILL_LEARN_RECIPE, row[0]);
|
|
||||||
// Actually learn the recipe now
|
|
||||||
qlen = MakeAnyLenString(&query, "INSERT INTO char_recipe_list "
|
|
||||||
" SET recipe_id = %u, char_id = %u, madecount = 0 "
|
|
||||||
" ON DUPLICATE KEY UPDATE madecount = madecount;"
|
|
||||||
, recipeID, CharacterID());
|
|
||||||
|
|
||||||
if (!database.RunQuery(query, qlen, errbuf)) {
|
// Only give Learn message if character doesn't know the recipe
|
||||||
LogFile->write(EQEMuLog::Error, "Error in LearnRecipe query '%s': %s", query, errbuf);
|
if (row[1] != nullptr)
|
||||||
}
|
return;
|
||||||
safe_delete_array(query);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mysql_free_result(result);
|
Message_StringID(4, TRADESKILL_LEARN_RECIPE, row[0]);
|
||||||
|
// Actually learn the recipe now
|
||||||
|
query = StringFormat("INSERT INTO char_recipe_list "
|
||||||
|
"SET recipe_id = %u, char_id = %u, madecount = 0 "
|
||||||
|
"ON DUPLICATE KEY UPDATE madecount = madecount;",
|
||||||
|
recipeID, CharacterID());
|
||||||
|
results = database.QueryDatabase(query);
|
||||||
|
if (!results.Success())
|
||||||
|
LogFile->write(EQEMuLog::Error, "Error in LearnRecipe query '%s': %s", query.c_str(), results.ErrorMessage().c_str());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user