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