ofs | hex dump | ascii |
---|
0000 | 00 00 01 00 01 00 30 30 00 00 01 00 20 00 a8 25 00 00 16 00 00 00 28 00 00 00 30 00 00 00 60 00 | ......00.......%......(...0...`. |
0020 | 00 00 01 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................................ |
0040 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................................ |
0060 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................................ |
0080 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................................ |
00a0 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................................ |
00c0 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................................ |
00e0 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................................ |
0100 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................................ |
0120 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................................ |
0140 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0d 39 59 28 0f 3f | ...........................9Y(.? |
0160 | 5c 95 0d 3c 57 26 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | \..<W&.......................... |
0180 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................................ |
01a0 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................................ |
01c0 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................................ |
01e0 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................................ |
0200 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10 40 50 10 11 3f 5e 95 12 3f 5e f5 33 6c | ...................@P..?^..?^.3l |
0220 | 91 f9 11 3e 5d f5 10 3d 5a 8d 15 40 55 0c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ...>]..=Z..@U................... |
0240 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................................ |
0260 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................................ |
0280 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................................ |
02a0 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................................ |
02c0 | 00 00 00 00 00 00 00 00 00 00 00 00 00 01 0f 3b 59 56 11 40 5d eb 2b 62 85 f7 63 aa d8 ff 6e b9 | ...............;YV.@].+b..c...n. |
02e0 | e9 ff 62 a9 d7 ff 27 5d 7e f6 10 3f 5d e8 0d 3c 56 4d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ..b...']~..?]..<VM.............. |
0300 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................................ |
0320 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................................ |
0340 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................................ |
0360 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................................ |
0380 | 00 00 00 00 00 00 0f 3b 58 34 13 42 61 d3 1d 50 70 f5 58 9c c8 ff 6e b9 e9 ff 6e b9 e9 ff 6e b9 | .......;X4.Ba..Pp.X...n...n...n. |
03a0 | e9 ff 6e b9 e9 ff 6e b9 e9 ff 53 95 c0 ff 18 48 69 f4 12 41 60 c1 0e 37 5a 25 00 00 00 00 00 00 | ..n...n...S....Hi..A`..7Z%...... |
03c0 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................................ |
03e0 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................................ |
0400 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................................ |
0420 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2c 35 | ..............................,5 |
0440 | 38 57 34 36 33 f2 15 44 61 f5 47 86 af fe 6d b8 e8 ff 6e b9 e9 ff 6e b9 e9 ff 6e b9 e9 ff 6e b9 | 8W463..Da.G...m...n...n...n...n. |
0460 | e9 ff 6e b9 e9 ff 6e b9 e9 ff 6e b9 e9 ff 6b b6 e6 ff 41 7d a4 fd 12 40 5d f6 13 42 60 88 17 46 | ..n...n...n...k...A}...@]..B`..F |
0480 | 5d 0b 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ]............................... |
04a0 | 00 00 00 00/*
Minetest
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
#include "nodemetadata.h"
#include "exceptions.h"
#include "log.h"
#include "inventorymanager.h"
#include "inventory.h"
#include "mapblock.h"
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
RollbackNode::RollbackNode(Map *map, v3s16 p, IGameDef *gamedef)
{
INodeDefManager *ndef = gamedef->ndef();
MapNode n = map->getNodeNoEx(p);
name = ndef->get(n).name;
param1 = n.param1;
param2 = n.param2;
NodeMetadata *metap = map->getNodeMetadata(p);
if (metap) {
std::ostringstream os(std::ios::binary);
metap->serialize(os);
meta = os.str();
}
}
std::string RollbackAction::toString() const
{
std::ostringstream os(std::ios::binary);
switch (type) {
case TYPE_SET_NODE:
os << "set_node " << PP(p);
os << ": (" << serializeJsonString(n_old.name);
os << ", " << itos(n_old.param1);
os << ", " << itos(n_old.param2);
os << ", " << serializeJsonString(n_old.meta);
os << ") -> (" << serializeJsonString(n_new.name);
os << ", " << itos(n_new.param1);
os << ", " << itos(n_new.param2);
os << ", " << serializeJsonString(n_new.meta);
os << ')';
case TYPE_MODIFY_INVENTORY_STACK:
os << "modify_inventory_stack (";
os << serializeJsonString(inventory_location);
os << ", " << serializeJsonString(inventory_list);
os << ", " << inventory_index;
os << ", " << (inventory_add ? "add" : "remove");
os << ", " << serializeJsonString(inventory_stack.getItemString());
os << ')';
default:
return "<unknown action>";
}
return os.str();
}
bool RollbackAction::isImportant(IGameDef *gamedef) const
{
if (type != TYPE_SET_NODE)
return true;
// If names differ, action is always important
if(n_old.name != n_new.name)
return true;
// If metadata differs, action is always important
if(n_old.meta != n_new.meta)
return true;
INodeDefManager *ndef = gamedef->ndef();
// Both are of the same name, so a single definition is needed
const ContentFeatures &def = ndef->get(n_old.name);
// If the type is flowing liquid, action is not important
if (def.liquid_type == LIQUID_FLOWING)
return false;
// Otherwise action is important
return true;
}
bool RollbackAction::getPosition(v3s16 *dst | .......9U..<Y.n...n...64..64..64 |
0c60 | 2e ff 36 34 2e ff 36 34 2e ff 36 34 2e ff 38 39 36 ff 40 4c 50 ff 6e b9 e9 ff 6e b9 e9 ff 6e b9 | ..64..64..64..896.@LP.n...n...n. |
0c80 | e9 ff 61 7c 89 ff 53 3c 2
return true;
case TYPE_MODIFY_INVENTORY_STACK: {
InventoryLocation loc;
loc.deSerialize(inventory_location);
if (loc.type != InventoryLocation::NODEMETA) {
return false;
}
if (dst) *dst = loc.p;
return true; }
default:
return false;
}
}
bool RollbackAction::applyRevert(Map *map, InventoryManager *imgr, IGameDef *gamedef) const
{
try {
switch (type) {
case TYPE_NOTHING:
return true;
case TYPE_SET_NODE: {
INodeDefManager *ndef = gamedef->ndef();
// Make sure position is loaded from disk
map->emergeBlock(getContainerPos(p, MAP_BLOCKSIZE), false);
// Check current node
MapNode current_node = map->getNodeNoEx(p);
std::string current_name = ndef->get(current_node).name;
// If current node not the new node, it's bad
if (current_name != n_new.name) {
return false;
}
// Create rollback node
MapNode n(ndef, n_old.name, n_old.param1, n_old.param2);
// Set rollback node
try {
if (!map->addNodeWithEvent(p, n)) {
infostream << "RollbackAction::applyRevert(): "
<< "AddNodeWithEvent failed at "
<< PP(p) << " for " << n_old.name
<< std::endl;
return false;
}
if (n_old.meta.empty()) {
map->removeNodeMetadata(p);
} else {
NodeMetadata *meta = map->getNodeMetadata(p);
if (!meta) {
meta = new NodeMetadata(gamedef);
if (!map->setNodeMetadata(p, meta)) {
delete meta;
infostream << "RollbackAction::applyRevert(): "
<< "setNodeMetadata failed at "
<< PP(p) << " for " << n_old.name
<< std::endl;
return false;
}
}
std::istringstream is(n_old.meta, std::ios::binary);
meta->deSerialize(is);
}
// Inform other things that the meta data has changed
v3s16 blockpos = getContainerPos(p, MAP_BLOCKSIZE);
MapEditEvent event;
event.type = MEET_BLOCK_NODE_METADATA_CHANGED;
event.p = blockpos;
map->dispatchEvent(&event);
// Set the block to be saved
MapBlock *block = map->getBlockNoCreateNoEx(blockpos);
if (block) {
block->raiseModified(MOD_STATE_WRITE_NEEDED,
MOD_REASON_REPORT_META_CHANGE);
}
} catch (InvalidPositionException &e) {
infostream << "RollbackAction::applyRevert(): "
<< "InvalidPositionException: " << e.what()
<< std::endl;
return false;
}
// Success
return true; }
case TYPE_MODIFY_INVENTORY_STACK: {
InventoryLocation loc;
loc.deSerialize(inventory_location);
std::string real_name = gamedef->idef()->getAlias(inventory_stack.name);
Inventory *inv = imgr->getInventory(loc);
if (!inv) {
infostream << "RollbackAction::applyRevert(): Could not get "
"inventory at " << inventory_location << std::endl;
return false;
}
InventoryList *list = inv->getList(invent d2 73 ff 16 d2 | v...s...s...s...s...s...s...s... |
1360 | 73 ff 16 d2 73 ff 16 d2 73 ff 16 d2 73 ff 16 d2 73 ff 13 b5 63 ff 0d 69 3e ff 08 5f 40 ff 4f e9 | s...s...s...s...s...c..i>
"inventory list \"" << inventory_list << "\" in "
<< inventory_location << std::endl;
return false;
}
if (list->getSize() <= inventory_index) {
infostream << "RollbackAction::applyRevert(): List index "
<< inventory_index << " too large in "
<< "inventory list \"" << inventory_list << "\" in "
<< inventory_location << std::endl;
}
// If item was added, take away item, otherwise add removed item
if (inventory_add) {
// Silently ignore different current item
if (list->getItem(inventory_index).name != real_name)
return false;
list->takeItem(inventory_index, inventory_stack.count);
} else {
list->addItem(inventory_index, inventory_stack);
}
// Inventory was modified; send to clients
imgr->setInventoryModified(loc);
return true; }
default:
errorstream << "RollbackAction::applyRevert(): type not handled"
<< std::endl;
return false;
}
} catch(SerializationError &e) {
errorstream << "RollbackAction::applyRevert(): n_old.name=" << n_old.name
<< ", SerializationError: " << e.what() << std::endl;
}
return false;
}
|