diff options
Diffstat (limited to 'src/server/game/Tools/PlayerDump.cpp')
-rw-r--r-- | src/server/game/Tools/PlayerDump.cpp | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/src/server/game/Tools/PlayerDump.cpp b/src/server/game/Tools/PlayerDump.cpp index b37cb909b0d..a818c38dc58 100644 --- a/src/server/game/Tools/PlayerDump.cpp +++ b/src/server/game/Tools/PlayerDump.cpp @@ -25,6 +25,7 @@ #include "Player.h" #include "World.h" #include <boost/algorithm/string/find.hpp> +#include <fstream> #include <sstream> // static data @@ -809,7 +810,7 @@ bool PlayerDumpWriter::GetDump(ObjectGuid::LowType guid, std::string& dump) return true; } -DumpReturn PlayerDumpWriter::WriteDump(std::string const& file, ObjectGuid::LowType guid) +DumpReturn PlayerDumpWriter::WriteDumpToFile(std::string const& file, ObjectGuid::LowType guid) { if (sWorld->getBoolConfig(CONFIG_PDUMP_NO_PATHS)) if (strchr(file.c_str(), '\\') || strchr(file.c_str(), '/')) @@ -835,6 +836,14 @@ DumpReturn PlayerDumpWriter::WriteDump(std::string const& file, ObjectGuid::LowT return ret; } +DumpReturn PlayerDumpWriter::WriteDumpToString(std::string& dump, ObjectGuid::LowType guid) +{ + DumpReturn ret = DUMP_SUCCESS; + if (!GetDump(guid, dump)) + ret = DUMP_CHARACTER_DELETED; + return ret; +} + // Reading - High-level functions inline void FixNULLfields(std::string& line) { @@ -847,16 +856,12 @@ inline void FixNULLfields(std::string& line) } } -DumpReturn PlayerDumpReader::LoadDump(std::string const& file, uint32 account, std::string name, ObjectGuid::LowType guid) +DumpReturn PlayerDumpReader::LoadDump(std::istream& input, uint32 account, std::string name, ObjectGuid::LowType guid) { uint32 charcount = AccountMgr::GetCharactersCount(account); if (charcount >= sWorld->getIntConfig(CONFIG_CHARACTERS_PER_REALM)) return DUMP_TOO_MANY_CHARS; - FileHandle fin = GetFileHandle(file.c_str(), "r"); - if (!fin) - return DUMP_FILE_OPEN_ERROR; - std::string newguid, chraccount; // make sure the same guid doesn't already exist and is safe to use @@ -905,8 +910,7 @@ DumpReturn PlayerDumpReader::LoadDump(std::string const& file, uint32 account, s std::map<uint64, uint64> equipmentSetIds; uint64 equipmentSetGuidOffset = sObjectMgr->_equipmentSetGuid; - static size_t const BUFFER_SIZE = 32000; - char buf[BUFFER_SIZE] = { }; + std::string line; uint8 gender = GENDER_NONE; uint8 race = RACE_NONE; @@ -917,17 +921,8 @@ DumpReturn PlayerDumpReader::LoadDump(std::string const& file, uint32 account, s size_t lineNumber = 0; CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction(); - while (!feof(fin.get())) + while (std::getline(input, line)) { - if (!fgets(buf, BUFFER_SIZE, fin.get())) - { - if (feof(fin.get())) - break; - return DUMP_FILE_BROKEN; - } - - std::string line; - line.assign(buf); ++lineNumber; // skip empty strings @@ -1047,6 +1042,9 @@ DumpReturn PlayerDumpReader::LoadDump(std::string const& file, uint32 account, s trans->Append(line.c_str()); } + if (input.fail() && !input.eof()) + return DUMP_FILE_BROKEN; + CharacterDatabase.CommitTransaction(trans); // in case of name conflict player has to rename at login anyway @@ -1064,3 +1062,17 @@ DumpReturn PlayerDumpReader::LoadDump(std::string const& file, uint32 account, s return DUMP_SUCCESS; } + +DumpReturn PlayerDumpReader::LoadDumpFromString(std::string const& dump, uint32 account, std::string name, ObjectGuid::LowType guid) +{ + std::istringstream input(dump); + return LoadDump(input, account, name, guid); +} + +DumpReturn PlayerDumpReader::LoadDumpFromFile(std::string const& file, uint32 account, std::string name, ObjectGuid::LowType guid) +{ + std::ifstream input(file); + if (!input) + return DUMP_FILE_OPEN_ERROR; + return LoadDump(input, account, name, guid); +} |