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"
24 class ClientConnection;
27 : public WorldManipulator {
30 Server(const Config::Network &, World &, const World::Config &, const WorldSave &);
33 // wait for data to arrive for at most dt milliseconds
34 void Wait(int dt) noexcept;
35 // true if there's data waiting to be handled
36 bool Ready() noexcept;
41 UDPsocket &GetSocket() noexcept { return serv_sock; }
42 UDPpacket &GetPacket() noexcept { return serv_pack; }
44 World &GetWorld() noexcept { return world; }
45 const WorldSave &GetWorldSave() noexcept { return save; }
47 void SetPlayerModel(const Model &) noexcept;
48 bool HasPlayerModel() const noexcept;
49 const Model &GetPlayerModel() const noexcept;
51 Player *JoinPlayer(const std::string &name);
53 void SetBlock(Chunk &, int, const Block &) override;
55 /// for use by client connections when they receive a line from the player
56 void DispatchMessage(CLIContext &, const std::string &);
58 /// send message to all connected clients
59 void DistributeMessage(std::uint8_t type, std::uint32_t ref, const std::string &msg);
62 void HandlePacket(const UDPpacket &);
64 ClientConnection &GetClient(const IPaddress &);
71 SDLNet_SocketSet serv_set;
72 std::list<ClientConnection> clients;
75 ChunkIndex &spawn_index;
76 const WorldSave &save;
77 const Model *player_model;