2021-09-13 15:53:43 +03:00
|
|
|
//
|
|
|
|
// Created by Neirokan on 30.04.2020
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ENGINE_CLIENTUDP_H
|
|
|
|
#define ENGINE_CLIENTUDP_H
|
|
|
|
|
|
|
|
#include "ReliableMsg.h"
|
|
|
|
#include "UDPSocket.h"
|
|
|
|
#include <memory>
|
|
|
|
|
2021-10-30 15:59:55 +03:00
|
|
|
class ClientUDP {
|
2021-09-13 15:53:43 +03:00
|
|
|
protected:
|
|
|
|
UDPSocket _socket;
|
2021-10-30 15:59:55 +03:00
|
|
|
double _lastBroadcast = -std::numeric_limits<double>::max();
|
|
|
|
bool _working = false;
|
|
|
|
sf::Uint16 _port{};
|
|
|
|
sf::IpAddress _ip{};
|
2021-09-13 15:53:43 +03:00
|
|
|
|
|
|
|
bool process();
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-09-13 15:53:43 +03:00
|
|
|
bool timeout(sf::Uint16 id);
|
|
|
|
|
|
|
|
public:
|
|
|
|
// create new ClientUDP()
|
|
|
|
explicit ClientUDP();
|
|
|
|
|
|
|
|
[[nodiscard]] bool isWorking() const;
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-09-13 15:53:43 +03:00
|
|
|
[[nodiscard]] bool connected() const;
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-09-13 15:53:43 +03:00
|
|
|
void connect(sf::IpAddress ip, sf::Uint16 port);
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-09-13 15:53:43 +03:00
|
|
|
void disconnect();
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-09-13 15:53:43 +03:00
|
|
|
void update();
|
|
|
|
|
2021-10-28 16:58:02 +03:00
|
|
|
[[nodiscard]] sf::IpAddress serverIp() const { return _ip; }
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-10-28 16:58:02 +03:00
|
|
|
[[nodiscard]] sf::Uint16 serverPort() const { return _port; }
|
2021-10-25 22:32:55 +03:00
|
|
|
|
2021-09-13 15:53:43 +03:00
|
|
|
// virtual functions
|
2021-10-31 11:39:08 +03:00
|
|
|
virtual void updatePacket() {};
|
|
|
|
|
|
|
|
virtual void processInit(sf::Packet &packet) {};
|
|
|
|
|
|
|
|
virtual void processUpdate(sf::Packet &packet) {};
|
|
|
|
|
|
|
|
virtual void processNewClient(sf::Packet &packet) {};
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-31 11:39:08 +03:00
|
|
|
virtual void processDisconnect(sf::Uint16 targetId) {};
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-31 11:39:08 +03:00
|
|
|
virtual void processCustomPacket(sf::Packet &packet) {};
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-31 11:39:08 +03:00
|
|
|
virtual void processDisconnected() {};
|
2021-10-16 20:22:55 +03:00
|
|
|
|
|
|
|
virtual ~ClientUDP() = default;
|
2021-09-13 15:53:43 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif //INC_3DZAVR_CLIENTUDP_H
|