]> git.lizzy.rs Git - dragonfireclient.git/blob - src/rollback.h
Update jsoncpp to 1.9.4 (#10477)
[dragonfireclient.git] / src / rollback.h
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
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.
9
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.
14
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.
18 */
19
20 #pragma once
21
22 #include <string>
23 #include "irr_v3d.h"
24 #include "rollback_interface.h"
25 #include <list>
26 #include <vector>
27 #include "sqlite3.h"
28
29 class IGameDef;
30
31 struct ActionRow;
32 struct Entity;
33
34 class RollbackManager: public IRollbackManager
35 {
36 public:
37         RollbackManager(const std::string & world_path, IGameDef * gamedef);
38         ~RollbackManager();
39
40         void reportAction(const RollbackAction & action_);
41         std::string getActor();
42         bool isActorGuess();
43         void setActor(const std::string & actor, bool is_guess);
44         std::string getSuspect(v3s16 p, float nearness_shortcut,
45                         float min_nearness);
46         void flush();
47
48         void addAction(const RollbackAction & action);
49         std::list<RollbackAction> getEntriesSince(time_t first_time);
50         std::list<RollbackAction> getNodeActors(v3s16 pos, int range,
51                         time_t seconds, int limit);
52         std::list<RollbackAction> getRevertActions(
53                         const std::string & actor_filter, time_t seconds);
54
55 private:
56         void registerNewActor(const int id, const std::string & name);
57         void registerNewNode(const int id, const std::string & name);
58         int getActorId(const std::string & name);
59         int getNodeId(const std::string & name);
60         const char * getActorName(const int id);
61         const char * getNodeName(const int id);
62         bool createTables();
63         bool initDatabase();
64         bool registerRow(const ActionRow & row);
65         const std::list<ActionRow> actionRowsFromSelect(sqlite3_stmt * stmt);
66         ActionRow actionRowFromRollbackAction(const RollbackAction & action);
67         const std::list<RollbackAction> rollbackActionsFromActionRows(
68                         const std::list<ActionRow> & rows);
69         const std::list<ActionRow> getRowsSince(time_t firstTime,
70                         const std::string & actor);
71         const std::list<ActionRow> getRowsSince_range(time_t firstTime, v3s16 p,
72                         int range, int limit);
73         const std::list<RollbackAction> getActionsSince_range(time_t firstTime, v3s16 p,
74                         int range, int limit);
75         const std::list<RollbackAction> getActionsSince(time_t firstTime,
76                         const std::string & actor = "");
77         void migrate(const std::string & filepath);
78         static float getSuspectNearness(bool is_guess, v3s16 suspect_p,
79                 time_t suspect_t, v3s16 action_p, time_t action_t);
80
81
82         IGameDef *gamedef = nullptr;
83
84         std::string current_actor;
85         bool current_actor_is_guess = false;
86
87         std::list<RollbackAction> action_todisk_buffer;
88         std::list<RollbackAction> action_latest_buffer;
89
90         std::string database_path;
91         sqlite3 * db;
92         sqlite3_stmt * stmt_insert;
93         sqlite3_stmt * stmt_replace;
94         sqlite3_stmt * stmt_select;
95         sqlite3_stmt * stmt_select_range;
96         sqlite3_stmt * stmt_select_withActor;
97         sqlite3_stmt * stmt_knownActor_select;
98         sqlite3_stmt * stmt_knownActor_insert;
99         sqlite3_stmt * stmt_knownNode_select;
100         sqlite3_stmt * stmt_knownNode_insert;
101
102         std::vector<Entity> knownActors;
103         std::vector<Entity> knownNodes;
104 };