diff options
author | Loïc Blot <nerzhul@users.noreply.github.com> | 2018-06-13 21:58:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-13 21:58:34 +0200 |
commit | 9a1d3584c22013860ec4b664858076ab6ddf3ea1 (patch) | |
tree | 444af0cbb0f77fa2ff47123b3e3b46d83b01e5c2 /src/server.h | |
parent | 10634f0443c478ff08daf80388198931befaa95c (diff) | |
download | minetest-9a1d3584c22013860ec4b664858076ab6ddf3ea1.tar.gz minetest-9a1d3584c22013860ec4b664858076ab6ddf3ea1.tar.bz2 minetest-9a1d3584c22013860ec4b664858076ab6ddf3ea1.zip |
Server: move shutdown parts to a specific shutdown state object (#7437)
* Server: move shutdown parts to a specific shutdown state object
Diffstat (limited to 'src/server.h')
-rw-r--r-- | src/server.h | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/src/server.h b/src/server.h index 39cf56027..02c69e491 100644 --- a/src/server.h +++ b/src/server.h @@ -128,6 +128,7 @@ public: ~Server(); DISABLE_CLASS_COPY(Server); + void init(); void start(); void stop(); // This is mainly a way to pass the time to the server. @@ -201,7 +202,7 @@ public: inline double getUptime() const { return m_uptime.m_value; } // read shutdown state - inline bool getShutdownRequested() const { return m_shutdown_requested; } + inline bool isShutdownRequested() const { return m_shutdown_state.is_requested; } // request server to shutdown void requestShutdown(const std::string &msg, bool reconnect, float delay = 0.0f); @@ -348,9 +349,25 @@ public: std::mutex m_env_mutex; private: - friend class EmergeThread; friend class RemoteClient; + friend class TestServerShutdownState; + + struct ShutdownState { + friend class TestServerShutdownState; + public: + bool is_requested = false; + bool should_reconnect = false; + std::string message; + + void reset(); + void trigger(float delay, const std::string &msg, bool reconnect); + void tick(float dtime, Server *server); + std::wstring getShutdownTimerMessage() const; + bool isTimerRunning() const { return m_timer > 0.0f; } + private: + float m_timer = 0.0f; + }; void SendMovement(session_t peer_id); void SendHP(session_t peer_id, u16 hp); @@ -368,7 +385,7 @@ private: void SetBlocksNotSent(std::map<v3s16, MapBlock *>& block); - void SendChatMessage(session_t peer_id, const ChatMessage &message); + virtual void SendChatMessage(session_t peer_id, const ChatMessage &message); void SendTimeOfDay(session_t peer_id, u16 time, f32 time_speed); void SendPlayerHP(session_t peer_id); @@ -586,10 +603,7 @@ private: Random stuff */ - bool m_shutdown_requested = false; - std::string m_shutdown_msg; - bool m_shutdown_ask_reconnect = false; - float m_shutdown_timer = 0.0f; + ShutdownState m_shutdown_state; ChatInterface *m_admin_chat; std::string m_admin_nick; |