R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
NetworkFactory.cpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2025
3** Created by IamSwan on 06/12/2025.
4** File description:
5** NetworkFactory.cpp
6*/
7
8#include "NetworkFactory.hpp"
9#include <enet/enet.h>
10#include "Enet/ENetAddress.hpp"
11#include "Enet/ENetHost.hpp"
12#include "Enet/ENetPacket.hpp"
13
15 return enet_initialize() == 0;
16}
17
19 enet_deinitialize();
20}
21
22std::unique_ptr<IHost> createServerHost(const IAddress &address, size_t maxClients, size_t channelLimit,
23 uint32_t incomingBandwidth, uint32_t outgoingBandwidth) {
24 return std::make_unique<ENetHostWrapper>(address, maxClients, channelLimit, incomingBandwidth,
25 outgoingBandwidth);
26}
27
28std::unique_ptr<IHost> createClientHost(size_t channelLimit, uint32_t incomingBandwidth,
29 uint32_t outgoingBandwidth) {
30 return std::make_unique<ENetHostWrapper>(channelLimit, incomingBandwidth, outgoingBandwidth);
31}
32
33std::unique_ptr<IPacket> createPacket(const std::vector<uint8_t> &data, uint32_t flags) {
34 return std::make_unique<ENetPacketWrapper>(data, flags);
35}
36
37std::unique_ptr<IAddress> createAddress(const std::string &host, uint16_t port) {
38 return std::make_unique<ENetAddressWrapper>(host, port);
39}
bool initializeNetworking()
Initialize the networking subsystem.
void deinitializeNetworking()
Cleanup the networking subsystem.
std::unique_ptr< IPacket > createPacket(const std::vector< uint8_t > &data, uint32_t flags)
Create a network packet with the given data and flags.
std::unique_ptr< IAddress > createAddress(const std::string &host, uint16_t port)
Create a network address.
std::unique_ptr< IHost > createClientHost(size_t channelLimit, uint32_t incomingBandwidth, uint32_t outgoingBandwidth)
Create a host for client-side networking.
std::unique_ptr< IHost > createServerHost(const IAddress &address, size_t maxClients, size_t channelLimit, uint32_t incomingBandwidth, uint32_t outgoingBandwidth)
Create a host for server-side networking.
Interface representing a network address (IP + port).
Definition IAddress.hpp:21