X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fnet%2FClientConnection.hpp;h=fb6420acfed074959df27449741d3cb80cb5526c;hb=36923ee2defd0848c5a530721114d4e553872305;hp=acbee6ec98ce47a7ee15979e4f296f1efc4e36b1;hpb=99345b497912db65204d48348140fc774dcb6989;p=blank.git diff --git a/src/net/ClientConnection.hpp b/src/net/ClientConnection.hpp index acbee6e..fb6420a 100644 --- a/src/net/ClientConnection.hpp +++ b/src/net/ClientConnection.hpp @@ -4,6 +4,7 @@ #include "Connection.hpp" #include "ConnectionHandler.hpp" +#include #include @@ -28,14 +29,44 @@ public: void AttachPlayer(Entity &); void DetachPlayer(); + bool HasPlayer() const noexcept { return player; } + Entity &Player() noexcept { return *player; } + const Entity &Player() const noexcept { return *player; } + +private: + struct SpawnStatus { + // the entity in question + Entity *const entity = nullptr; + // sequence number of the spawn packet or -1 after it's been ack'd + std::int32_t spawn_pack = -1; + // sequence number of the despawn packet or -1 if no despawn has been sent + std::int32_t despawn_pack = -1; + + explicit SpawnStatus(Entity &); + ~SpawnStatus(); + }; + +private: + void OnPacketReceived(std::uint16_t) override; + void OnPacketLost(std::uint16_t) override; void On(const Packet::Login &) override; void On(const Packet::Part &) override; + void On(const Packet::PlayerUpdate &) override; + + bool CanSpawn(const Entity &) const noexcept; + bool CanDespawn(const Entity &) const noexcept; + + void SendSpawn(SpawnStatus &); + void SendDespawn(SpawnStatus &); + void SendUpdate(SpawnStatus &); private: Server &server; Connection conn; Entity *player; + std::list spawns; + unsigned int confirm_wait; };