]> git.localhorst.tv Git - blank.git/blob - src/server/Server.hpp
give network players a model
[blank.git] / src / server / Server.hpp
1 #ifndef BLANK_SERVER_SERVER_HPP
2 #define BLANK_SERVER_SERVER_HPP
3
4 #include <list>
5 #include <SDL_net.h>
6
7
8 namespace blank {
9
10 class CompositeModel;
11 class World;
12
13 namespace server {
14
15 class ClientConnection;
16
17 class Server {
18
19 public:
20         struct Config {
21                 Uint16 port = 12354;
22         };
23
24 public:
25         Server(const Config &, World &);
26         ~Server();
27
28         void Handle();
29
30         void Update(int dt);
31
32         UDPsocket &GetSocket() noexcept { return serv_sock; }
33         UDPpacket &GetPacket() noexcept { return serv_pack; }
34
35         World &GetWorld() noexcept { return world; }
36
37         void SetPlayerModel(const CompositeModel &) noexcept;
38         bool HasPlayerModel() const noexcept;
39         const CompositeModel &GetPlayerModel() const noexcept;
40
41 private:
42         void HandlePacket(const UDPpacket &);
43
44         ClientConnection &GetClient(const IPaddress &);
45
46 private:
47         UDPsocket serv_sock;
48         UDPpacket serv_pack;
49         std::list<ClientConnection> clients;
50
51         World &world;
52         const CompositeModel *player_model;
53
54 };
55
56 }
57 }
58
59 #endif