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 "AchievementMgr.h"
20#include "Creature.h"
21#include "DatabaseEnv.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 "VMapManager2.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 };
46
47 struct DisableData
48 {
50 std::set<uint32> params[2]; // params0, params1
51 };
52
53 // single disables here with optional data
54 typedef std::map<uint32, DisableData> DisableTypeMap;
55 // global disable map by source
56 typedef std::map<DisableType, DisableTypeMap> DisableMap;
57
58 DisableMap m_DisableMap;
59
60 uint8 MAX_DISABLE_TYPES = 9;
61}
62
64{
65 uint32 oldMSTime = getMSTime();
66
67 // reload case
68 for (DisableMap::iterator itr = m_DisableMap.begin(); itr != m_DisableMap.end(); ++itr)
69 itr->second.clear();
70
71 m_DisableMap.clear();
72
73 QueryResult result = WorldDatabase.Query("SELECT sourceType, entry, flags, params_0, params_1 FROM disables");
74
75 uint32 total_count = 0;
76
77 if (!result)
78 {
79 TC_LOG_INFO("server.loading", ">> Loaded 0 disables. DB table `disables` is empty!");
80 return;
81 }
82
83 Field* fields;
84 do
85 {
86 fields = result->Fetch();
87 DisableType type = DisableType(fields[0].GetUInt32());
88 if (type >= MAX_DISABLE_TYPES)
89 {
90 TC_LOG_ERROR("sql.sql", "Invalid type {} specified in `disables` table, skipped.", type);
91 continue;
92 }
93
94 uint32 entry = fields[1].GetUInt32();
95 uint16 flags = fields[2].GetUInt16();
96 std::string params_0 = fields[3].GetString();
97 std::string params_1 = fields[4].GetString();
98
99 DisableData data;
100 data.flags = flags;
101
102 switch (type)
103 {
105 if (!(sSpellMgr->GetSpellInfo(entry) || flags & SPELL_DISABLE_DEPRECATED_SPELL))
106 {
107 TC_LOG_ERROR("sql.sql", "Spell entry {} from `disables` doesn't exist in dbc, skipped.", entry);
108 continue;
109 }
110
112 {
113 TC_LOG_ERROR("sql.sql", "Disable flags for spell {} are invalid, skipped.", entry);
114 continue;
115 }
116
118 {
119 for (std::string_view mapStr : Trinity::Tokenize(params_0, ',', true))
120 {
121 if (Optional<uint32> mapId = Trinity::StringTo<uint32>(mapStr))
122 data.params[0].insert(*mapId);
123 else
124 TC_LOG_ERROR("sql.sql", "Disable map '{}' for spell {} is invalid, skipped.", std::string(mapStr), entry);
125 }
126 }
127
129 {
130 for (std::string_view areaStr : Trinity::Tokenize(params_1, ',', true))
131 {
132 if (Optional<uint32> areaId = Trinity::StringTo<uint32>(areaStr))
133 data.params[1].insert(*areaId);
134 else
135 TC_LOG_ERROR("sql.sql", "Disable area '{}' for spell {} is invalid, skipped.", std::string(areaStr), entry);
136 }
137 }
138
139 break;
140 // checked later
142 break;
143 case DISABLE_TYPE_MAP:
145 {
146 MapEntry const* mapEntry = sMapStore.LookupEntry(entry);
147 if (!mapEntry)
148 {
149 TC_LOG_ERROR("sql.sql", "Map entry {} from `disables` doesn't exist in dbc, skipped.", entry);
150 continue;
151 }
152 bool isFlagInvalid = false;
153 switch (mapEntry->InstanceType)
154 {
155 case MAP_COMMON:
156 if (flags)
157 isFlagInvalid = true;
158 break;
159 case MAP_INSTANCE:
160 case MAP_RAID:
167 if (!flags)
168 isFlagInvalid = true;
169 break;
170 case MAP_BATTLEGROUND:
171 case MAP_ARENA:
172 TC_LOG_ERROR("sql.sql", "Battleground map {} specified to be disabled in map case, skipped.", entry);
173 continue;
174 }
175 if (isFlagInvalid)
176 {
177 TC_LOG_ERROR("sql.sql", "Disable flags for map {} are invalid, skipped.", entry);
178 continue;
179 }
180 break;
181 }
183 if (!sBattlemasterListStore.LookupEntry(entry))
184 {
185 TC_LOG_ERROR("sql.sql", "Battleground entry {} from `disables` doesn't exist in dbc, skipped.", entry);
186 continue;
187 }
188 if (flags)
189 TC_LOG_ERROR("sql.sql", "Disable flags specified for battleground {}, useless data.", entry);
190 break;
192 if (entry > MAX_OUTDOORPVP_TYPES)
193 {
194 TC_LOG_ERROR("sql.sql", "OutdoorPvPTypes value {} from `disables` is invalid, skipped.", entry);
195 continue;
196 }
197 if (flags)
198 TC_LOG_ERROR("sql.sql", "Disable flags specified for outdoor PvP {}, useless data.", entry);
199 break;
201 if (!sAchievementCriteriaStore.LookupEntry(entry))
202 {
203 TC_LOG_ERROR("sql.sql", "Achievement Criteria entry {} from `disables` doesn't exist in dbc, skipped.", entry);
204 continue;
205 }
206 if (flags)
207 TC_LOG_ERROR("sql.sql", "Disable flags specified for Achievement Criteria {}, useless data.", entry);
208 break;
210 {
211 MapEntry const* mapEntry = sMapStore.LookupEntry(entry);
212 if (!mapEntry)
213 {
214 TC_LOG_ERROR("sql.sql", "Map entry {} from `disables` doesn't exist in dbc, skipped.", entry);
215 continue;
216 }
217 switch (mapEntry->InstanceType)
218 {
219 case MAP_COMMON:
221 TC_LOG_INFO("misc", "Areaflag disabled for {} map {}.", MapTypeNames[mapEntry->InstanceType], entry);
223 TC_LOG_INFO("misc", "Liquid status disabled for {} map {}.", MapTypeNames[mapEntry->InstanceType], entry);
224 break;
225 case MAP_INSTANCE:
226 case MAP_RAID:
227 case MAP_BATTLEGROUND:
228 case MAP_ARENA:
230 TC_LOG_INFO("misc", "Height disabled for {} map {}.", MapTypeNames[mapEntry->InstanceType], entry);
232 TC_LOG_INFO("misc", "LoS disabled for {} map {}.", MapTypeNames[mapEntry->InstanceType], entry);
233 break;
234 default:
235 break;
236 }
237 break;
238 }
240 {
241 MapEntry const* mapEntry = sMapStore.LookupEntry(entry);
242 if (!mapEntry)
243 {
244 TC_LOG_ERROR("sql.sql", "Map entry {} from `disables` doesn't exist in dbc, skipped.", entry);
245 continue;
246 }
247 if (mapEntry->InstanceType <= std::ssize(MapTypeNames))
248 TC_LOG_INFO("misc", "Pathfinding disabled for {} map {}.", MapTypeNames[mapEntry->InstanceType], entry);
249 break;
250 }
251 default:
252 break;
253 }
254
255 m_DisableMap[type].insert(DisableTypeMap::value_type(entry, data));
256 ++total_count;
257 }
258 while (result->NextRow());
259
260 TC_LOG_INFO("server.loading", ">> Loaded {} disables in {} ms", total_count, GetMSTimeDiffToNow(oldMSTime));
261}
262
264{
265 uint32 oldMSTime = getMSTime();
266
267 uint32 count = m_DisableMap[DISABLE_TYPE_QUEST].size();
268 if (!count)
269 {
270 TC_LOG_INFO("server.loading", ">> Checked 0 quest disables.");
271 return;
272 }
273
274 // check only quests, rest already done at startup
275 for (DisableTypeMap::iterator itr = m_DisableMap[DISABLE_TYPE_QUEST].begin(); itr != m_DisableMap[DISABLE_TYPE_QUEST].end();)
276 {
277 const uint32 entry = itr->first;
278 if (!sObjectMgr->GetQuestTemplate(entry))
279 {
280 TC_LOG_ERROR("sql.sql", "Quest entry {} from `disables` doesn't exist, skipped.", entry);
281 m_DisableMap[DISABLE_TYPE_QUEST].erase(itr++);
282 continue;
283 }
284 if (itr->second.flags)
285 TC_LOG_ERROR("sql.sql", "Disable flags specified for quest {}, useless data.", entry);
286 ++itr;
287 }
288
289 TC_LOG_INFO("server.loading", ">> Checked {} quest disables in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
290}
291
292bool IsDisabledFor(DisableType type, uint32 entry, WorldObject const* ref, uint8 flags /*= 0*/)
293{
294 ASSERT(type < MAX_DISABLE_TYPES);
295 if (m_DisableMap[type].empty())
296 return false;
297
298 DisableTypeMap::iterator itr = m_DisableMap[type].find(entry);
299 if (itr == m_DisableMap[type].end()) // not disabled
300 return false;
301
302 switch (type)
303 {
305 {
306 uint16 spellFlags = itr->second.flags;
307 if (ref)
308 {
309 if ((ref->GetTypeId() == TYPEID_PLAYER && (spellFlags & SPELL_DISABLE_PLAYER)) ||
310 (ref->GetTypeId() == TYPEID_UNIT && ((spellFlags & SPELL_DISABLE_CREATURE) || (ref->ToCreature()->IsPet() && (spellFlags & SPELL_DISABLE_PET)))) ||
311 (ref->GetTypeId() == TYPEID_GAMEOBJECT && (spellFlags & SPELL_DISABLE_GAMEOBJECT)))
312 {
314 {
315 if (Map const* map = ref->FindMap())
316 {
317 if (spellFlags & SPELL_DISABLE_ARENAS && map->IsBattleArena())
318 return true; // Current map is Arena and this spell is disabled here
319
320 if (spellFlags & SPELL_DISABLE_BATTLEGROUNDS && map->IsBattleground())
321 return true; // Current map is a Battleground and this spell is disabled here
322 }
323 }
324
325 if (spellFlags & SPELL_DISABLE_MAP)
326 {
327 std::set<uint32> const& mapIds = itr->second.params[0];
328 if (mapIds.find(ref->GetMapId()) != mapIds.end())
329 return true; // Spell is disabled on current map
330
331 if (!(spellFlags & SPELL_DISABLE_AREA))
332 return false; // Spell is disabled on another map, but not this one, return false
333
334 // Spell is disabled in an area, but not explicitly our current mapId. Continue processing.
335 }
336
337 if (spellFlags & SPELL_DISABLE_AREA)
338 {
339 std::set<uint32> const& areaIds = itr->second.params[1];
340 if (areaIds.find(ref->GetAreaId()) != areaIds.end())
341 return true; // Spell is disabled in this area
342 return false; // Spell is disabled in another area, but not this one, return false
343 }
344 else
345 return true; // Spell disabled for all maps
346 }
347
348 return false;
349 }
350 else if (spellFlags & SPELL_DISABLE_DEPRECATED_SPELL) // call not from spellcast
351 return true;
352 else if (flags & SPELL_DISABLE_LOS)
353 return (spellFlags & SPELL_DISABLE_LOS) != 0;
354
355 break;
356 }
357 case DISABLE_TYPE_MAP:
359 if (Player const* player = ref->ToPlayer())
360 {
361 MapEntry const* mapEntry = sMapStore.LookupEntry(entry);
362 if (mapEntry->IsDungeon())
363 {
364 uint8 disabledModes = itr->second.flags;
365 Group const* group = player->GetGroup();
366 Difficulty targetDifficulty = group ? group->GetDifficultyID(mapEntry) : player->GetDifficultyID(mapEntry);
367 GetDownscaledMapDifficultyData(entry, targetDifficulty);
368 switch (targetDifficulty)
369 {
371 return (disabledModes & DUNGEON_STATUSFLAG_NORMAL) != 0;
373 return (disabledModes & DUNGEON_STATUSFLAG_HEROIC) != 0;
375 return (disabledModes & RAID_STATUSFLAG_10MAN_HEROIC) != 0;
377 return (disabledModes & RAID_STATUSFLAG_25MAN_HEROIC) != 0;
378 }
379 }
380 else if (mapEntry->InstanceType == MAP_COMMON)
381 return true;
382 }
383 return false;
385 return true;
390 return true;
392 return (flags & itr->second.flags) != 0;
393 }
394
395 return false;
396}
397
399{
400 return IsDisabledFor(DISABLE_TYPE_VMAP, entry, nullptr, flags);
401}
402
404{
405 return sWorld->getBoolConfig(CONFIG_ENABLE_MMAPS)
407}
408
409} // Namespace
@ MAP_COMMON
Definition DBCEnums.h:333
@ MAP_BATTLEGROUND
Definition DBCEnums.h:336
@ MAP_ARENA
Definition DBCEnums.h:337
@ MAP_INSTANCE
Definition DBCEnums.h:334
@ MAP_RAID
Definition DBCEnums.h:335
Difficulty
Definition DBCEnums.h:279
@ RAID_DIFFICULTY_25MAN_HEROIC
Definition DBCEnums.h:289
@ DUNGEON_DIFFICULTY_NORMAL
Definition DBCEnums.h:282
@ DUNGEON_DIFFICULTY_HEROIC
Definition DBCEnums.h:283
@ RAID_DIFFICULTY_10MAN_HEROIC
Definition DBCEnums.h:288
DBCStorage< AchievementCriteriaEntry > sAchievementCriteriaStore(AchievementCriteriafmt)
MapDifficultyEntry const * GetDownscaledMapDifficultyData(uint32 mapId, Difficulty &difficulty)
DBCStorage< BattlemasterListEntry > sBattlemasterListStore(BattlemasterListEntryfmt)
MapDifficultyEntry const * GetMapDifficultyData(uint32 mapId, Difficulty difficulty)
DBCStorage< MapEntry > sMapStore(MapEntryfmt)
std::shared_ptr< ResultSet > QueryResult
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
uint8_t uint8
Definition Define.h:135
uint16_t uint16
Definition Define.h:134
uint32_t uint32
Definition Define.h:133
std::set< uint32 > params[2]
uint16 flags
@ MMAP_DISABLE_PATHFINDING
Definition DisableMgr.h:58
@ SPELL_DISABLE_LOS
Definition DisableMgr.h:46
@ SPELL_DISABLE_CREATURE
Definition DisableMgr.h:41
@ SPELL_DISABLE_PET
Definition DisableMgr.h:42
@ SPELL_DISABLE_ARENAS
Definition DisableMgr.h:48
@ SPELL_DISABLE_MAP
Definition DisableMgr.h:44
@ SPELL_DISABLE_PLAYER
Definition DisableMgr.h:40
@ SPELL_DISABLE_DEPRECATED_SPELL
Definition DisableMgr.h:43
@ MAX_SPELL_DISABLE_TYPE
Definition DisableMgr.h:50
@ SPELL_DISABLE_BATTLEGROUNDS
Definition DisableMgr.h:49
@ SPELL_DISABLE_GAMEOBJECT
Definition DisableMgr.h:47
@ SPELL_DISABLE_AREA
Definition DisableMgr.h:45
DisableType
Definition DisableMgr.h:26
@ DISABLE_TYPE_SPELL
Definition DisableMgr.h:27
@ DISABLE_TYPE_MMAP
Definition DisableMgr.h:34
@ 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_ACHIEVEMENT_CRITERIA
Definition DisableMgr.h:31
@ DISABLE_TYPE_LFG_MAP
Definition DisableMgr.h:35
@ DISABLE_TYPE_OUTDOORPVP
Definition DisableMgr.h:32
#define ASSERT
Definition Errors.h:68
#define TC_LOG_ERROR(filterType__,...)
Definition Log.h:165
#define TC_LOG_INFO(filterType__,...)
Definition Log.h:159
@ TYPEID_GAMEOBJECT
Definition ObjectGuid.h:40
@ TYPEID_UNIT
Definition ObjectGuid.h:38
@ TYPEID_PLAYER
Definition ObjectGuid.h:39
#define sObjectMgr
Definition ObjectMgr.h:1721
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:738
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition Timer.h:57
uint32 getMSTime()
Definition Timer.h:33
Class used to access individual fields of database query result.
Definition Field.h:92
std::string GetString() const
Definition Field.cpp:125
uint16 GetUInt16() const
Definition Field.cpp:45
uint32 GetUInt32() const
Definition Field.cpp:61
Definition Group.h:165
Difficulty GetDifficultyID(MapEntry const *mapEntry) const
Definition Group.cpp:2116
Definition Map.h:302
static Creature * ToCreature(Object *o)
Definition Object.h:189
TypeID GetTypeId() const
Definition Object.h:93
static Player * ToPlayer(Object *o)
Definition Object.h:183
bool IsPet() const
Definition Unit.h:898
uint32 GetMapId() const
Definition Position.h:193
Map * FindMap() const
Definition Object.h:452
uint32 GetAreaId() const
Definition Object.h:376
#define sWorld
Definition World.h:901
@ CONFIG_ENABLE_MMAPS
Definition World.h:156
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:56
@ VMAP_DISABLE_LIQUIDSTATUS
@ VMAP_DISABLE_LOS
@ VMAP_DISABLE_HEIGHT
@ VMAP_DISABLE_AREAFLAG
uint32 InstanceType
bool IsDungeon() const