TrinityCore
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 "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
35char const* MapTypeNames[] =
36{
37 "World",
38 "Dungeon",
39 "Raid",
40 "Battleground",
41 "Arena",
42 "Scenario"
43};
44
45namespace
46{
47 struct DisableData
48 {
50 std::unordered_set<uint32> params[2]; // params0, params1
51 };
52
53 // single disables here with optional data
54 typedef std::unordered_map<uint32, DisableData> DisableTypeMap;
55
56 std::array<DisableTypeMap, MAX_DISABLE_TYPES> m_DisableMap;
57}
58
60{
61 uint32 oldMSTime = getMSTime();
62
63 // reload case
64 for (std::size_t i = 0; i < m_DisableMap.size(); ++i)
65 m_DisableMap[i].clear();
66
67 QueryResult result = WorldDatabase.Query("SELECT sourceType, entry, flags, params_0, params_1 FROM disables");
68
69 uint32 total_count = 0;
70
71 if (!result)
72 {
73 TC_LOG_INFO("server.loading", ">> Loaded 0 disables. DB table `disables` is empty!");
74 return;
75 }
76
77 Field* fields;
78 do
79 {
80 fields = result->Fetch();
81 uint32 type = fields[0].GetUInt32();
82 if (type >= MAX_DISABLE_TYPES)
83 {
84 TC_LOG_ERROR("sql.sql", "Invalid type {} specified in `disables` table, skipped.", type);
85 continue;
86 }
87
88 uint32 entry = fields[1].GetUInt32();
89 uint16 flags = fields[2].GetUInt16();
90 std::string params_0 = fields[3].GetString();
91 std::string params_1 = fields[4].GetString();
92
93 DisableData data;
94 data.flags = flags;
95
96 switch (type)
97 {
99 if (!(sSpellMgr->GetSpellInfo(entry, DIFFICULTY_NONE) || flags & SPELL_DISABLE_DEPRECATED_SPELL))
100 {
101 TC_LOG_ERROR("sql.sql", "Spell entry {} from `disables` doesn't exist in dbc, skipped.", entry);
102 continue;
103 }
104
106 {
107 TC_LOG_ERROR("sql.sql", "Disable flags for spell {} are invalid, skipped.", entry);
108 continue;
109 }
110
112 {
113 for (std::string_view mapStr : Trinity::Tokenize(params_0, ',', true))
114 {
115 if (Optional<uint32> mapId = Trinity::StringTo<uint32>(mapStr))
116 data.params[0].insert(*mapId);
117 else
118 TC_LOG_ERROR("sql.sql", "Disable map '{}' for spell {} is invalid, skipped.", mapStr, entry);
119 }
120 }
121
123 {
124 for (std::string_view areaStr : Trinity::Tokenize(params_1, ',', true))
125 {
126 if (Optional<uint32> areaId = Trinity::StringTo<uint32>(areaStr))
127 data.params[1].insert(*areaId);
128 else
129 TC_LOG_ERROR("sql.sql", "Disable area '{}' for spell {} is invalid, skipped.", areaStr, entry);
130 }
131 }
132
133 break;
134 // checked later
136 break;
137 case DISABLE_TYPE_MAP:
139 {
140 MapEntry const* mapEntry = sMapStore.LookupEntry(entry);
141 if (!mapEntry)
142 {
143 TC_LOG_ERROR("sql.sql", "Map entry {} from `disables` doesn't exist in dbc, skipped.", entry);
144 continue;
145 }
146 bool isFlagInvalid = false;
147 switch (mapEntry->InstanceType)
148 {
149 case MAP_COMMON:
150 if (flags)
151 isFlagInvalid = true;
152 break;
153 case MAP_INSTANCE:
154 case MAP_RAID:
155 if (flags & DUNGEON_STATUSFLAG_HEROIC && !sDB2Manager.GetMapDifficultyData(entry, DIFFICULTY_HEROIC))
157 if (flags & RAID_STATUSFLAG_10MAN_HEROIC && !sDB2Manager.GetMapDifficultyData(entry, DIFFICULTY_10_HC))
159 if (flags & RAID_STATUSFLAG_25MAN_HEROIC && !sDB2Manager.GetMapDifficultyData(entry, DIFFICULTY_25_HC))
161 if (!flags)
162 isFlagInvalid = true;
163 break;
164 case MAP_BATTLEGROUND:
165 case MAP_ARENA:
166 TC_LOG_ERROR("sql.sql", "Battleground map {} specified to be disabled in map case, skipped.", entry);
167 continue;
168 }
169 if (isFlagInvalid)
170 {
171 TC_LOG_ERROR("sql.sql", "Disable flags for map {} are invalid, skipped.", entry);
172 continue;
173 }
174 break;
175 }
177 if (!sBattlemasterListStore.LookupEntry(entry))
178 {
179 TC_LOG_ERROR("sql.sql", "Battleground entry {} from `disables` doesn't exist in dbc, skipped.", entry);
180 continue;
181 }
182 if (flags)
183 TC_LOG_ERROR("sql.sql", "Disable flags specified for battleground {}, useless data.", entry);
184 break;
186 if (entry > MAX_OUTDOORPVP_TYPES)
187 {
188 TC_LOG_ERROR("sql.sql", "OutdoorPvPTypes value {} from `disables` is invalid, skipped.", entry);
189 continue;
190 }
191 if (flags)
192 TC_LOG_ERROR("sql.sql", "Disable flags specified for outdoor PvP {}, useless data.", entry);
193 break;
195 if (!sCriteriaStore.LookupEntry(entry))
196 {
197 TC_LOG_ERROR("sql.sql", "Criteria entry {} from `disables` doesn't exist in dbc, skipped.", entry);
198 continue;
199 }
200 if (flags)
201 TC_LOG_ERROR("sql.sql", "Disable flags specified for Criteria {}, useless data.", entry);
202 break;
204 {
205 MapEntry const* mapEntry = sMapStore.LookupEntry(entry);
206 if (!mapEntry)
207 {
208 TC_LOG_ERROR("sql.sql", "Map entry {} from `disables` doesn't exist in dbc, skipped.", entry);
209 continue;
210 }
211 switch (mapEntry->InstanceType)
212 {
213 case MAP_COMMON:
215 TC_LOG_INFO("misc", "Areaflag disabled for {} map {}.", MapTypeNames[mapEntry->InstanceType], entry);
217 TC_LOG_INFO("misc", "Liquid status disabled for {} map {}.", MapTypeNames[mapEntry->InstanceType], entry);
218 break;
219 case MAP_INSTANCE:
220 case MAP_RAID:
221 case MAP_BATTLEGROUND:
222 case MAP_ARENA:
223 case MAP_SCENARIO:
225 TC_LOG_INFO("misc", "Height disabled for {} map {}.", MapTypeNames[mapEntry->InstanceType], entry);
227 TC_LOG_INFO("misc", "LoS disabled for {} map {}.", MapTypeNames[mapEntry->InstanceType], entry);
228 break;
229 }
230 break;
231 }
233 {
234 MapEntry const* mapEntry = sMapStore.LookupEntry(entry);
235 if (!mapEntry)
236 {
237 TC_LOG_ERROR("sql.sql", "Map entry {} from `disables` doesn't exist in dbc, skipped.", entry);
238 continue;
239 }
240 if (mapEntry->InstanceType <= MAP_SCENARIO)
241 TC_LOG_INFO("misc", "Pathfinding disabled for {} map {}.", MapTypeNames[mapEntry->InstanceType], entry);
242 break;
243 }
244 default:
245 break;
246 }
247
248 m_DisableMap[type][entry] = std::move(data);
249 ++total_count;
250 }
251 while (result->NextRow());
252
253 TC_LOG_INFO("server.loading", ">> Loaded {} disables in {} ms", total_count, GetMSTimeDiffToNow(oldMSTime));
254}
255
257{
258 uint32 oldMSTime = getMSTime();
259
260 std::size_t count = m_DisableMap[DISABLE_TYPE_QUEST].size();
261 if (!count)
262 {
263 TC_LOG_INFO("server.loading", ">> Checked 0 quest disables.");
264 return;
265 }
266
267 // check only quests, rest already done at startup
268 for (auto itr = m_DisableMap[DISABLE_TYPE_QUEST].begin(); itr != m_DisableMap[DISABLE_TYPE_QUEST].end();)
269 {
270 uint32 entry = itr->first;
271 if (!sObjectMgr->GetQuestTemplate(entry))
272 {
273 TC_LOG_ERROR("sql.sql", "Quest entry {} from `disables` doesn't exist, skipped.", entry);
274 m_DisableMap[DISABLE_TYPE_QUEST].erase(itr++);
275 continue;
276 }
277 if (itr->second.flags)
278 TC_LOG_ERROR("sql.sql", "Disable flags specified for quest {}, useless data.", entry);
279 ++itr;
280 }
281
282 TC_LOG_INFO("server.loading", ">> Checked {} quest disables in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
283}
284
285bool IsDisabledFor(DisableType type, uint32 entry, WorldObject const* ref, uint8 flags /*= 0*/)
286{
288 if (m_DisableMap[type].empty())
289 return false;
290
291 DisableTypeMap::iterator itr = m_DisableMap[type].find(entry);
292 if (itr == m_DisableMap[type].end()) // not disabled
293 return false;
294
295 switch (type)
296 {
298 {
299 uint16 spellFlags = itr->second.flags;
300 if (ref)
301 {
302 if ((ref->GetTypeId() == TYPEID_PLAYER && (spellFlags & SPELL_DISABLE_PLAYER)) ||
303 (ref->GetTypeId() == TYPEID_UNIT && ((spellFlags & SPELL_DISABLE_CREATURE) || (ref->ToUnit()->IsPet() && (spellFlags & SPELL_DISABLE_PET)))) ||
304 (ref->GetTypeId() == TYPEID_GAMEOBJECT && (spellFlags & SPELL_DISABLE_GAMEOBJECT)))
305 {
307 {
308 if (Map const* map = ref->FindMap())
309 {
310 if (spellFlags & SPELL_DISABLE_ARENAS && map->IsBattleArena())
311 return true; // Current map is Arena and this spell is disabled here
312
313 if (spellFlags & SPELL_DISABLE_BATTLEGROUNDS && map->IsBattleground())
314 return true; // Current map is a Battleground and this spell is disabled here
315 }
316 }
317
318 if (spellFlags & SPELL_DISABLE_MAP)
319 {
320 std::unordered_set<uint32> const& mapIds = itr->second.params[0];
321 if (mapIds.find(ref->GetMapId()) != mapIds.end())
322 return true; // Spell is disabled on current map
323
324 if (!(spellFlags & SPELL_DISABLE_AREA))
325 return false; // Spell is disabled on another map, but not this one, return false
326
327 // Spell is disabled in an area, but not explicitly our current mapId. Continue processing.
328 }
329
330 if (spellFlags & SPELL_DISABLE_AREA)
331 {
332 std::unordered_set<uint32> const& areaIds = itr->second.params[1];
333 if (areaIds.find(ref->GetAreaId()) != areaIds.end())
334 return true; // Spell is disabled in this area
335 return false; // Spell is disabled in another area, but not this one, return false
336 }
337 else
338 return true; // Spell disabled for all maps
339 }
340
341 return false;
342 }
343 else if (spellFlags & SPELL_DISABLE_DEPRECATED_SPELL) // call not from spellcast
344 return true;
345 else if (flags & SPELL_DISABLE_LOS)
346 return (spellFlags & SPELL_DISABLE_LOS) != 0;
347
348 break;
349 }
350 case DISABLE_TYPE_MAP:
352 if (!ref)
353 return true;
354 if (Player const* player = ref->ToPlayer())
355 {
356 MapEntry const* mapEntry = sMapStore.LookupEntry(entry);
357 if (mapEntry->IsDungeon())
358 {
359 uint8 disabledModes = itr->second.flags;
360 Difficulty targetDifficulty = player->GetDifficultyID(mapEntry);
361 sDB2Manager.GetDownscaledMapDifficultyData(entry, targetDifficulty);
362 switch (targetDifficulty)
363 {
365 return (disabledModes & DUNGEON_STATUSFLAG_NORMAL) != 0;
367 return (disabledModes & DUNGEON_STATUSFLAG_HEROIC) != 0;
368 case DIFFICULTY_10_HC:
369 return (disabledModes & RAID_STATUSFLAG_10MAN_HEROIC) != 0;
370 case DIFFICULTY_25_HC:
371 return (disabledModes & RAID_STATUSFLAG_25MAN_HEROIC) != 0;
372 default:
373 return false;
374 }
375 }
376 else if (mapEntry->InstanceType == MAP_COMMON)
377 return true;
378 }
379 return false;
381 return true;
386 return true;
388 return (flags & itr->second.flags) != 0;
389 default:
390 break;
391 }
392
393 return false;
394}
395
397{
398 return IsDisabledFor(DISABLE_TYPE_VMAP, entry, nullptr, flags);
399}
400
402{
403 return sWorld->getBoolConfig(CONFIG_ENABLE_MMAPS)
405}
406
407} // Namespace
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:538
@ MAP_COMMON
Definition: DBCEnums.h:1228
@ MAP_SCENARIO
Definition: DBCEnums.h:1233
@ MAP_BATTLEGROUND
Definition: DBCEnums.h:1231
@ MAP_ARENA
Definition: DBCEnums.h:1232
@ MAP_INSTANCE
Definition: DBCEnums.h:1229
@ MAP_RAID
Definition: DBCEnums.h:1230
Difficulty
Definition: DBCEnums.h:873
@ DIFFICULTY_NONE
Definition: DBCEnums.h:874
@ DIFFICULTY_25_HC
Definition: DBCEnums.h:880
@ DIFFICULTY_NORMAL
Definition: DBCEnums.h:875
@ DIFFICULTY_HEROIC
Definition: DBCEnums.h:876
@ DIFFICULTY_10_HC
Definition: DBCEnums.h:879
std::shared_ptr< ResultSet > QueryResult
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
uint8_t uint8
Definition: Define.h:144
uint16_t uint16
Definition: Define.h:143
uint32_t uint32
Definition: Define.h:142
std::unordered_set< uint32 > params[2]
Definition: DisableMgr.cpp:50
uint16 flags
Definition: DisableMgr.cpp:49
@ MMAP_DISABLE_PATHFINDING
Definition: DisableMgr.h:60
@ SPELL_DISABLE_LOS
Definition: DisableMgr.h:48
@ SPELL_DISABLE_CREATURE
Definition: DisableMgr.h:43
@ SPELL_DISABLE_PET
Definition: DisableMgr.h:44
@ SPELL_DISABLE_ARENAS
Definition: DisableMgr.h:50
@ SPELL_DISABLE_MAP
Definition: DisableMgr.h:46
@ SPELL_DISABLE_PLAYER
Definition: DisableMgr.h:42
@ SPELL_DISABLE_DEPRECATED_SPELL
Definition: DisableMgr.h:45
@ MAX_SPELL_DISABLE_TYPE
Definition: DisableMgr.h:52
@ SPELL_DISABLE_BATTLEGROUNDS
Definition: DisableMgr.h:51
@ SPELL_DISABLE_GAMEOBJECT
Definition: DisableMgr.h:49
@ SPELL_DISABLE_AREA
Definition: DisableMgr.h:47
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
@ MAX_DISABLE_TYPES
Definition: DisableMgr.h:37
@ 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:68
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:165
#define TC_LOG_INFO(filterType__,...)
Definition: Log.h:159
@ TYPEID_GAMEOBJECT
Definition: ObjectGuid.h:43
@ TYPEID_UNIT
Definition: ObjectGuid.h:40
@ TYPEID_PLAYER
Definition: ObjectGuid.h:41
#define sObjectMgr
Definition: ObjectMgr.h:1946
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:849
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:90
std::string GetString() const
Definition: Field.cpp:118
uint16 GetUInt16() const
Definition: Field.cpp:46
uint32 GetUInt32() const
Definition: Field.cpp:62
Definition: Map.h:189
static Unit * ToUnit(Object *o)
Definition: Object.h:225
TypeID GetTypeId() const
Definition: Object.h:173
static Player * ToPlayer(Object *o)
Definition: Object.h:213
bool IsPet() const
Definition: Unit.h:740
constexpr uint32 GetMapId() const
Definition: Position.h:201
Map * FindMap() const
Definition: Object.h:625
uint32 GetAreaId() const
Definition: Object.h:546
#define sWorld
Definition: World.h:931
@ CONFIG_ENABLE_MMAPS
Definition: World.h:168
void CheckQuestDisables()
Definition: DisableMgr.cpp:256
bool IsDisabledFor(DisableType type, uint32 entry, WorldObject const *ref, uint8 flags)
Definition: DisableMgr.cpp:285
char const * MapTypeNames[]
Definition: DisableMgr.cpp:35
bool IsVMAPDisabledFor(uint32 entry, uint8 flags)
Definition: DisableMgr.cpp:396
bool IsPathfindingEnabled(uint32 mapId)
Definition: DisableMgr.cpp:401
void LoadDisables()
Definition: DisableMgr.cpp:59
TC_COMMON_API std::vector< std::string_view > Tokenize(std::string_view str, char sep, bool keepEmpty)
Definition: Util.cpp:56
@ VMAP_DISABLE_LIQUIDSTATUS
Definition: VMapManager2.h:62
@ VMAP_DISABLE_LOS
Definition: VMapManager2.h:61
@ VMAP_DISABLE_HEIGHT
Definition: VMapManager2.h:60
@ VMAP_DISABLE_AREAFLAG
Definition: VMapManager2.h:59
int8 InstanceType
bool IsDungeon() const