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 "Log.h"
23#include "Map.h"
24#include "ObjectMgr.h"
25#include "OutdoorPvP.h"
26#include "Player.h"
27#include "SpellMgr.h"
28#include "StringConvert.h"
29#include "VMapManager2.h"
30#include "World.h"
31
32namespace DisableMgr
33{
34
35namespace
36{
37 struct DisableData
38 {
40 std::set<uint32> params[2]; // params0, params1
41 };
42
43 // single disables here with optional data
44 typedef std::map<uint32, DisableData> DisableTypeMap;
45 // global disable map by source
46 typedef std::map<DisableType, DisableTypeMap> DisableMap;
47
48 DisableMap m_DisableMap;
49
50 uint8 MAX_DISABLE_TYPES = 9;
51}
52
54{
55 uint32 oldMSTime = getMSTime();
56
57 // reload case
58 for (DisableMap::iterator itr = m_DisableMap.begin(); itr != m_DisableMap.end(); ++itr)
59 itr->second.clear();
60
61 m_DisableMap.clear();
62
63 QueryResult result = WorldDatabase.Query("SELECT sourceType, entry, flags, params_0, params_1 FROM disables");
64
65 uint32 total_count = 0;
66
67 if (!result)
68 {
69 TC_LOG_INFO("server.loading", ">> Loaded 0 disables. DB table `disables` is empty!");
70 return;
71 }
72
73 Field* fields;
74 do
75 {
76 fields = result->Fetch();
77 DisableType type = DisableType(fields[0].GetUInt32());
78 if (type >= MAX_DISABLE_TYPES)
79 {
80 TC_LOG_ERROR("sql.sql", "Invalid type {} specified in `disables` table, skipped.", type);
81 continue;
82 }
83
84 uint32 entry = fields[1].GetUInt32();
85 uint16 flags = fields[2].GetUInt16();
86 std::string params_0 = fields[3].GetString();
87 std::string params_1 = fields[4].GetString();
88
89 DisableData data;
90 data.flags = flags;
91
92 switch (type)
93 {
95 if (!(sSpellMgr->GetSpellInfo(entry) || flags & SPELL_DISABLE_DEPRECATED_SPELL))
96 {
97 TC_LOG_ERROR("sql.sql", "Spell entry {} from `disables` doesn't exist in dbc, skipped.", entry);
98 continue;
99 }
100
102 {
103 TC_LOG_ERROR("sql.sql", "Disable flags for spell {} are invalid, skipped.", entry);
104 continue;
105 }
106
108 {
109 for (std::string_view mapStr : Trinity::Tokenize(params_0, ',', true))
110 {
111 if (Optional<uint32> mapId = Trinity::StringTo<uint32>(mapStr))
112 data.params[0].insert(*mapId);
113 else
114 TC_LOG_ERROR("sql.sql", "Disable map '{}' for spell {} is invalid, skipped.", std::string(mapStr), entry);
115 }
116 }
117
119 {
120 for (std::string_view areaStr : Trinity::Tokenize(params_1, ',', true))
121 {
122 if (Optional<uint32> areaId = Trinity::StringTo<uint32>(areaStr))
123 data.params[1].insert(*areaId);
124 else
125 TC_LOG_ERROR("sql.sql", "Disable area '{}' for spell {} is invalid, skipped.", std::string(areaStr), entry);
126 }
127 }
128
129 break;
130 // checked later
132 break;
133 case DISABLE_TYPE_MAP:
135 {
136 MapEntry const* mapEntry = sMapStore.LookupEntry(entry);
137 if (!mapEntry)
138 {
139 TC_LOG_ERROR("sql.sql", "Map entry {} from `disables` doesn't exist in dbc, skipped.", entry);
140 continue;
141 }
142 bool isFlagInvalid = false;
143 switch (mapEntry->InstanceType)
144 {
145 case MAP_COMMON:
146 if (flags)
147 isFlagInvalid = true;
148 break;
149 case MAP_INSTANCE:
150 case MAP_RAID:
157 if (!flags)
158 isFlagInvalid = true;
159 break;
160 case MAP_BATTLEGROUND:
161 case MAP_ARENA:
162 TC_LOG_ERROR("sql.sql", "Battleground map {} specified to be disabled in map case, skipped.", entry);
163 continue;
164 }
165 if (isFlagInvalid)
166 {
167 TC_LOG_ERROR("sql.sql", "Disable flags for map {} are invalid, skipped.", entry);
168 continue;
169 }
170 break;
171 }
173 if (!sBattlemasterListStore.LookupEntry(entry))
174 {
175 TC_LOG_ERROR("sql.sql", "Battleground entry {} from `disables` doesn't exist in dbc, skipped.", entry);
176 continue;
177 }
178 if (flags)
179 TC_LOG_ERROR("sql.sql", "Disable flags specified for battleground {}, useless data.", entry);
180 break;
182 if (entry > MAX_OUTDOORPVP_TYPES)
183 {
184 TC_LOG_ERROR("sql.sql", "OutdoorPvPTypes value {} from `disables` is invalid, skipped.", entry);
185 continue;
186 }
187 if (flags)
188 TC_LOG_ERROR("sql.sql", "Disable flags specified for outdoor PvP {}, useless data.", entry);
189 break;
191 if (!sAchievementCriteriaStore.LookupEntry(entry))
192 {
193 TC_LOG_ERROR("sql.sql", "Achievement Criteria entry {} from `disables` doesn't exist in dbc, skipped.", entry);
194 continue;
195 }
196 if (flags)
197 TC_LOG_ERROR("sql.sql", "Disable flags specified for Achievement Criteria {}, useless data.", entry);
198 break;
200 {
201 MapEntry const* mapEntry = sMapStore.LookupEntry(entry);
202 if (!mapEntry)
203 {
204 TC_LOG_ERROR("sql.sql", "Map entry {} from `disables` doesn't exist in dbc, skipped.", entry);
205 continue;
206 }
207 switch (mapEntry->InstanceType)
208 {
209 case MAP_COMMON:
211 TC_LOG_INFO("misc", "Areaflag disabled for world map {}.", entry);
213 TC_LOG_INFO("misc", "Liquid status disabled for world map {}.", entry);
214 break;
215 case MAP_INSTANCE:
216 case MAP_RAID:
218 TC_LOG_INFO("misc", "Height disabled for instance map {}.", entry);
220 TC_LOG_INFO("misc", "LoS disabled for instance map {}.", entry);
221 break;
222 case MAP_BATTLEGROUND:
224 TC_LOG_INFO("misc", "Height disabled for battleground map {}.", entry);
226 TC_LOG_INFO("misc", "LoS disabled for battleground map {}.", entry);
227 break;
228 case MAP_ARENA:
230 TC_LOG_INFO("misc", "Height disabled for arena map {}.", entry);
232 TC_LOG_INFO("misc", "LoS disabled for arena map {}.", 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 switch (mapEntry->InstanceType)
248 {
249 case MAP_COMMON:
250 TC_LOG_INFO("misc", "Pathfinding disabled for world map {}.", entry);
251 break;
252 case MAP_INSTANCE:
253 case MAP_RAID:
254 TC_LOG_INFO("misc", "Pathfinding disabled for instance map {}.", entry);
255 break;
256 case MAP_BATTLEGROUND:
257 TC_LOG_INFO("misc", "Pathfinding disabled for battleground map {}.", entry);
258 break;
259 case MAP_ARENA:
260 TC_LOG_INFO("misc", "Pathfinding disabled for arena map {}.", entry);
261 break;
262 default:
263 break;
264 }
265 break;
266 }
267 default:
268 break;
269 }
270
271 m_DisableMap[type].insert(DisableTypeMap::value_type(entry, data));
272 ++total_count;
273 }
274 while (result->NextRow());
275
276 TC_LOG_INFO("server.loading", ">> Loaded {} disables in {} ms", total_count, GetMSTimeDiffToNow(oldMSTime));
277}
278
280{
281 uint32 oldMSTime = getMSTime();
282
283 uint32 count = m_DisableMap[DISABLE_TYPE_QUEST].size();
284 if (!count)
285 {
286 TC_LOG_INFO("server.loading", ">> Checked 0 quest disables.");
287 return;
288 }
289
290 // check only quests, rest already done at startup
291 for (DisableTypeMap::iterator itr = m_DisableMap[DISABLE_TYPE_QUEST].begin(); itr != m_DisableMap[DISABLE_TYPE_QUEST].end();)
292 {
293 const uint32 entry = itr->first;
294 if (!sObjectMgr->GetQuestTemplate(entry))
295 {
296 TC_LOG_ERROR("sql.sql", "Quest entry {} from `disables` doesn't exist, skipped.", entry);
297 m_DisableMap[DISABLE_TYPE_QUEST].erase(itr++);
298 continue;
299 }
300 if (itr->second.flags)
301 TC_LOG_ERROR("sql.sql", "Disable flags specified for quest {}, useless data.", entry);
302 ++itr;
303 }
304
305 TC_LOG_INFO("server.loading", ">> Checked {} quest disables in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
306}
307
308bool IsDisabledFor(DisableType type, uint32 entry, WorldObject const* ref, uint8 flags /*= 0*/)
309{
310 ASSERT(type < MAX_DISABLE_TYPES);
311 if (m_DisableMap[type].empty())
312 return false;
313
314 DisableTypeMap::iterator itr = m_DisableMap[type].find(entry);
315 if (itr == m_DisableMap[type].end()) // not disabled
316 return false;
317
318 switch (type)
319 {
321 {
322 uint16 spellFlags = itr->second.flags;
323 if (ref)
324 {
325 if ((ref->GetTypeId() == TYPEID_PLAYER && (spellFlags & SPELL_DISABLE_PLAYER)) ||
326 (ref->GetTypeId() == TYPEID_UNIT && ((spellFlags & SPELL_DISABLE_CREATURE) || (ref->ToCreature()->IsPet() && (spellFlags & SPELL_DISABLE_PET)))) ||
327 (ref->GetTypeId() == TYPEID_GAMEOBJECT && (spellFlags & SPELL_DISABLE_GAMEOBJECT)))
328 {
330 {
331 if (Map const* map = ref->FindMap())
332 {
333 if (spellFlags & SPELL_DISABLE_ARENAS && map->IsBattleArena())
334 return true; // Current map is Arena and this spell is disabled here
335
336 if (spellFlags & SPELL_DISABLE_BATTLEGROUNDS && map->IsBattleground())
337 return true; // Current map is a Battleground and this spell is disabled here
338 }
339 }
340
341 if (spellFlags & SPELL_DISABLE_MAP)
342 {
343 std::set<uint32> const& mapIds = itr->second.params[0];
344 if (mapIds.find(ref->GetMapId()) != mapIds.end())
345 return true; // Spell is disabled on current map
346
347 if (!(spellFlags & SPELL_DISABLE_AREA))
348 return false; // Spell is disabled on another map, but not this one, return false
349
350 // Spell is disabled in an area, but not explicitly our current mapId. Continue processing.
351 }
352
353 if (spellFlags & SPELL_DISABLE_AREA)
354 {
355 std::set<uint32> const& areaIds = itr->second.params[1];
356 if (areaIds.find(ref->GetAreaId()) != areaIds.end())
357 return true; // Spell is disabled in this area
358 return false; // Spell is disabled in another area, but not this one, return false
359 }
360 else
361 return true; // Spell disabled for all maps
362 }
363
364 return false;
365 }
366 else if (spellFlags & SPELL_DISABLE_DEPRECATED_SPELL) // call not from spellcast
367 return true;
368 else if (flags & SPELL_DISABLE_LOS)
369 return (spellFlags & SPELL_DISABLE_LOS) != 0;
370
371 break;
372 }
373 case DISABLE_TYPE_MAP:
375 if (Player const* player = ref->ToPlayer())
376 {
377 MapEntry const* mapEntry = sMapStore.LookupEntry(entry);
378 if (mapEntry->IsDungeon())
379 {
380 uint8 disabledModes = itr->second.flags;
381 Difficulty targetDifficulty = player->GetDifficulty(mapEntry->IsRaid());
382 GetDownscaledMapDifficultyData(entry, targetDifficulty);
383 switch (targetDifficulty)
384 {
386 return (disabledModes & DUNGEON_STATUSFLAG_NORMAL) != 0;
388 return (disabledModes & DUNGEON_STATUSFLAG_HEROIC) != 0;
390 return (disabledModes & RAID_STATUSFLAG_10MAN_HEROIC) != 0;
392 return (disabledModes & RAID_STATUSFLAG_25MAN_HEROIC) != 0;
393 }
394 }
395 else if (mapEntry->InstanceType == MAP_COMMON)
396 return true;
397 }
398 return false;
400 return true;
405 return true;
407 return (flags & itr->second.flags) != 0;
408 }
409
410 return false;
411}
412
414{
415 return IsDisabledFor(DISABLE_TYPE_VMAP, entry, nullptr, flags);
416}
417
419{
420 return sWorld->getBoolConfig(CONFIG_ENABLE_MMAPS)
422}
423
424} // Namespace
@ MAP_COMMON
Definition DBCEnums.h:335
@ MAP_BATTLEGROUND
Definition DBCEnums.h:338
@ MAP_ARENA
Definition DBCEnums.h:339
@ MAP_INSTANCE
Definition DBCEnums.h:336
@ MAP_RAID
Definition DBCEnums.h:337
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)
MapDifficulty const * GetDownscaledMapDifficultyData(uint32 mapId, Difficulty &difficulty)
DBCStorage< BattlemasterListEntry > sBattlemasterListStore(BattlemasterListEntryfmt)
MapDifficulty 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 Map.h:281
static Creature * ToCreature(Object *o)
Definition Object.h:186
TypeID GetTypeId() const
Definition Object.h:93
static Player * ToPlayer(Object *o)
Definition Object.h:180
bool IsPet() const
Definition Unit.h:884
uint32 GetMapId() const
Definition Position.h:193
Map * FindMap() const
Definition Object.h:450
uint32 GetAreaId() const
Definition Object.h:374
#define sWorld
Definition World.h:900
@ 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
bool IsRaid() const