Well for example i have this packet struct
class HeaderPacket
{
protected:
std::vector<char> data;
public:
const std::vector<char> getData() { return data; }
HeaderPacket(char cmd = 0, unsigned int id = 0)
{
data.insert(data.end(), cmd, sizeof(cmd));
data.insert(data.end(), id, sizeof(id));
}
};
A simple enum with the packets types
enum PacketType : char
{
PACKET_Handshake = 0x01,
PACKET_Hello = 0x02
};
And when my client connect, I do that :
HeaderPacket *thepacket = new HeaderPacket(PACKET_Handshake, 5);
ENetPacket *packet = enet_packet_create(&thepacket->getData(), thepacket->getData().size(), ENET_PACKET_FLAG_RELIABLE);
enet_peer_send(event.peer, 0, packet);
There is probably beginner errors, sorry