Advertisement
Guest User

Untitled

a guest
Jul 24th, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. bool IOLoginData::saveItems(const Player* player, const ItemBlockList& itemList, DBInsert& query_insert)
  2. {
  3. Database* db = Database::getInstance();
  4. typedef std::pair<Container*, uint32_t> Stack;
  5. std::list<Stack> stackList;
  6.  
  7. Item* item = NULL;
  8. int32_t runningId = 101;
  9. for(ItemBlockList::const_iterator it = itemList.begin(); it != itemList.end(); ++it, ++runningId)
  10. {
  11. item = it->second;
  12. PropWriteStream propWriteStream;
  13. item->serializeAttr(propWriteStream);
  14.  
  15. //antidupe
  16. std::string key = "serial";
  17. boost::any value = item->getAttribute(key.c_str());
  18. if(value.empty())
  19. {
  20. item->generateSerial();
  21. value = item->getAttribute(key.c_str());
  22. }
  23.  
  24. item->eraseAttribute(key.c_str());
  25. //
  26.  
  27. uint32_t attributesSize = 0;
  28. const char* attributes = propWriteStream.getStream(attributesSize);
  29.  
  30.  
  31. std::stringstream buffer;
  32. buffer << player->getGUID() << "," << it->first << "," << runningId << "," << item->getID() << ","
  33. << (int32_t)item->getSubType() << "," << db->escapeBlob(attributes, attributesSize) << "," << db->escapeString(boost::any_cast<std::string>(value).c_str());
  34.  
  35. if(!query_insert.addRow(buffer))
  36. return false;
  37.  
  38. if(Container* container = item->getContainer())
  39. stackList.push_back(Stack(container, runningId));
  40. }
  41.  
  42. while(stackList.size())
  43. {
  44. Stack stack = stackList.front();
  45. stackList.pop_front();
  46.  
  47. Container* container = stack.first;
  48. for(uint32_t i = 0; i < container->size(); ++i, ++runningId)
  49. {
  50. item = container->getItem(i);
  51. if(Container* subContainer = item->getContainer())
  52. stackList.push_back(Stack(subContainer, runningId));
  53.  
  54. PropWriteStream propWriteStream;
  55. item->serializeAttr(propWriteStream);
  56.  
  57. //antidupe
  58. std::string key = "serial";
  59. boost::any value = item->getAttribute(key.c_str());
  60. if(value.empty())
  61. {
  62. item->generateSerial();
  63. value = item->getAttribute(key.c_str());
  64. }
  65.  
  66. item->eraseAttribute(key.c_str());
  67. //
  68.  
  69.  
  70. uint32_t attributesSize = 0;
  71. const char* attributes = propWriteStream.getStream(attributesSize);
  72.  
  73. std::stringstream buffer;
  74. buffer << player->getGUID() << "," << stack.second << "," << runningId << "," << item->getID() << ","
  75. << (int32_t)item->getSubType() << "," << db->escapeBlob(attributes, attributesSize) << "," << db->escapeString(boost::any_cast<std::string>(value).c_str());
  76. if(!query_insert.addRow(buffer))
  77. return false;
  78. }
  79. }
  80.  
  81. return query_insert.execute();
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement