R-Type
UdpServer.hpp
Go to the documentation of this file.
1 /*
2 ** EPITECH PROJECT, 2023
3 ** UdpServer.hpp
4 ** File description:
5 ** UdpServer
6 */
7 
8 #ifndef UDPSERVER_HPP_
9 #define UDPSERVER_HPP_
10 
12 #include "RType.hpp"
13 #include "SafeQueue.hpp"
15 #include <array>
16 #include <asio.hpp>
17 #include <iostream>
18 #include <map>
19 #include "Entity.hpp"
20 #include "Protocol.hpp"
21 
22 namespace RType::Server
23 {
27  {
28  public:
29  UdpServer(asio::io_context &IOContext, unsigned short port, SafeQueue<struct RType::Event> &eventQueue);
30  ~UdpServer();
31 
35  void handleData(struct RType::Protocol::HeaderDataPacket &header, unsigned short port);
39  void sendInformation(uint8_t packetType, std::vector<std::byte> dataToSend, asio::ip::udp::endpoint &endpoint);
42  void handleString(struct RType::Protocol::HeaderDataPacket header, unsigned short port);
45  void handleConnexion(struct RType::Protocol::HeaderDataPacket header, unsigned short port);
48  void handleDisconnexion(struct RType::Protocol::HeaderDataPacket header, unsigned short port);
50  void run();
51  void handleTextureResponse(struct RType::Protocol::HeaderDataPacket header, unsigned short port);
52  void handleCollisionResponse(struct RType::Protocol::HeaderDataPacket header, unsigned short port);
53  void handleInput(struct RType::Protocol::HeaderDataPacket header, unsigned short port);
54 
55  std::map<unsigned short, asio::ip::udp::endpoint> &getListClients();
56 
57  protected:
58  private:
59  unsigned short indexPlayer;
60  asio::steady_timer _timer;
61  asio::steady_timer _timerTCP;
62  asio::signal_set _signal;
63  SafeQueue<struct RType::Event> &_eventQueue;
64  asio::ip::udp::endpoint _clientEndpoint;
65  std::unordered_map<uint8_t, std::function<void(struct RType::Protocol::HeaderDataPacket, unsigned port)>>
66  _commands;
67  };
68 } // namespace RType::Server
69 #endif /* !UDPSERVER_HPP_ */
Definition: ACommunication.hpp:20
UdpServer Class that create a UDP server that client can connect to communicate.
Definition: UdpServer.hpp:27
void handleString(struct RType::Protocol::HeaderDataPacket header, unsigned short port)
Handle String that will be retrieve and push a event.
Definition: UdpServer.cpp:82
void handleConnexion(struct RType::Protocol::HeaderDataPacket header, unsigned short port)
Handle Connexion that will be retrieve and push a event.
Definition: UdpServer.cpp:100
void handleData(struct RType::Protocol::HeaderDataPacket &header, unsigned short port)
Handle the data depends of the header.
Definition: UdpServer.cpp:109
UdpServer(asio::io_context &IOContext, unsigned short port, SafeQueue< struct RType::Event > &eventQueue)
Definition: UdpServer.cpp:11
void run()
Start the UDP Server.
Definition: UdpServer.cpp:43
~UdpServer()
Definition: UdpServer.cpp:32
void handleInput(struct RType::Protocol::HeaderDataPacket header, unsigned short port)
Definition: UdpServer.cpp:45
void handleTextureResponse(struct RType::Protocol::HeaderDataPacket header, unsigned short port)
Definition: UdpServer.cpp:56
void handleCollisionResponse(struct RType::Protocol::HeaderDataPacket header, unsigned short port)
Definition: UdpServer.cpp:69
void sendInformation(uint8_t packetType, std::vector< std::byte > dataToSend, asio::ip::udp::endpoint &endpoint)
Function that will send informations to connected clients.
Definition: UdpServer.cpp:119
void handleDisconnexion(struct RType::Protocol::HeaderDataPacket header, unsigned short port)
Handle Disconnexion that will be retrieve and push a event.
Definition: UdpServer.cpp:89
std::map< unsigned short, asio::ip::udp::endpoint > & getListClients()
Definition: UdpServer.cpp:117
Definition: ClientSession.hpp:16
Definition: Protocol.hpp:68