Luanti 5.15.0-dev
 
Loading...
Searching...
No Matches
rollback_interface.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 "irr_v3d.h"
8#include <string>
9#include <list>
10#include "inventory.h"
11
12class Map;
13class IGameDef;
15
17{
18 std::string name;
19 int param1 = 0;
20 int param2 = 0;
21 std::string meta;
22
23 bool operator == (const RollbackNode &other) const
24 {
25 return (name == other.name && param1 == other.param1 &&
26 param2 == other.param2 && meta == other.meta);
27 }
28 bool operator != (const RollbackNode &other) const
29 {
30 return !(*this == other);
31 }
32
33 RollbackNode() = default;
34
35 RollbackNode(Map *map, v3s16 p, IGameDef *gamedef);
36};
37
38
40{
46
47 time_t unix_time = 0;
48 std::string actor;
49 bool actor_is_guess = false;
51
55
56 std::string inventory_location;
57 std::string inventory_list;
61
62 RollbackAction() = default;
63
64 void setSetNode(v3s16 p_, const RollbackNode &n_old_,
65 const RollbackNode &n_new_)
66 {
68 p = p_;
69 n_old = n_old_;
70 n_new = n_new_;
71 }
72
73 void setModifyInventoryStack(const std::string &inventory_location_,
74 const std::string &inventory_list_, u32 index_,
75 bool add_, const ItemStack &inventory_stack_)
76 {
78 inventory_location = inventory_location_;
79 inventory_list = inventory_list_;
80 inventory_index = index_;
81 inventory_add = add_;
82 inventory_stack = inventory_stack_;
83 }
84
85 // String should not contain newlines or nulls
86 std::string toString() const;
87
88 // Eg. flowing water level changes are not important
89 bool isImportant(IGameDef *gamedef) const;
90
91 bool getPosition(v3s16 *dst) const;
92
93 bool applyRevert(Map *map, InventoryManager *imgr, IGameDef *gamedef) const;
94};
95
96
98{
99public:
100 virtual void reportAction(const RollbackAction &action) = 0;
101 virtual std::string getActor() = 0;
102 virtual bool isActorGuess() = 0;
103 virtual void setActor(const std::string &actor, bool is_guess) = 0;
104 virtual std::string getSuspect(v3s16 p, float nearness_shortcut,
105 float min_nearness) = 0;
106
107 virtual ~IRollbackManager() = default;;
108 virtual void flush() = 0;
109 // Get all actors that did something to position p, but not further than
110 // <seconds> in history
111 virtual std::list<RollbackAction> getNodeActors(v3s16 pos, int range,
112 time_t seconds, int limit) = 0;
113 // Get actions to revert <seconds> of history made by <actor>
114 virtual std::list<RollbackAction> getRevertActions(const std::string &actor,
115 time_t seconds) = 0;
116};
117
118
120{
121public:
123 const std::string & actor, bool is_guess = false) :
124 rollback(rollback_)
125 {
126 if (rollback) {
129 rollback->setActor(actor, is_guess);
130 }
131 }
138
139private:
141 std::string old_actor;
143};
Definition gamedef.h:26
Definition rollback_interface.h:98
virtual void setActor(const std::string &actor, bool is_guess)=0
virtual std::string getActor()=0
virtual void reportAction(const RollbackAction &action)=0
virtual void flush()=0
virtual std::string getSuspect(v3s16 p, float nearness_shortcut, float min_nearness)=0
virtual ~IRollbackManager()=default
virtual std::list< RollbackAction > getRevertActions(const std::string &actor, time_t seconds)=0
virtual bool isActorGuess()=0
virtual std::list< RollbackAction > getNodeActors(v3s16 pos, int range, time_t seconds, int limit)=0
Definition inventorymanager.h:96
Definition map.h:100
Definition rollback_interface.h:120
RollbackScopeActor(IRollbackManager *rollback_, const std::string &actor, bool is_guess=false)
Definition rollback_interface.h:122
std::string old_actor
Definition rollback_interface.h:141
~RollbackScopeActor()
Definition rollback_interface.h:132
IRollbackManager * rollback
Definition rollback_interface.h:140
bool old_actor_guess
Definition rollback_interface.h:142
core::vector3d< s16 > v3s16
Definition irr_v3d.h:13
Definition inventory.h:21
Definition rollback_interface.h:40
bool applyRevert(Map *map, InventoryManager *imgr, IGameDef *gamedef) const
Definition rollback_interface.cpp:112
void setSetNode(v3s16 p_, const RollbackNode &n_old_, const RollbackNode &n_new_)
Definition rollback_interface.h:64
std::string inventory_location
Definition rollback_interface.h:56
std::string actor
Definition rollback_interface.h:48
bool getPosition(v3s16 *dst) const
Definition rollback_interface.cpp:92
bool inventory_add
Definition rollback_interface.h:59
RollbackNode n_new
Definition rollback_interface.h:54
std::string inventory_list
Definition rollback_interface.h:57
bool isImportant(IGameDef *gamedef) const
Definition rollback_interface.cpp:71
RollbackNode n_old
Definition rollback_interface.h:53
u32 inventory_index
Definition rollback_interface.h:58
RollbackAction()=default
std::string toString() const
Definition rollback_interface.cpp:39
Type
Definition rollback_interface.h:41
@ TYPE_MODIFY_INVENTORY_STACK
Definition rollback_interface.h:44
@ TYPE_SET_NODE
Definition rollback_interface.h:43
@ TYPE_NOTHING
Definition rollback_interface.h:42
Type type
Definition rollback_interface.h:50
time_t unix_time
Definition rollback_interface.h:47
bool actor_is_guess
Definition rollback_interface.h:49
v3s16 p
Definition rollback_interface.h:52
void setModifyInventoryStack(const std::string &inventory_location_, const std::string &inventory_list_, u32 index_, bool add_, const ItemStack &inventory_stack_)
Definition rollback_interface.h:73
ItemStack inventory_stack
Definition rollback_interface.h:60
Definition rollback_interface.h:17
bool operator==(const RollbackNode &other) const
Definition rollback_interface.h:23
int param2
Definition rollback_interface.h:20
std::string meta
Definition rollback_interface.h:21
std::string name
Definition rollback_interface.h:18
RollbackNode()=default
bool operator!=(const RollbackNode &other) const
Definition rollback_interface.h:28
int param1
Definition rollback_interface.h:19
static std::string p(std::string path)
Definition test_filesys.cpp:64