Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
rollback.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5#pragma once
6
7#include <string>
8#include "irr_v3d.h"
10#include <list>
11#include <vector>
12#include "sqlite3.h"
13
14class IGameDef;
15
16struct ActionRow;
17struct Entity;
18
20{
21public:
22 RollbackManager(const std::string & world_path, IGameDef * gamedef);
24
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();
32
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);
38
39private:
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);
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);
63
64
65 IGameDef *gamedef = nullptr;
66
67 std::string current_actor;
69
70 std::list<RollbackAction> action_todisk_buffer;
71 std::list<RollbackAction> action_latest_buffer;
72
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;
84
85 std::vector<Entity> knownActors;
86 std::vector<Entity> knownNodes;
87};
Definition gamedef.h:36
Definition rollback_interface.h:97
Definition rollback.h:20
static float getSuspectNearness(bool is_guess, v3s16 suspect_p, time_t suspect_t, v3s16 action_p, time_t action_t)
Definition rollback.cpp:650
void flush()
Definition rollback.cpp:765
sqlite3_stmt * stmt_knownNode_insert
Definition rollback.h:83
void reportAction(const RollbackAction &action_)
Definition rollback.cpp:675
std::list< RollbackAction > getRevertActions(const std::string &actor_filter, time_t seconds)
Definition rollback.cpp:807
std::string getSuspect(v3s16 p, float nearness_shortcut, float min_nearness)
Definition rollback.cpp:722
int getNodeId(const std::string &name)
Definition rollback.cpp:142
std::string current_actor
Definition rollback.h:67
void registerNewActor(const int id, const std::string &name)
Definition rollback.cpp:108
const std::list< ActionRow > getRowsSince_range(time_t firstTime, v3s16 p, int range, int limit)
Definition rollback.cpp:614
std::vector< Entity > knownActors
Definition rollback.h:85
bool current_actor_is_guess
Definition rollback.h:68
std::vector< Entity > knownNodes
Definition rollback.h:86
RollbackManager(const std::string &world_path, IGameDef *gamedef)
Definition rollback.cpp:77
sqlite3_stmt * stmt_select
Definition rollback.h:77
bool registerRow(const ActionRow &row)
Definition rollback.cpp:364
~RollbackManager()
Definition rollback.cpp:90
sqlite3_stmt * stmt_select_range
Definition rollback.h:78
bool isActorGuess()
Definition rollback.cpp:711
const std::list< RollbackAction > getActionsSince(time_t firstTime, const std::string &actor="")
Definition rollback.cpp:641
void addAction(const RollbackAction &action)
Definition rollback.cpp:786
const std::list< RollbackAction > rollbackActionsFromActionRows(const std::list< ActionRow > &rows)
Definition rollback.cpp:551
sqlite3_stmt * stmt_knownActor_insert
Definition rollback.h:81
bool initDatabase()
Definition rollback.cpp:235
void setActor(const std::string &actor, bool is_guess)
Definition rollback.cpp:716
sqlite3_stmt * stmt_knownActor_select
Definition rollback.h:80
const char * getActorName(const int id)
Definition rollback.cpp:162
void registerNewNode(const int id, const std::string &name)
Definition rollback.cpp:115
sqlite3_stmt * stmt_select_withActor
Definition rollback.h:79
bool createTables()
Definition rollback.cpp:188
std::list< RollbackAction > action_latest_buffer
Definition rollback.h:71
ActionRow actionRowFromRollbackAction(const RollbackAction &action)
Definition rollback.cpp:516
const char * getNodeName(const int id)
Definition rollback.cpp:175
std::list< RollbackAction > getNodeActors(v3s16 pos, int range, time_t seconds, int limit)
Definition rollback.cpp:797
IGameDef * gamedef
Definition rollback.h:65
std::list< RollbackAction > action_todisk_buffer
Definition rollback.h:70
const std::list< RollbackAction > getActionsSince_range(time_t firstTime, v3s16 p, int range, int limit)
Definition rollback.cpp:634
const std::list< ActionRow > getRowsSince(time_t firstTime, const std::string &actor)
Definition rollback.cpp:598
std::string getActor()
Definition rollback.cpp:706
sqlite3_stmt * stmt_insert
Definition rollback.h:75
sqlite3 * db
Definition rollback.h:74
const std::list< ActionRow > actionRowsFromSelect(sqlite3_stmt *stmt)
Definition rollback.cpp:449
std::string database_path
Definition rollback.h:73
sqlite3_stmt * stmt_replace
Definition rollback.h:76
int getActorId(const std::string &name)
Definition rollback.cpp:122
sqlite3_stmt * stmt_knownNode_select
Definition rollback.h:82
core::vector3d< s16 > v3s16
Definition irr_v3d.h:13
Definition rollback.cpp:50
Definition rollback.cpp:70
Definition rollback_interface.h:40
static std::string p(std::string path)
Definition test_filesys.cpp:53