mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-20 05:01:29 +00:00
Merge pull request #201 from addtheice/RunQueryToDatabaseQuery_zone_mob
Run query to database query zone mob
This commit is contained in:
commit
1cd5970649
51
zone/mob.cpp
51
zone/mob.cpp
@ -3928,36 +3928,26 @@ void Mob::TarGlobal(const char *varname, const char *value, const char *duration
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Mob::DelGlobal(const char *varname) {
|
void Mob::DelGlobal(const char *varname) {
|
||||||
// delglobal(varname)
|
|
||||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
|
||||||
char *query = 0;
|
|
||||||
int qgZoneid=zone->GetZoneID();
|
int qgZoneid=zone->GetZoneID();
|
||||||
int qgCharid=0;
|
int qgCharid=0;
|
||||||
int qgNpcid=0;
|
int qgNpcid=0;
|
||||||
|
|
||||||
if (this->IsNPC())
|
if (this->IsNPC())
|
||||||
{
|
|
||||||
qgNpcid = this->GetNPCTypeID();
|
qgNpcid = this->GetNPCTypeID();
|
||||||
}
|
|
||||||
|
|
||||||
if (this->IsClient())
|
if (this->IsClient())
|
||||||
{
|
|
||||||
qgCharid = this->CastToClient()->CharacterID();
|
qgCharid = this->CastToClient()->CharacterID();
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
qgCharid = -qgNpcid; // make char id negative npc id as a fudge
|
qgCharid = -qgNpcid; // make char id negative npc id as a fudge
|
||||||
}
|
|
||||||
|
|
||||||
if (!database.RunQuery(query,
|
std::string query = StringFormat("DELETE FROM quest_globals "
|
||||||
MakeAnyLenString(&query,
|
"WHERE name='%s' && (npcid=0 || npcid=%i) "
|
||||||
"DELETE FROM quest_globals WHERE name='%s'"
|
"&& (charid=0 || charid=%i) "
|
||||||
" && (npcid=0 || npcid=%i) && (charid=0 || charid=%i) && (zoneid=%i || zoneid=0)",
|
"&& (zoneid=%i || zoneid=0)",
|
||||||
varname,qgNpcid,qgCharid,qgZoneid),errbuf))
|
varname, qgNpcid, qgCharid, qgZoneid);
|
||||||
{
|
|
||||||
//_log(QUESTS, "DelGlobal error deleting %s : %s", varname, errbuf);
|
database.QueryDatabase(query);
|
||||||
}
|
|
||||||
safe_delete_array(query);
|
|
||||||
|
|
||||||
if(zone)
|
if(zone)
|
||||||
{
|
{
|
||||||
@ -3980,33 +3970,22 @@ void Mob::DelGlobal(const char *varname) {
|
|||||||
// Inserts global variable into quest_globals table
|
// Inserts global variable into quest_globals table
|
||||||
void Mob::InsertQuestGlobal(int charid, int npcid, int zoneid, const char *varname, const char *varvalue, int duration) {
|
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"
|
// Make duration string either "unix_timestamp(now()) + xxx" or "NULL"
|
||||||
std::stringstream duration_ss;
|
std::stringstream duration_ss;
|
||||||
|
|
||||||
if (duration == INT_MAX)
|
if (duration == INT_MAX)
|
||||||
{
|
|
||||||
duration_ss << "NULL";
|
duration_ss << "NULL";
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
duration_ss << "unix_timestamp(now()) + " << duration;
|
duration_ss << "unix_timestamp(now()) + " << duration;
|
||||||
}
|
|
||||||
|
|
||||||
//NOTE: this should be escaping the contents of arglist
|
//NOTE: this should be escaping the contents of arglist
|
||||||
//npcwise a malicious script can arbitrarily alter the DB
|
//npcwise a malicious script can arbitrarily alter the DB
|
||||||
uint32 last_id = 0;
|
uint32 last_id = 0;
|
||||||
if (!database.RunQuery(query, MakeAnyLenString(&query,
|
std::string query = StringFormat("REPLACE INTO quest_globals "
|
||||||
"REPLACE INTO quest_globals (charid, npcid, zoneid, name, value, expdate)"
|
"(charid, npcid, zoneid, name, value, expdate)"
|
||||||
"VALUES (%i, %i, %i, '%s', '%s', %s)",
|
"VALUES (%i, %i, %i, '%s', '%s', %s)",
|
||||||
charid, npcid, zoneid, varname, varvalue, duration_ss.str().c_str()
|
charid, npcid, zoneid, varname, varvalue, duration_ss.str().c_str());
|
||||||
), errbuf))
|
database.QueryDatabase(query);
|
||||||
{
|
|
||||||
//_log(QUESTS, "SelGlobal error inserting %s : %s", varname, errbuf);
|
|
||||||
}
|
|
||||||
safe_delete_array(query);
|
|
||||||
|
|
||||||
if(zone)
|
if(zone)
|
||||||
{
|
{
|
||||||
@ -4032,14 +4011,12 @@ void Mob::InsertQuestGlobal(int charid, int npcid, int zoneid, const char *varna
|
|||||||
qgu->npc_id = npcid;
|
qgu->npc_id = npcid;
|
||||||
qgu->char_id = charid;
|
qgu->char_id = charid;
|
||||||
qgu->zone_id = zoneid;
|
qgu->zone_id = zoneid;
|
||||||
|
|
||||||
if(duration == INT_MAX)
|
if(duration == INT_MAX)
|
||||||
{
|
|
||||||
qgu->expdate = 0xFFFFFFFF;
|
qgu->expdate = 0xFFFFFFFF;
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
qgu->expdate = Timer::GetTimeSeconds() + duration;
|
qgu->expdate = Timer::GetTimeSeconds() + duration;
|
||||||
}
|
|
||||||
strcpy((char*)qgu->name, varname);
|
strcpy((char*)qgu->name, varname);
|
||||||
strcpy((char*)qgu->value, varvalue);
|
strcpy((char*)qgu->value, varvalue);
|
||||||
qgu->id = last_id;
|
qgu->id = last_id;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user