]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/server.h
Update minetest.conf.example and src/settings_translation_file.cpp
[dragonfireclient.git] / src / server.h
index f53e23a3acde5d3174dab431adee86127c2176e1..6d66c938602e20b476c57656cbd54a8fc9c46978 100644 (file)
@@ -32,6 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "util/numeric.h"
 #include "util/thread.h"
 #include "environment.h"
+#include "chat_interface.h"
 #include "clientiface.h"
 #include "network/networkpacket.h"
 #include <string>
@@ -171,7 +172,8 @@ class Server : public con::PeerHandler, public MapEventReceiver,
                const std::string &path_world,
                const SubgameSpec &gamespec,
                bool simple_singleplayer_mode,
-               bool ipv6
+               bool ipv6,
+               ChatInterface *iface = NULL
        );
        ~Server();
        void start(Address bind_addr);
@@ -220,7 +222,8 @@ class Server : public con::PeerHandler, public MapEventReceiver,
 
        void Send(NetworkPacket* pkt);
 
-       // Environment must be locked when called
+       // Both setter and getter need no envlock,
+       // can be called freely from threads
        void setTimeOfDay(u32 time);
 
        /*
@@ -244,8 +247,13 @@ class Server : public con::PeerHandler, public MapEventReceiver,
                        { return m_shutdown_requested; }
 
        // request server to shutdown
-       inline void requestShutdown(void)
-                       { m_shutdown_requested = true; }
+       inline void requestShutdown() { m_shutdown_requested = true; }
+       void requestShutdown(const std::string &msg, bool reconnect)
+       {
+               m_shutdown_requested = true;
+               m_shutdown_msg = msg;
+               m_shutdown_ask_reconnect = reconnect;
+       }
 
        // Returns -1 if failed, sound handle on success
        // Envlock
@@ -264,34 +272,21 @@ class Server : public con::PeerHandler, public MapEventReceiver,
 
        void notifyPlayer(const char *name, const std::wstring &msg);
        void notifyPlayers(const std::wstring &msg);
-       void spawnParticle(const char *playername,
+       void spawnParticle(const std::string &playername,
                v3f pos, v3f velocity, v3f acceleration,
                float expirationtime, float size,
-               bool collisiondetection, bool vertical, std::string texture);
-
-       void spawnParticleAll(v3f pos, v3f velocity, v3f acceleration,
-               float expirationtime, float size,
-               bool collisiondetection, bool vertical, std::string texture);
+               bool collisiondetection, bool vertical, const std::string &texture);
 
-       u32 addParticleSpawner(const char *playername,
-               u16 amount, float spawntime,
+       u32 addParticleSpawner(u16 amount, float spawntime,
                v3f minpos, v3f maxpos,
                v3f minvel, v3f maxvel,
                v3f minacc, v3f maxacc,
                float minexptime, float maxexptime,
                float minsize, float maxsize,
-               bool collisiondetection, bool vertical, std::string texture);
+               bool collisiondetection, bool vertical, const std::string &texture,
+               const std::string &playername);
 
-       u32 addParticleSpawnerAll(u16 amount, float spawntime,
-               v3f minpos, v3f maxpos,
-               v3f minvel, v3f maxvel,
-               v3f minacc, v3f maxacc,
-               float minexptime, float maxexptime,
-               float minsize, float maxsize,
-               bool collisiondetection, bool vertical, std::string texture);
-
-       void deleteParticleSpawner(const char *playername, u32 id);
-       void deleteParticleSpawnerAll(u32 id);
+       void deleteParticleSpawner(const std::string &playername, u32 id);
 
        // Creates or resets inventory
        Inventory* createDetachedInventory(const std::string &name);
@@ -322,10 +317,10 @@ class Server : public con::PeerHandler, public MapEventReceiver,
        IWritableNodeDefManager* getWritableNodeDefManager();
        IWritableCraftDefManager* getWritableCraftDefManager();
 
-       const ModSpec* getModSpec(const std::string &modname);
+       const ModSpec* getModSpec(const std::string &modname) const;
        void getModNames(std::vector<std::string> &modlist);
        std::string getBuiltinLuaPath();
-       inline std::string getWorldPath()
+       inline std::string getWorldPath() const
                        { return m_path_world; }
 
        inline bool isSingleplayer()
@@ -343,8 +338,11 @@ class Server : public con::PeerHandler, public MapEventReceiver,
        bool hudChange(Player *player, u32 id, HudElementStat stat, void *value);
        bool hudSetFlags(Player *player, u32 flags, u32 mask);
        bool hudSetHotbarItemcount(Player *player, s32 hotbar_itemcount);
+       s32 hudGetHotbarItemcount(Player *player);
        void hudSetHotbarImage(Player *player, std::string name);
+       std::string hudGetHotbarImage(Player *player);
        void hudSetHotbarSelectedImage(Player *player, std::string name);
+       std::string hudGetHotbarSelectedImage(Player *player);
 
        inline Address getPeerAddress(u16 peer_id)
                        { return m_con.GetPeerAddress(peer_id); }
@@ -363,6 +361,8 @@ class Server : public con::PeerHandler, public MapEventReceiver,
        void deletingPeer(con::Peer *peer, bool timeout);
 
        void DenySudoAccess(u16 peer_id);
+       void DenyAccessVerCompliant(u16 peer_id, u16 proto_ver, AccessDeniedCode reason,
+               const std::string &str_reason = "", bool reconnect = false);
        void DenyAccess(u16 peer_id, AccessDeniedCode reason, const std::string &custom_reason="");
        void acceptAuth(u16 peer_id, bool forSudoMode);
        void DenyAccess_Legacy(u16 peer_id, const std::wstring &reason);
@@ -371,7 +371,9 @@ class Server : public con::PeerHandler, public MapEventReceiver,
                        u8* ser_vers, u16* prot_vers, u8* major, u8* minor, u8* patch,
                        std::string* vers_string);
 
-       void SendPlayerHPOrDie(u16 peer_id, bool die) { die ? DiePlayer(peer_id) : SendPlayerHP(peer_id); }
+       void printToConsoleOnly(const std::string &text);
+
+       void SendPlayerHPOrDie(PlayerSAO *player);
        void SendPlayerBreath(u16 peer_id);
        void SendInventory(PlayerSAO* playerSAO);
        void SendMovePlayer(u16 peer_id);
@@ -379,6 +381,9 @@ class Server : public con::PeerHandler, public MapEventReceiver,
        // Bind address
        Address m_bind_addr;
 
+       // Environment mutex (envlock)
+       Mutex m_env_mutex;
+
 private:
 
        friend class EmergeThread;
@@ -387,7 +392,8 @@ class Server : public con::PeerHandler, public MapEventReceiver,
        void SendMovement(u16 peer_id);
        void SendHP(u16 peer_id, u8 hp);
        void SendBreath(u16 peer_id, u16 breath);
-       void SendAccessDenied(u16 peer_id, AccessDeniedCode reason, const std::string &custom_reason);
+       void SendAccessDenied(u16 peer_id, AccessDeniedCode reason,
+               const std::string &custom_reason, bool reconnect = false);
        void SendAccessDenied_Legacy(u16 peer_id, const std::wstring &reason);
        void SendDeathscreen(u16 peer_id,bool set_camera_point_target, v3f camera_point_target);
        void SendItemDef(u16 peer_id,IItemDefManager *itemdef, u16 protocol_version);
@@ -470,6 +476,12 @@ class Server : public con::PeerHandler, public MapEventReceiver,
        void DeleteClient(u16 peer_id, ClientDeletionReason reason);
        void UpdateCrafting(Player *player);
 
+       // This returns the answer to the sender of wmessage, or "" if there is none
+       std::wstring handleChat(const std::string &name, const std::wstring &wname,
+               const std::wstring &wmessage,
+               u16 peer_id_to_avoid_sending = PEER_ID_INEXISTENT);
+       void handleAdminChat(const ChatEventChat *evt);
+
        v3f findSpawnPos();
 
        // When called, connection mutex should be locked
@@ -487,7 +499,7 @@ class Server : public con::PeerHandler, public MapEventReceiver,
 
                Call with env and con locked.
        */
