mirror of
https://github.com/EQEmu/Server.git
synced 2026-04-02 16:32:26 +00:00
- License was intended to be GPLv3 per earlier commit of GPLv3 LICENSE FILE - This is confirmed by the inclusion of libraries that are incompatible with GPLv2 - This is also confirmed by KLS and the agreement of KLS's predecessors - Added GPLv3 license headers to the compilable source files - Removed Folly licensing in strings.h since the string functions do not match the Folly functions and are standard functions - this must have been left over from previous implementations - Removed individual contributor license headers since the project has been under the "developer" mantle for many years - Removed comments on files that were previously automatically generated since they've been manually modified multiple times and there are no automatic scripts referencing them (removed in 2023)
177 lines
4.5 KiB
C++
177 lines
4.5 KiB
C++
/* EQEmu: EQEmulator
|
|
|
|
Copyright (C) 2001-2026 EQEmu Development Team
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
#include "qglobals.h"
|
|
|
|
#include "common/strings.h"
|
|
#include "zone/client.h"
|
|
#include "zone/zone.h"
|
|
|
|
void QGlobalCache::AddGlobal(uint32 id, QGlobal global)
|
|
{
|
|
global.id = id;
|
|
qGlobalBucket.push_back(global);
|
|
}
|
|
|
|
void QGlobalCache::RemoveGlobal(std::string name, uint32 npcID, uint32 charID, uint32 zoneID)
|
|
{
|
|
auto iter = qGlobalBucket.begin();
|
|
while(iter != qGlobalBucket.end())
|
|
{
|
|
if(name.compare((*iter).name) == 0)
|
|
{
|
|
if((npcID == (*iter).npc_id || (*iter).npc_id == 0) &&
|
|
(charID == (*iter).char_id || (*iter).char_id == 0) &&
|
|
(zoneID == (*iter).zone_id || (*iter).zone_id == 0))
|
|
{
|
|
qGlobalBucket.erase(iter);
|
|
return;
|
|
}
|
|
}
|
|
++iter;
|
|
}
|
|
}
|
|
|
|
void QGlobalCache::Combine(std::list<QGlobal> &cacheA, std::list<QGlobal> cacheB, uint32 npcID, uint32 charID, uint32 zoneID)
|
|
{
|
|
auto iter = cacheB.begin();
|
|
while(iter != cacheB.end())
|
|
{
|
|
QGlobal cur = (*iter);
|
|
|
|
if((cur.npc_id == npcID || cur.npc_id == 0) && (cur.char_id == charID || cur.char_id == 0) &&
|
|
(cur.zone_id == zoneID || cur.zone_id == 0))
|
|
{
|
|
if(Timer::GetTimeSeconds() < cur.expdate)
|
|
{
|
|
cacheA.push_back(cur);
|
|
}
|
|
}
|
|
++iter;
|
|
}
|
|
}
|
|
|
|
void QGlobalCache::GetQGlobals(std::list<QGlobal> &globals, NPC *n, Client *c, Zone *z) {
|
|
globals.clear();
|
|
|
|
QGlobalCache *npc_c = nullptr;
|
|
QGlobalCache *char_c = nullptr;
|
|
QGlobalCache *zone_c = nullptr;
|
|
uint32 npc_id = 0;
|
|
uint32 char_id = 0;
|
|
uint32 zone_id = 0;
|
|
|
|
if(n) {
|
|
npc_id = n->GetNPCTypeID();
|
|
npc_c = n->GetQGlobals();
|
|
}
|
|
|
|
if(c) {
|
|
char_id = c->CharacterID();
|
|
char_c = c->GetQGlobals();
|
|
}
|
|
|
|
if(z) {
|
|
zone_id = z->GetZoneID();
|
|
zone_c = z->GetQGlobals();
|
|
}
|
|
|
|
if(!npc_c && n) {
|
|
npc_c = n->CreateQGlobals();
|
|
npc_c->LoadByNPCID(npc_id);
|
|
}
|
|
|
|
if(!char_c && c) {
|
|
char_c = c->CreateQGlobals();
|
|
char_c->LoadByCharID(char_id);
|
|
}
|
|
|
|
if(!zone_c && z) {
|
|
zone_c = z->CreateQGlobals();
|
|
zone_c->LoadByZoneID(zone_id);
|
|
zone_c->LoadByGlobalContext();
|
|
}
|
|
|
|
if(npc_c) {
|
|
QGlobalCache::Combine(globals, npc_c->GetBucket(), npc_id, char_id, zone_id);
|
|
}
|
|
|
|
if(char_c) {
|
|
QGlobalCache::Combine(globals, char_c->GetBucket(), npc_id, char_id, zone_id);
|
|
}
|
|
|
|
if(zone_c) {
|
|
QGlobalCache::Combine(globals, zone_c->GetBucket(), npc_id, char_id, zone_id);
|
|
}
|
|
}
|
|
|
|
void QGlobalCache::PurgeExpiredGlobals()
|
|
{
|
|
if(!qGlobalBucket.size())
|
|
return;
|
|
|
|
auto iter = qGlobalBucket.begin();
|
|
while(iter != qGlobalBucket.end())
|
|
{
|
|
QGlobal cur = (*iter);
|
|
if(Timer::GetTimeSeconds() > cur.expdate)
|
|
{
|
|
iter = qGlobalBucket.erase(iter);
|
|
continue;
|
|
}
|
|
++iter;
|
|
}
|
|
}
|
|
|
|
void QGlobalCache::LoadByNPCID(uint32 npcID)
|
|
{
|
|
std::string query = StringFormat("SELECT name, charid, npcid, zoneid, value, expdate "
|
|
"FROM quest_globals WHERE npcid = %d", npcID);
|
|
LoadBy(query);
|
|
}
|
|
|
|
void QGlobalCache::LoadByCharID(uint32 charID)
|
|
{
|
|
std::string query = StringFormat("SELECT name, charid, npcid, zoneid, value, expdate "
|
|
"FROM quest_globals WHERE charid = %d && npcid = 0", charID);
|
|
LoadBy(query);
|
|
}
|
|
|
|
void QGlobalCache::LoadByZoneID(uint32 zoneID)
|
|
{
|
|
std::string query = StringFormat("SELECT name, charid, npcid, zoneid, value, expdate "
|
|
"FROM quest_globals WHERE zoneid = %d && npcid = 0 && charid = 0", zoneID);
|
|
LoadBy(query);
|
|
}
|
|
|
|
void QGlobalCache::LoadByGlobalContext()
|
|
{
|
|
std::string query = "SELECT name, charid, npcid, zoneid, value, expdate "
|
|
"FROM quest_globals WHERE zoneid = 0 && npcid = 0 && charid = 0";
|
|
LoadBy(query);
|
|
}
|
|
|
|
void QGlobalCache::LoadBy(const std::string &query)
|
|
{
|
|
auto results = database.QueryDatabase(query);
|
|
if (!results.Success())
|
|
return;
|
|
|
|
for (auto row = results.begin(); row != results.end(); ++row)
|
|
AddGlobal(0, QGlobal(row[0], Strings::ToInt(row[1]), Strings::ToInt(row[2]), Strings::ToInt(row[3]), row[4], row[5] ? Strings::ToInt(row[5]) : 0xFFFFFFFF));
|
|
}
|