TrinityCore
Loading...
Searching...
No Matches
DisableMgr.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "DisableMgr.h"
19#include "CriteriaHandler.h"
20#include "DatabaseEnv.h"
21#include "DB2Stores.h"
22#include "Group.h"
23#include "Log.h"
24#include "Map.h"
25#include "ObjectMgr.h"
26#include "OutdoorPvP.h"
27#include "Player.h"
28#include "SpellMgr.h"
29#include "StringConvert.h"
30#include "VMapManager.h"
31#include "World.h"
32
33namespace DisableMgr
34{
35
36namespace
37{
38 constexpr std::string_view MapTypeNames[] =
39 {
40 "World",
41 "Dungeon",
42 "Raid",
43 "Battleground",
44 "Arena",
45 "Scenario",
46 "WowLabs",
47 "House interior",
48 "Housing neighborhood"
49 };
50
51 struct DisableData
52 {
54 std::unordered_set<uint32> params[2]; // params0, params1
55 };
56
57 // single disables here with optional data
58 typedef std::unordered_map<uint32, DisableData> DisableTypeMap;
59
60 std::array<DisableTypeMap, MAX_DISABLE_TYPES> m_DisableMap;
61}
62
64{
65 uint32 oldMSTime = getMSTime();
66
67 // reload case
68 for (std::size_t i = 0; i < m_DisableMap.size(); ++i)
69 m_DisableMap[i].clear();
70
71 QueryResult result = WorldDatabase.Query("SELECT sourceType, entry, flags, params_0, params_1 FROM disables");
72
73 uint32 total_count = 0;
74
75 if (!result)
76 {
77 TC_LOG_INFO("server.loading", ">> Loaded 0 disables. DB table `disables` is empty!");
78 return;
79 }
80
81 Field* fields;
82 do
83 {
84 fields = result->Fetch();
85 uint32 type = fields[0].GetUInt32();
86 if (type >= MAX_DISABLE_TYPES)
87 {
88 TC_LOG_ERROR("sql.sql", "Invalid type {} specified in `disables` table, skipped.", type);
89 continue;
90 }
91
92 uint32 entry = fields[1].GetUInt32();
93 uint16 flags = fields[2].GetUInt16();
94 std::string params_0 = fields[3].GetString();
95 std::string params_1 = fields[4].GetString();
96
97 DisableData data;
98 data.flags = flags;
99
100 switch (type)
101 {
103 if (!(sSpellMgr->GetSpellInfo(entry, DIFFICULTY_NONE) || flags & SPELL_DISABLE_DEPRECATED_SPELL))
104 {
105 TC_LOG_ERROR("sql.sql", "Spell entry {} from `disables` doesn't exist in dbc, skipped.", entry);
106 continue;
107 }
108
110 {
111 TC_LOG_ERROR("sql.sql", "Disable flags for spell {} are invalid, skipped.", entry);
112 continue;
113 }
114
116 {
117 for (std::string_view mapStr : Trinity::Tokenize(params_0, ',', true))
118 {
119 if (Optional<uint32> mapId = Trinity::StringTo<uint32>(mapStr))
120 data.params[0].insert(*mapId);
121 else
122 TC_LOG_ERROR("sql.sql", "Disable map '{}' for spell {} is invalid, skipped.", mapStr, entry);
123 }
124 }
125
127 {
128 for (std::string_view areaStr : Trinity::Tokenize(params_1, ',', true))
129 {
130 if (Optional<uint32> areaId = Trinity::StringTo<uint32>(areaStr))
131 data.params[1].insert(*areaId);
132 else
133 TC_LOG_ERROR("sql.sql", "Disable area '{}' for spell {} is invalid, skipped.", areaStr, entry);
134 }
135 }
136
137 break;
138 // checked later
140 break;
141 case DISABLE_TYPE_MAP:
143 {
144 MapEntry const* mapEntry = sMapStore.LookupEntry(entry);
145 if (!mapEntry)
146 {
147 TC_LOG_ERROR("sql.sql", "Map entry {} from `disables` doesn't exist in dbc, skipped.", entry);
148 continue;
149 }
150 bool isFlagInvalid = false;
151 switch (mapEntry->InstanceType)
152 {
153 case MAP_COMMON:
154 if (flags)
155 isFlagInvalid = true;
156 break;
157 case MAP_INSTANCE:
158 case MAP_RAID:
159 if (flags & DUNGEON_STATUSFLAG_HEROIC && !sDB2Manager.GetMapDifficultyData(entry, DIFFICULTY_HEROIC))
161 if (flags & RAID_STATUSFLAG_10MAN_HEROIC && !sDB2Manager.GetMapDifficultyData(entry, DIFFICULTY_10_HC))
163 if (flags & RAID_STATUSFLAG_25MAN_HEROIC && !sDB2Manager.GetMapDifficultyData(entry, DIFFICULTY_25_HC))
165 if (!flags)
166 isFlagInvalid = true;
167 break;
168 case MAP_BATTLEGROUND:
169 case MAP_ARENA:
170 TC_LOG_ERROR("sql.sql", "Battleground map {} specified to be disabled in map case, skipped.", entry);
171 continue;
172 }
173 if (isFlagInvalid)
174 {
175 TC_LOG_ERROR("sql.sql", "Disable flags for map {} are invalid, skipped.", entry);
176 continue;
177 }
178 break;
179 }
181 if (!sBattlemasterListStore.LookupEntry(entry))
182 {
183 TC_LOG_ERROR("sql.sql", "Battleground entry {} from `disables` doesn't exist in dbc, skipped.", entry);
184 continue;
185 }
186 if (flags)
187 TC_LOG_ERROR("sql.sql", "Disable flags specified for battleground {}, useless data.", entry);
188 break;
190 if (entry > MAX_OUTDOORPVP_TYPES)
191 {
192 TC_LOG_ERROR("sql.sql", "OutdoorPvPTypes value {} from `disables` is invalid, skipped.", entry);
193 continue;
194 }
195 if (flags)
196 TC_LOG_ERROR("sql.sql", "Disable flags specified for outdoor PvP {}, useless data.", entry);
197 break;
199 if (!sCriteriaStore.LookupEntry(entry))
200 {
201 TC_LOG_ERROR("sql.sql", "Criteria entry {} from `disables` doesn't exist in dbc, skipped.", entry);
202 continue;
203 }
204 if (flags)
205 TC_LOG_ERROR("sql.sql", "Disable flags specified for Criteria {}, useless data.", entry);
206 break;
208 {
209 MapEntry const* mapEntry = sMapStore.LookupEntry(entry);
210 if (!mapEntry)
211 {
212 TC_LOG_ERROR("sql.sql", "Map entry {} from `disables` doesn't exist in dbc, skipped.", entry);
213 continue;
214 }
215 switch (mapEntry->InstanceType)
216 {
217 case MAP_COMMON:
219 TC_LOG_INFO("misc", "Areaflag disabled for {} map {}.", MapTypeNames[mapEntry->InstanceType], entry);
221 TC_LOG_INFO("misc", "Liquid status disabled for {} map {}.", MapTypeNames[mapEntry->InstanceType], entry);
222 break;
223 case MAP_INSTANCE:
224 case MAP_RAID:
225 case MAP_BATTLEGROUND:
226 case MAP_ARENA:
227 case MAP_SCENARIO:
229 TC_LOG_INFO("misc", "Height disabled for {} map {}.", MapTypeNames[mapEntry->InstanceType], entry);
231 TC_LOG_INFO("misc", "LoS disabled for {} map {}.", MapTypeNames[mapEntry->InstanceType], entry);
232 break;
233 default:
234 break;
235 }
236 break;
237 }
239 {
240 MapEntry const* mapEntry = sMapStore.LookupEntry(entry);
241 if (!mapEntry)
242 {
243 TC_LOG_ERROR("sql.sql", "Map entry {} from `disables` doesn't exist in dbc, skipped.", entry);
244 continue;
245 }
246 if (mapEntry->InstanceType <= std::ssize(MapTypeNames))
247 TC_LOG_INFO("misc", "Pathfinding disabled for {} map {}.", MapTypeNames[mapEntry->InstanceType], entry);
248 break;
249 }
251 {
252 if (!sPhaseStore.LookupEntry(entry))
253 {
254 TC_LOG_ERROR("sql.sql", "Phase entry {} from `disables` doesn't exist in dbc, skipped.", entry);
255 continue;
256 }
257 if (flags)
258 TC_LOG_ERROR("sql.sql", "Disable flags specified for phase {}, useless data.", entry);
259 break;
260 }
261 default:
262 break;
263 }
264
265 m_DisableMap[type][entry] = std::move(data);
266 ++total_count;
267 }
268 while (result->NextRow());
269
270 TC_LOG_INFO("server.loading", ">> Loaded {} disables in {} ms", total_count, GetMSTimeDiffToNow(oldMSTime));
271}
272
274{
275 uint32 oldMSTime = getMSTime();
276
277 std::size_t count = m_DisableMap[DISABLE_TYPE_QUEST].size();
278 if (!count)
279 {
280 TC_LOG_INFO("server.loading", ">> Checked 0 quest disables.");
281 return;
282 }
283
284 // check only quests, rest already done at startup
285 for (auto itr = m_DisableMap[DISABLE_TYPE_QUEST].begin(); itr != m_DisableMap[DISABLE_TYPE_QUEST].end();)
286 {
287 uint32 entry = itr->first;
288 if (!sObjectMgr->GetQuestTemplate(entry))
289 {
290 TC_LOG_ERROR("sql.sql", "Quest entry {} from `disables` doesn't exist, skipped.", entry);
291 m_DisableMap[DISABLE_TYPE_QUEST].erase(itr++);
292 continue;
293 }
294 if (itr->second.flags)
295 TC_LOG_ERROR("sql.sql", "Disable flags specified for quest {}, useless data.", entry);
296 ++itr;
297 }
298
299 TC_LOG_INFO("server.loading", ">> Checked {} quest disables in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
300}
301
302bool IsDisabledFor(DisableType type, uint32 entry, WorldObject const* ref, uint8 flags /*= 0*/)
303{
305 if (m_DisableMap[type].empty())
306 return false;
307
308 DisableTypeMap::iterator itr = m_DisableMap[type].find(entry);
309 if (itr == m_DisableMap[type].end()) // not disabled
310 return false;
311
312 switch (type)
313 {
315 {
316 uint16 spellFlags = itr->second.flags;
317 if (ref)
318 {
319 if ((ref->GetTypeId() == TYPEID_PLAYER && (spellFlags & SPELL_DISABLE_PLAYER)) ||
320 (ref->GetTypeId() == TYPEID_UNIT && ((spellFlags & SPELL_DISABLE_CREATURE) || (ref->ToUnit()->IsPet() && (spellFlags & SPELL_DISABLE_PET)))) ||
321 (ref->GetTypeId() == TYPEID_GAMEOBJECT && (spellFlags & SPELL_DISABLE_GAMEOBJECT)))
322 {
324 {
325 if (Map const* map = ref->FindMap())
326 {
327 if (spellFlags & SPELL_DISABLE_ARENAS && map->IsBattleArena())
328 return true; // Current map is Arena and this spell is disabled here
329
330 if (spellFlags & SPELL_DISABLE_BATTLEGROUNDS && map->IsBattleground())
331 return true; // Current map is a Battleground and this spell is disabled here
332 }
333 }
334
335 if (spellFlags & SPELL_DISABLE_MAP)
336 {
337 std::unordered_set<uint32> const& mapIds = itr->second.params[0];
338 if (mapIds.find(ref->GetMapId()) != mapIds.end())
339 return true; // Spell is disabled on current map
340
341 if (!(spellFlags & SPELL_DISABLE_AREA))
342 return false; // Spell is disabled on another map, but not this one, return false
343
344 // Spell is disabled in an area, but not explicitly our current mapId. Continue processing.
345 }
346
347 if (spellFlags & SPELL_DISABLE_AREA)
348 {
349 std::unordered_set<uint32> const& areaIds = itr->second.params[1];
350 if (areaIds.find(ref->GetAreaId()) != areaIds.end())
351 return true; // Spell is disabled in this area
352 return false; // Spell is disabled in another area, but not this one, return false
353 }
354 else
355 return true; // Spell disabled for all maps
356 }
357
358 return false;
359 }
360 else if (spellFlags & SPELL_DISABLE_DEPRECATED_SPELL) // call not from spellcast
361 return true;
362 else if (flags & SPELL_DISABLE_LOS)
363 return (spellFlags & SPELL_DISABLE_LOS) != 0;
364
365 break;
366 }
367 case DISABLE_TYPE_MAP:
369 if (!ref)
370 return true;
371 if (Player const* player = ref->ToPlayer())
372 {
373 MapEntry const* mapEntry = sMapStore.LookupEntry(entry);
374 if (mapEntry->IsDungeon())
375 {
376 uint8 disabledModes = itr->second.flags;
377 Group const* group = player->GetGroup();
378 Difficulty targetDifficulty = group ? group->GetDifficultyID(mapEntry) : player->GetDifficultyID(mapEntry);
379 MapDifficultyEntry const* mapDifficulty = sDB2Manager.GetDownscaledMapDifficultyData(entry, targetDifficulty);
380 if (!mapDifficulty)
381 return false;
382 switch (Difficulty(mapDifficulty->DifficultyID))
383 {
385 return (disabledModes & DUNGEON_STATUSFLAG_NORMAL) != 0;
387 return (disabledModes & DUNGEON_STATUSFLAG_HEROIC) != 0;
388 case DIFFICULTY_10_HC:
389 return (disabledModes & RAID_STATUSFLAG_10MAN_HEROIC) != 0;
390 case DIFFICULTY_25_HC:
391 return (disabledModes & RAID_STATUSFLAG_25MAN_HEROIC) != 0;
392 default:
393 return false;
394 }
395 }
396 else if (mapEntry->InstanceType == MAP_COMMON)
397 return true;
398 }
399 return false;
401 return true;
407 return true;
409 return (flags & itr->second.flags) != 0;
410 default:
411 break;
412 }
413
414 return false;
415}
416
418{
419 return IsDisabledFor(DISABLE_TYPE_VMAP, entry, nullptr, flags);
420}
421
423{
424 return sWorld->getBoolConfig(CONFIG_ENABLE_MMAPS)
426}
427
428} // Namespace
DB2Storage< PhaseEntry > sPhaseStore("Phase.db2", &PhaseLoadInfo::Instance)
DB2Storage< BattlemasterListEntry > sBattlemasterListStore("BattlemasterList.db2", &BattlemasterListLoadInfo::Instance)
DB2Storage< MapEntry > sMapStore("Map.db2", &MapLoadInfo::Instance)
DB2Storage< CriteriaEntry > sCriteriaStore("Criteria.db2", &CriteriaLoadInfo::Instance)
#define sDB2Manager
Definition DB2Stores.h:579
@ MAP_COMMON
Definition DBCEnums.h:1599
@ MAP_SCENARIO
Definition DBCEnums.h:1604
@ MAP_BATTLEGROUND
Definition DBCEnums.h:1602
@ MAP_ARENA
Definition DBCEnums.h:1603
@ MAP_INSTANCE
Definition DBCEnums.h:1600
@ MAP_RAID
Definition DBCEnums.h:1601
Difficulty
Definition DBCEnums.h:935
@ DIFFICULTY_NONE
Definition DBCEnums.h:936
@ DIFFICULTY_25_HC
Definition DBCEnums.h:942
@ DIFFICULTY_NORMAL
Definition DBCEnums.h:937
@ DIFFICULTY_HEROIC
Definition DBCEnums.h:938
@ DIFFICULTY_10_HC
Definition DBCEnums.h:941
std::shared_ptr< ResultSet > QueryResult
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
uint8_t uint8
Definition Define.h:156
uint16_t uint16
Definition Define.h:155
uint32_t uint32
Definition Define.h:154
std::unordered_set< uint32 > params[2]
uint16 flags
@ MMAP_DISABLE_PATHFINDING
Definition DisableMgr.h:61
@ SPELL_DISABLE_LOS
Definition DisableMgr.h:49
@ SPELL_DISABLE_CREATURE
Definition DisableMgr.h:44
@ SPELL_DISABLE_PET
Definition DisableMgr.h:45
@ SPELL_DISABLE_ARENAS
Definition DisableMgr.h:51
@ SPELL_DISABLE_MAP
Definition DisableMgr.h:47
@ SPELL_DISABLE_PLAYER
Definition DisableMgr.h:43
@ SPELL_DISABLE_DEPRECATED_SPELL
Definition DisableMgr.h:46
@ MAX_SPELL_DISABLE_TYPE
Definition DisableMgr.h:53
@ SPELL_DISABLE_BATTLEGROUNDS
Definition DisableMgr.h:52
@ SPELL_DISABLE_GAMEOBJECT
Definition DisableMgr.h:50
@ SPELL_DISABLE_AREA
Definition DisableMgr.h:48
DisableType
Definition DisableMgr.h:26
@ DISABLE_TYPE_SPELL
Definition DisableMgr.h:27
@ DISABLE_TYPE_CRITERIA
Definition DisableMgr.h:31
@ DISABLE_TYPE_MMAP
Definition DisableMgr.h:34
@ DISABLE_TYPE_PHASE_AREA
Definition DisableMgr.h:36
@ MAX_DISABLE_TYPES
Definition DisableMgr.h:38
@ DISABLE_TYPE_VMAP
Definition DisableMgr.h:33
@ DISABLE_TYPE_QUEST
Definition DisableMgr.h:28
@ DISABLE_TYPE_MAP
Definition DisableMgr.h:29
@ DISABLE_TYPE_BATTLEGROUND
Definition DisableMgr.h:30
@ DISABLE_TYPE_LFG_MAP
Definition DisableMgr.h:35
@ DISABLE_TYPE_OUTDOORPVP
Definition DisableMgr.h:32
#define ASSERT
Definition Errors.h:72
#define TC_LOG_ERROR(filterType__, message__,...)
Definition Log.h:182
#define TC_LOG_INFO(filterType__, message__,...)
Definition Log.h:176
@ TYPEID_GAMEOBJECT
Definition ObjectGuid.h:46
@ TYPEID_UNIT
Definition ObjectGuid.h:43
@ TYPEID_PLAYER
Definition ObjectGuid.h:44
#define sObjectMgr
Definition ObjectMgr.h:1873
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:25
@ MAX_OUTDOORPVP_TYPES
Definition OutdoorPvP.h:36
@ DUNGEON_STATUSFLAG_NORMAL
@ RAID_STATUSFLAG_10MAN_HEROIC
@ RAID_STATUSFLAG_25MAN_HEROIC
@ DUNGEON_STATUSFLAG_HEROIC
#define sSpellMgr
Definition SpellMgr.h:812
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition Timer.h:57
uint32 getMSTime()
Definition Timer.h:33
TypeID GetTypeId() const
Definition BaseEntity.h:166
Class used to access individual fields of database query result.
Definition Field.h:94
uint32 GetUInt32() const noexcept
Definition Field.cpp:57
uint16 GetUInt16() const noexcept
Definition Field.cpp:43
std::string GetString() const noexcept
Definition Field.cpp:113
Definition Group.h:209
Difficulty GetDifficultyID(MapEntry const *mapEntry) const
Definition Group.cpp:1318
Definition Map.h:227
Player * ToPlayer()
Definition Object.h:126
Unit * ToUnit()
Definition Object.h:116
bool IsPet() const
Definition Unit.h:763
constexpr uint32 GetMapId() const
Definition Position.h:216
Map * FindMap() const
Definition Object.h:412
uint32 GetAreaId() const
Definition Object.h:333
#define sWorld
Definition World.h:919
@ CONFIG_ENABLE_MMAPS
Definition World.h:168
void CheckQuestDisables()
bool IsDisabledFor(DisableType type, uint32 entry, WorldObject const *ref, uint8 flags)
bool IsVMAPDisabledFor(uint32 entry, uint8 flags)
bool IsPathfindingEnabled(uint32 mapId)
void LoadDisables()
TC_COMMON_API std::vector< std::string_view > Tokenize(std::string_view str, char sep, bool keepEmpty)
Definition Util.cpp:57
@ VMAP_DISABLE_LIQUIDSTATUS
Definition VMapManager.h:58
@ VMAP_DISABLE_LOS
Definition VMapManager.h:57
@ VMAP_DISABLE_HEIGHT
Definition VMapManager.h:56
@ VMAP_DISABLE_AREAFLAG
Definition VMapManager.h:55
int8 InstanceType
bool IsDungeon() const