1 #ifndef BLANK_NET_CLIENTCONNECTION_HPP_
2 #define BLANK_NET_CLIENTCONNECTION_HPP_
4 #include "Connection.hpp"
5 #include "ConnectionHandler.hpp"
6 #include "../app/IntervalTimer.hpp"
17 class ClientConnection
18 : public ConnectionHandler {
21 explicit ClientConnection(Server &, const IPaddress &);
24 bool Matches(const IPaddress &addr) const noexcept { return conn.Matches(addr); }
28 Connection &GetConnection() noexcept { return conn; }
29 bool Disconnected() const noexcept { return conn.Closed(); }
31 void AttachPlayer(Entity &);
33 bool HasPlayer() const noexcept { return player; }
34 Entity &Player() noexcept { return *player; }
35 const Entity &Player() const noexcept { return *player; }
39 // the entity in question
40 Entity *const entity = nullptr;
41 // sequence number of the spawn packet or -1 after it's been ack'd
42 std::int32_t spawn_pack = -1;
43 // sequence number of the despawn packet or -1 if no despawn has been sent
44 std::int32_t despawn_pack = -1;
46 explicit SpawnStatus(Entity &);
51 void OnPacketReceived(std::uint16_t) override;
52 void OnPacketLost(std::uint16_t) override;
54 void On(const Packet::Login &) override;
55 void On(const Packet::Part &) override;
56 void On(const Packet::PlayerUpdate &) override;
58 bool CanSpawn(const Entity &) const noexcept;
59 bool CanDespawn(const Entity &) const noexcept;
61 void SendSpawn(SpawnStatus &);
62 void SendDespawn(SpawnStatus &);
63 void SendUpdate(SpawnStatus &);
69 std::list<SpawnStatus> spawns;
70 unsigned int confirm_wait;
71 std::uint16_t player_update_pack;
72 IntervalTimer player_update_timer;