3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
26 #include "exceptions.h"
27 #include "inventory.h"
32 class InventoryManager;
41 bool operator == (const RollbackNode &other)
43 return (name == other.name && param1 == other.param1 &&
44 param2 == other.param2 && meta == other.meta);
46 bool operator != (const RollbackNode &other) { return !(*this == other); }
49 RollbackNode(Map *map, v3s16 p, IGameDef *gamedef);
58 TYPE_MODIFY_INVENTORY_STACK,
69 std::string inventory_location;
70 std::string inventory_list;
73 ItemStack inventory_stack;
81 void setSetNode(v3s16 p_, const RollbackNode &n_old_,
82 const RollbackNode &n_new_)
90 void setModifyInventoryStack(const std::string &inventory_location_,
91 const std::string &inventory_list_, int index_,
92 bool add_, const ItemStack &inventory_stack_)
94 type = TYPE_MODIFY_INVENTORY_STACK;
95 inventory_location = inventory_location_;
96 inventory_list = inventory_list_;
97 inventory_index = index_;
99 inventory_stack = inventory_stack_;
102 // String should not contain newlines or nulls
103 std::string toString() const;
105 // Eg. flowing water level changes are not important
106 bool isImportant(IGameDef *gamedef) const;
108 bool getPosition(v3s16 *dst) const;
110 bool applyRevert(Map *map, InventoryManager *imgr, IGameDef *gamedef) const;
114 class IRollbackManager
117 virtual void reportAction(const RollbackAction &action) = 0;
118 virtual std::string getActor() = 0;
119 virtual bool isActorGuess() = 0;
120 virtual void setActor(const std::string &actor, bool is_guess) = 0;
121 virtual std::string getSuspect(v3s16 p, float nearness_shortcut,
122 float min_nearness) = 0;
124 virtual ~IRollbackManager() {};
125 virtual void flush() = 0;
126 // Get all actors that did something to position p, but not further than
127 // <seconds> in history
128 virtual std::list<RollbackAction> getNodeActors(v3s16 pos, int range,
129 time_t seconds, int limit) = 0;
130 // Get actions to revert <seconds> of history made by <actor>
131 virtual std::list<RollbackAction> getRevertActions(const std::string &actor,
136 class RollbackScopeActor
139 RollbackScopeActor(IRollbackManager * rollback_,
140 const std::string & actor, bool is_guess = false) :
144 old_actor = rollback->getActor();
145 old_actor_guess = rollback->isActorGuess();
146 rollback->setActor(actor, is_guess);
149 ~RollbackScopeActor()
152 rollback->setActor(old_actor, old_actor_guess);
157 IRollbackManager * rollback;
158 std::string old_actor;
159 bool old_actor_guess;