]> git.localhorst.tv Git - blank.git/blob - src/server/Server.hpp
added simple command line
[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         void Handle();
33
34         void Update(int dt);
35
36         UDPsocket &GetSocket() noexcept { return serv_sock; }
37         UDPpacket &GetPacket() noexcept { return serv_pack; }
38
39         World &GetWorld() noexcept { return world; }
40         const WorldSave &GetWorldSave() noexcept { return save; }
41
42         void SetPlayerModel(const Model &) noexcept;
43         bool HasPlayerModel() const noexcept;
44         const Model &GetPlayerModel() const noexcept;
45
46         Player *JoinPlayer(const std::string &name);
47
48         void SetBlock(Chunk &, int, const Block &) override;
49
50         /// for use by client connections when they receive a line from the player
51         void DispatchMessage(Player &, const std::string &);
52
53         /// send message to all connected clients
54         void DistributeMessage(std::uint8_t type, std::uint32_t ref, const std::string &msg);
55
56 private:
57         void HandlePacket(const UDPpacket &);
58
59         ClientConnection &GetClient(const IPaddress &);
60
61         void SendAll();
62
63 private:
64         UDPsocket serv_sock;
65         UDPpacket serv_pack;
66         std::list<ClientConnection> clients;
67
68         World &world;
69         ChunkIndex &spawn_index;
70         const WorldSave &save;
71         const Model *player_model;
72
73         CLI cli;
74
75 };
76
77 }
78 }
79
80 #endif