]> git.localhorst.tv Git - blank.git/blob - src/net/Client.hpp
ee848c0d74729db9976cf382ccfe8ad1d83b512d
[blank.git] / src / net / Client.hpp
1 #ifndef BLANK_NET_CLIENT_HPP_
2 #define BLANK_NET_CLIENT_HPP_
3
4 #include "Connection.hpp"
5 #include "../app/IntervalTimer.hpp"
6
7 #include <string>
8 #include <SDL_net.h>
9
10
11 namespace blank {
12
13 class World;
14
15 class Client {
16
17 public:
18         struct Config {
19                 std::string host = "localhost";
20                 Uint16 port = 12354;
21         };
22
23 public:
24         explicit Client(const Config &);
25         ~Client();
26
27         void Handle();
28
29         void Update(int dt);
30
31         Connection &GetConnection() noexcept { return conn; }
32         const Connection &GetConnection() const noexcept { return conn; }
33
34         std::uint16_t SendPing();
35         std::uint16_t SendLogin(const std::string &);
36         std::uint16_t SendPart();
37         // this may not send the update at all, in which case it returns -1
38         int SendPlayerUpdate(const Entity &);
39
40 private:
41         void HandlePacket(const UDPpacket &);
42
43 private:
44         Connection conn;
45         UDPsocket client_sock;
46         UDPpacket client_pack;
47         IntervalTimer update_timer;
48
49 };
50
51 }
52
53 #endif