Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
serverinventorymgr.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2010-2020 Minetest core development team
4
5#pragma once
6
7#include "inventorymanager.h"
8#include <cassert>
9#include <functional>
10#include <memory>
11#include <unordered_map>
12
13class IItemDefManager;
15
17{
18public:
20 virtual ~ServerInventoryManager() = default;
21
23 {
24 assert(!m_env);
25 m_env = env;
26 }
27
28 // virtual: Overwritten by MockInventoryManager for the unittests
29 virtual Inventory *getInventory(const InventoryLocation &loc);
30 virtual void setInventoryModified(const InventoryLocation &loc);
31
32 // Creates or resets inventory
33 Inventory *createDetachedInventory(const std::string &name, IItemDefManager *idef,
34 const std::string &player = "");
35 bool removeDetachedInventory(const std::string &name);
36 bool checkDetachedInventoryAccess(const InventoryLocation &loc, const std::string &player) const;
37
38 void sendDetachedInventories(const std::string &peer_name, bool incremental,
39 std::function<void(const std::string &, Inventory *)> apply_cb);
40
41protected:
43 {
44 std::unique_ptr<Inventory> inventory;
45 std::string owner;
46 };
47
49
50 std::unordered_map<std::string, DetachedInventory> m_detached_inventories;
51};
Definition itemdef.h:129
Definition inventorymanager.h:96
Definition inventory.h:314
Definition serverenvironment.h:219
Definition serverinventorymgr.h:17
ServerInventoryManager()
Definition serverinventorymgr.cpp:13
Inventory * createDetachedInventory(const std::string &name, IItemDefManager *idef, const std::string &player="")
Definition serverinventorymgr.cpp:87
bool checkDetachedInventoryAccess(const InventoryLocation &loc, const std::string &player) const
Definition serverinventorymgr.cpp:155
std::unordered_map< std::string, DetachedInventory > m_detached_inventories
Definition serverinventorymgr.h:50
bool removeDetachedInventory(const std::string &name)
Definition serverinventorymgr.cpp:127
virtual void setInventoryModified(const InventoryLocation &loc)
Definition serverinventorymgr.cpp:56
void sendDetachedInventories(const std::string &peer_name, bool incremental, std::function< void(const std::string &, Inventory *)> apply_cb)
Definition serverinventorymgr.cpp:167
virtual ~ServerInventoryManager()=default
void setEnv(ServerEnvironment *env)
Definition serverinventorymgr.h:22
ServerEnvironment * m_env
Definition serverinventorymgr.h:48
virtual Inventory * getInventory(const InventoryLocation &loc)
Definition serverinventorymgr.cpp:17
Definition inventorymanager.h:18
Definition serverinventorymgr.h:43
std::unique_ptr< Inventory > inventory
Definition serverinventorymgr.h:44
std::string owner
Definition serverinventorymgr.h:45