vectozavr-shooter/engine/network/ServerUDP.h

58 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_SERVERUDP_H
#define ENGINE_SERVERUDP_H
2021-10-09 13:41:12 +03:00
#include "../World.h"
#include "../Camera.h"
2021-09-13 15:53:43 +03:00
#include "ReliableMsg.h"
#include "UDPSocket.h"
#include <memory>
2022-07-21 05:49:29 +03:00
#include <limits>
2021-09-13 15:53:43 +03:00
#include <set>
2021-10-30 15:59:55 +03:00
class ServerUDP {
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;
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);
std::set<sf::Uint16> _clients{};
public:
explicit ServerUDP();
2021-10-31 11:39:08 +03:00
2021-09-13 15:53:43 +03:00
[[nodiscard]] bool isWorking() const;
2021-10-31 11:39:08 +03:00
2021-09-13 15:53:43 +03:00
bool start(sf::Uint16 port);
2021-10-31 11:39:08 +03:00
2021-09-13 15:53:43 +03:00
void stop();
2021-10-31 11:39:08 +03:00
2021-09-13 15:53:43 +03:00
void update();
2021-10-31 11:39:08 +03:00
virtual void updateInfo() {};
2021-09-13 15:53:43 +03:00
// virtual functions
2021-10-31 11:39:08 +03:00
virtual void broadcast() {};
2021-09-13 15:53:43 +03:00
2021-10-03 07:47:05 +03:00
// here you have to send Init message _back to 'targetId' and send NewClient message to all '_clients'
2021-10-31 11:39:08 +03:00
virtual void processConnect(sf::Uint16 senderId) {};
virtual void processClientUpdate(sf::Uint16 senderId, sf::Packet &packet) {};
virtual void processDisconnect(sf::Uint16 senderId) {};
2021-09-13 15:53:43 +03:00
2021-10-31 11:39:08 +03:00
virtual void processCustomPacket(sf::Packet &packet, sf::Uint16 senderId) {};
2021-09-13 15:53:43 +03:00
2021-10-31 11:39:08 +03:00
virtual void processStop() {};
2021-10-16 20:22:55 +03:00
virtual ~ServerUDP();
2021-09-13 15:53:43 +03:00
};
#endif //INC_3DZAVR_SERVERUDP_H