ddnet/src/engine/shared/uuid_manager.h
heinrich5991 5ae37e6c72 Add protocol extension with UUIDs
This system can easily be extended by independent authors without
collisions, something the old system with plain increasing integers did
not allow.

Do this by utilizing the previously unused message code `NETMSG_NULL`
which has a value of 0.

This works for engine and game messages, snapshot items and events.
2017-05-25 00:52:43 +02:00

55 lines
1,014 B
C++

#ifndef ENGINE_SHARED_UUID_MANAGER_H
#define ENGINE_SHARED_UUID_MANAGER_H
#include <base/tl/array.h>
enum
{
UUID_MAXSTRSIZE = 37, // 12345678-0123-5678-0123-567890123456
UUID_INVALID=-2,
UUID_UNKNOWN=-1,
OFFSET_UUID=1<<16,
};
struct CUuid
{
unsigned char m_aData[16];
bool operator==(const CUuid &Other);
bool operator!=(const CUuid &Other);
};
CUuid CalculateUuid(const char *pName);
void FormatUuid(CUuid Uuid, char *pBuffer, unsigned BufferLength);
struct CName
{
CUuid m_Uuid;
const char *m_pName;
};
class CPacker;
class CUnpacker;
class CUuidManager
{
array<CName> m_aNames;
public:
void RegisterName(int ID, const char *pName);
CUuid GetUuid(int ID) const;
const char *GetName(int ID) const;
int LookupUuid(CUuid Uuid) const;
int UnpackUuid(CUnpacker *pUnpacker) const;
int UnpackUuid(CUnpacker *pUnpacker, CUuid *pOut) const;
void PackUuid(int ID, CPacker *pPacker) const;
void DebugDump() const;
};
extern CUuidManager g_UuidManager;
#endif // ENGINE_SHARED_UUID_MANAGER_H