]> git.lizzy.rs Git - dragonfireclient.git/blob - src/server.h
Translated using Weblate (Turkish)
[dragonfireclient.git] / src / server.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #pragma once
21
22 #include "irr_v3d.h"
23 #include "map.h"
24 #include "hud.h"
25 #include "gamedef.h"
26 #include "serialization.h" // For SER_FMT_VER_INVALID
27 #include "content/mods.h"
28 #include "inventorymanager.h"
29 #include "content/subgames.h"
30 #include "tileanimation.h" // TileAnimationParams
31 #include "particles.h" // ParticleParams
32 #include "network/peerhandler.h"
33 #include "network/address.h"
34 #include "util/numeric.h"
35 #include "util/thread.h"
36 #include "util/basic_macros.h"
37 #include "util/metricsbackend.h"
38 #include "serverenvironment.h"
39 #include "clientiface.h"
40 #include "chatmessage.h"
41 #include "translation.h"
42 #include <string>
43 #include <list>
44 #include <map>
45 #include <vector>
46 #include <unordered_set>
47
48 class ChatEvent;
49 struct ChatEventChat;
50 struct ChatInterface;
51 class IWritableItemDefManager;
52 class NodeDefManager;
53 class IWritableCraftDefManager;
54 class BanManager;
55 class EventManager;
56 class Inventory;
57 class ModChannelMgr;
58 class RemotePlayer;
59 class PlayerSAO;
60 struct PlayerHPChangeReason;
61 class IRollbackManager;
62 struct RollbackAction;
63 class EmergeManager;
64 class ServerScripting;
65 class ServerEnvironment;
66 struct SimpleSoundSpec;
67 struct CloudParams;
68 struct SkyboxParams;
69 struct SunParams;
70 struct MoonParams;
71 struct StarParams;
72 class ServerThread;
73 class ServerModManager;
74 class ServerInventoryManager;
75
76 enum ClientDeletionReason {
77         CDR_LEAVE,
78         CDR_TIMEOUT,
79         CDR_DENY
80 };
81
82 struct MediaInfo
83 {
84         std::string path;
85         std::string sha1_digest; // base64-encoded
86         bool no_announce; // true: not announced in TOCLIENT_ANNOUNCE_MEDIA (at player join)
87
88         MediaInfo(const std::string &path_="",
89                   const std::string &sha1_digest_=""):
90                 path(path_),
91                 sha1_digest(sha1_digest_),
92                 no_announce(false)
93         {
94         }
95 };
96
97 struct ServerSoundParams
98 {
99         enum Type {
100                 SSP_LOCAL,
101                 SSP_POSITIONAL,
102                 SSP_OBJECT
103         } type = SSP_LOCAL;
104         float gain = 1.0f;
105         float fade = 0.0f;
106         float pitch = 1.0f;
107         bool loop = false;
108         float max_hear_distance = 32 * BS;
109         v3f pos;
110         u16 object = 0;
111         std::string to_player = "";
112         std::string exclude_player = "";
113
114         v3f getPos(ServerEnvironment *env, bool *pos_exists) const;
115 };
116
117 struct ServerPlayingSound
118 {
119         ServerSoundParams params;
120         SimpleSoundSpec spec;
121         std::unordered_set<session_t> clients; // peer ids
122 };
123
124 struct MinimapMode {
125         MinimapType type = MINIMAP_TYPE_OFF;
126         std::string label;
127         u16 size = 0;
128         std::string texture;
129         u16 scale = 1;
130 };
131
132 // structure for everything getClientInfo returns, for convenience
133 struct ClientInfo {
134         ClientState state;
135         Address addr;
136         u32 uptime;
137         u8 ser_vers;
138         u16 prot_vers;
139         u8 major, minor, patch;
140         std::string vers_string, lang_code;
141 };
142
143 class Server : public con::PeerHandler, public MapEventReceiver,
144                 public IGameDef
145 {
146 public:
147         /*
148                 NOTE: Every public method should be thread-safe
149         */
150
151         Server(
152                 const std::string &path_world,
153                 const SubgameSpec &gamespec,
154                 bool simple_singleplayer_mode,
155                 Address bind_addr,
156                 bool dedicated,
157                 ChatInterface *iface = nullptr,
158                 std::string *on_shutdown_errmsg = nullptr
159         );
160         ~Server();
161         DISABLE_CLASS_COPY(Server);
162
163         void start();
164         void stop();
165         // This is mainly a way to pass the time to the server.
166         // Actual processing is done in an another thread.
167         void step(float dtime);
168         // This is run by ServerThread and does the actual processing
169         void AsyncRunStep(bool initial_step=false);
170         void Receive();
171         PlayerSAO* StageTwoClientInit(session_t peer_id);
172
173         /*
174          * Command Handlers
175          */
176
177         void handleCommand(NetworkPacket* pkt);
178
179         void handleCommand_Null(NetworkPacket* pkt) {};
180         void handleCommand_Deprecated(NetworkPacket* pkt);
181         void handleCommand_Init(NetworkPacket* pkt);
182         void handleCommand_Init2(NetworkPacket* pkt);
183         void handleCommand_ModChannelJoin(NetworkPacket *pkt);
184         void handleCommand_ModChannelLeave(NetworkPacket *pkt);
185         void handleCommand_ModChannelMsg(NetworkPacket *pkt);
186         void handleCommand_RequestMedia(NetworkPacket* pkt);
187         void handleCommand_ClientReady(NetworkPacket* pkt);
188         void handleCommand_GotBlocks(NetworkPacket* pkt);
189         void handleCommand_PlayerPos(NetworkPacket* pkt);
190         void handleCommand_DeletedBlocks(NetworkPacket* pkt);
191         void handleCommand_InventoryAction(NetworkPacket* pkt);
192         void handleCommand_ChatMessage(NetworkPacket* pkt);
193         void handleCommand_Damage(NetworkPacket* pkt);
194         void handleCommand_PlayerItem(NetworkPacket* pkt);
195         void handleCommand_Respawn(NetworkPacket* pkt);
196         void handleCommand_Interact(NetworkPacket* pkt);
197         void handleCommand_RemovedSounds(NetworkPacket* pkt);
198         void handleCommand_NodeMetaFields(NetworkPacket* pkt);
199         void handleCommand_InventoryFields(NetworkPacket* pkt);
200         void handleCommand_FirstSrp(NetworkPacket* pkt);
201         void handleCommand_SrpBytesA(NetworkPacket* pkt);
202         void handleCommand_SrpBytesM(NetworkPacket* pkt);
203         void handleCommand_HaveMedia(NetworkPacket *pkt);
204
205         void ProcessData(NetworkPacket *pkt);
206
207         void Send(NetworkPacket *pkt);
208         void Send(session_t peer_id, NetworkPacket *pkt);
209
210         // Helper for handleCommand_PlayerPos and handleCommand_Interact
211         void process_PlayerPos(RemotePlayer *player, PlayerSAO *playersao,
212                 NetworkPacket *pkt);
213
214         // Both setter and getter need no envlock,
215         // can be called freely from threads
216         void setTimeOfDay(u32 time);
217
218         /*
219                 Shall be called with the environment locked.
220                 This is accessed by the map, which is inside the environment,
221                 so it shouldn't be a problem.
222         */
223         void onMapEditEvent(const MapEditEvent &event);
224
225         // Connection must be locked when called
226         std::string getStatusString();
227         inline double getUptime() const { return m_uptime_counter->get(); }
228
229         // read shutdown state
230         inline bool isShutdownRequested() const { return m_shutdown_state.is_requested; }
231
232         // request server to shutdown
233         void requestShutdown(const std::string &msg, bool reconnect, float delay = 0.0f);
234
235         // Returns -1 if failed, sound handle on success
236         // Envlock
237         s32 playSound(const SimpleSoundSpec &spec, const ServerSoundParams &params,
238                         bool ephemeral=false);
239         void stopSound(s32 handle);
240         void fadeSound(s32 handle, float step, float gain);
241
242         // Envlock
243         std::set<std::string> getPlayerEffectivePrivs(const std::string &name);
244         bool checkPriv(const std::string &name, const std::string &priv);
245         void reportPrivsModified(const std::string &name=""); // ""=all
246         void reportInventoryFormspecModified(const std::string &name);
247         void reportFormspecPrependModified(const std::string &name);
248
249         void setIpBanned(const std::string &ip, const std::string &name);
250         void unsetIpBanned(const std::string &ip_or_name);
251         std::string getBanDescription(const std::string &ip_or_name);
252
253         void notifyPlayer(const char *name, const std::wstring &msg);
254         void notifyPlayers(const std::wstring &msg);
255
256         void spawnParticle(const std::string &playername,
257                 const ParticleParameters &p);
258
259         u32 addParticleSpawner(const ParticleSpawnerParameters &p,
260                 ServerActiveObject *attached, const std::string &playername);
261
262         void deleteParticleSpawner(const std::string &playername, u32 id);
263
264         bool dynamicAddMedia(std::string filepath, u32 token,
265                 const std::string &to_player, bool ephemeral);
266
267         ServerInventoryManager *getInventoryMgr() const { return m_inventory_mgr.get(); }
268         void sendDetachedInventory(Inventory *inventory, const std::string &name, session_t peer_id);
269
270         // Envlock and conlock should be locked when using scriptapi
271         ServerScripting *getScriptIface(){ return m_script; }
272
273         // actions: time-reversed list
274         // Return value: success/failure
275         bool rollbackRevertActions(const std::list<RollbackAction> &actions,
276                         std::list<std::string> *log);
277
278         // IGameDef interface
279         // Under envlock
280         virtual IItemDefManager* getItemDefManager();
281         virtual const NodeDefManager* getNodeDefManager();
282         virtual ICraftDefManager* getCraftDefManager();
283         virtual u16 allocateUnknownNodeId(const std::string &name);
284         IRollbackManager *getRollbackManager() { return m_rollback; }
285         virtual EmergeManager *getEmergeManager() { return m_emerge; }
286         virtual ModMetadataDatabase *getModStorageDatabase() { return m_mod_storage_database; }
287
288         IWritableItemDefManager* getWritableItemDefManager();
289         NodeDefManager* getWritableNodeDefManager();
290         IWritableCraftDefManager* getWritableCraftDefManager();
291
292         virtual const std::vector<ModSpec> &getMods() const;
293         virtual const ModSpec* getModSpec(const std::string &modname) const;
294         void getModNames(std::vector<std::string> &modlist);
295         std::string getBuiltinLuaPath();
296         virtual std::string getWorldPath() const { return m_path_world; }
297
298         inline bool isSingleplayer()
299                         { return m_simple_singleplayer_mode; }
300
301         inline void setAsyncFatalError(const std::string &error)
302                         { m_async_fatal_error.set(error); }
303         inline void setAsyncFatalError(const LuaError &e)
304         {
305                 setAsyncFatalError(std::string("Lua: ") + e.what());
306         }
307
308         bool showFormspec(const char *name, const std::string &formspec, const std::string &formname);
309         Map & getMap() { return m_env->getMap(); }
310         ServerEnvironment & getEnv() { return *m_env; }
311         v3f findSpawnPos();
312
313         u32 hudAdd(RemotePlayer *player, HudElement *element);
314         bool hudRemove(RemotePlayer *player, u32 id);
315         bool hudChange(RemotePlayer *player, u32 id, HudElementStat stat, void *value);
316         bool hudSetFlags(RemotePlayer *player, u32 flags, u32 mask);
317         bool hudSetHotbarItemcount(RemotePlayer *player, s32 hotbar_itemcount);
318         void hudSetHotbarImage(RemotePlayer *player, const std::string &name);
319         void hudSetHotbarSelectedImage(RemotePlayer *player, const std::string &name);
320
321         Address getPeerAddress(session_t peer_id);
322
323         void setLocalPlayerAnimations(RemotePlayer *player, v2s32 animation_frames[4],
324                         f32 frame_speed);
325         void setPlayerEyeOffset(RemotePlayer *player, const v3f &first, const v3f &third);
326
327         void setSky(RemotePlayer *player, const SkyboxParams &params);
328         void setSun(RemotePlayer *player, const SunParams &params);
329         void setMoon(RemotePlayer *player, const MoonParams &params);
330         void setStars(RemotePlayer *player, const StarParams &params);
331
332         void setClouds(RemotePlayer *player, const CloudParams &params);
333
334         void overrideDayNightRatio(RemotePlayer *player, bool do_override, float brightness);
335
336         /* con::PeerHandler implementation. */
337         void peerAdded(con::Peer *peer);
338         void deletingPeer(con::Peer *peer, bool timeout);
339
340         void DenySudoAccess(session_t peer_id);
341         void DenyAccessVerCompliant(session_t peer_id, u16 proto_ver, AccessDeniedCode reason,
342                 const std::string &str_reason = "", bool reconnect = false);
343         void DenyAccess(session_t peer_id, AccessDeniedCode reason,
344                 const std::string &custom_reason = "");
345         void acceptAuth(session_t peer_id, bool forSudoMode);
346         void DenyAccess_Legacy(session_t peer_id, const std::wstring &reason);
347         void DisconnectPeer(session_t peer_id);
348         bool getClientConInfo(session_t peer_id, con::rtt_stat_type type, float *retval);
349         bool getClientInfo(session_t peer_id, ClientInfo &ret);
350
351         void printToConsoleOnly(const std::string &text);
352
353         void HandlePlayerHPChange(PlayerSAO *sao, const PlayerHPChangeReason &reason);
354         void SendPlayerHP(PlayerSAO *sao);
355         void SendPlayerBreath(PlayerSAO *sao);
356         void SendInventory(PlayerSAO *playerSAO, bool incremental);
357         void SendMovePlayer(session_t peer_id);
358         void SendPlayerSpeed(session_t peer_id, const v3f &added_vel);
359         void SendPlayerFov(session_t peer_id);
360
361         void SendMinimapModes(session_t peer_id,
362                         std::vector<MinimapMode> &modes,
363                         size_t wanted_mode);
364
365         void sendDetachedInventories(session_t peer_id, bool incremental);
366
367         virtual bool registerModStorage(ModMetadata *storage);
368         virtual void unregisterModStorage(const std::string &name);
369
370         bool joinModChannel(const std::string &channel);
371         bool leaveModChannel(const std::string &channel);
372         bool sendModChannelMessage(const std::string &channel, const std::string &message);
373         ModChannel *getModChannel(const std::string &channel);
374
375         // Send block to specific player only
376         bool SendBlock(session_t peer_id, const v3s16 &blockpos);
377
378         // Get or load translations for a language
379         Translations *getTranslationLanguage(const std::string &lang_code);
380
381         static ModMetadataDatabase *openModStorageDatabase(const std::string &world_path);
382
383         static ModMetadataDatabase *openModStorageDatabase(const std::string &backend,
384                         const std::string &world_path, const Settings &world_mt);
385
386         static bool migrateModStorageDatabase(const GameParams &game_params,
387                         const Settings &cmd_args);
388
389         // Bind address
390         Address m_bind_addr;
391
392         // Environment mutex (envlock)
393         std::mutex m_env_mutex;
394
395 private:
396         friend class EmergeThread;
397         friend class RemoteClient;
398         friend class TestServerShutdownState;
399
400         struct ShutdownState {
401                 friend class TestServerShutdownState;
402                 public:
403                         bool is_requested = false;
404                         bool should_reconnect = false;
405                         std::string message;
406
407                         void reset();
408                         void trigger(float delay, const std::string &msg, bool reconnect);
409                         void tick(float dtime, Server *server);
410                         std::wstring getShutdownTimerMessage() const;
411                         bool isTimerRunning() const { return m_timer > 0.0f; }
412                 private:
413                         float m_timer = 0.0f;
414         };
415
416         struct PendingDynamicMediaCallback {
417                 std::string filename; // only set if media entry and file is to be deleted
418                 float expiry_timer;
419                 std::unordered_set<session_t> waiting_players;
420         };
421
422         void init();
423
424         void SendMovement(session_t peer_id);
425         void SendHP(session_t peer_id, u16 hp);
426         void SendBreath(session_t peer_id, u16 breath);
427         void SendAccessDenied(session_t peer_id, AccessDeniedCode reason,
428                 const std::string &custom_reason, bool reconnect = false);
429         void SendAccessDenied_Legacy(session_t peer_id, const std::wstring &reason);
430         void SendDeathscreen(session_t peer_id, bool set_camera_point_target,
431                 v3f camera_point_target);
432         void SendItemDef(session_t peer_id, IItemDefManager *itemdef, u16 protocol_version);
433         void SendNodeDef(session_t peer_id, const NodeDefManager *nodedef,
434                 u16 protocol_version);
435
436         /* mark blocks not sent for all clients */
437         void SetBlocksNotSent(std::map<v3s16, MapBlock *>& block);
438
439
440         virtual void SendChatMessage(session_t peer_id, const ChatMessage &message);
441         void SendTimeOfDay(session_t peer_id, u16 time, f32 time_speed);
442
443         void SendLocalPlayerAnimations(session_t peer_id, v2s32 animation_frames[4],
444                 f32 animation_speed);
445         void SendEyeOffset(session_t peer_id, v3f first, v3f third);
446         void SendPlayerPrivileges(session_t peer_id);
447         void SendPlayerInventoryFormspec(session_t peer_id);
448         void SendPlayerFormspecPrepend(session_t peer_id);
449         void SendShowFormspecMessage(session_t peer_id, const std::string &formspec,
450                 const std::string &formname);
451         void SendHUDAdd(session_t peer_id, u32 id, HudElement *form);
452         void SendHUDRemove(session_t peer_id, u32 id);
453         void SendHUDChange(session_t peer_id, u32 id, HudElementStat stat, void *value);
454         void SendHUDSetFlags(session_t peer_id, u32 flags, u32 mask);
455         void SendHUDSetParam(session_t peer_id, u16 param, const std::string &value);
456         void SendSetSky(session_t peer_id, const SkyboxParams &params);
457         void SendSetSun(session_t peer_id, const SunParams &params);
458         void SendSetMoon(session_t peer_id, const MoonParams &params);
459         void SendSetStars(session_t peer_id, const StarParams &params);
460         void SendCloudParams(session_t peer_id, const CloudParams &params);
461         void SendOverrideDayNightRatio(session_t peer_id, bool do_override, float ratio);
462         void broadcastModChannelMessage(const std::string &channel,
463                         const std::string &message, session_t from_peer);
464
465         /*
466                 Send a node removal/addition event to all clients except ignore_id.
467                 Additionally, if far_players!=NULL, players further away than
468                 far_d_nodes are ignored and their peer_ids are added to far_players
469         */
470         // Envlock and conlock should be locked when calling these
471         void sendRemoveNode(v3s16 p, std::unordered_set<u16> *far_players = nullptr,
472                         float far_d_nodes = 100);
473         void sendAddNode(v3s16 p, MapNode n,
474                         std::unordered_set<u16> *far_players = nullptr,
475                         float far_d_nodes = 100, bool remove_metadata = true);
476
477         void sendMetadataChanged(const std::list<v3s16> &meta_updates,
478                         float far_d_nodes = 100);
479
480         // Environment and Connection must be locked when called
481         void SendBlockNoLock(session_t peer_id, MapBlock *block, u8 ver, u16 net_proto_version);
482
483         // Sends blocks to clients (locks env and con on its own)
484         void SendBlocks(float dtime);
485
486         bool addMediaFile(const std::string &filename, const std::string &filepath,
487                         std::string *filedata = nullptr, std::string *digest = nullptr);
488         void fillMediaCache();
489         void sendMediaAnnouncement(session_t peer_id, const std::string &lang_code);
490         void sendRequestedMedia(session_t peer_id,
491                         const std::vector<std::string> &tosend);
492         void stepPendingDynMediaCallbacks(float dtime);
493
494         // Adds a ParticleSpawner on peer with peer_id (PEER_ID_INEXISTENT == all)
495         void SendAddParticleSpawner(session_t peer_id, u16 protocol_version,
496                 const ParticleSpawnerParameters &p, u16 attached_id, u32 id);
497
498         void SendDeleteParticleSpawner(session_t peer_id, u32 id);
499
500         // Spawns particle on peer with peer_id (PEER_ID_INEXISTENT == all)
501         void SendSpawnParticle(session_t peer_id, u16 protocol_version,
502                 const ParticleParameters &p);
503
504         void SendActiveObjectRemoveAdd(RemoteClient *client, PlayerSAO *playersao);
505         void SendActiveObjectMessages(session_t peer_id, const std::string &datas,
506                 bool reliable = true);
507         void SendCSMRestrictionFlags(session_t peer_id);
508
509         /*
510                 Something random
511         */
512
513         void HandlePlayerDeath(PlayerSAO* sao, const PlayerHPChangeReason &reason);
514         void RespawnPlayer(session_t peer_id);
515         void DeleteClient(session_t peer_id, ClientDeletionReason reason);
516         void UpdateCrafting(RemotePlayer *player);
517         bool checkInteractDistance(RemotePlayer *player, const f32 d, const std::string &what);
518
519         void handleChatInterfaceEvent(ChatEvent *evt);
520
521         // This returns the answer to the sender of wmessage, or "" if there is none
522         std::wstring handleChat(const std::string &name, std::wstring wmessage_input,
523                 bool check_shout_priv = false, RemotePlayer *player = nullptr);
524         void handleAdminChat(const ChatEventChat *evt);
525
526         // When called, connection mutex should be locked
527         RemoteClient* getClient(session_t peer_id, ClientState state_min = CS_Active);
528         RemoteClient* getClientNoEx(session_t peer_id, ClientState state_min = CS_Active);
529
530         // When called, environment mutex should be locked
531         std::string getPlayerName(session_t peer_id);
532         PlayerSAO *getPlayerSAO(session_t peer_id);
533
534         /*
535                 Get a player from memory or creates one.
536                 If player is already connected, return NULL
537                 Does not verify/modify auth info and password.
538
539                 Call with env and con locked.
540         */
541         PlayerSAO *emergePlayer(const char *name, session_t peer_id, u16 proto_version);
542
543         void handlePeerChanges();
544
545         /*
546                 Variables
547         */
548         // World directory
549         std::string m_path_world;
550         // Subgame specification
551         SubgameSpec m_gamespec;
552         // If true, do not allow multiple players and hide some multiplayer
553         // functionality
554         bool m_simple_singleplayer_mode;
555         u16 m_max_chatmessage_length;
556         // For "dedicated" server list flag
557         bool m_dedicated;
558         Settings *m_game_settings = nullptr;
559
560         // Thread can set; step() will throw as ServerError
561         MutexedVariable<std::string> m_async_fatal_error;
562
563         // Some timers
564         float m_liquid_transform_timer = 0.0f;
565         float m_liquid_transform_every = 1.0f;
566         float m_masterserver_timer = 0.0f;
567         float m_emergethread_trigger_timer = 0.0f;
568         float m_savemap_timer = 0.0f;
569         IntervalLimiter m_map_timer_and_unload_interval;
570
571         // Environment
572         ServerEnvironment *m_env = nullptr;
573
574         // Reference to the server map until ServerEnvironment is initialized
575         // after that this variable must be a nullptr
576         ServerMap *m_startup_server_map = nullptr;
577
578         // server connection
579         std::shared_ptr<con::Connection> m_con;
580
581         // Ban checking
582         BanManager *m_banmanager = nullptr;
583
584         // Rollback manager (behind m_env_mutex)
585         IRollbackManager *m_rollback = nullptr;
586
587         // Emerge manager
588         EmergeManager *m_emerge = nullptr;
589
590         // Scripting
591         // Envlock and conlock should be locked when using Lua
592         ServerScripting *m_script = nullptr;
593
594         // Item definition manager
595         IWritableItemDefManager *m_itemdef;
596
597         // Node definition manager
598         NodeDefManager *m_nodedef;
599
600         // Craft definition manager
601         IWritableCraftDefManager *m_craftdef;
602
603         // Mods
604         std::unique_ptr<ServerModManager> m_modmgr;
605
606         std::unordered_map<std::string, Translations> server_translations;
607
608         /*
609                 Threads
610         */
611         // A buffer for time steps
612         // step() increments and AsyncRunStep() run by m_thread reads it.
613         float m_step_dtime = 0.0f;
614         std::mutex m_step_dtime_mutex;
615
616         // The server mainly operates in this thread
617         ServerThread *m_thread = nullptr;
618
619         /*
620                 Time related stuff
621         */
622         // Timer for sending time of day over network
623         float m_time_of_day_send_timer = 0.0f;
624
625         /*
626                 Client interface
627         */
628         ClientInterface m_clients;
629
630         /*
631                 Peer change queue.
632                 Queues stuff from peerAdded() and deletingPeer() to
633                 handlePeerChanges()
634         */
635         std::queue<con::PeerChange> m_peer_change_queue;
636
637         std::unordered_map<session_t, std::string> m_formspec_state_data;
638
639         /*
640                 Random stuff
641         */
642
643         ShutdownState m_shutdown_state;
644
645         ChatInterface *m_admin_chat;
646         std::string m_admin_nick;
647
648         // if a mod-error occurs in the on_shutdown callback, the error message will
649         // be written into this
650         std::string *const m_on_shutdown_errmsg;
651
652         /*
653                 Map edit event queue. Automatically receives all map edits.
654                 The constructor of this class registers us to receive them through
655                 onMapEditEvent
656
657                 NOTE: Should these be moved to actually be members of
658                 ServerEnvironment?
659         */
660
661         /*
662                 Queue of map edits from the environment for sending to the clients
663                 This is behind m_env_mutex
664         */
665         std::queue<MapEditEvent*> m_unsent_map_edit_queue;
666         /*
667                 If a non-empty area, map edit events contained within are left
668                 unsent. Done at map generation time to speed up editing of the
669                 generated area, as it will be sent anyway.
670                 This is behind m_env_mutex
671         */
672         VoxelArea m_ignore_map_edit_events_area;
673
674         // media files known to server
675         std::unordered_map<std::string, MediaInfo> m_media;
676
677         // pending dynamic media callbacks, clients inform the server when they have a file fetched
678         std::unordered_map<u32, PendingDynamicMediaCallback> m_pending_dyn_media;
679         float m_step_pending_dyn_media_timer = 0.0f;
680
681         /*
682                 Sounds
683         */
684         std::unordered_map<s32, ServerPlayingSound> m_playing_sounds;
685         s32 m_next_sound_id = 0; // positive values only
686         s32 nextSoundId();
687
688         std::unordered_map<std::string, ModMetadata *> m_mod_storages;
689         ModMetadataDatabase *m_mod_storage_database = nullptr;
690         float m_mod_storage_save_timer = 10.0f;
691
692         // CSM restrictions byteflag
693         u64 m_csm_restriction_flags = CSMRestrictionFlags::CSM_RF_NONE;
694         u32 m_csm_restriction_noderange = 8;
695
696         // ModChannel manager
697         std::unique_ptr<ModChannelMgr> m_modchannel_mgr;
698
699         // Inventory manager
700         std::unique_ptr<ServerInventoryManager> m_inventory_mgr;
701
702         // Global server metrics backend
703         std::unique_ptr<MetricsBackend> m_metrics_backend;
704
705         // Server metrics
706         MetricCounterPtr m_uptime_counter;
707         MetricGaugePtr m_player_gauge;
708         MetricGaugePtr m_timeofday_gauge;
709         // current server step lag
710         MetricGaugePtr m_lag_gauge;
711         MetricCounterPtr m_aom_buffer_counter;
712         MetricCounterPtr m_packet_recv_counter;
713         MetricCounterPtr m_packet_recv_processed_counter;
714 };
715
716 /*
717         Runs a simple dedicated server loop.
718
719         Shuts down when kill is set to true.
720 */
721 void dedicated_server_loop(Server &server, bool &kill);