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.
24 #include "rollback_interface.h"
34 class RollbackManager : public IRollbackManager
37 RollbackManager(const std::string &world_path, IGameDef *gamedef);
40 void reportAction(const RollbackAction &action_);
41 std::string getActor();
43 void setActor(const std::string &actor, bool is_guess);
44 std::string getSuspect(v3s16 p, float nearness_shortcut, float min_nearness);
47 void addAction(const RollbackAction &action);
48 std::list<RollbackAction> getEntriesSince(time_t first_time);
49 std::list<RollbackAction> getNodeActors(
50 v3s16 pos, int range, time_t seconds, int limit);
51 std::list<RollbackAction> getRevertActions(
52 const std::string &actor_filter, time_t seconds);
55 void registerNewActor(const int id, const std::string &name);
56 void registerNewNode(const int id, const std::string &name);
57 int getActorId(const std::string &name);
58 int getNodeId(const std::string &name);
59 const char *getActorName(const int id);
60 const char *getNodeName(const int id);
63 bool registerRow(const ActionRow &row);
64 const std::list<ActionRow> actionRowsFromSelect(sqlite3_stmt *stmt);
65 ActionRow actionRowFromRollbackAction(const RollbackAction &action);
66 const std::list<RollbackAction> rollbackActionsFromActionRows(
67 const std::list<ActionRow> &rows);
68 const std::list<ActionRow> getRowsSince(
69 time_t firstTime, const std::string &actor);
70 const std::list<ActionRow> getRowsSince_range(
71 time_t firstTime, v3s16 p, int range, int limit);
72 const std::list<RollbackAction> getActionsSince_range(
73 time_t firstTime, v3s16 p, int range, int limit);
74 const std::list<RollbackAction> getActionsSince(
75 time_t firstTime, const std::string &actor = "");
76 void migrate(const std::string &filepath);
77 static float getSuspectNearness(bool is_guess, v3s16 suspect_p, time_t suspect_t,
78 v3s16 action_p, time_t action_t);
80 IGameDef *gamedef = nullptr;
82 std::string current_actor;
83 bool current_actor_is_guess = false;
85 std::list<RollbackAction> action_todisk_buffer;
86 std::list<RollbackAction> action_latest_buffer;
88 std::string database_path;
90 sqlite3_stmt *stmt_insert;
91 sqlite3_stmt *stmt_replace;
92 sqlite3_stmt *stmt_select;
93 sqlite3_stmt *stmt_select_range;
94 sqlite3_stmt *stmt_select_withActor;
95 sqlite3_stmt *stmt_knownActor_select;
96 sqlite3_stmt *stmt_knownActor_insert;
97 sqlite3_stmt *stmt_knownNode_select;
98 sqlite3_stmt *stmt_knownNode_insert;
100 std::vector<Entity> knownActors;
101 std::vector<Entity> knownNodes;