2021-09-13 15:53:43 +03:00
|
|
|
//
|
|
|
|
// Created by Neirokan on 30.04.2020
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ENGINE_UDPCONNECTION_H
|
|
|
|
#define ENGINE_UDPCONNECTION_H
|
|
|
|
|
|
|
|
#include <SFML/Network.hpp>
|
|
|
|
|
2021-10-12 20:18:56 +03:00
|
|
|
class UDPConnection final {
|
2021-09-13 15:53:43 +03:00
|
|
|
private:
|
2021-10-28 16:58:02 +03:00
|
|
|
const sf::Uint16 _id;
|
|
|
|
const sf::IpAddress _ip;
|
|
|
|
const sf::Uint16 _port;
|
2021-09-13 15:53:43 +03:00
|
|
|
double lastMsg;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit UDPConnection(sf::Uint16 id, sf::IpAddress ip, sf::Uint16 port);
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-09-13 15:53:43 +03:00
|
|
|
[[nodiscard]] sf::Uint16 id() const;
|
2021-10-31 11:39:08 +03:00
|
|
|
|
|
|
|
[[nodiscard]] const sf::IpAddress &ip() const;
|
|
|
|
|
2021-09-13 15:53:43 +03:00
|
|
|
[[nodiscard]] sf::Uint16 port() const;
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-09-13 15:53:43 +03:00
|
|
|
[[nodiscard]] bool timeout() const;
|
2021-10-31 11:39:08 +03:00
|
|
|
|
|
|
|
[[nodiscard]] bool same(sf::IpAddress &ip, sf::Uint16 port) const;
|
|
|
|
|
2021-09-13 15:53:43 +03:00
|
|
|
void update();
|
2021-10-31 11:39:08 +03:00
|
|
|
|
|
|
|
void send(sf::UdpSocket &socket, sf::Packet &packet);
|
2021-09-13 15:53:43 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif //INC_3DZAVR_UDPCONNECTION_H
|