Minetest 5.9.0-dev
 
Loading...
Searching...
No Matches
serverinventorymgr.h
Go to the documentation of this file.
1/*
2Minetest
3Copyright (C) 2010-2020 Minetest core development team
4
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU Lesser General Public License as published by
7the Free Software Foundation; either version 2.1 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public License along
16with this program; if not, write to the Free Software Foundation, Inc.,
1751 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18*/
19
20#pragma once
21
22#include "inventorymanager.h"
23#include <cassert>
24#include <functional>
25#include <memory>
26#include <unordered_map>
27
28class IItemDefManager;
30
32{
33public:
35 virtual ~ServerInventoryManager() = default;
36
38 {
39 assert(!m_env);
40 m_env = env;
41 }
42
43 // virtual: Overwritten by MockInventoryManager for the unittests
44 virtual Inventory *getInventory(const InventoryLocation &loc);
45 virtual void setInventoryModified(const InventoryLocation &loc);
46
47 // Creates or resets inventory
48 Inventory *createDetachedInventory(const std::string &name, IItemDefManager *idef,
49 const std::string &player = "");
50 bool removeDetachedInventory(const std::string &name);
51 bool checkDetachedInventoryAccess(const InventoryLocation &loc, const std::string &player) const;
52
53 void sendDetachedInventories(const std::string &peer_name, bool incremental,
54 std::function<void(const std::string &, Inventory *)> apply_cb);
55
56protected:
58 {
59 std::unique_ptr<Inventory> inventory;
60 std::string owner;
61 };
62
64
65 std::unordered_map<std::string, DetachedInventory> m_detached_inventories;
66};
Definition: itemdef.h:143
Definition: inventorymanager.h:111
Definition: inventory.h:329
Definition: serverenvironment.h:220
Definition: serverinventorymgr.h:32
ServerInventoryManager()
Definition: serverinventorymgr.cpp:28
Inventory * createDetachedInventory(const std::string &name, IItemDefManager *idef, const std::string &player="")
Definition: serverinventorymgr.cpp:102
bool checkDetachedInventoryAccess(const InventoryLocation &loc, const std::string &player) const
Definition: serverinventorymgr.cpp:170
std::unordered_map< std::string, DetachedInventory > m_detached_inventories
Definition: serverinventorymgr.h:65
bool removeDetachedInventory(const std::string &name)
Definition: serverinventorymgr.cpp:142
virtual void setInventoryModified(const InventoryLocation &loc)
Definition: serverinventorymgr.cpp:71
void sendDetachedInventories(const std::string &peer_name, bool incremental, std::function< void(const std::string &, Inventory *)> apply_cb)
Definition: serverinventorymgr.cpp:182
virtual ~ServerInventoryManager()=default
void setEnv(ServerEnvironment *env)
Definition: serverinventorymgr.h:37
ServerEnvironment * m_env
Definition: serverinventorymgr.h:63
virtual Inventory * getInventory(const InventoryLocation &loc)
Definition: serverinventorymgr.cpp:32
Definition: inventorymanager.h:33
Definition: serverinventorymgr.h:58
std::unique_ptr< Inventory > inventory
Definition: serverinventorymgr.h:59
std::string owner
Definition: serverinventorymgr.h:60