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"
7 #include "../world/EntityState.hpp"
18 class ClientConnection
19 : public ConnectionHandler {
22 explicit ClientConnection(Server &, const IPaddress &);
25 bool Matches(const IPaddress &addr) const noexcept { return conn.Matches(addr); }
29 Connection &GetConnection() noexcept { return conn; }
30 bool Disconnected() const noexcept { return conn.Closed(); }
32 void AttachPlayer(Entity &);
34 bool HasPlayer() const noexcept { return player; }
35 Entity &Player() noexcept { return *player; }
36 const Entity &Player() const noexcept { return *player; }
40 // the entity in question
41 Entity *const entity = nullptr;
42 // sequence number of the spawn packet or -1 after it's been ack'd
43 std::int32_t spawn_pack = -1;
44 // sequence number of the despawn packet or -1 if no despawn has been sent
45 std::int32_t despawn_pack = -1;
47 explicit SpawnStatus(Entity &);
52 void OnPacketReceived(std::uint16_t) override;
53 void OnPacketLost(std::uint16_t) override;
55 void On(const Packet::Login &) override;
56 void On(const Packet::Part &) override;
57 void On(const Packet::PlayerUpdate &) override;
59 bool CanSpawn(const Entity &) const noexcept;
60 bool CanDespawn(const Entity &) const noexcept;
62 void SendSpawn(SpawnStatus &);
63 void SendDespawn(SpawnStatus &);
64 void SendUpdate(SpawnStatus &);
66 void CheckPlayerFix();
72 std::list<SpawnStatus> spawns;
73 unsigned int confirm_wait;
74 EntityState player_update_state;
75 std::uint16_t player_update_pack;
76 IntervalTimer player_update_timer;