Network code documentation for my turn-based game 1.0
Loading...
Searching...
No Matches
server_network_interface.h
Go to the documentation of this file.
1#pragma once
2
3#include "packet.h"
4
5#include <functional>
6
12 public:
13 ServerNetworkInterface() noexcept = default;
15 default;
17 ServerNetworkInterface&& other) noexcept = default;
19 const ServerNetworkInterface& other) noexcept = default;
21 const ServerNetworkInterface& other) = default;
22 virtual ~ServerNetworkInterface() noexcept = default;
23
24 virtual void SendPacket(sf::Packet* packet, Port client_id) noexcept = 0;
25
31 virtual void PollEvents() noexcept = 0;
32
34 const std::function<void(ClientPacket* client_packet)>& callback) {
36 }
37
39 const std::function<void(Port client_port)>& callback) {
40 disconnect_callback_ = callback;
41 }
42
43protected:
44 std::function<void(ClientPacket* packet_data)> packet_received_callback_;
45 std::function<void(Port client_port)> disconnect_callback_;
46};
ServerNetworkInterface is an interface to communicates with multiple clients.
Definition server_network_interface.h:11
std::function< void(Port client_port)> disconnect_callback_
Definition server_network_interface.h:45
void RegisterClientDisconnectionCallback(const std::function< void(Port client_port)> &callback)
Definition server_network_interface.h:38
void RegisterPacketReceivedCallback(const std::function< void(ClientPacket *client_packet)> &callback)
Definition server_network_interface.h:33
std::function< void(ClientPacket *packet_data) packet_received_callback_)
Definition server_network_interface.h:44
ServerNetworkInterface() noexcept=default
virtual void SendPacket(sf::Packet *packet, Port client_id) noexcept=0
virtual void PollEvents() noexcept=0
PollEvents is a pure virtual method which must poll the network events such as client connections/dis...
ClientPacket is an object containing data that a client wishes to send to the server and its remote p...
Definition packet.h:24
std::uint16_t Port
Definition types.h:19