-       PlayerSAO *emergePlayer(const char *name, u16 peer_id);
+       PlayerSAO *emergePlayer(const char *name, u16 peer_id, u16 proto_version);
 
        void handlePeerChanges();
 
@@ -518,7 +530,6 @@ class Server : public con::PeerHandler, public MapEventReceiver,
 
        // Environment
        ServerEnvironment *m_env;
-       JMutex m_env_mutex;
 
        // server connection
        con::Connection m_con;
@@ -559,7 +570,7 @@ class Server : public con::PeerHandler, public MapEventReceiver,
        // A buffer for time steps
        // step() increments and AsyncRunStep() run by m_thread reads it.
        float m_step_dtime;
-       JMutex m_step_dtime_mutex;
+       Mutex m_step_dtime_mutex;
 
        // current server step lag counter
        float m_lag;
@@ -593,6 +604,11 @@ class Server : public con::PeerHandler, public MapEventReceiver,
        */
 
        bool m_shutdown_requested;
+       std::string m_shutdown_msg;
+       bool m_shutdown_ask_reconnect;
+
+       ChatInterface *m_admin_chat;
+       std::string m_admin_nick;
 
        /*
                Map edit event queue. Automatically receives all map edits.
@@ -647,14 +663,16 @@ class Server : public con::PeerHandler, public MapEventReceiver,
                Particles
        */
        std::vector<u32> m_particlespawner_ids;
+
+       DISABLE_CLASS_COPY(Server);
 };
 
 /*
        Runs a simple dedicated server loop.
 
-       Shuts down when run is set to false.
+       Shuts down when kill is set to true.
 */
-void dedicated_server_loop(Server &server, bool &run);
+void dedicated_server_loop(Server &server, bool &kill);
 
 #endif