aboutsummaryrefslogtreecommitdiff
path: root/src/inventorymanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/inventorymanager.cpp')
-rw-r--r--src/inventorymanager.cpp73
1 files changed, 72 insertions, 1 deletions
diff --git a/src/inventorymanager.cpp b/src/inventorymanager.cpp
index 06978fbb9..85668d645 100644
--- a/src/inventorymanager.cpp
+++ b/src/inventorymanager.cpp
@@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "main.h" // for g_settings
#include "settings.h"
#include "craftdef.h"
+#include "rollback_interface.h"
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
@@ -200,6 +201,14 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
}
/*
+ Do not handle rollback if both inventories are that of the same player
+ */
+ bool ignore_rollback = (
+ from_inv.type == InventoryLocation::PLAYER &&
+ to_inv.type == InventoryLocation::PLAYER &&
+ from_inv.name == to_inv.name);
+
+ /*
Collect information of endpoints
*/
@@ -344,6 +353,41 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
<<std::endl;
/*
+ Record rollback information
+ */
+ if(!ignore_rollback)
+ {
+ IRollbackReportSink *rollback = gamedef->rollback();
+
+ // If source is not infinite, record item take
+ if(!src_can_take_count != -1){
+ RollbackAction action;
+ std::string loc;
+ {
+ std::ostringstream os(std::ios::binary);
+ from_inv.serialize(os);
+ loc = os.str();
+ }
+ action.setModifyInventoryStack(loc, from_list, from_i, false,
+ src_item.getItemString());
+ rollback->reportAction(action);
+ }
+ // If destination is not infinite, record item put
+ if(!dst_can_put_count != -1){
+ RollbackAction action;
+ std::string loc;
+ {
+ std::ostringstream os(std::ios::binary);
+ to_inv.serialize(os);
+ loc = os.str();
+ }
+ action.setModifyInventoryStack(loc, to_list, to_i, true,
+ src_item.getItemString());
+ rollback->reportAction(action);
+ }
+ }
+
+ /*
Report move to endpoints
*/
@@ -405,7 +449,7 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
L, from_inv.p, from_list, from_i, src_item, player);
}
}
-
+
mgr->setInventoryModified(from_inv);
if(inv_from != inv_to)
mgr->setInventoryModified(to_inv);
@@ -489,6 +533,11 @@ void IDropAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
}
/*
+ Do not handle rollback if inventory is player's
+ */
+ bool ignore_src_rollback = (from_inv.type == InventoryLocation::PLAYER);
+
+ /*
Collect information of endpoints
*/
@@ -575,6 +624,28 @@ void IDropAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
scriptapi_nodemeta_inventory_on_take(
L, from_inv.p, from_list, from_i, src_item, player);
}
+
+ /*
+ Record rollback information
+ */
+ if(!ignore_src_rollback)
+ {
+ IRollbackReportSink *rollback = gamedef->rollback();
+
+ // If source is not infinite, record item take
+ if(!src_can_take_count != -1){
+ RollbackAction action;
+ std::string loc;
+ {
+ std::ostringstream os(std::ios::binary);
+ from_inv.serialize(os);
+ loc = os.str();
+ }
+ action.setModifyInventoryStack(loc, from_list, from_i,
+ false, src_item.getItemString());
+ rollback->reportAction(action);
+ }
+ }
}
void IDropAction::clientApply(InventoryManager *mgr, IGameDef *gamedef)