1#ifndef BOMBERMAN_NET_NETSEND_H
2#define BOMBERMAN_NET_NETSEND_H
29 template<std::
size_t N>
33 const uint8_t channelId =
static_cast<uint8_t
>(channel);
34 ENetPacket* pkt = enet_packet_create(bytes.data(), bytes.size(), flags);
37 LOG_NET_PACKET_ERROR(
"Failed to allocate packet ({} bytes) for channel {}",
42 if (enet_peer_send(peer, channelId, pkt) != 0)
44 LOG_NET_PACKET_ERROR(
"Failed to queue packet on channel {}",
channelName(channelId));
45 enet_packet_destroy(pkt);
53 inline void flush(ENetHost* host)
55 if (host ==
nullptr)
return;
57 enet_host_flush(host);
61 template<std::
size_t N>
65 return queueOnChannel(peer, EChannel::ControlReliable, ENET_PACKET_FLAG_RELIABLE, bytes);
69 template<std::
size_t N>
73 return queueOnChannel(peer, EChannel::GameplayReliable, ENET_PACKET_FLAG_RELIABLE, bytes);
77 template<std::
size_t N>
85 template<std::
size_t N>
89 return queueOnChannel(peer, EChannel::SnapshotUnreliable, 0, bytes);
93 template<std::
size_t N>
97 return queueOnChannel(peer, EChannel::CorrectionUnreliable, 0, bytes);
Shared client/server wire contract for the multiplayer protocol.
Shared multiplayer protocol types and transport-facing wire helpers.
Definition ClientPrediction.cpp:13
bool queueUnreliableInput(ENetPeer *peer, const std::array< uint8_t, N > &bytes)
Queues an unreliable input packet.
Definition NetSend.h:79
bool queueOnChannel(ENetPeer *peer, EChannel channel, uint32_t flags, const std::array< uint8_t, N > &bytes)
Queues a pre-serialized byte buffer on an explicit channel.
Definition NetSend.h:31
EChannel
ENet channel identifiers used by the current protocol.
Definition NetCommon.h:108
constexpr std::string_view channelName(uint8_t id)
Returns a human-readable name for a channel ID.
Definition NetCommon.h:118
void flush(ENetHost *host)
Flushes all currently queued packets for this host.
Definition NetSend.h:53
bool queueReliableGame(ENetPeer *peer, const std::array< uint8_t, N > &bytes)
Queues a reliable gameplay packet.
Definition NetSend.h:71
bool queueUnreliableSnapshot(ENetPeer *peer, const std::array< uint8_t, N > &bytes)
Queues an unreliable snapshot packet.
Definition NetSend.h:87
bool queueReliableControl(ENetPeer *peer, const std::array< uint8_t, N > &bytes)
Queues a reliable control packet.
Definition NetSend.h:63
bool queueUnreliableCorrection(ENetPeer *peer, const std::array< uint8_t, N > &bytes)
Queues an unreliable owner-correction packet.
Definition NetSend.h:95