mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-12 17:51:28 +00:00
InsertQuestGlobal converted to QueryDatabase
This commit is contained in:
parent
37d3daaf9a
commit
58343480ff
@ -1335,34 +1335,26 @@ void QuestManager::setglobal(const char *varname, const char *newvalue, int opti
|
|||||||
|
|
||||||
/* Inserts global variable into quest_globals table */
|
/* Inserts global variable into quest_globals table */
|
||||||
int QuestManager::InsertQuestGlobal(int charid, int npcid, int zoneid, const char *varname, const char *varvalue, int duration) {
|
int QuestManager::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::string durationText = (duration == INT_MAX)? "NULL": StringFormat("unix_timestamp(now()) + %i", duration);
|
||||||
if (duration == INT_MAX) {
|
|
||||||
duration_ss << "NULL";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
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;
|
|
||||||
if (!database.RunQuery(query, MakeAnyLenString(&query,
|
|
||||||
"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, nullptr, nullptr, &last_id))
|
|
||||||
{
|
|
||||||
std::cerr << "setglobal error inserting " << varname << " : " << errbuf << std::endl;
|
|
||||||
}
|
|
||||||
safe_delete_array(query);
|
|
||||||
|
|
||||||
if(zone) {
|
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, durationText.c_str());
|
||||||
|
auto results = database.QueryDatabase(query);
|
||||||
|
if (!results.Success())
|
||||||
|
std::cerr << "setglobal error inserting " << varname << " : " << results.ErrorMessage() << std::endl;
|
||||||
|
|
||||||
|
if(!zone)
|
||||||
|
return 0;
|
||||||
|
|
||||||
/* Delete existing qglobal data and update zone processes */
|
/* Delete existing qglobal data and update zone processes */
|
||||||
ServerPacket* pack = new ServerPacket(ServerOP_QGlobalDelete, sizeof(ServerQGlobalDelete_Struct));
|
ServerPacket* pack = new ServerPacket(ServerOP_QGlobalDelete, sizeof(ServerQGlobalDelete_Struct));
|
||||||
ServerQGlobalDelete_Struct *qgd = (ServerQGlobalDelete_Struct*)pack->pBuffer;
|
ServerQGlobalDelete_Struct *qgd = (ServerQGlobalDelete_Struct*)pack->pBuffer;
|
||||||
@ -1385,15 +1377,12 @@ int QuestManager::InsertQuestGlobal(int charid, int npcid, int zoneid, const cha
|
|||||||
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) {
|
|
||||||
qgu->expdate = 0xFFFFFFFF;
|
qgu->expdate = (duration == INT_MAX)? 0xFFFFFFFF: Timer::GetTimeSeconds() + duration;
|
||||||
}
|
|
||||||
else {
|
|
||||||
qgu->expdate = Timer::GetTimeSeconds() + duration;
|
|
||||||
}
|
|
||||||
strcpy((char*)qgu->name, varname);
|
strcpy((char*)qgu->name, varname);
|
||||||
strn0cpy((char*)qgu->value, varvalue, 128);
|
strn0cpy((char*)qgu->value, varvalue, 128);
|
||||||
qgu->id = last_id;
|
qgu->id = results.LastInsertedID();
|
||||||
qgu->from_zone_id = zone->GetZoneID();
|
qgu->from_zone_id = zone->GetZoneID();
|
||||||
qgu->from_instance_id = zone->GetInstanceID();
|
qgu->from_instance_id = zone->GetInstanceID();
|
||||||
|
|
||||||
@ -1409,7 +1398,6 @@ int QuestManager::InsertQuestGlobal(int charid, int npcid, int zoneid, const cha
|
|||||||
|
|
||||||
worldserver.SendPacket(pack);
|
worldserver.SendPacket(pack);
|
||||||
safe_delete(pack);
|
safe_delete(pack);
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user