86 lines
1.4 KiB
C++
86 lines
1.4 KiB
C++
#ifndef NET_PROTOCOL_H
|
|
#define NET_PROTOCOL_H
|
|
|
|
|
|
#include "stdint.h"
|
|
#include <arpa/inet.h>
|
|
|
|
class CNetworkUInt32
|
|
{
|
|
public:
|
|
CNetworkUInt32() : m_uValue(0) {}
|
|
CNetworkUInt32( uint32_t uValue ) : m_uValue(htonl(uValue)) {}
|
|
operator uint32_t() const {
|
|
return htonl(m_uValue);
|
|
}
|
|
uint32_t m_uValue;
|
|
};
|
|
|
|
enum EMessageType: uint32_t
|
|
{
|
|
MESSAGE_PLAYER_JOINED,
|
|
MESSAGE_PLAYER_JOINED_CALLBACK,
|
|
MESSAGE_PLAYER_LEFT,
|
|
MESSAGE_ENTITY_CLASS_SYNC,
|
|
MESSAGE_ENTITY_DATA_SYNC,
|
|
|
|
k_EMessage_PlayerSetLocalEntity,
|
|
};
|
|
|
|
struct PlayerJoined_t
|
|
{
|
|
EMessageType m_eType;
|
|
int8_t m_szPlayerName[256];
|
|
};
|
|
|
|
struct PlayerJoinedCallback_t
|
|
{
|
|
EMessageType m_eType;
|
|
CNetworkUInt32 m_uPlayerIndex;
|
|
};
|
|
|
|
struct PlayerLeft_t
|
|
{
|
|
EMessageType m_eType;
|
|
CNetworkUInt32 m_uPlayerIndex;
|
|
};
|
|
|
|
struct EntityClass_t
|
|
{
|
|
EMessageType m_eType;
|
|
CNetworkUInt32 m_uIndex;
|
|
int8_t m_szEntityName[256];
|
|
};
|
|
|
|
struct EntityDataSync_t
|
|
{
|
|
EMessageType m_eType;
|
|
CNetworkUInt32 m_uIndex;
|
|
CNetworkUInt32 m_uCount;
|
|
};
|
|
|
|
struct EntityDataSyncValue_t
|
|
{
|
|
CNetworkUInt32 m_uVariableIndex;
|
|
CNetworkUInt32 m_uVariableSize;
|
|
};
|
|
|
|
struct SetLocalEntity_t
|
|
{
|
|
EMessageType m_eType;
|
|
CNetworkUInt32 m_uIndex;
|
|
};
|
|
|
|
union PlayerPacket_t
|
|
{
|
|
EMessageType m_eType;
|
|
PlayerJoined_t m_playerJoined;
|
|
PlayerJoinedCallback_t m_playerJoinedCallback;
|
|
PlayerLeft_t m_playerLeft;
|
|
EntityClass_t m_entityClass;
|
|
EntityDataSync_t m_entityData;
|
|
SetLocalEntity_t m_setLocalEntity;
|
|
};
|
|
|
|
#endif
|