64 lines
1.4 KiB
C++
64 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include "blitz/network/Connexion.h"
|
|
|
|
namespace blitz {
|
|
|
|
namespace game {
|
|
|
|
class Player;
|
|
|
|
} // namespace game
|
|
|
|
|
|
namespace server {
|
|
|
|
class Server;
|
|
|
|
struct KeepAlive {
|
|
std::uint64_t keepAliveID = 0;
|
|
std::uint64_t sendTime;
|
|
bool recievedResponse = false;
|
|
};
|
|
|
|
|
|
class ServerConnexion : public network::Connexion {
|
|
private:
|
|
Server* m_Server;
|
|
std::uint8_t m_ID;
|
|
KeepAlive m_KeepAlive;
|
|
game::Player* m_Player;
|
|
std::string m_ChatColor;
|
|
|
|
public:
|
|
ServerConnexion(Server* server, network::TCPSocket& socket, std::uint8_t id);
|
|
ServerConnexion(ServerConnexion&& move);
|
|
virtual ~ServerConnexion();
|
|
|
|
void Start();
|
|
|
|
virtual void HandlePacket(const protocol::PlayerLoginPacket* packet) override;
|
|
virtual void HandlePacket(const protocol::KeepAlivePacket* packet) override;
|
|
virtual void HandlePacket(const protocol::DisconnectPacket* packet) override;
|
|
virtual void HandlePacket(const protocol::ChatPacket* packet) override;
|
|
virtual void HandlePacket(const protocol::PlayerPositionAndRotationPacket* packet) override;
|
|
virtual void HandlePacket(const protocol::PlayerShootPacket* packet) override;
|
|
|
|
std::uint8_t GetID() const {
|
|
return m_ID;
|
|
}
|
|
|
|
virtual bool UpdateSocket();
|
|
|
|
private:
|
|
void RegisterHandlers();
|
|
void CheckKeepAlive();
|
|
void SendKeepAlive();
|
|
void InitConnection();
|
|
void InitPlayerChatColor();
|
|
void SendPlayers();
|
|
};
|
|
|
|
} // namespace server
|
|
} // namespace blitz
|