vectozavr-shooter/engine/network/ClientUDP.h

53 lines
1.2 KiB
C
Raw Normal View History

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>
class ClientUDP
{
protected:
UDPSocket _socket;
double _lastBroadcast;
bool _working;
2021-10-25 22:32:55 +03:00
sf::Uint16 _port;
sf::IpAddress _ip;
2021-09-13 15:53:43 +03:00
bool process();
bool timeout(sf::Uint16 id);
public:
// create new ClientUDP()
explicit ClientUDP();
[[nodiscard]] bool isWorking() const;
[[nodiscard]] bool connected() const;
void connect(sf::IpAddress ip, sf::Uint16 port);
void disconnect();
void update();
2021-10-25 22:32:55 +03:00
[[nodiscard]] sf::IpAddress ip() const { return _ip; }
[[nodiscard]] sf::Uint16 port() const { return _port; }
2021-09-13 15:53:43 +03:00
// virtual functions
virtual void updatePacket(){};
virtual void processInit(sf::Packet& packet){};
virtual void processUpdate(sf::Packet& packet){};
virtual void processNewClient(sf::Packet& packet){};
virtual void processDisconnect(sf::Uint16 targetId){};
virtual void processCustomPacket(MsgType type, sf::Packet& packet){};
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