R-Type
UdpClient.hpp
Go to the documentation of this file.
1 /*
2 ** EPITECH PROJECT, 2023
3 ** UdpClient.hpp
4 ** File description:
5 ** UdpClient
6 */
7 
8 #ifndef UDPCLIENT_HPP_
9 #define UDPCLIENT_HPP_
10 
12 #include "RType.hpp"
14 #include <asio.hpp>
15 #include <iostream>
16 #include "SafeQueue.hpp"
17 
18 namespace RType::Client
19 {
21  {
22  public:
23  UdpClient(asio::io_context &IOContext, asio::ip::udp::endpoint &serverEndpoint,
24  SafeQueue<struct RType::Event> &eventQueue);
25  ~UdpClient();
26 
27  void handleTransformComponent(struct RType::Protocol::HeaderDataPacket header, unsigned short port);
28  void handleTextureComponent(struct RType::Protocol::HeaderDataPacket header, unsigned short port);
29  void handleCollisionComponent(struct RType::Protocol::HeaderDataPacket header, unsigned short port);
30  void handleControllableComponent(struct RType::Protocol::HeaderDataPacket header, unsigned short port);
31  void handleTextureState(struct RType::Protocol::HeaderDataPacket header, unsigned short port);
32  void handleScore(struct RType::Protocol::HeaderDataPacket header, unsigned short port);
33  void handleEndGame(struct RType::Protocol::HeaderDataPacket header, unsigned short port);
34 
37  void handleString(struct RType::Protocol::HeaderDataPacket header, unsigned short port);
40  void handleDisconnexion(struct RType::Protocol::HeaderDataPacket header, unsigned short port);
44  void sendDataInformation(std::vector<std::byte> dataInformation, uint8_t packetType);
46  void run();
50  void handleData(struct RType::Protocol::HeaderDataPacket &, unsigned short port);
51 
52  protected:
53  private:
54  asio::io_context &_IOContext;
55  asio::ip::udp::endpoint &_serverEndpoint;
56  std::unordered_map<uint8_t,
57  std::function<void(struct RType::Protocol::HeaderDataPacket header, unsigned short port)>>
58  _commands;
59  SafeQueue<struct RType::Event> &_eventQueue;
60  };
61 } // namespace RType::Client
62 #endif /* !UDPCLIENT_HPP_ */
Definition: ACommunication.hpp:20
Definition: UdpClient.hpp:21
void handleControllableComponent(struct RType::Protocol::HeaderDataPacket header, unsigned short port)
Definition: UdpClient.cpp:50
~UdpClient()
Definition: UdpClient.cpp:39
void handleCollisionComponent(struct RType::Protocol::HeaderDataPacket header, unsigned short port)
Definition: UdpClient.cpp:98
void run()
Launch the Udp Client.
Definition: UdpClient.cpp:144
void handleString(struct RType::Protocol::HeaderDataPacket header, unsigned short port)
Handle String.
Definition: UdpClient.cpp:108
UdpClient(asio::io_context &IOContext, asio::ip::udp::endpoint &serverEndpoint, SafeQueue< struct RType::Event > &eventQueue)
Definition: UdpClient.cpp:11
void handleEndGame(struct RType::Protocol::HeaderDataPacket header, unsigned short port)
Definition: UdpClient.cpp:41
void handleData(struct RType::Protocol::HeaderDataPacket &, unsigned short port)
Handle the data depends of the header.
Definition: UdpClient.cpp:130
void handleDisconnexion(struct RType::Protocol::HeaderDataPacket header, unsigned short port)
Handle Disconnexion.
Definition: UdpClient.cpp:121
void handleTextureComponent(struct RType::Protocol::HeaderDataPacket header, unsigned short port)
Definition: UdpClient.cpp:88
void handleScore(struct RType::Protocol::HeaderDataPacket header, unsigned short port)
Definition: UdpClient.cpp:70
void sendDataInformation(std::vector< std::byte > dataInformation, uint8_t packetType)
Function that will send information to the server.
Definition: UdpClient.cpp:138
void handleTransformComponent(struct RType::Protocol::HeaderDataPacket header, unsigned short port)
Definition: UdpClient.cpp:60
void handleTextureState(struct RType::Protocol::HeaderDataPacket header, unsigned short port)
Definition: UdpClient.cpp:79
Definition: RTypeClient.hpp:20
Definition: Protocol.hpp:68