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