Slightly refactor ObjectGuid and add support for clamping client transmitted GUIDs (#5)
This commit is contained in:
+23
-2
@@ -72,6 +72,11 @@ std::string ObjectGuid::GetString() const
|
||||
return str.str();
|
||||
}
|
||||
|
||||
void ObjectGuid::Set(uint64 const& guid)
|
||||
{
|
||||
m_guid = guid;
|
||||
}
|
||||
|
||||
template<HighGuid high>
|
||||
uint32 ObjectGuidGenerator<high>::Generate()
|
||||
{
|
||||
@@ -111,7 +116,9 @@ ByteBuffer& operator<< (ByteBuffer& buf, ObjectGuid const& guid)
|
||||
|
||||
ByteBuffer &operator>>(ByteBuffer& buf, ObjectGuid& guid)
|
||||
{
|
||||
guid.Set(buf.read<uint64>());
|
||||
uint64 value = buf.read<uint64>();
|
||||
ObjectGuid::ClampPlayerGuid(value);
|
||||
guid.Set(value);
|
||||
return buf;
|
||||
}
|
||||
|
||||
@@ -123,10 +130,24 @@ ByteBuffer& operator<< (ByteBuffer& buf, PackedGuid const& guid)
|
||||
|
||||
ByteBuffer &operator>>(ByteBuffer& buf, PackedGuidReader const& guid)
|
||||
{
|
||||
guid.m_guidPtr->Set(buf.readPackGUID());
|
||||
uint64 value = buf.readPackGUID();
|
||||
ObjectGuid::ClampPlayerGuid(value);
|
||||
guid.m_guidPtr->Set(value);
|
||||
return buf;
|
||||
}
|
||||
|
||||
// If the GUID is a player GUID, clamp it to the low guid or we open
|
||||
// ourselves to packet manipulation where a player can send their low
|
||||
// guid with a mutple of 0xFFFFFFFF+1 added to it, causing hashing to
|
||||
// fail but some other functionality to succeed
|
||||
void ObjectGuid::ClampPlayerGuid(uint64& value)
|
||||
{
|
||||
if (ObjectGuid::GetHigh(value) == HIGHGUID_PLAYER)
|
||||
{
|
||||
value = static_cast<uint64>(GetCounter(value, HasEntry(HIGHGUID_PLAYER)));
|
||||
}
|
||||
}
|
||||
|
||||
template class ObjectGuidGenerator<HIGHGUID_ITEM>;
|
||||
template class ObjectGuidGenerator<HIGHGUID_PLAYER>;
|
||||
template class ObjectGuidGenerator<HIGHGUID_GAMEOBJECT>;
|
||||
|
||||
+12
-5
@@ -141,19 +141,26 @@ class MANGOS_DLL_SPEC ObjectGuid
|
||||
public: // modifiers
|
||||
PackedGuidReader ReadAsPacked() { return PackedGuidReader(*this); }
|
||||
|
||||
void Set(uint64 const& guid) { m_guid = guid; }
|
||||
void Set(uint64 const& guid);
|
||||
void Clear() { m_guid = 0; }
|
||||
|
||||
PackedGuid WriteAsPacked() const;
|
||||
public: // accessors
|
||||
uint64 const& GetRawValue() const { return m_guid; }
|
||||
HighGuid GetHigh() const { return HighGuid((m_guid >> 48) & 0x0000FFFF); }
|
||||
static HighGuid GetHigh(uint64 guid) { return HighGuid((guid >> 48) & 0x0000FFFF); }
|
||||
static void ClampPlayerGuid(uint64& value);
|
||||
HighGuid GetHigh() const { return GetHigh(m_guid); }
|
||||
uint32 GetEntry() const { return HasEntry() ? uint32((m_guid >> 24) & UI64LIT(0x0000000000FFFFFF)) : 0; }
|
||||
uint32 GetCounter() const
|
||||
{
|
||||
return HasEntry()
|
||||
? uint32(m_guid & UI64LIT(0x0000000000FFFFFF))
|
||||
: uint32(m_guid & UI64LIT(0x00000000FFFFFFFF));
|
||||
return GetCounter(m_guid, HasEntry());
|
||||
}
|
||||
|
||||
static uint32 GetCounter(uint64 guid, bool hasEntry)
|
||||
{
|
||||
return hasEntry
|
||||
? uint32(guid & UI64LIT(0x0000000000FFFFFF))
|
||||
: uint32(guid & UI64LIT(0x00000000FFFFFFFF));
|
||||
}
|
||||
|
||||
static uint32 GetMaxCounter(HighGuid high)
|
||||
|
||||
Reference in New Issue
Block a user