mirror of
https://github.com/mangosfour/server.git
synced 2025-12-26 07:37:02 +00:00
[sql/updates/2008_10_23_01_mangos_command.sql sql/updates/2008_10_23_02_mangos_mangos_string.sql] Better 'pdump' commands args checking and related error output.
This commit is contained in:
parent
b10349a737
commit
0c9f783ddc
9 changed files with 203 additions and 70 deletions
|
|
@ -24,7 +24,7 @@
|
|||
#include "ObjectMgr.h"
|
||||
|
||||
// Character Dump tables
|
||||
#define DUMP_TABLE_COUNT 20
|
||||
#define DUMP_TABLE_COUNT 19
|
||||
|
||||
struct DumpTable
|
||||
{
|
||||
|
|
@ -256,11 +256,8 @@ void StoreGUID(QueryResult *result,uint32 data,uint32 field, std::set<uint32>& g
|
|||
}
|
||||
|
||||
// Writing - High-level functions
|
||||
bool PlayerDumpWriter::DumpTable(std::string& dump, uint32 guid, char const*tableFrom, char const*tableTo, DumpTableType type)
|
||||
void PlayerDumpWriter::DumpTable(std::string& dump, uint32 guid, char const*tableFrom, char const*tableTo, DumpTableType type)
|
||||
{
|
||||
if (!tableFrom || !tableTo)
|
||||
return false;
|
||||
|
||||
GUIDs const* guids = NULL;
|
||||
char const* fieldname = NULL;
|
||||
|
||||
|
|
@ -278,7 +275,7 @@ bool PlayerDumpWriter::DumpTable(std::string& dump, uint32 guid, char const*tabl
|
|||
|
||||
// for guid set stop if set is empty
|
||||
if(guids && guids->empty())
|
||||
return true; // nothing to do
|
||||
return; // nothing to do
|
||||
|
||||
// setup for guids case start position
|
||||
GUIDs::const_iterator guids_itr;
|
||||
|
|
@ -296,7 +293,7 @@ bool PlayerDumpWriter::DumpTable(std::string& dump, uint32 guid, char const*tabl
|
|||
|
||||
QueryResult *result = CharacterDatabase.PQuery("SELECT * FROM %s WHERE %s", tableFrom, wherestr.c_str());
|
||||
if(!result)
|
||||
return false;
|
||||
return;
|
||||
|
||||
do
|
||||
{
|
||||
|
|
@ -326,8 +323,6 @@ bool PlayerDumpWriter::DumpTable(std::string& dump, uint32 guid, char const*tabl
|
|||
delete result;
|
||||
}
|
||||
while(guids && guids_itr != guids->end()); // not set case iterate single time, set case iterate for all guids
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string PlayerDumpWriter::GetDump(uint32 guid)
|
||||
|
|
@ -336,28 +331,29 @@ std::string PlayerDumpWriter::GetDump(uint32 guid)
|
|||
for(int i = 0; i < DUMP_TABLE_COUNT; i++)
|
||||
DumpTable(dump, guid, dumpTables[i].name, dumpTables[i].name, dumpTables[i].type);
|
||||
|
||||
// TODO: Add instance/group/gifts..
|
||||
// TODO: Add instance/group..
|
||||
// TODO: Add a dump level option to skip some non-important tables
|
||||
|
||||
return dump;
|
||||
}
|
||||
|
||||
bool PlayerDumpWriter::WriteDump(std::string file, uint32 guid)
|
||||
DumpReturn PlayerDumpWriter::WriteDump(std::string file, uint32 guid)
|
||||
{
|
||||
FILE *fout = fopen(file.c_str(), "w");
|
||||
if (!fout) { sLog.outError("Failed to open file!\r\n"); return false; }
|
||||
if (!fout)
|
||||
return DUMP_FILE_OPEN_ERROR;
|
||||
|
||||
std::string dump = GetDump(guid);
|
||||
|
||||
fprintf(fout,"%s\n",dump.c_str());
|
||||
fclose(fout);
|
||||
return true;
|
||||
return DUMP_SUCCESS;
|
||||
}
|
||||
|
||||
// Reading - High-level functions
|
||||
#define ROLLBACK {CharacterDatabase.RollbackTransaction(); fclose(fin); return false;}
|
||||
#define ROLLBACK(DR) {CharacterDatabase.RollbackTransaction(); fclose(fin); return (DR);}
|
||||
|
||||
bool PlayerDumpReader::LoadDump(std::string file, uint32 account, std::string name, uint32 guid)
|
||||
DumpReturn PlayerDumpReader::LoadDump(std::string file, uint32 account, std::string name, uint32 guid)
|
||||
{
|
||||
// check character count
|
||||
{
|
||||
|
|
@ -370,12 +366,13 @@ bool PlayerDumpReader::LoadDump(std::string file, uint32 account, std::string na
|
|||
delete result;
|
||||
|
||||
if (charcount >= 10)
|
||||
return false;
|
||||
return DUMP_TOO_MANY_CHARS;
|
||||
}
|
||||
}
|
||||
|
||||
FILE *fin = fopen(file.c_str(), "r");
|
||||
if(!fin)
|
||||
return false;
|
||||
return DUMP_FILE_OPEN_ERROR;
|
||||
|
||||
QueryResult * result = NULL;
|
||||
char newguid[20], chraccount[20], newpetid[20], currpetid[20], lastpetid[20];
|
||||
|
|
@ -431,8 +428,7 @@ bool PlayerDumpReader::LoadDump(std::string file, uint32 account, std::string na
|
|||
if(!fgets(buf, 32000, fin))
|
||||
{
|
||||
if(feof(fin)) break;
|
||||
sLog.outError("LoadPlayerDump: File read error!");
|
||||
ROLLBACK;
|
||||
ROLLBACK(DUMP_FILE_BROKEN);
|
||||
}
|
||||
|
||||
std::string line; line.assign(buf);
|
||||
|
|
@ -446,7 +442,7 @@ bool PlayerDumpReader::LoadDump(std::string file, uint32 account, std::string na
|
|||
if(tn.empty())
|
||||
{
|
||||
sLog.outError("LoadPlayerDump: Can't extract table name from line: '%s'!", line.c_str());
|
||||
ROLLBACK;
|
||||
ROLLBACK(DUMP_FILE_BROKEN);
|
||||
}
|
||||
|
||||
DumpTableType type;
|
||||
|
|
@ -463,27 +459,33 @@ bool PlayerDumpReader::LoadDump(std::string file, uint32 account, std::string na
|
|||
if (i == DUMP_TABLE_COUNT)
|
||||
{
|
||||
sLog.outError("LoadPlayerDump: Unknown table: '%s'!", tn.c_str());
|
||||
ROLLBACK;
|
||||
ROLLBACK(DUMP_FILE_BROKEN);
|
||||
}
|
||||
|
||||
// change the data to server values
|
||||
switch(type)
|
||||
{
|
||||
case DTT_CHAR_TABLE:
|
||||
if(!changenth(line, 1, newguid)) ROLLBACK;
|
||||
if(!changenth(line, 1, newguid))
|
||||
ROLLBACK(DUMP_FILE_BROKEN);
|
||||
break;
|
||||
|
||||
case DTT_CHARACTER: // character t.
|
||||
{
|
||||
if(!changenth(line, 1, newguid)) ROLLBACK;
|
||||
if(!changenth(line, 1, newguid))
|
||||
ROLLBACK(DUMP_FILE_BROKEN);
|
||||
|
||||
// guid, data field:guid, items
|
||||
if(!changenth(line, 2, chraccount)) ROLLBACK;
|
||||
if(!changenth(line, 2, chraccount))
|
||||
ROLLBACK(DUMP_FILE_BROKEN);
|
||||
std::string vals = getnth(line, 3);
|
||||
if(!changetoknth(vals, OBJECT_FIELD_GUID+1, newguid)) ROLLBACK;
|
||||
if(!changetoknth(vals, OBJECT_FIELD_GUID+1, newguid))
|
||||
ROLLBACK(DUMP_FILE_BROKEN);
|
||||
for(uint16 field = PLAYER_FIELD_INV_SLOT_HEAD; field < PLAYER_FARSIGHT; field++)
|
||||
if(!changetokGuid(vals, field+1, items, objmgr.m_hiItemGuid, true)) ROLLBACK;
|
||||
if(!changenth(line, 3, vals.c_str())) ROLLBACK;
|
||||
if(!changetokGuid(vals, field+1, items, objmgr.m_hiItemGuid, true))
|
||||
ROLLBACK(DUMP_FILE_BROKEN);
|
||||
if(!changenth(line, 3, vals.c_str()))
|
||||
ROLLBACK(DUMP_FILE_BROKEN);
|
||||
if (name == "")
|
||||
{
|
||||
// check if the original name already exists
|
||||
|
|
@ -495,38 +497,50 @@ bool PlayerDumpReader::LoadDump(std::string file, uint32 account, std::string na
|
|||
{
|
||||
delete result;
|
||||
// rename on login: `at_login` field 30 in raw field list
|
||||
if(!changenth(line, 30, "1")) ROLLBACK;
|
||||
if(!changenth(line, 30, "1"))
|
||||
ROLLBACK(DUMP_FILE_BROKEN);
|
||||
}
|
||||
}
|
||||
else if(!changenth(line, 4, name.c_str())) ROLLBACK;
|
||||
else if(!changenth(line, 4, name.c_str()))
|
||||
ROLLBACK(DUMP_FILE_BROKEN);
|
||||
|
||||
break;
|
||||
}
|
||||
case DTT_INVENTORY: // character_inventory t.
|
||||
{
|
||||
if(!changenth(line, 1, newguid)) ROLLBACK;
|
||||
if(!changenth(line, 1, newguid))
|
||||
ROLLBACK(DUMP_FILE_BROKEN);
|
||||
|
||||
// bag, item
|
||||
if(!changeGuid(line, 2, items, objmgr.m_hiItemGuid, true)) ROLLBACK;
|
||||
if(!changeGuid(line, 4, items, objmgr.m_hiItemGuid)) ROLLBACK;
|
||||
if(!changeGuid(line, 2, items, objmgr.m_hiItemGuid, true))
|
||||
ROLLBACK(DUMP_FILE_BROKEN);
|
||||
if(!changeGuid(line, 4, items, objmgr.m_hiItemGuid))
|
||||
ROLLBACK(DUMP_FILE_BROKEN);
|
||||
break;
|
||||
}
|
||||
case DTT_ITEM: // item_instance t.
|
||||
{
|
||||
// item, owner, data field:item, owner guid
|
||||
if(!changeGuid(line, 1, items, objmgr.m_hiItemGuid)) ROLLBACK;
|
||||
if(!changenth(line, 2, newguid)) ROLLBACK;
|
||||
if(!changeGuid(line, 1, items, objmgr.m_hiItemGuid))
|
||||
ROLLBACK(DUMP_FILE_BROKEN);
|
||||
if(!changenth(line, 2, newguid))
|
||||
ROLLBACK(DUMP_FILE_BROKEN);
|
||||
std::string vals = getnth(line,3);
|
||||
if(!changetokGuid(vals, OBJECT_FIELD_GUID+1, items, objmgr.m_hiItemGuid)) ROLLBACK;
|
||||
if(!changetoknth(vals, ITEM_FIELD_OWNER+1, newguid)) ROLLBACK;
|
||||
if(!changenth(line, 3, vals.c_str())) ROLLBACK;
|
||||
if(!changetokGuid(vals, OBJECT_FIELD_GUID+1, items, objmgr.m_hiItemGuid))
|
||||
ROLLBACK(DUMP_FILE_BROKEN);
|
||||
if(!changetoknth(vals, ITEM_FIELD_OWNER+1, newguid))
|
||||
ROLLBACK(DUMP_FILE_BROKEN);
|
||||
if(!changenth(line, 3, vals.c_str()))
|
||||
ROLLBACK(DUMP_FILE_BROKEN);
|
||||
break;
|
||||
}
|
||||
case DTT_ITEM_GIFT: // character_gift
|
||||
{
|
||||
// guid,item_guid,
|
||||
if(!changenth(line, 1, newguid)) ROLLBACK;
|
||||
if(!changeGuid(line, 2, items, objmgr.m_hiItemGuid)) ROLLBACK;
|
||||
if(!changenth(line, 1, newguid))
|
||||
ROLLBACK(DUMP_FILE_BROKEN);
|
||||
if(!changeGuid(line, 2, items, objmgr.m_hiItemGuid))
|
||||
ROLLBACK(DUMP_FILE_BROKEN);
|
||||
break;
|
||||
}
|
||||
case DTT_PET: // character_pet t
|
||||
|
|
@ -548,8 +562,10 @@ bool PlayerDumpReader::LoadDump(std::string file, uint32 account, std::string na
|
|||
}
|
||||
|
||||
// item, entry, owner, ...
|
||||
if(!changenth(line, 1, newpetid)) ROLLBACK;
|
||||
if(!changenth(line, 3, newguid)) ROLLBACK;
|
||||
if(!changenth(line, 1, newpetid))
|
||||
ROLLBACK(DUMP_FILE_BROKEN);
|
||||
if(!changenth(line, 3, newguid))
|
||||
ROLLBACK(DUMP_FILE_BROKEN);
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
@ -559,27 +575,34 @@ bool PlayerDumpReader::LoadDump(std::string file, uint32 account, std::string na
|
|||
|
||||
// lookup currpetid and match to new inserted pet id
|
||||
std::map<uint32, uint32> :: const_iterator petids_iter = petids.find(atoi(currpetid));
|
||||
if(petids_iter == petids.end()) ROLLBACK; // couldn't find new inserted id
|
||||
if(petids_iter == petids.end()) // couldn't find new inserted id
|
||||
ROLLBACK(DUMP_FILE_BROKEN);
|
||||
|
||||
snprintf(newpetid, 20, "%d", petids_iter->second);
|
||||
|
||||
if(!changenth(line, 1, newpetid)) ROLLBACK;
|
||||
if(!changenth(line, 1, newpetid))
|
||||
ROLLBACK(DUMP_FILE_BROKEN);
|
||||
|
||||
break;
|
||||
}
|
||||
case DTT_MAIL: // mail
|
||||
{
|
||||
// id,messageType,stationery,sender,receiver
|
||||
if(!changeGuid(line, 1, mails, objmgr.m_mailid)) ROLLBACK;
|
||||
if(!changenth(line, 5, newguid)) ROLLBACK;
|
||||
if(!changeGuid(line, 1, mails, objmgr.m_mailid))
|
||||
ROLLBACK(DUMP_FILE_BROKEN);
|
||||
if(!changenth(line, 5, newguid))
|
||||
ROLLBACK(DUMP_FILE_BROKEN);
|
||||
break;
|
||||
}
|
||||
case DTT_MAIL_ITEM: // mail_items
|
||||
{
|
||||
// mail_id,item_guid,item_template,receiver
|
||||
if(!changeGuid(line, 1, mails, objmgr.m_mailid)) ROLLBACK;
|
||||
if(!changeGuid(line, 2, items, objmgr.m_hiItemGuid)) ROLLBACK;
|
||||
if(!changenth(line, 4, newguid)) ROLLBACK;
|
||||
if(!changeGuid(line, 1, mails, objmgr.m_mailid))
|
||||
ROLLBACK(DUMP_FILE_BROKEN);
|
||||
if(!changeGuid(line, 2, items, objmgr.m_hiItemGuid))
|
||||
ROLLBACK(DUMP_FILE_BROKEN);
|
||||
if(!changenth(line, 4, newguid))
|
||||
ROLLBACK(DUMP_FILE_BROKEN);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
@ -587,7 +610,8 @@ bool PlayerDumpReader::LoadDump(std::string file, uint32 account, std::string na
|
|||
break;
|
||||
}
|
||||
|
||||
if(!CharacterDatabase.Execute(line.c_str())) ROLLBACK;
|
||||
if(!CharacterDatabase.Execute(line.c_str()))
|
||||
ROLLBACK(DUMP_FILE_BROKEN);
|
||||
}
|
||||
|
||||
CharacterDatabase.CommitTransaction();
|
||||
|
|
@ -600,5 +624,5 @@ bool PlayerDumpReader::LoadDump(std::string file, uint32 account, std::string na
|
|||
|
||||
fclose(fin);
|
||||
|
||||
return true;
|
||||
return DUMP_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue