forked from The-Cataclysm-Preservation-Project/TrinityCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjectGuid.cpp
More file actions
160 lines (141 loc) · 4.93 KB
/
ObjectGuid.cpp
File metadata and controls
160 lines (141 loc) · 4.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ObjectGuid.h"
#include "Errors.h"
#include "ByteBuffer.h"
#include "Log.h"
#include "World.h"
#include <iomanip>
#include <sstream>
ObjectGuid const ObjectGuid::Empty = ObjectGuid();
uint8& ObjectGuid::operator[](uint32 index)
{
ASSERT(index < sizeof(uint64));
return _data._bytes[index];
}
uint8 const& ObjectGuid::operator[](uint32 index) const
{
ASSERT(index < sizeof(uint64));
return _data._bytes[index];
}
char const* ObjectGuid::GetTypeName(HighGuid high)
{
switch (high)
{
case HighGuid::Item: return "Item";
case HighGuid::Player: return "Player";
case HighGuid::GameObject: return "Gameobject";
case HighGuid::Transport: return "Transport";
case HighGuid::Unit: return "Creature";
case HighGuid::Pet: return "Pet";
case HighGuid::Vehicle: return "Vehicle";
case HighGuid::DynamicObject: return "DynObject";
case HighGuid::Corpse: return "Corpse";
case HighGuid::AreaTrigger: return "AreaTrigger";
case HighGuid::BattleGround: return "Battleground";
case HighGuid::Mo_Transport: return "MoTransport";
case HighGuid::Instance: return "InstanceID";
case HighGuid::Group: return "Group";
case HighGuid::Guild: return "Guild";
default:
return "<unknown>";
}
}
std::string ObjectGuid::ToString() const
{
std::ostringstream str;
str << "GUID Full: 0x" << std::hex << std::setw(16) << std::setfill('0') << _data._guid << std::dec;
str << " Type: " << GetTypeName();
if (HasEntry())
str << (IsPet() ? " Pet number: " : " Entry: ") << GetEntry() << " ";
str << " Low: " << GetCounter();
return str.str();
}
ObjectGuid ObjectGuid::Global(HighGuid type, LowType counter)
{
return ObjectGuid(type, counter);
}
ObjectGuid ObjectGuid::MapSpecific(HighGuid type, uint32 entry, LowType counter)
{
return ObjectGuid(type, entry, counter);
}
void PackedGuid::Set(ObjectGuid guid)
{
_packedSize = 1;
_packedGuid = { };
uint64 raw = guid.GetRawValue();
for (uint8 i = 0; i < 8; ++i)
{
uint8 byte = (raw >> (i * 8)) & 0xFF;
_packedGuid[_packedSize] = byte;
if (byte)
{
_packedGuid[0] |= uint8(1 << i);
++_packedSize;
}
}
}
ByteBuffer& operator<<(ByteBuffer& buf, ObjectGuid const& guid)
{
buf << uint64(guid.GetRawValue());
return buf;
}
ByteBuffer& operator>>(ByteBuffer& buf, ObjectGuid& guid)
{
guid.Set(buf.read<uint64>());
return buf;
}
ByteBuffer& operator<<(ByteBuffer& buf, PackedGuid const& guid)
{
buf.append(guid._packedGuid.data(), guid._packedSize);
return buf;
}
ByteBuffer& operator<<(ByteBuffer& buf, PackedGuidWriter const& guid)
{
buf.appendPackGUID(guid.Guid.GetRawValue());
return buf;
}
ByteBuffer& operator>>(ByteBuffer& buf, PackedGuidReader const& guid)
{
buf.readPackGUID(reinterpret_cast<uint64&>(guid.Guid));
return buf;
}
void ObjectGuidGeneratorBase::HandleCounterOverflow(HighGuid high)
{
TC_LOG_ERROR("misc", "%s guid overflow!! Can't continue, shutting down server. ", ObjectGuid::GetTypeName(high));
World::StopNow(ERROR_EXIT_CODE);
}
void ObjectGuidGeneratorBase::CheckGuidTrigger(ObjectGuid::LowType guidlow)
{
if (!sWorld->IsGuidAlert() && guidlow > sWorld->getIntConfig(CONFIG_RESPAWN_GUIDALERTLEVEL))
sWorld->TriggerGuidAlert();
else if (!sWorld->IsGuidWarning() && guidlow > sWorld->getIntConfig(CONFIG_RESPAWN_GUIDWARNLEVEL))
sWorld->TriggerGuidWarning();
}
#define GUID_TRAIT_INSTANTIATE_GUID( HIGH_GUID ) \
template class TC_GAME_API ObjectGuidGenerator< HIGH_GUID >;
GUID_TRAIT_INSTANTIATE_GUID(HighGuid::Container)
GUID_TRAIT_INSTANTIATE_GUID(HighGuid::Player)
GUID_TRAIT_INSTANTIATE_GUID(HighGuid::GameObject)
GUID_TRAIT_INSTANTIATE_GUID(HighGuid::Transport)
GUID_TRAIT_INSTANTIATE_GUID(HighGuid::Unit)
GUID_TRAIT_INSTANTIATE_GUID(HighGuid::Pet)
GUID_TRAIT_INSTANTIATE_GUID(HighGuid::Vehicle)
GUID_TRAIT_INSTANTIATE_GUID(HighGuid::DynamicObject)
GUID_TRAIT_INSTANTIATE_GUID(HighGuid::Mo_Transport)
GUID_TRAIT_INSTANTIATE_GUID(HighGuid::Instance)
GUID_TRAIT_INSTANTIATE_GUID(HighGuid::Group)