]> git.localhorst.tv Git - blank.git/blob - src/server/Server.hpp
composite model is the canonical model
[blank.git] / src / server / Server.hpp
1 #ifndef BLANK_SERVER_SERVER_HPP
2 #define BLANK_SERVER_SERVER_HPP
3
4 #include "../app/Config.hpp"
5 #include "../world/World.hpp"
6 #include "../world/WorldManipulator.hpp"
7
8 #include <list>
9 #include <SDL_net.h>
10
11
12 namespace blank {
13
14 class ChunkIndex;
15 class Model;
16 class Player;
17 class WorldSave;
18
19 namespace server {
20
21 class ClientConnection;
22
23 class Server
24 : public WorldManipulator {
25
26 public:
27         Server(const Config::Network &, World &, const World::Config &, const WorldSave &);
28         ~Server();
29
30         void Handle();
31
32         void Update(int dt);
33
34         UDPsocket &GetSocket() noexcept { return serv_sock; }
35         UDPpacket &GetPacket() noexcept { return serv_pack; }
36
37         World &GetWorld() noexcept { return world; }
38         const WorldSave &GetWorldSave() noexcept { return save; }
39
40         void SetPlayerModel(const Model &) noexcept;
41         bool HasPlayerModel() const noexcept;
42         const Model &GetPlayerModel() const noexcept;
43
44         Player *JoinPlayer(const std::string &name);
45
46         void SetBlock(Chunk &, int, const Block &) override;
47
48 private:
49         void HandlePacket(const UDPpacket &);
50
51         ClientConnection &GetClient(const IPaddress &);
52
53 private:
54         UDPsocket serv_sock;
55         UDPpacket serv_pack;
56         std::list<ClientConnection> clients;
57
58         World &world;
59         ChunkIndex &spawn_index;
60         const WorldSave &save;
61         const Model *player_model;
62
63 };
64
65 }
66 }
67
68 #endif