]> git.localhorst.tv Git - blank.git/blob - src/net/ClientConnection.hpp
also tell connection handlers about ack'd packets
[blank.git] / src / net / ClientConnection.hpp
1 #ifndef BLANK_NET_CLIENTCONNECTION_HPP_
2 #define BLANK_NET_CLIENTCONNECTION_HPP_
3
4 #include "Connection.hpp"
5 #include "ConnectionHandler.hpp"
6
7 #include <SDL_net.h>
8
9
10 namespace blank {
11
12 class Entity;
13 class Server;
14
15 class ClientConnection
16 : public ConnectionHandler {
17
18 public:
19         explicit ClientConnection(Server &, const IPaddress &);
20         ~ClientConnection();
21
22         bool Matches(const IPaddress &addr) const noexcept { return conn.Matches(addr); }
23
24         void Update(int dt);
25
26         Connection &GetConnection() noexcept { return conn; }
27         bool Disconnected() const noexcept { return conn.Closed(); }
28
29         void AttachPlayer(Entity &);
30         void DetachPlayer();
31         bool HasPlayer() const noexcept { return player; }
32         Entity &Player() noexcept { return *player; }
33
34         void On(const Packet::Login &) override;
35         void On(const Packet::Part &) override;
36         void On(const Packet::PlayerUpdate &) override;
37
38 private:
39         Server &server;
40         Connection conn;
41         Entity *player;
42
43 };
44
45 }
46
47 #endif