Include backtrace in error message when LuaErrors occur
[minetest-c55.git] / src / rollback.h
blobc57e38ab0bbc7330c1b78dd0cbb07a1c7726801a
1 /*
2 Minetest
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_HEADER
21 #define ROLLBACK_HEADER
23 #include <string>
24 #include "irr_v3d.h"
25 #include "rollback_interface.h"
26 #include <list>
27 #include <vector>
28 #include "sqlite3.h"
30 class IGameDef;
32 struct ActionRow;
33 struct Entity;
35 class RollbackManager: public IRollbackManager
37 public:
38 RollbackManager(const std::string & world_path, IGameDef * gamedef);
39 ~RollbackManager();
41 void reportAction(const RollbackAction & action_);
42 std::string getActor();
43 bool isActorGuess();
44 void setActor(const std::string & actor, bool is_guess);
45 std::string getSuspect(v3s16 p, float nearness_shortcut,
46 float min_nearness);
47 void flush();
49 void addAction(const RollbackAction & action);
50 std::list<RollbackAction> getEntriesSince(time_t first_time);
51 std::list<RollbackAction> getNodeActors(v3s16 pos, int range,
52 time_t seconds, int limit);
53 std::list<RollbackAction> getRevertActions(
54 const std::string & actor_filter, time_t seconds);
56 private:
57 void registerNewActor(const int id, const std::string & name);
58 void registerNewNode(const int id, const std::string & name);
59 int getActorId(const std::string & name);
60 int getNodeId(const std::string & name);
61 const char * getActorName(const int id);
62 const char * getNodeName(const int id);
63 bool createTables();
64 void initDatabase();
65 bool registerRow(const ActionRow & row);
66 const std::list<ActionRow> actionRowsFromSelect(sqlite3_stmt * stmt);
67 ActionRow actionRowFromRollbackAction(const RollbackAction & action);
68 const std::list<RollbackAction> rollbackActionsFromActionRows(
69 const std::list<ActionRow> & rows);
70 const std::list<ActionRow> getRowsSince(time_t firstTime,
71 const std::string & actor);
72 const std::list<ActionRow> getRowsSince_range(time_t firstTime, v3s16 p,
73 int range, int limit);
74 const std::list<RollbackAction> getActionsSince_range(time_t firstTime, v3s16 p,
75 int range, int limit);
76 const std::list<RollbackAction> getActionsSince(time_t firstTime,
77 const std::string & actor = "");
78 void migrate(const std::string & filepath);
79 static float getSuspectNearness(bool is_guess, v3s16 suspect_p,
80 time_t suspect_t, v3s16 action_p, time_t action_t);
83 IGameDef * gamedef;
85 std::string current_actor;
86 bool current_actor_is_guess;
88 std::list<RollbackAction> action_todisk_buffer;
89 std::list<RollbackAction> action_latest_buffer;
91 std::string database_path;
92 sqlite3 * db;
93 sqlite3_stmt * stmt_insert;
94 sqlite3_stmt * stmt_replace;
95 sqlite3_stmt * stmt_select;
96 sqlite3_stmt * stmt_select_range;
97 sqlite3_stmt * stmt_select_withActor;
98 sqlite3_stmt * stmt_knownActor_select;
99 sqlite3_stmt * stmt_knownActor_insert;
100 sqlite3_stmt * stmt_knownNode_select;
101 sqlite3_stmt * stmt_knownNode_insert;
103 std::vector<Entity> knownActors;
104 std::vector<Entity> knownNodes;
107 #endif