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.
20 #ifndef ROLLBACK_INTERFACE_HEADER
21 #define ROLLBACK_INTERFACE_HEADER
27 #include "exceptions.h"
28 #include "inventory.h"
33 class InventoryManager;
42 bool operator == (const RollbackNode &other)
44 return (name == other.name && param1 == other.param1 &&
45 param2 == other.param2 && meta == other.meta);
47 bool operator != (const RollbackNode &other) { return !(*this == other); }
54 RollbackNode(Map *map, v3s16 p, IGameDef *gamedef);
63 TYPE_MODIFY_INVENTORY_STACK,
74 std::string inventory_location;
75 std::string inventory_list;
78 ItemStack inventory_stack;
86 void setSetNode(v3s16 p_, const RollbackNode &n_old_,
87 const RollbackNode &n_new_)
95 void setModifyInventoryStack(const std::string &inventory_location_,
96 const std::string &inventory_list_, int index_,
97 bool add_, const ItemStack &inventory_stack_)
99 type = TYPE_MODIFY_INVENTORY_STACK;
100 inventory_location = inventory_location_;
101 inventory_list = inventory_list_;
102 inventory_index = index_;
103 inventory_add = add_;
104 inventory_stack = inventory_stack_;
107 // String should not contain newlines or nulls
108 std::string toString() const;
110 // Eg. flowing water level changes are not important
111 bool isImportant(IGameDef *gamedef) const;
113 bool getPosition(v3s16 *dst) const;
115 bool applyRevert(Map *map, InventoryManager *imgr, IGameDef *gamedef) const;
119 class IRollbackManager
122 virtual void reportAction(const RollbackAction &action) = 0;
123 virtual std::string getActor() = 0;
124 virtual bool isActorGuess() = 0;
125 virtual void setActor(const std::string &actor, bool is_guess) = 0;
126 virtual std::string getSuspect(v3s16 p, float nearness_shortcut,
127 float min_nearness) = 0;
129 virtual ~IRollbackManager() {};
130 virtual void flush() = 0;
131 // Get all actors that did something to position p, but not further than
132 // <seconds> in history
133 virtual std::list<RollbackAction> getNodeActors(v3s16 pos, int range,
134 time_t seconds, int limit) = 0;
135 // Get actions to revert <seconds> of history made by <actor>
136 virtual std::list<RollbackAction> getRevertActions(const std::string &actor,
141 class RollbackScopeActor
144 RollbackScopeActor(IRollbackManager * rollback_,
145 const std::string & actor, bool is_guess = false) :
149 old_actor = rollback->getActor();
150 old_actor_guess = rollback->isActorGuess();
151 rollback->setActor(actor, is_guess);
154 ~RollbackScopeActor()
157 rollback->setActor(old_actor, old_actor_guess);
162 IRollbackManager * rollback;
163 std::string old_actor;
164 bool old_actor_guess;