Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
LegacyTransportSupport.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
7
8#include <algorithm>
9#include <vector>
10
11namespace LegacyTransport
12{
13 namespace
14 {
16
17 typedef std::vector<LegacyTransportEntry> LegacyTransportEntryStore;
18
19 LegacyTransportEntryStore& GetLegacyTransportEntries()
20 {
21 static LegacyTransportEntryStore entries;
22 return entries;
23 }
24
25 LegacyTransportEntryStore::const_iterator FindByDbEntry(uint32 dbEntry)
26 {
27 LegacyTransportEntryStore const& entries = GetLegacyTransportEntries();
28 return std::find_if(entries.begin(), entries.end(), [dbEntry](LegacyTransportEntry const& entry)
29 {
30 return entry.DbEntry == dbEntry;
31 });
32 }
33
34 LegacyTransportEntryStore::const_iterator FindByClientEntry(uint32 clientEntry)
35 {
36 LegacyTransportEntryStore const& entries = GetLegacyTransportEntries();
37 return std::find_if(entries.begin(), entries.end(), [clientEntry](LegacyTransportEntry const& entry)
38 {
39 return entry.ClientEntry == clientEntry;
40 });
41 }
42
43 bool HasFlag(LegacyTransportEntry const& entry, uint32 flag)
44 {
45 return (entry.Flags & flag) != 0;
46 }
47 }
48
50 {
51 GetLegacyTransportEntries().clear();
52 }
53
55 {
56 if (!entry.DbEntry || !entry.ClientEntry || !entry.SpawnMask || (entry.Flags & ~SupportedLegacyTransportFlags))
57 return false;
58
59 LegacyTransportEntryStore& entries = GetLegacyTransportEntries();
60 for (LegacyTransportEntryStore::const_iterator itr = entries.begin(); itr != entries.end(); ++itr)
61 {
62 if (itr->DbEntry == entry.DbEntry && itr->ClientEntry != entry.ClientEntry)
63 return false;
64
65 if (itr->DbEntry == entry.DbEntry && itr->MapId == entry.MapId && itr->SpawnMask == entry.SpawnMask)
66 return false;
67 }
68
69 entries.push_back(entry);
70 return true;
71 }
72
74 {
75 LegacyTransportEntryStore::const_iterator itr = FindByDbEntry(dbEntry);
76 return itr != GetLegacyTransportEntries().end() && HasFlag(*itr, LEGACY_TRANSPORT_FLAG_PRESERVE_PASSENGER_GAMEOBJECT_VISIBILITY);
77 }
78
80 {
81 LegacyTransportEntryStore::const_iterator itr = FindByClientEntry(clientEntry);
82 return itr != GetLegacyTransportEntries().end() && HasFlag(*itr, LEGACY_TRANSPORT_FLAG_PRESERVE_PASSENGER_GAMEOBJECT_VISIBILITY);
83 }
84
86 {
87 return FindByDbEntry(dbEntry) != GetLegacyTransportEntries().end();
88 }
89
91 {
92 LegacyTransportEntryStore::const_iterator itr = FindByDbEntry(dbEntry);
93 return itr != GetLegacyTransportEntries().end() ? itr->ClientEntry : dbEntry;
94 }
95
96 uint32 GetAllowedSpawnMask(uint32 dbEntry, uint32 mapId, uint32 spawnMask)
97 {
98 uint32 allowedSpawnMask = 0;
99 LegacyTransportEntryStore const& entries = GetLegacyTransportEntries();
100 for (LegacyTransportEntryStore::const_iterator itr = entries.begin(); itr != entries.end(); ++itr)
101 if (itr->DbEntry == dbEntry && itr->MapId == mapId)
102 allowedSpawnMask |= itr->SpawnMask & spawnMask;
103
104 return allowedSpawnMask;
105 }
106
107 bool IsAllowedOnMap(uint32 dbEntry, uint32 mapId, uint32 spawnMode)
108 {
109 if (spawnMode >= 32)
110 return false;
111
112 return (GetAllowedSpawnMask(dbEntry, mapId, 1u << spawnMode) & (1u << spawnMode)) != 0;
113 }
114
116 {
117 return IsDeeprunSubwayClientEntry(clientEntry);
118 }
119
128}
std::uint32_t uint32
Definition Define.h:77
std::uint64_t uint64
Definition Define.h:76
bool ShouldPreservePassengerGameObjectVisibility(uint32 clientEntry)
void LogMissingAnimationData(uint32, uint32, uint32)
bool IsDeeprunSubwayClientEntry(uint32 clientEntry)
@ LEGACY_TRANSPORT_FLAG_PRESERVE_PASSENGER_GAMEOBJECT_VISIBILITY
void LogRegisteredSpawn(LegacyTransportSpawnDiagnostic const &)
bool IsDeeprunSubwayDbEntry(uint32 dbEntry)
void LogCreateAttempt(LegacyTransportSpawnDiagnostic const &)
uint32 GetClientEntryForDbEntry(uint32 dbEntry)
void LogCreateFailure(LegacyTransportSpawnDiagnostic const &)
void LogCreateSuccess(LegacyTransportSpawnDiagnostic const &, uint64, uint32, uint32, uint32, uint32, uint32, uint32, uint32)
bool IsLocalTransportDbEntry(uint32 dbEntry)
void LogMissingCreateAnimationData(uint32, uint32, uint32)
void LogNoRegisteredSpawns(uint32, uint32)
bool IsAllowedOnMap(uint32 dbEntry, uint32 mapId, uint32 spawnMode)
void LogSpawnCount(uint32, uint32, uint32)
uint32 GetAllowedSpawnMask(uint32 dbEntry, uint32 mapId, uint32 spawnMask)
bool AddLegacyTransportEntry(LegacyTransportEntry const &entry)
int HasFlag(lua_State *L, Object *obj)
uint32 Flags
uint32 ClientEntry
uint32 MapId
uint32 DbEntry
uint32 SpawnMask