-void RollbackAction::fromStream(std::istream &is) throw(SerializationError)
-{
- int c = is.get();
- if(c != '['){
- is.putback(c);
- throw SerializationError("RollbackAction: starting [ not found");
- }
-
- std::string id;
- std::getline(is, id, ' ');
-
- if(id == "set_node")
- {
- c = is.get();
- if(c != '('){
- is.putback(c);
- throw SerializationError("RollbackAction: starting ( not found");
- }
- // Position
- std::string px_raw;
- std::string py_raw;
- std::string pz_raw;
- std::getline(is, px_raw, ',');
- std::getline(is, py_raw, ',');
- std::getline(is, pz_raw, ')');
- c = is.get();
- if(c != ' '){
- is.putback(c);
- throw SerializationError("RollbackAction: after-p ' ' not found");
- }
- v3s16 loaded_p(stoi(px_raw), stoi(py_raw), stoi(pz_raw));
- // Old node
- std::string old_name;
- try{
- old_name = deSerializeJsonString(is);
- }catch(SerializationError &e){
- errorstream<<"Serialization error in RollbackAction::fromStream(): "
- <<"old_name: "<<e.what()<<std::endl;
- throw e;
- }
- c = is.get();
- if(c != ' '){
- is.putback(c);
- throw SerializationError("RollbackAction: after-old_name ' ' not found");
- }
- std::string old_p1_raw;
- std::string old_p2_raw;
- std::getline(is, old_p1_raw, ' ');
- std::getline(is, old_p2_raw, ' ');
- int old_p1 = stoi(old_p1_raw);
- int old_p2 = stoi(old_p2_raw);
- std::string old_meta;
- try{
- old_meta = deSerializeJsonString(is);
- }catch(SerializationError &e){
- errorstream<<"Serialization error in RollbackAction::fromStream(): "
- <<"old_meta: "<<e.what()<<std::endl;
- throw e;
- }
- c = is.get();
- if(c != ' '){
- is.putback(c);
- throw SerializationError("RollbackAction: after-old_meta ' ' not found");
- }
- // New node
- std::string new_name;
- try{
- new_name = deSerializeJsonString(is);
- }catch(SerializationError &e){
- errorstream<<"Serialization error in RollbackAction::fromStream(): "
- <<"new_name: "<<e.what()<<std::endl;
- throw e;
- }
- c = is.get();
- if(c != ' '){
- is.putback(c);
- throw SerializationError("RollbackAction: after-new_name ' ' not found");
- }
- std::string new_p1_raw;
- std::string new_p2_raw;
- std::getline(is, new_p1_raw, ' ');
- std::getline(is, new_p2_raw, ' ');
- int new_p1 = stoi(new_p1_raw);
- int new_p2 = stoi(new_p2_raw);
- std::string new_meta;
- try{
- new_meta = deSerializeJsonString(is);
- }catch(SerializationError &e){
- errorstream<<"Serialization error in RollbackAction::fromStream(): "
- <<"new_meta: "<<e.what()<<std::endl;
- throw e;
- }
- c = is.get();
- if(c != ']'){
- is.putback(c);
- throw SerializationError("RollbackAction: after-new_meta ] not found");
- }
- // Set values
- type = TYPE_SET_NODE;
- p = loaded_p;
- n_old.name = old_name;
- n_old.param1 = old_p1;
- n_old.param2 = old_p2;
- n_old.meta = old_meta;
- n_new.name = new_name;
- n_new.param1 = new_p1;
- n_new.param2 = new_p2;
- n_new.meta = new_meta;
- }
- else if(id == "modify_inventory_stack")
- {
- // Location
- std::string location;
- try{
- location = deSerializeJsonString(is);
- }catch(SerializationError &e){
- errorstream<<"Serialization error in RollbackAction::fromStream(): "
- <<"location: "<<e.what()<<std::endl;
- throw e;
- }
- c = is.get();
- if(c != ' '){
- is.putback(c);
- throw SerializationError("RollbackAction: after-loc ' ' not found");
- }
- // List
- std::string listname;
- try{
- listname = deSerializeJsonString(is);
- }catch(SerializationError &e){
- errorstream<<"Serialization error in RollbackAction::fromStream(): "
- <<"listname: "<<e.what()<<std::endl;
- throw e;
- }
- c = is.get();
- if(c != ' '){
- is.putback(c);
- throw SerializationError("RollbackAction: after-list ' ' not found");
- }
- // Index
- std::string index_raw;
- std::getline(is, index_raw, ' ');
- // add/remove
- std::string addremove;
- std::getline(is, addremove, ' ');
- if(addremove != "add" && addremove != "remove"){
- throw SerializationError("RollbackAction: addremove is not add or remove");
- }
- // Itemstring
- std::string stack;
- try{
- stack = deSerializeJsonString(is);
- }catch(SerializationError &e){
- errorstream<<"Serialization error in RollbackAction::fromStream(): "
- <<"stack: "<<e.what()<<std::endl;
- throw e;
- }
- // Set values
- type = TYPE_MODIFY_INVENTORY_STACK;
- inventory_location = location;
- inventory_list = listname;
- inventory_index = stoi(index_raw);
- inventory_add = (addremove == "add");
- inventory_stack = stack;
- }
- else
- {
- throw SerializationError("RollbackAction: Unknown id");
- }
-}