Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool IOLoginData::saveItems(const Player* player, const ItemBlockList& itemList, DBInsert& query_insert)
- {
- Database* db = Database::getInstance();
- typedef std::pair<Container*, uint32_t> Stack;
- std::list<Stack> stackList;
- Item* item = NULL;
- int32_t runningId = 101;
- for(ItemBlockList::const_iterator it = itemList.begin(); it != itemList.end(); ++it, ++runningId)
- {
- item = it->second;
- PropWriteStream propWriteStream;
- item->serializeAttr(propWriteStream);
- //antidupe
- std::string key = "serial";
- boost::any value = item->getAttribute(key.c_str());
- if(value.empty())
- {
- item->generateSerial();
- value = item->getAttribute(key.c_str());
- }
- item->eraseAttribute(key.c_str());
- //
- uint32_t attributesSize = 0;
- const char* attributes = propWriteStream.getStream(attributesSize);
- std::stringstream buffer;
- buffer << player->getGUID() << "," << it->first << "," << runningId << "," << item->getID() << ","
- << (int32_t)item->getSubType() << "," << db->escapeBlob(attributes, attributesSize) << "," << db->escapeString(boost::any_cast<std::string>(value).c_str());
- if(!query_insert.addRow(buffer))
- return false;
- if(Container* container = item->getContainer())
- stackList.push_back(Stack(container, runningId));
- }
- while(stackList.size())
- {
- Stack stack = stackList.front();
- stackList.pop_front();
- Container* container = stack.first;
- for(uint32_t i = 0; i < container->size(); ++i, ++runningId)
- {
- item = container->getItem(i);
- if(Container* subContainer = item->getContainer())
- stackList.push_back(Stack(subContainer, runningId));
- PropWriteStream propWriteStream;
- item->serializeAttr(propWriteStream);
- //antidupe
- std::string key = "serial";
- boost::any value = item->getAttribute(key.c_str());
- if(value.empty())
- {
- item->generateSerial();
- value = item->getAttribute(key.c_str());
- }
- item->eraseAttribute(key.c_str());
- //
- uint32_t attributesSize = 0;
- const char* attributes = propWriteStream.getStream(attributesSize);
- std::stringstream buffer;
- buffer << player->getGUID() << "," << stack.second << "," << runningId << "," << item->getID() << ","
- << (int32_t)item->getSubType() << "," << db->escapeBlob(attributes, attributesSize) << "," << db->escapeString(boost::any_cast<std::string>(value).c_str());
- if(!query_insert.addRow(buffer))
- return false;
- }
- }
- return query_insert.execute();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement