R-Type  1.0.1.0
Rewrite of the R-Type game with networking ability
Loading...
Searching...
No Matches
NetworkManager.hpp
1/*
2** EPITECH PROJECT, 2023
3** Network.hpp
4** File description:
5** Network.hpp
6*/
7
8#ifndef R_TYPE_NETWORKMANAGER_HPP
9#define R_TYPE_NETWORKMANAGER_HPP
10
11#include "uranus/engine/Engine.hpp"
12#include "Packets.hpp"
13#include "Random.hpp"
14#include <saturnity/Saturnity.hpp>
15
16namespace rtype::client::network {
18 public:
19 static std::shared_ptr<NetworkManager> &getInstance();
20
21 void init();
22
23 void connectTcpClient(const std::string &host, std::uint16_t port);
24 void connectUdpClient(const std::string &host, std::uint16_t port);
25
26 void runTcpClient();
27 void runUdpClient();
28
29 void stopTcpClient();
30 void stopUdpClient();
31
32 void send(sa::AbstractPacket &packet);
33 void send(const std::shared_ptr<sa::AbstractPacket> &packet);
34 void send(const std::unique_ptr<sa::AbstractPacket> &packet);
35
36 const std::shared_ptr<sa::TCPClient> &getTcpClient() const
37 {
38 return _tcpClient;
39 }
40
41 const std::shared_ptr<sa::UDPClient> &getUdpClient() const
42 {
43 return _udpClient;
44 }
45
46 std::string imGuiHost = "127.0.0.1";
47 std::string imGuiTcpPort = "2409";
48 std::string imGuiUdpPort = "2410";
49 std::string imGuiUsername; // NOLINT
50 bool imGuiReady;
51 std::uint16_t tcpPort = 2409;
52 std::uint16_t udpPort = 2410;
53
54 std::uint32_t uid = 0;
55 private:
56 Random _random;
57
59 {
60 imGuiUsername = "Player-" + std::to_string(_random.generate(0, 99999999));
61// this->imGuiHost.reserve(128);
62// this->imGuiTcpPort.reserve(128);
63// this->imGuiUdpPort.reserve(128);
64// this->imGuiUsername.reserve(128);
65 this->imGuiReady = false;
66 }
67
68 static std::shared_ptr<NetworkManager> networkManager;
69 std::shared_ptr<spdlog::logger> _logger;
70
71 std::shared_ptr<sa::PacketRegistry> _udpPacketRegistry;
72 std::shared_ptr<sa::PacketRegistry> _tcpPacketRegistry;
73
74 std::shared_ptr<sa::TCPClient> _tcpClient;
75 std::shared_ptr<sa::UDPClient> _udpClient;
76
77 void registerUdpCallback();
78 void registerTcpCallback();
79
80 void registerUdpPacketHandlers();
81 void registerTcpPacketHandlers();
82 };
83}
84
85#endif //R_TYPE_NETWORKMANAGER_HPP
All packets used in the project.
Definition: Random.hpp:13
short generate(short min, short max)
Generate a random short using the std::default_random_engine & uniform_int_distribution.
Definition: Random.hpp:26
Definition: NetworkManager.hpp:17