networking i guess

This commit is contained in:
2026-02-28 21:07:44 +02:00
parent e83f7cd448
commit 03c560c2b7
68 changed files with 1348 additions and 121 deletions

76
game/shared/netprotocol.h Normal file
View File

@@ -0,0 +1,76 @@
#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,
};
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;
};
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;
};
#endif