R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
ENetPeer.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2025
3** Created by IamSwan on 06/12/2025.
4** File description:
5** ENetPeer.hpp
6*/
7
8#pragma once
9
10#include <enet/enet.h>
11#include <memory>
12#include "ENetAddress.hpp"
13#include "IPeer.hpp"
14
15class ENetPeerWrapper final : public IPeer {
16 public:
17 explicit ENetPeerWrapper(ENetPeer *peer);
18
19 bool send(std::unique_ptr<IPacket> packet, uint8_t channelID) override;
20 void disconnect(uint32_t data) override;
21 void disconnectNow(uint32_t data) override;
22 void disconnectLater(uint32_t data) override;
23
24 [[nodiscard]] PeerState getState() const override;
25 [[nodiscard]] const IAddress &getAddress() const override;
26 [[nodiscard]] uint32_t getID() const override;
27 [[nodiscard]] uint32_t getRoundTripTime() const override;
28 void setData(void *data) override;
29 [[nodiscard]] void *getData() const override;
30
31 [[nodiscard]] ENetPeer *getNativePeer() const;
32
33 private:
34 ENetPeer *_peer;
35 mutable std::unique_ptr<ENetAddressWrapper> _cachedAddress;
36};
PeerState
Represents the connection state of a peer.
Definition IPeer.hpp:19
void setData(void *data) override
Set application-specific data associated with this peer.
Definition ENetPeer.cpp:121
uint32_t getRoundTripTime() const override
Get the round-trip time (ping) to this peer.
Definition ENetPeer.cpp:114
void * getData() const override
Get application-specific data associated with this peer.
Definition ENetPeer.cpp:127
ENetPeer * getNativePeer() const
Definition ENetPeer.cpp:59
PeerState getState() const override
Get the current state of this peer.
Definition ENetPeer.cpp:63
ENetPeer * _peer
Definition ENetPeer.hpp:34
void disconnectNow(uint32_t data) override
Force an immediate disconnect from this peer.
Definition ENetPeer.cpp:46
void disconnectLater(uint32_t data) override
Disconnect from this peer after all queued packets are sent.
Definition ENetPeer.cpp:52
void disconnect(uint32_t data) override
Disconnect from this peer.
Definition ENetPeer.cpp:40
bool send(std::unique_ptr< IPacket > packet, uint8_t channelID) override
Send a packet to this peer.
Definition ENetPeer.cpp:19
std::unique_ptr< ENetAddressWrapper > _cachedAddress
Definition ENetPeer.hpp:35
const IAddress & getAddress() const override
Get the address of this peer.
Definition ENetPeer.cpp:94
uint32_t getID() const override
Get a unique identifier for this peer.
Definition ENetPeer.cpp:107
Interface representing a network address (IP + port).
Definition IAddress.hpp:21
Interface representing a remote peer in the network.
Definition IPeer.hpp:40