summaryrefslogtreecommitdiff
path: root/src/server.h
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2020-05-07 22:38:41 +0200
committerGitHub <noreply@github.com>2020-05-07 22:38:41 +0200
commit454dbf83a9bf292910c1495a2aa49fd8b960c28f (patch)
treed3f53bb5914bae385198d3290863ee1c94832dfd /src/server.h
parent650168cadac2a45277a9527ae79efb288ba7a4a4 (diff)
downloadminetest-454dbf83a9bf292910c1495a2aa49fd8b960c28f.tar.gz
minetest-454dbf83a9bf292910c1495a2aa49fd8b960c28f.tar.bz2
minetest-454dbf83a9bf292910c1495a2aa49fd8b960c28f.zip
Server class code cleanups (#9769)
* Server::overrideDayNightRatio doesn't require to return bool There is no sense to sending null player, the caller should send a valid object * Server::init: make private & cleanup This function is always called before start() and loads some variables which can be loaded in constructor directly. Make it private and call it directly in start * Split Server inventory responsibility to a dedicated object This splits permit to found various historical issues: * duplicate lookups on player connection * sending inventory to non related player when a player connects * non friendly lookups on detached inventories ownership This reduce the detached inventory complexity and also increased the lookup performance in a quite interesting way for servers with thousands of inventories.
Diffstat (limited to 'src/server.h')
-rw-r--r--src/server.h33
1 files changed, 10 insertions, 23 deletions
diff --git a/src/server.h b/src/server.h
index 71059dd30..7a1de9370 100644
--- a/src/server.h
+++ b/src/server.h
@@ -68,6 +68,7 @@ struct MoonParams;
struct StarParams;
class ServerThread;
class ServerModManager;
+class ServerInventoryManager;
enum ClientDeletionReason {
CDR_LEAVE,
@@ -116,7 +117,7 @@ struct ServerPlayingSound
};
class Server : public con::PeerHandler, public MapEventReceiver,
- public InventoryManager, public IGameDef
+ public IGameDef
{
public:
/*
@@ -134,7 +135,6 @@ public:
~Server();
DISABLE_CLASS_COPY(Server);
- void init();
void start();
void stop();
// This is mainly a way to pass the time to the server.
@@ -196,12 +196,6 @@ public:
*/
void onMapEditEvent(const MapEditEvent &event);
- /*
- Shall be called with the environment and the connection locked.
- */
- Inventory* getInventory(const InventoryLocation &loc);
- void setInventoryModified(const InventoryLocation &loc);
-
// Connection must be locked when called
std::wstring getStatusString();
inline double getUptime() const { return m_uptime_counter->get(); }
@@ -253,10 +247,8 @@ public:
void deleteParticleSpawner(const std::string &playername, u32 id);
- // Creates or resets inventory
- Inventory *createDetachedInventory(const std::string &name,
- const std::string &player = "");
- bool removeDetachedInventory(const std::string &name);
+ ServerInventoryManager *getInventoryMgr() const { return m_inventory_mgr.get(); }
+ void sendDetachedInventory(Inventory *inventory, const std::string &name, session_t peer_id);
// Envlock and conlock should be locked when using scriptapi
ServerScripting *getScriptIface(){ return m_script; }
@@ -318,7 +310,7 @@ public:
void setClouds(RemotePlayer *player, const CloudParams &params);
- bool overrideDayNightRatio(RemotePlayer *player, bool do_override, float brightness);
+ void overrideDayNightRatio(RemotePlayer *player, bool do_override, float brightness);
/* con::PeerHandler implementation. */
void peerAdded(con::Peer *peer);
@@ -389,6 +381,8 @@ private:
float m_timer = 0.0f;
};
+ void init();
+
void SendMovement(session_t peer_id);
void SendHP(session_t peer_id, u16 hp);
void SendBreath(session_t peer_id, u16 breath);
@@ -457,8 +451,6 @@ private:
void sendRequestedMedia(session_t peer_id,
const std::vector<std::string> &tosend);
- void sendDetachedInventory(const std::string &name, session_t peer_id);
-
// Adds a ParticleSpawner on peer with peer_id (PEER_ID_INEXISTENT == all)
void SendAddParticleSpawner(session_t peer_id, u16 protocol_version,
u16 amount, float spawntime,
@@ -656,14 +648,6 @@ private:
s32 m_next_sound_id = 0; // positive values only
s32 nextSoundId();
- /*
- Detached inventories (behind m_env_mutex)
- */
- // key = name
- std::map<std::string, Inventory*> m_detached_inventories;
- // value = "" (visible to all players) or player name
- std::map<std::string, std::string> m_detached_inventories_player;
-
std::unordered_map<std::string, ModMetadata *> m_mod_storages;
float m_mod_storage_save_timer = 10.0f;
@@ -674,6 +658,9 @@ private:
// ModChannel manager
std::unique_ptr<ModChannelMgr> m_modchannel_mgr;
+ // Inventory manager
+ std::unique_ptr<ServerInventoryManager> m_inventory_mgr;
+
// Global server metrics backend
std::unique_ptr<MetricsBackend> m_metrics_backend;