X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fserver%2FServer.hpp;h=f81c9cea205b4918edfbb26e4da3c1357402baa4;hb=ce10bfbe252d5598bbb559c6ce55aed1b9393227;hp=c12b86aa75ba0b4d9e17e726aab2c54c44474491;hpb=d91257ba2a51416683be3f54fe16cb2e96ae29f5;p=blank.git diff --git a/src/server/Server.hpp b/src/server/Server.hpp index c12b86a..f81c9ce 100644 --- a/src/server/Server.hpp +++ b/src/server/Server.hpp @@ -2,9 +2,12 @@ #define BLANK_SERVER_SERVER_HPP #include "../app/Config.hpp" +#include "../shared/CLI.hpp" #include "../world/World.hpp" #include "../world/WorldManipulator.hpp" +#include +#include #include #include @@ -12,7 +15,9 @@ namespace blank { class ChunkIndex; -class CompositeModel; +class CLIContext; +class CommandService; +class Model; class Player; class WorldSave; @@ -27,6 +32,10 @@ public: 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); @@ -37,28 +46,40 @@ public: 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; ChunkIndex &spawn_index; const WorldSave &save; - const CompositeModel *player_model; + const Model *player_model; + + CLI cli; + std::unique_ptr cmd_srv; };