PDA

View Full Version : Deleteing Globals


jsr
09-10-2019, 03:24 AM
I need to delete a player's quest global, but from an event timer so there is no player context in (e), instead I have a client using getrandomclient().

There's only one function I can find to delete quest globals, which is delete_global(char *name), this function doesn't include the player.

So I'm looking to add a function that lets you delete a global specifying a client id. Is this all I need to do?

1. Add the new function to the luabind register in lua_general.cpp.
2. Add a function to lua_general.cpp that calls the function in questmgr.cpp
3. Add a new function (delete_char_global) to questmgr.cpp and questmgr.h, that takes and uses uses an additional clientid parameter.

lua_general.cpp

luabind::def("delete_char_global", &lua_delete_char_global),



void lua_delete_char_global(const char *name, int charid) {
quest_manager.delcharglobal(name, charid);
}


questmgr.h

void delcharglobal(const char * varname, int charid);


questmgr.cpp

void QuestManager::delcharglobal(const char *varname, int charid) {
QuestManagerCurrentQuestVars();
int qgZoneid = zone->GetZoneID();
int qgCharid = charid;
int qgNpcid = owner ? owner->GetNPCTypeID() : 0; // encounter scripts don't have an owner

/* QS: PlayerLogQGlobalUpdate */
if (RuleB(QueryServ, PlayerLogQGlobalUpdate) && qgCharid && qgCharid > 0 && initiator && initiator->IsClient()) {
std::string event_desc = StringFormat("Deleted :: qglobal:%s zoneid:%i instid:%i", varname, initiator->GetZoneID(), initiator->GetInstanceID());
QServ->PlayerLogEvent(Player_Log_QGlobal_Update, qgCharid, event_desc);
}

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);
auto results = database.QueryDatabase(query);
if (!results.Success())
std::cerr << "delglobal error deleting " << varname << " : " << results.ErrorMessage() << std::endl;

if (!zone)
return;

auto pack = new ServerPacket(ServerOP_QGlobalDelete, sizeof(ServerQGlobalDelete_Struct));
ServerQGlobalDelete_Struct *qgu = (ServerQGlobalDelete_Struct *)pack->pBuffer;

qgu->npc_id = qgNpcid;
qgu->char_id = qgCharid;
qgu->zone_id = qgZoneid;
strcpy(qgu->name, varname);

entity_list.DeleteQGlobal(std::string((char *)qgu->name), qgu->npc_id, qgu->char_id, qgu->zone_id);
zone->DeleteQGlobal(std::string((char *)qgu->name), qgu->npc_id, qgu->char_id, qgu->zone_id);

worldserver.SendPacket(pack);
safe_delete(pack);
}