1 #ifndef BLANK_SERVER_SERVER_HPP
2 #define BLANK_SERVER_SERVER_HPP
4 #include "../app/Config.hpp"
5 #include "../shared/CLI.hpp"
6 #include "../world/World.hpp"
7 #include "../world/WorldManipulator.hpp"
26 class ClientConnection;
29 : public WorldManipulator {
32 Server(const Config::Network &, World &, const World::Config &, const WorldSave &);
35 // wait for data to arrive for at most dt milliseconds
36 void Wait(int dt) noexcept;
37 // true if there's data waiting to be handled
38 bool Ready() noexcept;
43 UDPsocket &GetSocket() noexcept { return serv_sock; }
44 UDPpacket &GetPacket() noexcept { return serv_pack; }
46 World &GetWorld() noexcept { return world; }
47 const WorldSave &GetWorldSave() noexcept { return save; }
49 void SetPlayerModel(const Model &) noexcept;
50 bool HasPlayerModel() const noexcept;
51 const Model &GetPlayerModel() const noexcept;
53 Player *JoinPlayer(const std::string &name);
55 void SetBlock(Chunk &, int, const Block &) override;
57 /// for use by client connections when they receive a line from the player
58 void DispatchMessage(CLIContext &, const std::string &);
60 /// send message to all connected clients
61 void DistributeMessage(std::uint8_t type, std::uint32_t ref, const std::string &msg);
64 void HandlePacket(const UDPpacket &);
66 ClientConnection &GetClient(const IPaddress &);
73 SDLNet_SocketSet serv_set;
74 std::list<ClientConnection> clients;
77 ChunkIndex &spawn_index;
78 const WorldSave &save;
79 const Model *player_model;
82 std::unique_ptr<CommandService> cmd_srv;