Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
DisableMgr.cpp
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#include "AchievementMgr.h"
7#include "DisableMgr.h"
8#include "ObjectMgr.h"
9#include "OutdoorPvP.h"
10#include "Player.h"
11#include "SpellMgr.h"
12#include "VMapManager2.h"
13
14namespace DisableMgr
15{
16
17 namespace
18 {
19 struct DisableData
20 {
21 uint8 flags;
22 std::set<uint32> params[2]; // params0, params1
23 };
24
25 // single disables here with optional data
26 typedef std::map<uint32, DisableData> DisableTypeMap;
27 // global disable map by source
28 typedef std::map<DisableType, DisableTypeMap> DisableMap;
29
30 DisableMap m_DisableMap;
31
32 uint8 MAX_DISABLE_TYPES = 8;
33 }
34
36 {
37 uint32 oldMSTime = getMSTime();
38
39 // reload case
40 for (DisableMap::iterator itr = m_DisableMap.begin(); itr != m_DisableMap.end(); ++itr)
41 itr->second.clear();
42
43 m_DisableMap.clear();
44
45 QueryResult result = WorldDatabase.Query("SELECT sourceType, entry, flags, params_0, params_1 FROM disables");
46
47 uint32 total_count = 0;
48
49 if (!result)
50 {
51 SF_LOG_INFO("server.loading", ">> Loaded 0 disables. DB table `disables` is empty!");
52 return;
53 }
54
55 Field* fields;
56 do
57 {
58 fields = result->Fetch();
59 DisableType type = DisableType(fields[0].GetUInt32());
60 if (type >= MAX_DISABLE_TYPES)
61 {
62 SF_LOG_ERROR("sql.sql", "Invalid type %u specified in `disables` table, skipped.", type);
63 continue;
64 }
65
66 uint32 entry = fields[1].GetUInt32();
67 uint8 flags = fields[2].GetUInt8();
68 std::string params_0 = fields[3].GetString();
69 std::string params_1 = fields[4].GetString();
70
71 DisableData data;
72 data.flags = flags;
73
74 switch (type)
75 {
77 if (!(sSpellMgr->GetSpellInfo(entry) || flags & SPELL_DISABLE_DEPRECATED_SPELL))
78 {
79 SF_LOG_ERROR("sql.sql", "Spell entry %u from `disables` doesn't exist in dbc, skipped.", entry);
80 continue;
81 }
82
83 if (!flags || flags > MAX_SPELL_DISABLE_TYPE)
84 {
85 SF_LOG_ERROR("sql.sql", "Disable flags for spell %u are invalid, skipped.", entry);
86 continue;
87 }
88
89 if (flags & SPELL_DISABLE_MAP)
90 {
91 Tokenizer tokens(params_0, ',');
92 for (uint8 i = 0; i < tokens.size(); )
93 data.params[0].insert(atoi(tokens[i++]));
94 }
95
96 if (flags & SPELL_DISABLE_AREA)
97 {
98 Tokenizer tokens(params_1, ',');
99 for (uint8 i = 0; i < tokens.size(); )
100 data.params[1].insert(atoi(tokens[i++]));
101 }
102
103 break;
104 // checked later
106 break;
107 case DISABLE_TYPE_MAP:
108 {
109 MapEntry const* mapEntry = sMapStore.LookupEntry(entry);
110 if (!mapEntry)
111 {
112 SF_LOG_ERROR("sql.sql", "Map entry %u from `disables` doesn't exist in dbc, skipped.", entry);
113 continue;
114 }
115 bool isFlagInvalid = false;
116 switch (mapEntry->map_type)
117 {
118 case MAP_COMMON:
119 if (flags)
120 isFlagInvalid = true;
121 break;
122 case MAP_DUNGEON:
125 if (!flags)
126 isFlagInvalid = true;
127 break;
128 case MAP_RAID:
137 if (!flags)
138 isFlagInvalid = true;
139 break;
140 case MAP_BATTLEGROUND:
141 case MAP_ARENA:
142 SF_LOG_ERROR("sql.sql", "Battleground map %u specified to be disabled in map case, skipped.", entry);
143 continue;
144 }
145 if (isFlagInvalid)
146 {
147 SF_LOG_ERROR("sql.sql", "Disable flags for map %u are invalid, skipped.", entry);
148 continue;
149 }
150 break;
151 }
153 if (!sBattlemasterListStore.LookupEntry(entry))
154 {
155 SF_LOG_ERROR("sql.sql", "Battleground entry %u from `disables` doesn't exist in dbc, skipped.", entry);
156 continue;
157 }
158 if (flags)
159 SF_LOG_ERROR("sql.sql", "Disable flags specified for battleground %u, useless data.", entry);
160 break;
162 if (entry > MAX_OUTDOORPVP_TYPES)
163 {
164 SF_LOG_ERROR("sql.sql", "OutdoorPvPTypes value %u from `disables` is invalid, skipped.", entry);
165 continue;
166 }
167 if (flags)
168 SF_LOG_ERROR("sql.sql", "Disable flags specified for outdoor PvP %u, useless data.", entry);
169 break;
171 if (!sAchievementMgr->GetAchievementCriteria(entry))
172 {
173 SF_LOG_ERROR("sql.sql", "Achievement Criteria entry %u from `disables` doesn't exist in dbc, skipped.", entry);
174 continue;
175 }
176 if (flags)
177 SF_LOG_ERROR("sql.sql", "Disable flags specified for Achievement Criteria %u, useless data.", entry);
178 break;
180 {
181 MapEntry const* mapEntry = sMapStore.LookupEntry(entry);
182 if (!mapEntry)
183 {
184 SF_LOG_ERROR("sql.sql", "Map entry %u from `disables` doesn't exist in dbc, skipped.", entry);
185 continue;
186 }
187 switch (mapEntry->map_type)
188 {
189 case MAP_COMMON:
190 if (flags & VMAP_DISABLE_AREAFLAG)
191 SF_LOG_INFO("misc", "Areaflag disabled for world map %u.", entry);
192 if (flags & VMAP_DISABLE_LIQUIDSTATUS)
193 SF_LOG_INFO("misc", "Liquid status disabled for world map %u.", entry);
194 break;
195 case MAP_DUNGEON:
196 if (flags & VMAP_DISABLE_HEIGHT)
197 SF_LOG_INFO("misc", "Height disabled for instance map %u.", entry);
198 if (flags & VMAP_DISABLE_LOS)
199 SF_LOG_INFO("misc", "LoS disabled for instance map %u.", entry);
200 break;
201 case MAP_RAID:
202 if (flags & VMAP_DISABLE_HEIGHT)
203 SF_LOG_INFO("misc", "Height disabled for raid map %u.", entry);
204 if (flags & VMAP_DISABLE_LOS)
205 SF_LOG_INFO("misc", "LoS disabled for raid map %u.", entry);
206 break;
207 case MAP_BATTLEGROUND:
208 if (flags & VMAP_DISABLE_HEIGHT)
209 SF_LOG_INFO("misc", "Height disabled for battleground map %u.", entry);
210 if (flags & VMAP_DISABLE_LOS)
211 SF_LOG_INFO("misc", "LoS disabled for battleground map %u.", entry);
212 break;
213 case MAP_ARENA:
214 if (flags & VMAP_DISABLE_HEIGHT)
215 SF_LOG_INFO("misc", "Height disabled for arena map %u.", entry);
216 if (flags & VMAP_DISABLE_LOS)
217 SF_LOG_INFO("misc", "LoS disabled for arena map %u.", entry);
218 break;
219 default:
220 break;
221 }
222 break;
223 }
225 {
226 MapEntry const* mapEntry = sMapStore.LookupEntry(entry);
227 if (!mapEntry)
228 {
229 SF_LOG_ERROR("sql.sql", "Map entry %u from `disables` doesn't exist in dbc, skipped.", entry);
230 continue;
231 }
232 switch (mapEntry->map_type)
233 {
234 case MAP_COMMON:
235 SF_LOG_INFO("misc", "Pathfinding disabled for world map %u.", entry);
236 break;
237 case MAP_DUNGEON:
238 case MAP_RAID:
239 SF_LOG_INFO("misc", "Pathfinding disabled for instance map %u.", entry);
240 break;
241 case MAP_BATTLEGROUND:
242 SF_LOG_INFO("misc", "Pathfinding disabled for battleground map %u.", entry);
243 break;
244 case MAP_ARENA:
245 SF_LOG_INFO("misc", "Pathfinding disabled for arena map %u.", entry);
246 break;
247 default:
248 break;
249 }
250 break;
251 }
252 default:
253 break;
254 }
255
256 m_DisableMap[type].insert(DisableTypeMap::value_type(entry, data));
257 ++total_count;
258 } while (result->NextRow());
259
260 SF_LOG_INFO("server.loading", ">> Loaded %u disables in %u 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 SF_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 SF_LOG_ERROR("sql.sql", "Quest entry %u from `disables` doesn't exist, skipped.", entry);
281 m_DisableMap[DISABLE_TYPE_QUEST].erase(itr++);
282 continue;
283 }
284 if (itr->second.flags)
285 SF_LOG_ERROR("sql.sql", "Disable flags specified for quest %u, useless data.", entry);
286 ++itr;
287 }
288
289 SF_LOG_INFO("server.loading", ">> Checked %u quest disables in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
290 }
291
292 bool IsDisabledFor(DisableType type, uint32 entry, Unit const* unit, uint8 flags)
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 uint8 spellFlags = itr->second.flags;
307 if (unit)
308 {
309 if ((spellFlags & SPELL_DISABLE_PLAYER && unit->GetTypeId() == TypeID::TYPEID_PLAYER) ||
310 (unit->GetTypeId() == TypeID::TYPEID_UNIT && ((unit->ToCreature()->IsPet() && spellFlags & SPELL_DISABLE_PET) || spellFlags & SPELL_DISABLE_CREATURE)))
311 {
312 if (spellFlags & SPELL_DISABLE_MAP)
313 {
314 std::set<uint32> const& mapIds = itr->second.params[0];
315 if (mapIds.find(unit->GetMapId()) != mapIds.end())
316 return true; // Spell is disabled on current map
317
318 if (!(spellFlags & SPELL_DISABLE_AREA))
319 return false; // Spell is disabled on another map, but not this one, return false
320
321 // Spell is disabled in an area, but not explicitly our current mapId. Continue processing.
322 }
323
324 if (spellFlags & SPELL_DISABLE_AREA)
325 {
326 std::set<uint32> const& areaIds = itr->second.params[1];
327 if (areaIds.find(unit->GetAreaId()) != areaIds.end())
328 return true; // Spell is disabled in this area
329 return false; // Spell is disabled in another area, but not this one, return false
330 }
331 else
332 return true; // Spell disabled for all maps
333 }
334
335 return false;
336 }
337 else if (spellFlags & SPELL_DISABLE_DEPRECATED_SPELL) // call not from spellcast
338 return true;
339 else if (flags & SPELL_DISABLE_LOS)
340 return spellFlags & SPELL_DISABLE_LOS;
341
342 break;
343 }
344 case DISABLE_TYPE_MAP:
345 if (Player const* player = unit->ToPlayer())
346 {
347 MapEntry const* mapEntry = sMapStore.LookupEntry(entry);
348 if (mapEntry->IsInstance())
349 {
350 uint8 disabledModes = itr->second.flags;
351 DifficultyID targetDifficulty = player->GetDifficulty(mapEntry);
352 GetDownscaledMapDifficultyData(entry, targetDifficulty);
353 switch (targetDifficulty)
354 {
356 return disabledModes & DUNGEON_STATUSFLAG_NORMAL;
358 return disabledModes & DUNGEON_STATUSFLAG_HEROIC;
360 return disabledModes & RAID_STATUSFLAG_10MAN_NORMAL;
362 return disabledModes & RAID_STATUSFLAG_10MAN_HEROIC;
364 return disabledModes & RAID_STATUSFLAG_25MAN_NORMAL;
366 return disabledModes & RAID_STATUSFLAG_25MAN_HEROIC;
367 case DIFFICULTY_FLEX:
368 return disabledModes & RAID_STATUSFLAG_10MAN_FLEX;
370 return disabledModes & RAID_STATUSFLAG_25MAN_LFR;
371 }
372 }
373 else if (mapEntry->map_type == MAP_COMMON)
374 return true;
375 }
376 return false;
378 if (!unit)
379 return true;
380 if (Player const* player = unit->ToPlayer())
381 if (player->IsGameMaster())
382 return false;
383 return true;
388 return true;
390 return flags & itr->second.flags;
391 }
392
393 return false;
394 }
395
396} // Namespace
#define sAchievementMgr
@ MAP_COMMON
Definition DBCEnums.h:393
@ MAP_DUNGEON
Definition DBCEnums.h:394
@ MAP_BATTLEGROUND
Definition DBCEnums.h:396
@ MAP_ARENA
Definition DBCEnums.h:397
@ MAP_RAID
Definition DBCEnums.h:395
DifficultyID
Definition DBCEnums.h:330
@ DIFFICULTY_10MAN_HEROIC
Definition DBCEnums.h:336
@ DIFFICULTY_25MAN_NORMAL
Definition DBCEnums.h:335
@ DIFFICULTY_NORMAL
Definition DBCEnums.h:332
@ DIFFICULTY_HEROIC
Definition DBCEnums.h:333
@ DIFFICULTY_25MAN_LFR
Definition DBCEnums.h:338
@ DIFFICULTY_FLEX
Definition DBCEnums.h:343
@ DIFFICULTY_10MAN_NORMAL
Definition DBCEnums.h:334
@ DIFFICULTY_25MAN_HEROIC
Definition DBCEnums.h:337
MapDifficulty const * GetMapDifficultyData(uint32 mapId, DifficultyID difficulty)
DBCStorage< BattlemasterListEntry > sBattlemasterListStore(BattlemasterListEntryfmt)
MapDifficulty const * GetDownscaledMapDifficultyData(uint32 mapId, DifficultyID &difficulty)
DBCStorage< MapEntry > sMapStore(MapEntryfmt)
std::uint8_t uint8
Definition Define.h:79
std::uint32_t uint32
Definition Define.h:77
@ VMAP_DISABLE_AREAFLAG
Definition DisableMgr.h:41
@ VMAP_DISABLE_HEIGHT
Definition DisableMgr.h:42
@ VMAP_DISABLE_LIQUIDSTATUS
Definition DisableMgr.h:44
@ VMAP_DISABLE_LOS
Definition DisableMgr.h:43
@ SPELL_DISABLE_LOS
Definition DisableMgr.h:33
@ SPELL_DISABLE_CREATURE
Definition DisableMgr.h:28
@ SPELL_DISABLE_PET
Definition DisableMgr.h:29
@ SPELL_DISABLE_MAP
Definition DisableMgr.h:31
@ SPELL_DISABLE_PLAYER
Definition DisableMgr.h:27
@ SPELL_DISABLE_DEPRECATED_SPELL
Definition DisableMgr.h:30
@ MAX_SPELL_DISABLE_TYPE
Definition DisableMgr.h:34
@ SPELL_DISABLE_AREA
Definition DisableMgr.h:32
DisableType
Definition DisableMgr.h:14
@ DISABLE_TYPE_SPELL
Definition DisableMgr.h:15
@ DISABLE_TYPE_MMAP
Definition DisableMgr.h:22
@ DISABLE_TYPE_VMAP
Definition DisableMgr.h:21
@ DISABLE_TYPE_QUEST
Definition DisableMgr.h:16
@ DISABLE_TYPE_MAP
Definition DisableMgr.h:17
@ DISABLE_TYPE_BATTLEGROUND
Definition DisableMgr.h:18
@ DISABLE_TYPE_ACHIEVEMENT_CRITERIA
Definition DisableMgr.h:19
@ DISABLE_TYPE_OUTDOORPVP
Definition DisableMgr.h:20
#define ASSERT
Definition Errors.h:29
#define SF_LOG_ERROR(filterType__,...)
Definition Log.h:143
#define SF_LOG_INFO(filterType__,...)
Definition Log.h:137
@ TYPEID_PLAYER
Definition Object.h:55
@ TYPEID_UNIT
Definition Object.h:54
#define sObjectMgr
Definition ObjectMgr.h:1617
#define MAX_OUTDOORPVP_TYPES
Definition OutdoorPvP.h:25
Skyfire::AutoPtr< ResultSet, Skyfire::Mutex > QueryResult
Definition QueryResult.h:48
@ RAID_STATUSFLAG_25MAN_LFR
@ DUNGEON_STATUSFLAG_NORMAL
@ RAID_STATUSFLAG_10MAN_HEROIC
@ RAID_STATUSFLAG_25MAN_NORMAL
@ RAID_STATUSFLAG_25MAN_HEROIC
@ RAID_STATUSFLAG_10MAN_FLEX
@ RAID_STATUSFLAG_10MAN_NORMAL
@ DUNGEON_STATUSFLAG_HEROIC
#define sSpellMgr
Definition SpellMgr.h:744
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition Timer.h:22
uint32 getMSTime()
Definition Timer.h:12
Definition Field.h:16
uint8 GetUInt8() const
Definition Field.h:26
std::string GetString() const
Definition Field.h:228
uint32 GetUInt32() const
Definition Field.h:105
Player * ToPlayer()
Definition Object.h:204
TypeID GetTypeId() const
Definition Object.h:131
Creature * ToCreature()
Definition Object.h:207
size_type size() const
Definition Util.h:46
Definition Unit.h:1367
bool IsPet() const
Definition Unit.h:1511
uint32 GetMapId() const
Definition Object.h:546
uint32 GetAreaId() const
Definition Object.cpp:1602
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition Main.cpp:40
void CheckQuestDisables()
bool IsDisabledFor(DisableType type, uint32 entry, Unit const *unit, uint8 flags)
void LoadDisables()
bool IsInstance() const
uint32 map_type