1 #ifndef BLANK_NET_CLIENTCONNECTION_HPP_
2 #define BLANK_NET_CLIENTCONNECTION_HPP_
4 #include "Connection.hpp"
5 #include "ConnectionHandler.hpp"
16 class ClientConnection
17 : public ConnectionHandler {
20 explicit ClientConnection(Server &, const IPaddress &);
23 bool Matches(const IPaddress &addr) const noexcept { return conn.Matches(addr); }
27 Connection &GetConnection() noexcept { return conn; }
28 bool Disconnected() const noexcept { return conn.Closed(); }
30 void AttachPlayer(Entity &);
32 bool HasPlayer() const noexcept { return player; }
33 Entity &Player() noexcept { return *player; }
34 const Entity &Player() const noexcept { return *player; }
38 // the entity in question
39 Entity *const entity = nullptr;
40 // sequence number of the spawn packet or -1 after it's been ack'd
41 std::int32_t spawn_pack = -1;
42 // sequence number of the despawn packet or -1 if no despawn has been sent
43 std::int32_t despawn_pack = -1;
45 explicit SpawnStatus(Entity &);
50 void OnPacketReceived(std::uint16_t) override;
51 void OnPacketLost(std::uint16_t) override;
53 void On(const Packet::Login &) override;
54 void On(const Packet::Part &) override;
55 void On(const Packet::PlayerUpdate &) override;
57 bool CanSpawn(const Entity &) const noexcept;
58 bool CanDespawn(const Entity &) const noexcept;
60 void SendSpawn(SpawnStatus &);
61 void SendDespawn(SpawnStatus &);
62 void SendUpdate(SpawnStatus &);
68 std::list<SpawnStatus> spawns;
69 unsigned int confirm_wait;