Fix enum setting used as requirement
[minetest.git] / src / server / rollback.h
blobc085b73135bd56a407c76eb525914b14805d823a
1 // Luanti
2 // SPDX-License-Identifier: LGPL-2.1-or-later
3 // Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 #pragma once
7 #include <string>
8 #include "irr_v3d.h"
9 #include "rollback_interface.h"
10 #include <list>
11 #include <vector>
12 #include "sqlite3.h"
14 class IGameDef;
16 struct ActionRow;
17 struct Entity;
19 class RollbackManager: public IRollbackManager
21 public:
22 RollbackManager(const std::string & world_path, IGameDef * gamedef);
23 ~RollbackManager();
25 void reportAction(const RollbackAction & action_);
26 std::string getActor();
27 bool isActorGuess();
28 void setActor(const std::string & actor, bool is_guess);
29 std::string getSuspect(v3s16 p, float nearness_shortcut,
30 float min_nearness);
31 void flush();
33 void addAction(const RollbackAction & action);
34 std::list<RollbackAction> getNodeActors(v3s16 pos, int range,
35 time_t seconds, int limit);
36 std::list<RollbackAction> getRevertActions(
37 const std::string & actor_filter, time_t seconds);
39 private:
40 void registerNewActor(const int id, const std::string & name);
41 void registerNewNode(const int id, const std::string & name);
42 int getActorId(const std::string & name);
43 int getNodeId(const std::string & name);
44 const char * getActorName(const int id);
45 const char * getNodeName(const int id);
46 bool createTables();
47 bool initDatabase();
48 bool registerRow(const ActionRow & row);
49 const std::list<ActionRow> actionRowsFromSelect(sqlite3_stmt * stmt);
50 ActionRow actionRowFromRollbackAction(const RollbackAction & action);
51 const std::list<RollbackAction> rollbackActionsFromActionRows(
52 const std::list<ActionRow> & rows);
53 const std::list<ActionRow> getRowsSince(time_t firstTime,
54 const std::string & actor);
55 const std::list<ActionRow> getRowsSince_range(time_t firstTime, v3s16 p,
56 int range, int limit);
57 const std::list<RollbackAction> getActionsSince_range(time_t firstTime, v3s16 p,
58 int range, int limit);
59 const std::list<RollbackAction> getActionsSince(time_t firstTime,
60 const std::string & actor = "");
61 static float getSuspectNearness(bool is_guess, v3s16 suspect_p,
62 time_t suspect_t, v3s16 action_p, time_t action_t);
65 IGameDef *gamedef = nullptr;
67 std::string current_actor;
68 bool current_actor_is_guess = false;
70 std::list<RollbackAction> action_todisk_buffer;
71 std::list<RollbackAction> action_latest_buffer;
73 std::string database_path;
74 sqlite3 * db;
75 sqlite3_stmt * stmt_insert;
76 sqlite3_stmt * stmt_replace;
77 sqlite3_stmt * stmt_select;
78 sqlite3_stmt * stmt_select_range;
79 sqlite3_stmt * stmt_select_withActor;
80 sqlite3_stmt * stmt_knownActor_select;
81 sqlite3_stmt * stmt_knownActor_insert;
82 sqlite3_stmt * stmt_knownNode_select;
83 sqlite3_stmt * stmt_knownNode_insert;
85 std::vector<Entity> knownActors;
86 std::vector<Entity> knownNodes;