]> git.lizzy.rs Git - dragonfireclient.git/blob - src/server.h
Merge pull request #465 from doserj/mod_selection_empty_modname_fix
[dragonfireclient.git] / src / server.h
1 /*
2 Minetest-c55
3 Copyright (C) 2010-2011 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 #ifndef SERVER_HEADER
21 #define SERVER_HEADER
22
23 #include "connection.h"
24 #include "environment.h"
25 #include "irrlichttypes_bloated.h"
26 #include <string>
27 #include "porting.h"
28 #include "map.h"
29 #include "inventory.h"
30 #include "ban.h"
31 #include "gamedef.h"
32 #include "serialization.h" // For SER_FMT_VER_INVALID
33 #include "mods.h"
34 #include "inventorymanager.h"
35 #include "subgame.h"
36 #include "sound.h"
37 #include "util/thread.h"
38 #include "util/string.h"
39 #include "rollback_interface.h" // Needed for rollbackRevertActions()
40 #include <list> // Needed for rollbackRevertActions()
41
42 struct LuaState;
43 typedef struct lua_State lua_State;
44 class IWritableItemDefManager;
45 class IWritableNodeDefManager;
46 class IWritableCraftDefManager;
47 class EventManager;
48 class PlayerSAO;
49 class IRollbackManager;
50
51 class ServerError : public std::exception
52 {
53 public:
54         ServerError(const std::string &s)
55         {
56                 m_s = "ServerError: ";
57                 m_s += s;
58         }
59         virtual ~ServerError() throw()
60         {}
61         virtual const char * what() const throw()
62         {
63                 return m_s.c_str();
64         }
65         std::string m_s;
66 };
67
68 /*
69         Some random functions
70 */
71 v3f findSpawnPos(ServerMap &map);
72
73 /*
74         A structure containing the data needed for queueing the fetching
75         of blocks.
76 */
77 struct QueuedBlockEmerge
78 {
79         v3s16 pos;
80         // key = peer_id, value = flags
81         core::map<u16, u8> peer_ids;
82 };
83
84 /*
85         This is a thread-safe class.
86 */
87 class BlockEmergeQueue
88 {
89 public:
90         BlockEmergeQueue()
91         {
92                 m_mutex.Init();
93         }
94
95         ~BlockEmergeQueue()
96         {
97                 JMutexAutoLock lock(m_mutex);
98
99                 core::list<QueuedBlockEmerge*>::Iterator i;
100                 for(i=m_queue.begin(); i!=m_queue.end(); i++)
101                 {
102                         QueuedBlockEmerge *q = *i;
103                         delete q;
104                 }
105         }
106
107         /*
108                 peer_id=0 adds with nobody to send to
109         */
110         void addBlock(u16 peer_id, v3s16 pos, u8 flags)
111         {
112                 DSTACK(__FUNCTION_NAME);
113
114                 JMutexAutoLock lock(m_mutex);
115
116                 if(peer_id != 0)
117                 {
118                         /*
119                                 Find if block is already in queue.
120                                 If it is, update the peer to it and quit.
121                         */
122                         core::list<QueuedBlockEmerge*>::Iterator i;
123                         for(i=m_queue.begin(); i!=m_queue.end(); i++)
124                         {
125                                 QueuedBlockEmerge *q = *i;
126                                 if(q->pos == pos)
127                                 {
128                                         q->peer_ids[peer_id] = flags;
129                                         return;
130                                 }
131                         }
132                 }
133
134                 /*
135                         Add the block
136                 */
137                 QueuedBlockEmerge *q = new QueuedBlockEmerge;
138                 q->pos = pos;
139                 if(peer_id != 0)
140                         q->peer_ids[peer_id] = flags;
141                 m_queue.push_back(q);
142         }
143
144         // Returned pointer must be deleted
145         // Returns NULL if queue is empty
146         QueuedBlockEmerge * pop()
147         {
148                 JMutexAutoLock lock(m_mutex);
149
150                 core::list<QueuedBlockEmerge*>::Iterator i = m_queue.begin();
151                 if(i == m_queue.end())
152                         return NULL;
153                 QueuedBlockEmerge *q = *i;
154                 m_queue.erase(i);
155                 return q;
156         }
157
158         u32 size()
159         {
160                 JMutexAutoLock lock(m_mutex);
161                 return m_queue.size();
162         }
163
164         u32 peerItemCount(u16 peer_id)
165         {
166                 JMutexAutoLock lock(m_mutex);
167
168                 u32 count = 0;
169
170                 core::list<QueuedBlockEmerge*>::Iterator i;
171                 for(i=m_queue.begin(); i!=m_queue.end(); i++)
172                 {
173                         QueuedBlockEmerge *q = *i;
174                         if(q->peer_ids.find(peer_id) != NULL)
175                                 count++;
176                 }
177
178                 return count;
179         }
180
181 private:
182         core::list<QueuedBlockEmerge*> m_queue;
183         JMutex m_mutex;
184 };
185
186 class Server;
187
188 class ServerThread : public SimpleThread
189 {
190         Server *m_server;
191
192 public:
193
194         ServerThread(Server *server):
195                 SimpleThread(),
196                 m_server(server)
197         {
198         }
199
200         void * Thread();
201 };
202
203 class EmergeThread : public SimpleThread
204 {
205         Server *m_server;
206
207 public:
208
209         EmergeThread(Server *server):
210                 SimpleThread(),
211                 m_server(server)
212         {
213         }
214
215         void * Thread();
216
217         void trigger()
218         {
219                 setRun(true);
220                 if(IsRunning() == false)
221                 {
222                         Start();
223                 }
224         }
225 };
226
227 struct PlayerInfo
228 {
229         u16 id;
230         char name[PLAYERNAME_SIZE];
231         v3f position;
232         Address address;
233         float avg_rtt;
234
235         PlayerInfo();
236         void PrintLine(std::ostream *s);
237 };
238
239 /*
240         Used for queueing and sorting block transfers in containers
241
242         Lower priority number means higher priority.
243 */
244 struct PrioritySortedBlockTransfer
245 {
246         PrioritySortedBlockTransfer(float a_priority, v3s16 a_pos, u16 a_peer_id)
247         {
248                 priority = a_priority;
249                 pos = a_pos;
250                 peer_id = a_peer_id;
251         }
252         bool operator < (PrioritySortedBlockTransfer &other)
253         {
254                 return priority < other.priority;
255         }
256         float priority;
257         v3s16 pos;
258         u16 peer_id;
259 };
260
261 struct MediaRequest
262 {
263         std::string name;
264
265         MediaRequest(const std::string &name_=""):
266                 name(name_)
267         {}
268 };
269
270 struct MediaInfo
271 {
272         std::string path;
273         std::string sha1_digest;
274
275         MediaInfo(const std::string path_="",
276                         const std::string sha1_digest_=""):
277                 path(path_),
278                 sha1_digest(sha1_digest_)
279         {
280         }
281 };
282
283 struct ServerSoundParams
284 {
285         float gain;
286         std::string to_player;
287         enum Type{
288                 SSP_LOCAL=0,
289                 SSP_POSITIONAL=1,
290                 SSP_OBJECT=2
291         } type;
292         v3f pos;
293         u16 object;
294         float max_hear_distance;
295         bool loop;
296
297         ServerSoundParams():
298                 gain(1.0),
299                 to_player(""),
300                 type(SSP_LOCAL),
301                 pos(0,0,0),
302                 object(0),
303                 max_hear_distance(32*BS),
304                 loop(false)
305         {}
306
307         v3f getPos(ServerEnvironment *env, bool *pos_exists) const;
308 };
309
310 struct ServerPlayingSound
311 {
312         ServerSoundParams params;
313         std::set<u16> clients; // peer ids
314 };
315
316 class RemoteClient
317 {
318 public:
319         // peer_id=0 means this client has no associated peer
320         // NOTE: If client is made allowed to exist while peer doesn't,
321         //       this has to be set to 0 when there is no peer.
322         //       Also, the client must be moved to some other container.
323         u16 peer_id;
324         // The serialization version to use with the client
325         u8 serialization_version;
326         //
327         u16 net_proto_version;
328         // Version is stored in here after INIT before INIT2
329         u8 pending_serialization_version;
330
331         bool definitions_sent;
332
333         RemoteClient():
334                 m_time_from_building(9999),
335                 m_excess_gotblocks(0)
336         {
337                 peer_id = 0;
338                 serialization_version = SER_FMT_VER_INVALID;
339                 net_proto_version = 0;
340                 pending_serialization_version = SER_FMT_VER_INVALID;
341                 definitions_sent = false;
342                 m_nearest_unsent_d = 0;
343                 m_nearest_unsent_reset_timer = 0.0;
344                 m_nothing_to_send_counter = 0;
345                 m_nothing_to_send_pause_timer = 0;
346         }
347         ~RemoteClient()
348         {
349         }
350
351         /*
352                 Finds block that should be sent next to the client.
353                 Environment should be locked when this is called.
354                 dtime is used for resetting send radius at slow interval
355         */
356         void GetNextBlocks(Server *server, float dtime,
357                         core::array<PrioritySortedBlockTransfer> &dest);
358
359         void GotBlock(v3s16 p);
360
361         void SentBlock(v3s16 p);
362
363         void SetBlockNotSent(v3s16 p);
364         void SetBlocksNotSent(core::map<v3s16, MapBlock*> &blocks);
365
366         s32 SendingCount()
367         {
368                 return m_blocks_sending.size();
369         }
370
371         // Increments timeouts and removes timed-out blocks from list
372         // NOTE: This doesn't fix the server-not-sending-block bug
373         //       because it is related to emerging, not sending.
374         //void RunSendingTimeouts(float dtime, float timeout);
375
376         void PrintInfo(std::ostream &o)
377         {
378                 o<<"RemoteClient "<<peer_id<<": "
379                                 <<"m_blocks_sent.size()="<<m_blocks_sent.size()
380                                 <<", m_blocks_sending.size()="<<m_blocks_sending.size()
381                                 <<", m_nearest_unsent_d="<<m_nearest_unsent_d
382                                 <<", m_excess_gotblocks="<<m_excess_gotblocks
383                                 <<std::endl;
384                 m_excess_gotblocks = 0;
385         }
386
387         // Time from last placing or removing blocks
388         float m_time_from_building;
389
390         /*JMutex m_dig_mutex;
391         float m_dig_time_remaining;
392         // -1 = not digging
393         s16 m_dig_tool_item;
394         v3s16 m_dig_position;*/
395
396         /*
397                 List of active objects that the client knows of.
398                 Value is dummy.
399         */
400         core::map<u16, bool> m_known_objects;
401
402 private:
403         /*
404                 Blocks that have been sent to client.
405                 - These don't have to be sent again.
406                 - A block is cleared from here when client says it has
407                   deleted it from it's memory
408
409                 Key is position, value is dummy.
410                 No MapBlock* is stored here because the blocks can get deleted.
411         */
412         core::map<v3s16, bool> m_blocks_sent;
413         s16 m_nearest_unsent_d;
414         v3s16 m_last_center;
415         float m_nearest_unsent_reset_timer;
416
417         /*
418                 Blocks that are currently on the line.
419                 This is used for throttling the sending of blocks.
420                 - The size of this list is limited to some value
421                 Block is added when it is sent with BLOCKDATA.
422                 Block is removed when GOTBLOCKS is received.
423                 Value is time from sending. (not used at the moment)
424         */
425         core::map<v3s16, float> m_blocks_sending;
426
427         /*
428                 Count of excess GotBlocks().
429                 There is an excess amount because the client sometimes
430                 gets a block so late that the server sends it again,
431                 and the client then sends two GOTBLOCKs.
432                 This is resetted by PrintInfo()
433         */
434         u32 m_excess_gotblocks;
435
436         // CPU usage optimization
437         u32 m_nothing_to_send_counter;
438         float m_nothing_to_send_pause_timer;
439 };
440
441 class Server : public con::PeerHandler, public MapEventReceiver,
442                 public InventoryManager, public IGameDef,
443                 public IBackgroundBlockEmerger
444 {
445 public:
446         /*
447                 NOTE: Every public method should be thread-safe
448         */
449
450         Server(
451                 const std::string &path_world,
452                 const std::string &path_config,
453                 const SubgameSpec &gamespec,
454                 bool simple_singleplayer_mode
455         );
456         ~Server();
457         void start(unsigned short port);
458         void stop();
459         // This is mainly a way to pass the time to the server.
460         // Actual processing is done in an another thread.
461         void step(float dtime);
462         // This is run by ServerThread and does the actual processing
463         void AsyncRunStep();
464         void Receive();
465         void ProcessData(u8 *data, u32 datasize, u16 peer_id);
466
467         core::list<PlayerInfo> getPlayerInfo();
468
469         // Environment must be locked when called
470         void setTimeOfDay(u32 time)
471         {
472                 m_env->setTimeOfDay(time);
473                 m_time_of_day_send_timer = 0;
474         }
475
476         bool getShutdownRequested()
477         {
478                 return m_shutdown_requested;
479         }
480
481         /*
482                 Shall be called with the environment locked.
483                 This is accessed by the map, which is inside the environment,
484                 so it shouldn't be a problem.
485         */
486         void onMapEditEvent(MapEditEvent *event);
487
488         /*
489                 Shall be called with the environment and the connection locked.
490         */
491         Inventory* getInventory(const InventoryLocation &loc);
492         void setInventoryModified(const InventoryLocation &loc);
493
494         // Connection must be locked when called
495         std::wstring getStatusString();
496
497         void requestShutdown(void)
498         {
499                 m_shutdown_requested = true;
500         }
501
502         // Returns -1 if failed, sound handle on success
503         // Envlock + conlock
504         s32 playSound(const SimpleSoundSpec &spec, const ServerSoundParams &params);
505         void stopSound(s32 handle);
506
507         // Envlock + conlock
508         std::set<std::string> getPlayerEffectivePrivs(const std::string &name);
509         bool checkPriv(const std::string &name, const std::string &priv);
510         void reportPrivsModified(const std::string &name=""); // ""=all
511         void reportInventoryFormspecModified(const std::string &name);
512
513         // Saves g_settings to configpath given at initialization
514         void saveConfig();
515
516         void setIpBanned(const std::string &ip, const std::string &name)
517         {
518                 m_banmanager.add(ip, name);
519                 return;
520         }
521
522         void unsetIpBanned(const std::string &ip_or_name)
523         {
524                 m_banmanager.remove(ip_or_name);
525                 return;
526         }
527
528         std::string getBanDescription(const std::string &ip_or_name)
529         {
530                 return m_banmanager.getBanDescription(ip_or_name);
531         }
532
533         Address getPeerAddress(u16 peer_id)
534         {
535                 return m_con.GetPeerAddress(peer_id);
536         }
537
538         // Envlock and conlock should be locked when calling this
539         void notifyPlayer(const char *name, const std::wstring msg);
540         void notifyPlayers(const std::wstring msg);
541
542         void queueBlockEmerge(v3s16 blockpos, bool allow_generate);
543
544         // Creates or resets inventory
545         Inventory* createDetachedInventory(const std::string &name);
546
547         // Envlock and conlock should be locked when using Lua
548         lua_State *getLua(){ return m_lua; }
549
550         // Envlock should be locked when using the rollback manager
551         IRollbackManager *getRollbackManager(){ return m_rollback; }
552
553         //TODO:  determine what should be locked when accessing the emerge manager
554         EmergeManager *getEmergeManager(){ return m_emerge; }
555
556         BiomeDefManager *getBiomeDef(){ return m_biomedef; }
557
558         // actions: time-reversed list
559         // Return value: success/failure
560         bool rollbackRevertActions(const std::list<RollbackAction> &actions,
561                         std::list<std::string> *log);
562
563         // IGameDef interface
564         // Under envlock
565         virtual IItemDefManager* getItemDefManager();
566         virtual INodeDefManager* getNodeDefManager();
567         virtual ICraftDefManager* getCraftDefManager();
568         virtual ITextureSource* getTextureSource();
569         virtual IShaderSource* getShaderSource();
570         virtual u16 allocateUnknownNodeId(const std::string &name);
571         virtual ISoundManager* getSoundManager();
572         virtual MtEventManager* getEventManager();
573         virtual IRollbackReportSink* getRollbackReportSink();
574
575         IWritableItemDefManager* getWritableItemDefManager();
576         IWritableNodeDefManager* getWritableNodeDefManager();
577         IWritableCraftDefManager* getWritableCraftDefManager();
578
579         const ModSpec* getModSpec(const std::string &modname);
580         void getModNames(core::list<std::string> &modlist);
581         std::string getBuiltinLuaPath();
582
583         std::string getWorldPath(){ return m_path_world; }
584
585         bool isSingleplayer(){ return m_simple_singleplayer_mode; }
586
587         void setAsyncFatalError(const std::string &error)
588         {
589                 m_async_fatal_error.set(error);
590         }
591
592         bool showFormspec(const char *name, const std::string &formspec, const std::string &formname);
593 private:
594
595         // con::PeerHandler implementation.
596         // These queue stuff to be processed by handlePeerChanges().
597         // As of now, these create and remove clients and players.
598         void peerAdded(con::Peer *peer);
599         void deletingPeer(con::Peer *peer, bool timeout);
600
601         /*
602                 Static send methods
603         */
604
605         static void SendMovement(con::Connection &con, u16 peer_id);
606         static void SendHP(con::Connection &con, u16 peer_id, u8 hp);
607         static void SendAccessDenied(con::Connection &con, u16 peer_id,
608                         const std::wstring &reason);
609         static void SendDeathscreen(con::Connection &con, u16 peer_id,
610                         bool set_camera_point_target, v3f camera_point_target);
611         static void SendItemDef(con::Connection &con, u16 peer_id,
612                         IItemDefManager *itemdef);
613         static void SendNodeDef(con::Connection &con, u16 peer_id,
614                         INodeDefManager *nodedef, u16 protocol_version);
615
616         /*
617                 Non-static send methods.
618                 Conlock should be always used.
619                 Envlock usage is documented badly but it's easy to figure out
620                 which ones access the environment.
621         */
622
623         // Envlock and conlock should be locked when calling these
624         void SendInventory(u16 peer_id);
625         void SendChatMessage(u16 peer_id, const std::wstring &message);
626         void BroadcastChatMessage(const std::wstring &message);
627         void SendPlayerHP(u16 peer_id);
628         void SendMovePlayer(u16 peer_id);
629         void SendPlayerPrivileges(u16 peer_id);
630         void SendPlayerInventoryFormspec(u16 peer_id);
631         void SendShowFormspecMessage(u16 peer_id, const std::string formspec, const std::string formname);
632         /*
633                 Send a node removal/addition event to all clients except ignore_id.
634                 Additionally, if far_players!=NULL, players further away than
635                 far_d_nodes are ignored and their peer_ids are added to far_players
636         */
637         // Envlock and conlock should be locked when calling these
638         void sendRemoveNode(v3s16 p, u16 ignore_id=0,
639                         core::list<u16> *far_players=NULL, float far_d_nodes=100);
640         void sendAddNode(v3s16 p, MapNode n, u16 ignore_id=0,
641                         core::list<u16> *far_players=NULL, float far_d_nodes=100);
642         void setBlockNotSent(v3s16 p);
643
644         // Environment and Connection must be locked when called
645         void SendBlockNoLock(u16 peer_id, MapBlock *block, u8 ver);
646
647         // Sends blocks to clients (locks env and con on its own)
648         void SendBlocks(float dtime);
649
650         void fillMediaCache();
651         void sendMediaAnnouncement(u16 peer_id);
652         void sendRequestedMedia(u16 peer_id,
653                         const core::list<MediaRequest> &tosend);
654
655         void sendDetachedInventory(const std::string &name, u16 peer_id);
656         void sendDetachedInventoryToAll(const std::string &name);
657         void sendDetachedInventories(u16 peer_id);
658
659         /*
660                 Something random
661         */
662
663         void DiePlayer(u16 peer_id);
664         void RespawnPlayer(u16 peer_id);
665
666         void UpdateCrafting(u16 peer_id);
667
668         // When called, connection mutex should be locked
669         RemoteClient* getClient(u16 peer_id);
670
671         // When called, environment mutex should be locked
672         std::string getPlayerName(u16 peer_id)
673         {
674                 Player *player = m_env->getPlayer(peer_id);
675                 if(player == NULL)
676                         return "[id="+itos(peer_id)+"]";
677                 return player->getName();
678         }
679
680         // When called, environment mutex should be locked
681         PlayerSAO* getPlayerSAO(u16 peer_id)
682         {
683                 Player *player = m_env->getPlayer(peer_id);
684                 if(player == NULL)
685                         return NULL;
686                 return player->getPlayerSAO();
687         }
688
689         /*
690                 Get a player from memory or creates one.
691                 If player is already connected, return NULL
692                 Does not verify/modify auth info and password.
693
694                 Call with env and con locked.
695         */
696         PlayerSAO *emergePlayer(const char *name, u16 peer_id);
697
698         // Locks environment and connection by its own
699         struct PeerChange;
700         void handlePeerChange(PeerChange &c);
701         void handlePeerChanges();
702
703         /*
704                 Variables
705         */
706
707         // World directory
708         std::string m_path_world;
709         // Path to user's configuration file ("" = no configuration file)
710         std::string m_path_config;
711         // Subgame specification
712         SubgameSpec m_gamespec;
713         // If true, do not allow multiple players and hide some multiplayer
714         // functionality
715         bool m_simple_singleplayer_mode;
716
717         // Thread can set; step() will throw as ServerError
718         MutexedVariable<std::string> m_async_fatal_error;
719
720         // Some timers
721         float m_liquid_transform_timer;
722         float m_print_info_timer;
723         float m_objectdata_timer;
724         float m_emergethread_trigger_timer;
725         float m_savemap_timer;
726         IntervalLimiter m_map_timer_and_unload_interval;
727
728         // NOTE: If connection and environment are both to be locked,
729         // environment shall be locked first.
730
731         // Environment
732         ServerEnvironment *m_env;
733         JMutex m_env_mutex;
734
735         // Connection
736         con::Connection m_con;
737         JMutex m_con_mutex;
738         // Connected clients (behind the con mutex)
739         core::map<u16, RemoteClient*> m_clients;
740
741         // Bann checking
742         BanManager m_banmanager;
743
744         // Rollback manager (behind m_env_mutex)
745         IRollbackManager *m_rollback;
746         bool m_rollback_sink_enabled;
747         bool m_enable_rollback_recording; // Updated once in a while
748
749         // Emerge manager
750         EmergeManager *m_emerge;
751
752         // Biome Definition Manager
753         BiomeDefManager *m_biomedef;
754
755         // Scripting
756         // Envlock and conlock should be locked when using Lua
757         lua_State *m_lua;
758
759         // Item definition manager
760         IWritableItemDefManager *m_itemdef;
761
762         // Node definition manager
763         IWritableNodeDefManager *m_nodedef;
764
765         // Craft definition manager
766         IWritableCraftDefManager *m_craftdef;
767
768         // Event manager
769         EventManager *m_event;
770
771         // Mods
772         std::vector<ModSpec> m_mods;
773
774         /*
775                 Threads
776         */
777
778         // A buffer for time steps
779         // step() increments and AsyncRunStep() run by m_thread reads it.
780         float m_step_dtime;
781         JMutex m_step_dtime_mutex;
782
783         // The server mainly operates in this thread
784         ServerThread m_thread;
785         // This thread fetches and generates map
786         EmergeThread m_emergethread;
787         // Queue of block coordinates to be processed by the emerge thread
788         BlockEmergeQueue m_emerge_queue;
789
790         /*
791                 Time related stuff
792         */
793
794         // Timer for sending time of day over network
795         float m_time_of_day_send_timer;
796         // Uptime of server in seconds
797         MutexedVariable<double> m_uptime;
798
799         /*
800                 Peer change queue.
801                 Queues stuff from peerAdded() and deletingPeer() to
802                 handlePeerChanges()
803         */
804         enum PeerChangeType
805         {
806                 PEER_ADDED,
807                 PEER_REMOVED
808         };
809         struct PeerChange
810         {
811                 PeerChangeType type;
812                 u16 peer_id;
813                 bool timeout;
814         };
815         Queue<PeerChange> m_peer_change_queue;
816
817         /*
818                 Random stuff
819         */
820
821         // Mod parent directory paths
822         core::list<std::string> m_modspaths;
823
824         bool m_shutdown_requested;
825
826         /*
827                 Map edit event queue. Automatically receives all map edits.
828                 The constructor of this class registers us to receive them through
829                 onMapEditEvent
830
831                 NOTE: Should these be moved to actually be members of
832                 ServerEnvironment?
833         */
834
835         /*
836                 Queue of map edits from the environment for sending to the clients
837                 This is behind m_env_mutex
838         */
839         Queue<MapEditEvent*> m_unsent_map_edit_queue;
840         /*
841                 Set to true when the server itself is modifying the map and does
842                 all sending of information by itself.
843                 This is behind m_env_mutex
844         */
845         bool m_ignore_map_edit_events;
846         /*
847                 If a non-empty area, map edit events contained within are left
848                 unsent. Done at map generation time to speed up editing of the
849                 generated area, as it will be sent anyway.
850                 This is behind m_env_mutex
851         */
852         VoxelArea m_ignore_map_edit_events_area;
853         /*
854                 If set to !=0, the incoming MapEditEvents are modified to have
855                 this peed id as the disabled recipient
856                 This is behind m_env_mutex
857         */
858         u16 m_ignore_map_edit_events_peer_id;
859
860         friend class EmergeThread;
861         friend class RemoteClient;
862
863         std::map<std::string,MediaInfo> m_media;
864
865         /*
866                 Sounds
867         */
868         std::map<s32, ServerPlayingSound> m_playing_sounds;
869         s32 m_next_sound_id;
870
871         /*
872                 Detached inventories (behind m_env_mutex)
873         */
874         // key = name
875         std::map<std::string, Inventory*> m_detached_inventories;
876 };
877
878 /*
879         Runs a simple dedicated server loop.
880
881         Shuts down when run is set to false.
882 */
883 void dedicated_server_loop(Server &server, bool &run);
884
885 #endif
886