]> git.localhorst.tv Git - blank.git/blob - src/server/Server.hpp
fix Location for debug build
[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 "../shared/CLI.hpp"
6 #include "../world/World.hpp"
7 #include "../world/WorldManipulator.hpp"
8
9 #include <cstdint>
10 #include <list>
11 #include <SDL_net.h>
12
13
14 namespace blank {
15
16 class ChunkIndex;
17 class Model;
18 class Player;
19 class WorldSave;
20
21 namespace server {
22
23 class ClientConnection;
24
25 class Server
26 : public WorldManipulator {
27
28 public:
29         Server(const Config::Network &, World &, const World::Config &, const WorldSave &);
30         ~Server();
31
32         // wait for data to arrive for at most dt milliseconds
33         void Wait(int dt) noexcept;
34         // true if there's data waiting to be handled
35         bool Ready() noexcept;
36         void Handle();
37
38         void Update(int dt);
39
40         UDPsocket &GetSocket() noexcept { return serv_sock; }
41         UDPpacket &GetPacket() noexcept { return serv_pack; }
42
43         World &GetWorld() noexcept { return world; }
44         const WorldSave &GetWorldSave() noexcept { return save; }
45
46         void SetPlayerModel(const Model &) noexcept;
47         bool HasPlayerModel() const noexcept;
48         const Model &GetPlayerModel() const noexcept;
49
50         Player *JoinPlayer(const std::string &name);
51
52         void SetBlock(Chunk &, int, const Block &) override;
53
54         /// for use by client connections when they receive a line from the player
55         void DispatchMessage(Player &, const std::string &);
56
57         /// send message to all connected clients
58         void DistributeMessage(std::uint8_t type, std::uint32_t ref, const std::string &msg);
59
60 private:
61         void HandlePacket(const UDPpacket &);
62
63         ClientConnection &GetClient(const IPaddress &);
64
65         void SendAll();
66
67 private:
68         UDPsocket serv_sock;
69         UDPpacket serv_pack;
70         SDLNet_SocketSet serv_set;
71         std::list<ClientConnection> clients;
72
73         World &world;
74         ChunkIndex &spawn_index;
75         const WorldSave &save;
76         const Model *player_model;
77
78         CLI cli;
79
80 };
81
82 }
83 }
84
85 #endif