mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-12 05:21:29 +00:00
InsertQuestGlobal converted to QueryDatabase
This commit is contained in:
parent
37d3daaf9a
commit
58343480ff
@ -172,7 +172,7 @@ void QuestManager::EndQuest() {
|
|||||||
cur = QTimerList.erase(cur);
|
cur = QTimerList.erase(cur);
|
||||||
else
|
else
|
||||||
++cur;
|
++cur;
|
||||||
}
|
}
|
||||||
run.owner->Depop();
|
run.owner->Depop();
|
||||||
}
|
}
|
||||||
quests_running_.pop();
|
quests_running_.pop();
|
||||||
@ -447,7 +447,7 @@ void QuestManager::settimer(const char *timer_name, int seconds) {
|
|||||||
|
|
||||||
end = QTimerList.end();
|
end = QTimerList.end();
|
||||||
while (cur != end) {
|
while (cur != end) {
|
||||||
if(cur->mob && cur->mob == owner && cur->name == timer_name)
|
if(cur->mob && cur->mob == owner && cur->name == timer_name)
|
||||||
{
|
{
|
||||||
cur->Timer_.Enable();
|
cur->Timer_.Enable();
|
||||||
cur->Timer_.Start(seconds * 1000, false);
|
cur->Timer_.Start(seconds * 1000, false);
|
||||||
@ -471,7 +471,7 @@ void QuestManager::settimerMS(const char *timer_name, int milliseconds) {
|
|||||||
|
|
||||||
end = QTimerList.end();
|
end = QTimerList.end();
|
||||||
while (cur != end) {
|
while (cur != end) {
|
||||||
if(cur->mob && cur->mob == owner && cur->name == timer_name)
|
if(cur->mob && cur->mob == owner && cur->name == timer_name)
|
||||||
{
|
{
|
||||||
cur->Timer_.Enable();
|
cur->Timer_.Enable();
|
||||||
cur->Timer_.Start(milliseconds, false);
|
cur->Timer_.Start(milliseconds, false);
|
||||||
@ -1308,7 +1308,7 @@ void QuestManager::setglobal(const char *varname, const char *newvalue, int opti
|
|||||||
|
|
||||||
if (initiator && initiator->IsClient()){ // some events like waypoint and spawn don't have a player involved
|
if (initiator && initiator->IsClient()){ // some events like waypoint and spawn don't have a player involved
|
||||||
qgCharid=initiator->CharacterID();
|
qgCharid=initiator->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
|
||||||
}
|
}
|
||||||
@ -1335,81 +1335,69 @@ 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 "
|
||||||
/* Delete existing qglobal data and update zone processes */
|
"(charid, npcid, zoneid, name, value, expdate)"
|
||||||
ServerPacket* pack = new ServerPacket(ServerOP_QGlobalDelete, sizeof(ServerQGlobalDelete_Struct));
|
"VALUES (%i, %i, %i, '%s', '%s', %s)",
|
||||||
ServerQGlobalDelete_Struct *qgd = (ServerQGlobalDelete_Struct*)pack->pBuffer;
|
charid, npcid, zoneid, varname, varvalue, durationText.c_str());
|
||||||
qgd->npc_id = npcid;
|
auto results = database.QueryDatabase(query);
|
||||||
qgd->char_id = charid;
|
if (!results.Success())
|
||||||
qgd->zone_id = zoneid;
|
std::cerr << "setglobal error inserting " << varname << " : " << results.ErrorMessage() << std::endl;
|
||||||
qgd->from_zone_id = zone->GetZoneID();
|
|
||||||
qgd->from_instance_id = zone->GetInstanceID();
|
|
||||||
strcpy(qgd->name, varname);
|
|
||||||
|
|
||||||
entity_list.DeleteQGlobal(std::string((char*)qgd->name), qgd->npc_id, qgd->char_id, qgd->zone_id);
|
if(!zone)
|
||||||
zone->DeleteQGlobal(std::string((char*)qgd->name), qgd->npc_id, qgd->char_id, qgd->zone_id);
|
return 0;
|
||||||
|
|
||||||
worldserver.SendPacket(pack);
|
/* Delete existing qglobal data and update zone processes */
|
||||||
safe_delete(pack);
|
ServerPacket* pack = new ServerPacket(ServerOP_QGlobalDelete, sizeof(ServerQGlobalDelete_Struct));
|
||||||
|
ServerQGlobalDelete_Struct *qgd = (ServerQGlobalDelete_Struct*)pack->pBuffer;
|
||||||
|
qgd->npc_id = npcid;
|
||||||
|
qgd->char_id = charid;
|
||||||
|
qgd->zone_id = zoneid;
|
||||||
|
qgd->from_zone_id = zone->GetZoneID();
|
||||||
|
qgd->from_instance_id = zone->GetInstanceID();
|
||||||
|
strcpy(qgd->name, varname);
|
||||||
|
|
||||||
/* Create new qglobal data and update zone processes */
|
entity_list.DeleteQGlobal(std::string((char*)qgd->name), qgd->npc_id, qgd->char_id, qgd->zone_id);
|
||||||
pack = new ServerPacket(ServerOP_QGlobalUpdate, sizeof(ServerQGlobalUpdate_Struct));
|
zone->DeleteQGlobal(std::string((char*)qgd->name), qgd->npc_id, qgd->char_id, qgd->zone_id);
|
||||||
ServerQGlobalUpdate_Struct *qgu = (ServerQGlobalUpdate_Struct*)pack->pBuffer;
|
|
||||||
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);
|
|
||||||
strn0cpy((char*)qgu->value, varvalue, 128);
|
|
||||||
qgu->id = last_id;
|
|
||||||
qgu->from_zone_id = zone->GetZoneID();
|
|
||||||
qgu->from_instance_id = zone->GetInstanceID();
|
|
||||||
|
|
||||||
QGlobal temp;
|
worldserver.SendPacket(pack);
|
||||||
temp.npc_id = npcid;
|
safe_delete(pack);
|
||||||
temp.char_id = charid;
|
|
||||||
temp.zone_id = zoneid;
|
|
||||||
temp.expdate = qgu->expdate;
|
|
||||||
temp.name.assign(qgu->name);
|
|
||||||
temp.value.assign(qgu->value);
|
|
||||||
entity_list.UpdateQGlobal(qgu->id, temp);
|
|
||||||
zone->UpdateQGlobal(qgu->id, temp);
|
|
||||||
|
|
||||||
worldserver.SendPacket(pack);
|
/* Create new qglobal data and update zone processes */
|
||||||
safe_delete(pack);
|
pack = new ServerPacket(ServerOP_QGlobalUpdate, sizeof(ServerQGlobalUpdate_Struct));
|
||||||
}
|
ServerQGlobalUpdate_Struct *qgu = (ServerQGlobalUpdate_Struct*)pack->pBuffer;
|
||||||
|
qgu->npc_id = npcid;
|
||||||
|
qgu->char_id = charid;
|
||||||
|
qgu->zone_id = zoneid;
|
||||||
|
|
||||||
|
qgu->expdate = (duration == INT_MAX)? 0xFFFFFFFF: Timer::GetTimeSeconds() + duration;
|
||||||
|
|
||||||
|
strcpy((char*)qgu->name, varname);
|
||||||
|
strn0cpy((char*)qgu->value, varvalue, 128);
|
||||||
|
qgu->id = results.LastInsertedID();
|
||||||
|
qgu->from_zone_id = zone->GetZoneID();
|
||||||
|
qgu->from_instance_id = zone->GetInstanceID();
|
||||||
|
|
||||||
|
QGlobal temp;
|
||||||
|
temp.npc_id = npcid;
|
||||||
|
temp.char_id = charid;
|
||||||
|
temp.zone_id = zoneid;
|
||||||
|
temp.expdate = qgu->expdate;
|
||||||
|
temp.name.assign(qgu->name);
|
||||||
|
temp.value.assign(qgu->value);
|
||||||
|
entity_list.UpdateQGlobal(qgu->id, temp);
|
||||||
|
zone->UpdateQGlobal(qgu->id, temp);
|
||||||
|
|
||||||
|
worldserver.SendPacket(pack);
|
||||||
|
safe_delete(pack);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1425,9 +1413,9 @@ void QuestManager::delglobal(const char *varname) {
|
|||||||
int qgZoneid=zone->GetZoneID();
|
int qgZoneid=zone->GetZoneID();
|
||||||
int qgCharid=0;
|
int qgCharid=0;
|
||||||
int qgNpcid=owner->GetNPCTypeID();
|
int qgNpcid=owner->GetNPCTypeID();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (initiator && initiator->IsClient()) // some events like waypoint and spawn don't have a player involved
|
if (initiator && initiator->IsClient()) // some events like waypoint and spawn don't have a player involved
|
||||||
{
|
{
|
||||||
qgCharid=initiator->CharacterID();
|
qgCharid=initiator->CharacterID();
|
||||||
@ -1709,7 +1697,7 @@ void QuestManager::showgrid(int grid) {
|
|||||||
pt.z = atof(row[2]);
|
pt.z = atof(row[2]);
|
||||||
pts.push_back(pt);
|
pts.push_back(pt);
|
||||||
}
|
}
|
||||||
mysql_free_result(result);
|
mysql_free_result(result);
|
||||||
initiator->SendPathPacket(pts);
|
initiator->SendPathPacket(pts);
|
||||||
}
|
}
|
||||||
else // DB query error!
|
else // DB query error!
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user