Luanti 5.19.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 Luanti 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 // args: name, inventory, owner
39 using SendCallbackFn = std::function<void(const std::string&, Inventory*, const std::string &)>;
40 void sendDetachedInventories(const std::string &filter_owner, bool incremental,
41 const SendCallbackFn &apply_cb);
42
43protected:
45 {
46 std::unique_ptr<Inventory> inventory;
47 std::string owner;
48 };
49
51
52 std::unordered_map<std::string, DetachedInventory> m_detached_inventories;
53};
Definition itemdef.h:146
InventoryManager()=default
Definition inventory.h:280
Definition serverenvironment.h:113
ServerInventoryManager()
Definition serverinventorymgr.cpp:13
void sendDetachedInventories(const std::string &filter_owner, bool incremental, const SendCallbackFn &apply_cb)
Definition serverinventorymgr.cpp:167
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:52
bool removeDetachedInventory(const std::string &name)
Definition serverinventorymgr.cpp:127
virtual void setInventoryModified(const InventoryLocation &loc)
Definition serverinventorymgr.cpp:56
virtual ~ServerInventoryManager()=default
void setEnv(ServerEnvironment *env)
Definition serverinventorymgr.h:22
ServerEnvironment * m_env
Definition serverinventorymgr.h:50
virtual Inventory * getInventory(const InventoryLocation &loc)
Definition serverinventorymgr.cpp:17
std::function< void(const std::string &, Inventory *, const std::string &)> SendCallbackFn
Definition serverinventorymgr.h:39
Definition inventorymanager.h:18
Definition serverinventorymgr.h:45
std::unique_ptr< Inventory > inventory
Definition serverinventorymgr.h:46
std::string owner
Definition serverinventorymgr.h:47