X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fserver%2FServer.hpp;h=9b89ab1bbc94692a400c7a3a6eda0054ca98a161;hb=d507e4b06e32aff46caacf961b310ba1050b232f;hp=bf2399180111354191c2a922bfe6754c84464ac7;hpb=8fdc24f0b3fb287f5d4e1c7d1f85ad85d5ed2414;p=blank.git diff --git a/src/server/Server.hpp b/src/server/Server.hpp index bf23991..9b89ab1 100644 --- a/src/server/Server.hpp +++ b/src/server/Server.hpp @@ -1,30 +1,39 @@ #ifndef BLANK_SERVER_SERVER_HPP #define BLANK_SERVER_SERVER_HPP +#include "../app/Config.hpp" +#include "../shared/CLI.hpp" +#include "../world/World.hpp" +#include "../world/WorldManipulator.hpp" + +#include #include #include namespace blank { -class CompositeModel; -class World; +class ChunkIndex; +class CLIContext; +class Model; +class Player; +class WorldSave; namespace server { class ClientConnection; -class Server { - -public: - struct Config { - Uint16 port = 12354; - }; +class Server +: public WorldManipulator { public: - Server(const Config &, World &); + Server(const Config::Network &, World &, const World::Config &, const WorldSave &); ~Server(); + // wait for data to arrive for at most dt milliseconds + void Wait(int dt) noexcept; + // true if there's data waiting to be handled + bool Ready() noexcept; void Handle(); void Update(int dt); @@ -33,23 +42,41 @@ public: UDPpacket &GetPacket() noexcept { return serv_pack; } World &GetWorld() noexcept { return world; } + const WorldSave &GetWorldSave() noexcept { return save; } - void SetPlayerModel(const CompositeModel &) noexcept; + void SetPlayerModel(const Model &) noexcept; bool HasPlayerModel() const noexcept; - const CompositeModel &GetPlayerModel() const noexcept; + const Model &GetPlayerModel() const noexcept; + + Player *JoinPlayer(const std::string &name); + + void SetBlock(Chunk &, int, const Block &) override; + + /// for use by client connections when they receive a line from the player + void DispatchMessage(CLIContext &, const std::string &); + + /// send message to all connected clients + void DistributeMessage(std::uint8_t type, std::uint32_t ref, const std::string &msg); private: void HandlePacket(const UDPpacket &); ClientConnection &GetClient(const IPaddress &); + void SendAll(); + private: UDPsocket serv_sock; UDPpacket serv_pack; + SDLNet_SocketSet serv_set; std::list clients; World &world; - const CompositeModel *player_model; + ChunkIndex &spawn_index; + const WorldSave &save; + const Model *player_model; + + CLI cli; };