]> git.localhorst.tv Git - blank.git/blobdiff - src/server/Server.hpp
add TCP based CLI
[blank.git] / src / server / Server.hpp
index cef98beaeba764844059a5663179513f5fcd5ce6..f81c9cea205b4918edfbb26e4da3c1357402baa4 100644 (file)
@@ -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 <cstdint>
+#include <memory>
 #include <list>
 #include <SDL_net.h>
 
@@ -12,6 +15,8 @@
 namespace blank {
 
 class ChunkIndex;
+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);
@@ -45,14 +54,23 @@ public:
 
        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<ClientConnection> clients;
 
        World &world;
@@ -60,6 +78,9 @@ private:
        const WorldSave &save;
        const Model *player_model;
 
+       CLI cli;
+       std::unique_ptr<CommandService> cmd_srv;
+
 };
 
 }