1 #ifndef BLANK_NET_CONNECTIONHANDLER_HPP_
2 #define BLANK_NET_CONNECTIONHANDLER_HPP_
11 class ConnectionHandler {
16 /// packet loss as factor
17 float PacketLoss() const noexcept { return packet_loss; }
18 /// smooth average round trip time in milliseconds
19 float RoundTripTime() const noexcept { return rtt; }
21 void PacketSent(std::uint16_t);
22 void PacketLost(std::uint16_t);
23 void PacketReceived(std::uint16_t);
25 void Handle(const UDPpacket &);
27 virtual void OnTimeout() { }
30 void UpdatePacketLoss() noexcept;
31 void UpdateRTT(std::uint16_t) noexcept;
32 bool SamplePacket(std::uint16_t) const noexcept;
33 int HeadDiff(std::uint16_t) const noexcept;
35 // called as soon as the remote end ack'd given packet
36 virtual void OnPacketReceived(std::uint16_t) { }
37 // called if the remote end probably didn't get given packet
38 virtual void OnPacketLost(std::uint16_t) { }
40 virtual void On(const Packet::Ping &) { }
41 virtual void On(const Packet::Login &) { }
42 virtual void On(const Packet::Join &) { }
43 virtual void On(const Packet::Part &) { }
44 virtual void On(const Packet::PlayerUpdate &) { }
45 virtual void On(const Packet::SpawnEntity &) { }
46 virtual void On(const Packet::DespawnEntity &) { }
47 virtual void On(const Packet::EntityUpdate &) { }
48 virtual void On(const Packet::PlayerCorrection &) { }
49 virtual void On(const Packet::ChunkBegin &) { }
50 virtual void On(const Packet::ChunkData &) { }
51 virtual void On(const Packet::BlockUpdate &) { }
52 virtual void On(const Packet::Message &) { }
55 unsigned int packets_lost;
56 unsigned int packets_received;
60 std::size_t stamp_cursor;
61 std::uint16_t stamp_last;