]> git.localhorst.tv Git - blank.git/blob - src/net/Connection.hpp
defined and implemented join and part packets
[blank.git] / src / net / Connection.hpp
1 #ifndef BLANK_NET_CONNECTION_HPP_
2 #define BLANK_NET_CONNECTION_HPP_
3
4 #include "Packet.hpp"
5 #include "../app/IntervalTimer.hpp"
6
7 #include <cstdint>
8 #include <SDL_net.h>
9
10
11 namespace blank {
12
13 class Connection {
14
15 public:
16         explicit Connection(const IPaddress &);
17
18         const IPaddress &Address() const noexcept { return addr; }
19
20         bool Matches(const IPaddress &) const noexcept;
21
22         bool ShouldPing() const noexcept;
23         bool TimedOut() const noexcept;
24
25         void Close() noexcept { closed = true; }
26         bool Closed() const noexcept { return closed || TimedOut(); }
27
28         void Update(int dt);
29
30         void SendPing(UDPpacket &, UDPsocket);
31
32         void Send(UDPpacket &, UDPsocket);
33         void Received(const UDPpacket &);
34
35 private:
36         void FlagSend() noexcept;
37         void FlagRecv() noexcept;
38
39 private:
40         IPaddress addr;
41         IntervalTimer send_timer;
42         IntervalTimer recv_timer;
43
44         Packet::TControl ctrl;
45
46         bool closed;
47
48 };
49
50 }
51
52 #endif