Merge pull request #201 from addtheice/RunQueryToDatabaseQuery_zone_mob

Run query to database query zone mob
This commit is contained in:
Alex 2014-08-22 13:47:48 -07:00
commit 1cd5970649

View File

@ -3928,36 +3928,26 @@ void Mob::TarGlobal(const char *varname, const char *value, const char *duration
}
void Mob::DelGlobal(const char *varname) {
// delglobal(varname)
char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0;
int qgZoneid=zone->GetZoneID();
int qgCharid=0;
int qgNpcid=0;
if (this->IsNPC())
{
qgNpcid = this->GetNPCTypeID();
}
if (this->IsClient())
{
qgCharid = this->CastToClient()->CharacterID();
}
else
{
qgCharid = -qgNpcid; // make char id negative npc id as a fudge
}
if (!database.RunQuery(query,
MakeAnyLenString(&query,
"DELETE FROM quest_globals WHERE name='%s'"
" && (npcid=0 || npcid=%i) && (charid=0 || charid=%i) && (zoneid=%i || zoneid=0)",
varname,qgNpcid,qgCharid,qgZoneid),errbuf))
{
//_log(QUESTS, "DelGlobal error deleting %s : %s", varname, errbuf);
}
safe_delete_array(query);
std::string query = StringFormat("DELETE FROM quest_globals "
"WHERE name='%s' && (npcid=0 || npcid=%i) "
"&& (charid=0 || charid=%i) "
"&& (zoneid=%i || zoneid=0)",
varname, qgNpcid, qgCharid, qgZoneid);
database.QueryDatabase(query);
if(zone)
{
@ -3980,33 +3970,22 @@ void Mob::DelGlobal(const char *varname) {
// Inserts global variable into quest_globals table
void Mob::InsertQuestGlobal(int charid, int npcid, int zoneid, const char *varname, const char *varvalue, int duration) {
char *query = 0;
char errbuf[MYSQL_ERRMSG_SIZE];
// Make duration string either "unix_timestamp(now()) + xxx" or "NULL"
std::stringstream duration_ss;
if (duration == INT_MAX)
{
duration_ss << "NULL";
}
else
{
duration_ss << "unix_timestamp(now()) + " << duration;
}
//NOTE: this should be escaping the contents of arglist
//npcwise a malicious script can arbitrarily alter the DB
uint32 last_id = 0;
if (!database.RunQuery(query, MakeAnyLenString(&query,
"REPLACE INTO quest_globals (charid, npcid, zoneid, name, value, expdate)"
std::string query = StringFormat("REPLACE INTO quest_globals "
"(charid, npcid, zoneid, name, value, expdate)"
"VALUES (%i, %i, %i, '%s', '%s', %s)",
charid, npcid, zoneid, varname, varvalue, duration_ss.str().c_str()
), errbuf))
{
//_log(QUESTS, "SelGlobal error inserting %s : %s", varname, errbuf);
}
safe_delete_array(query);
charid, npcid, zoneid, varname, varvalue, duration_ss.str().c_str());
database.QueryDatabase(query);
if(zone)
{
@ -4032,14 +4011,12 @@ void Mob::InsertQuestGlobal(int charid, int npcid, int zoneid, const char *varna
qgu->npc_id = npcid;
qgu->char_id = charid;
qgu->zone_id = zoneid;
if(duration == INT_MAX)
{
qgu->expdate = 0xFFFFFFFF;
}
else
{
qgu->expdate = Timer::GetTimeSeconds() + duration;
}
strcpy((char*)qgu->name, varname);
strcpy((char*)qgu->value, varvalue);
qgu->id = last_id;