R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
IPeer.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** IPeer.hpp
6*/
7
8#pragma once
9
10#include <cstdint>
11#include <memory>
12#include "IAddress.hpp"
13#include "IPacket.hpp"
14
31
40class IPeer {
41 public:
42 virtual ~IPeer() = default;
43
51 virtual bool send(std::unique_ptr<IPacket> packet, uint8_t channelID = 0) = 0;
52
58 virtual void disconnect(uint32_t data = 0) = 0;
59
65 virtual void disconnectNow(uint32_t data = 0) = 0;
66
72 virtual void disconnectLater(uint32_t data = 0) = 0;
73
78 [[nodiscard]] virtual PeerState getState() const = 0;
79
84 [[nodiscard]] virtual const IAddress &getAddress() const = 0;
85
90 [[nodiscard]] virtual uint32_t getID() const = 0;
91
96 [[nodiscard]] virtual uint32_t getRoundTripTime() const = 0;
97
102 virtual void setData(void *data) = 0;
103
108 [[nodiscard]] virtual void *getData() const = 0;
109};
PeerState
Represents the connection state of a peer.
Definition IPeer.hpp:19
@ CONNECTION_SUCCEEDED
Connection has succeeded.
@ DISCONNECT_LATER
Peer is scheduled to disconnect.
@ ACKNOWLEDGING_CONNECT
Connection acknowledgment is being sent.
@ ACKNOWLEDGING_DISCONNECT
Disconnect acknowledgment is being sent.
@ ZOMBIE
Peer is in a zombie state.
@ CONNECTION_PENDING
Connection is pending.
@ DISCONNECTED
Peer is disconnected.
@ CONNECTING
Connection to peer is being established.
@ CONNECTED
Peer is connected.
@ DISCONNECTING
Disconnection is in progress.
Interface representing a network address (IP + port).
Definition IAddress.hpp:21
Interface representing a remote peer in the network.
Definition IPeer.hpp:40
virtual void disconnect(uint32_t data=0)=0
Disconnect from this peer.
virtual const IAddress & getAddress() const =0
Get the address of this peer.
virtual uint32_t getID() const =0
Get a unique identifier for this peer.
virtual void disconnectLater(uint32_t data=0)=0
Disconnect from this peer after all queued packets are sent.
virtual void * getData() const =0
Get application-specific data associated with this peer.
virtual PeerState getState() const =0
Get the current state of this peer.
virtual bool send(std::unique_ptr< IPacket > packet, uint8_t channelID=0)=0
Send a packet to this peer.
virtual void disconnectNow(uint32_t data=0)=0
Force an immediate disconnect from this peer.
virtual void setData(void *data)=0
Set application-specific data associated with this peer.
virtual uint32_t getRoundTripTime() const =0
Get the round-trip time (ping) to this peer.
virtual ~IPeer()=default