Show
Ignore:
Timestamp:
11/19/08 13:37:14 (17 years ago)
Author:
yumileroy
Message:

[svn] * Merge CLI Commands with regular commands and give them level4 access. sec_console. Source mangos - thanks to ogeraisi for the amalgamated patch.
* Redid/Fixed/Added some lang strings.
* As usual remember this is a trunk rev so stability only guaranteed on northern countries of Mars and western parts of Pluto. No warranties outside the solar system, sorry :( . Check with your local government or dictator on regulations regarding export.

Original author: KingPin?
Date: 2008-10-26 13:32:42-05:00

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/game/PlayerDump.cpp

    r102 r112  
    2727 
    2828// Character Dump tables 
    29 #define DUMP_TABLE_COUNT 20 
     29#define DUMP_TABLE_COUNT 19 
    3030 
    3131struct DumpTable 
     
    259259 
    260260// Writing - High-level functions 
    261 bool PlayerDumpWriter::DumpTable(std::string& dump, uint32 guid, char const*tableFrom, char const*tableTo, DumpTableType type) 
    262 { 
    263     if (!tableFrom || !tableTo) 
    264         return false; 
    265  
     261void PlayerDumpWriter::DumpTable(std::string& dump, uint32 guid, char const*tableFrom, char const*tableTo, DumpTableType type) 
     262{ 
    266263    GUIDs const* guids = NULL; 
    267264    char const* fieldname = NULL; 
     
    281278    // for guid set stop if set is empty 
    282279    if(guids && guids->empty()) 
    283         return true;                                        // nothing to do 
     280        return;                                        // nothing to do 
    284281 
    285282    // setup for guids case start position 
     
    299296        QueryResult *result = CharacterDatabase.PQuery("SELECT * FROM %s WHERE %s", tableFrom, wherestr.c_str()); 
    300297        if(!result) 
    301             return false; 
     298            return; 
    302299 
    303300        do 
     
    329326    } 
    330327    while(guids && guids_itr != guids->end());              // not set case iterate single time, set case iterate for all guids 
    331  
    332     return true; 
    333328} 
    334329 
     
    339334        DumpTable(dump, guid, dumpTables[i].name, dumpTables[i].name, dumpTables[i].type); 
    340335 
    341     // TODO: Add instance/group/gifts.. 
     336    // TODO: Add instance/group.. 
    342337    // TODO: Add a dump level option to skip some non-important tables 
    343338 
     
    345340} 
    346341 
    347 bool PlayerDumpWriter::WriteDump(std::string file, uint32 guid) 
     342DumpReturn PlayerDumpWriter::WriteDump(std::string file, uint32 guid) 
    348343{ 
    349344    FILE *fout = fopen(file.c_str(), "w"); 
    350     if (!fout) { sLog.outError("Failed to open file!\r\n"); return false; } 
     345    if (!fout) 
     346                return DUMP_FILE_OPEN_ERROR; 
    351347 
    352348    std::string dump = GetDump(guid); 
     
    354350    fprintf(fout,"%s\n",dump.c_str()); 
    355351    fclose(fout); 
    356     return true; 
     352    return DUMP_SUCCESS; 
    357353} 
    358354 
    359355// Reading - High-level functions 
    360 #define ROLLBACK {CharacterDatabase.RollbackTransaction(); fclose(fin); return false;} 
    361  
    362 bool PlayerDumpReader::LoadDump(std::string file, uint32 account, std::string name, uint32 guid) 
     356#define ROLLBACK(DR) {CharacterDatabase.RollbackTransaction(); fclose(fin); return (DR);} 
     357 
     358DumpReturn PlayerDumpReader::LoadDump(std::string file, uint32 account, std::string name, uint32 guid) 
    363359{ 
    364360    // check character count 
     
    373369 
    374370            if (charcount >= 10) 
    375             { 
    376                 return false; 
    377             } 
     371                return DUMP_TOO_MANY_CHARS; 
    378372        } 
    379373    } 
    380374    FILE *fin = fopen(file.c_str(), "r"); 
    381     if(!fin) return false; 
     375    if(!fin) 
     376                return DUMP_FILE_OPEN_ERROR; 
    382377 
    383378    QueryResult * result = NULL; 
     
    435430        { 
    436431            if(feof(fin)) break; 
    437             sLog.outError("LoadPlayerDump: File read error!"); 
    438             ROLLBACK; 
     432            ROLLBACK(DUMP_FILE_BROKEN); 
    439433        } 
    440434 
     
    450444        { 
    451445            sLog.outError("LoadPlayerDump: Can't extract table name from line: '%s'!", line.c_str()); 
    452             ROLLBACK; 
     446            ROLLBACK(DUMP_FILE_BROKEN); 
    453447        } 
    454448 
     
    467461        { 
    468462            sLog.outError("LoadPlayerDump: Unknown table: '%s'!", tn.c_str()); 
    469             ROLLBACK; 
     463            ROLLBACK(DUMP_FILE_BROKEN); 
    470464        } 
    471465 
     
    474468        { 
    475469            case DTT_CHAR_TABLE: 
    476                 if(!changenth(line, 1, newguid)) ROLLBACK; 
     470                if(!changenth(line, 1, newguid)) 
     471                                        ROLLBACK(DUMP_FILE_BROKEN); 
    477472                break; 
    478473 
    479474            case DTT_CHARACTER:                             // character t. 
    480475            { 
    481                 if(!changenth(line, 1, newguid)) ROLLBACK; 
     476                if(!changenth(line, 1, newguid)) 
     477                                        ROLLBACK(DUMP_FILE_BROKEN); 
    482478 
    483479                // guid, data field:guid, items 
    484                 if(!changenth(line, 2, chraccount)) ROLLBACK; 
     480                if(!changenth(line, 2, chraccount)) 
     481                                        ROLLBACK(DUMP_FILE_BROKEN); 
     482 
    485483                std::string vals = getnth(line, 3); 
    486                 if(!changetoknth(vals, OBJECT_FIELD_GUID+1, newguid)) ROLLBACK; 
     484                if(!changetoknth(vals, OBJECT_FIELD_GUID+1, newguid)) 
     485                                        ROLLBACK(DUMP_FILE_BROKEN); 
     486 
    487487                for(uint16 field = PLAYER_FIELD_INV_SLOT_HEAD; field < PLAYER_FARSIGHT; field++) 
    488                     if(!changetokGuid(vals, field+1, items, objmgr.m_hiItemGuid, true)) ROLLBACK; 
    489                 if(!changenth(line, 3, vals.c_str())) ROLLBACK; 
     488                    if(!changetokGuid(vals, field+1, items, objmgr.m_hiItemGuid, true)) 
     489                                                ROLLBACK(DUMP_FILE_BROKEN); 
     490 
     491                if(!changenth(line, 3, vals.c_str())) 
     492                                        ROLLBACK(DUMP_FILE_BROKEN); 
     493 
    490494                if (name == "") 
    491495                { 
     
    499503                        delete result; 
    500504                                                            // rename on login: `at_login` field 30 in raw field list 
    501                         if(!changenth(line, 30, "1")) ROLLBACK; 
     505                        if(!changenth(line, 30, "1")) 
     506                                                        ROLLBACK(DUMP_FILE_BROKEN); 
    502507                    } 
    503508                } 
    504                 else if(!changenth(line, 4, name.c_str())) ROLLBACK; 
     509                else if(!changenth(line, 4, name.c_str())) 
     510                                        ROLLBACK(DUMP_FILE_BROKEN); 
    505511 
    506512                break; 
     
    508514            case DTT_INVENTORY:                             // character_inventory t. 
    509515            { 
    510                 if(!changenth(line, 1, newguid)) ROLLBACK; 
     516                if(!changenth(line, 1, newguid)) 
     517                                        ROLLBACK(DUMP_FILE_BROKEN); 
    511518 
    512519                // bag, item 
    513                 if(!changeGuid(line, 2, items, objmgr.m_hiItemGuid, true)) ROLLBACK; 
    514                 if(!changeGuid(line, 4, items, objmgr.m_hiItemGuid)) ROLLBACK; 
     520                if(!changeGuid(line, 2, items, objmgr.m_hiItemGuid, true)) 
     521                                        ROLLBACK(DUMP_FILE_BROKEN); 
     522                                if(!changeGuid(line, 4, items, objmgr.m_hiItemGuid)) 
     523                                        ROLLBACK(DUMP_FILE_BROKEN); 
    515524                break; 
    516525            } 
     
    518527            { 
    519528                // item, owner, data field:item, owner guid 
    520                 if(!changeGuid(line, 1, items, objmgr.m_hiItemGuid)) ROLLBACK; 
    521                 if(!changenth(line, 2, newguid)) ROLLBACK; 
     529                if(!changeGuid(line, 1, items, objmgr.m_hiItemGuid)) 
     530                                        ROLLBACK(DUMP_FILE_BROKEN); 
     531                                if(!changenth(line, 2, newguid)) 
     532                                        ROLLBACK(DUMP_FILE_BROKEN); 
     533 
    522534                std::string vals = getnth(line,3); 
    523                 if(!changetokGuid(vals, OBJECT_FIELD_GUID+1, items, objmgr.m_hiItemGuid)) ROLLBACK; 
    524                 if(!changetoknth(vals, ITEM_FIELD_OWNER+1, newguid)) ROLLBACK; 
    525                 if(!changenth(line, 3, vals.c_str())) ROLLBACK; 
     535                if(!changetokGuid(vals, OBJECT_FIELD_GUID+1, items, objmgr.m_hiItemGuid)) 
     536                                        ROLLBACK(DUMP_FILE_BROKEN); 
     537                                if(!changetoknth(vals, ITEM_FIELD_OWNER+1, newguid)) 
     538                                        ROLLBACK(DUMP_FILE_BROKEN); 
     539                                if(!changenth(line, 3, vals.c_str())) 
     540                                        ROLLBACK(DUMP_FILE_BROKEN); 
    526541                break; 
    527542            } 
     
    529544            { 
    530545                // guid,item_guid, 
    531                 if(!changenth(line, 1, newguid)) ROLLBACK; 
    532                 if(!changeGuid(line, 2, items, objmgr.m_hiItemGuid)) ROLLBACK; 
     546                if(!changenth(line, 1, newguid)) 
     547                                        ROLLBACK(DUMP_FILE_BROKEN); 
     548                                if(!changeGuid(line, 2, items, objmgr.m_hiItemGuid)) 
     549                                        ROLLBACK(DUMP_FILE_BROKEN); 
    533550                break; 
    534551            } 
     
    552569 
    553570                // item, entry, owner, ... 
    554                 if(!changenth(line, 1, newpetid)) ROLLBACK; 
    555                 if(!changenth(line, 3, newguid)) ROLLBACK; 
     571                if(!changenth(line, 1, newpetid)) 
     572                                        ROLLBACK(DUMP_FILE_BROKEN); 
     573                                if(!changenth(line, 3, newguid)) 
     574                                        ROLLBACK(DUMP_FILE_BROKEN); 
    556575 
    557576                break; 
     
    563582                // lookup currpetid and match to new inserted pet id 
    564583                std::map<uint32, uint32> :: const_iterator petids_iter = petids.find(atoi(currpetid)); 
    565                 if(petids_iter == petids.end()) ROLLBACK;   // couldn't find new inserted id 
     584                if(petids_iter == petids.end())             // couldn't find new inserted id 
     585                                        ROLLBACK(DUMP_FILE_BROKEN); 
    566586 
    567587                snprintf(newpetid, 20, "%d", petids_iter->second); 
    568588 
    569                 if(!changenth(line, 1, newpetid)) ROLLBACK; 
     589                if(!changenth(line, 1, newpetid)) 
     590                                        ROLLBACK(DUMP_FILE_BROKEN); 
    570591 
    571592                break; 
     
    574595            { 
    575596                // id,messageType,stationery,sender,receiver 
    576                 if(!changeGuid(line, 1, mails, objmgr.m_mailid)) ROLLBACK; 
    577                 if(!changenth(line, 5, newguid)) ROLLBACK; 
     597                if(!changeGuid(line, 1, mails, objmgr.m_mailid)) 
     598                                        ROLLBACK(DUMP_FILE_BROKEN); 
     599                                if(!changenth(line, 5, newguid)) 
     600                                        ROLLBACK(DUMP_FILE_BROKEN); 
    578601                break; 
    579602            } 
     
    581604            { 
    582605                // mail_id,item_guid,item_template,receiver 
    583                 if(!changeGuid(line, 1, mails, objmgr.m_mailid)) ROLLBACK; 
    584                 if(!changeGuid(line, 2, items, objmgr.m_hiItemGuid)) ROLLBACK; 
    585                 if(!changenth(line, 4, newguid)) ROLLBACK; 
     606                if(!changeGuid(line, 1, mails, objmgr.m_mailid)) 
     607                                        ROLLBACK(DUMP_FILE_BROKEN); 
     608                                if(!changeGuid(line, 2, items, objmgr.m_hiItemGuid)) 
     609                                        ROLLBACK(DUMP_FILE_BROKEN); 
     610                                if(!changenth(line, 4, newguid)) 
     611                                        ROLLBACK(DUMP_FILE_BROKEN); 
    586612                break; 
    587613            } 
     
    591617        } 
    592618 
    593         if(!CharacterDatabase.Execute(line.c_str())) ROLLBACK; 
     619        if(!CharacterDatabase.Execute(line.c_str())) 
     620                        ROLLBACK(DUMP_FILE_BROKEN); 
    594621    } 
    595622 
     
    604631    fclose(fin); 
    605632 
    606     return true; 
    607 } 
     633    return DUMP_SUCCESS; 
     634}