Changeset 112 for trunk/src/game/PlayerDump.cpp
- Timestamp:
- 11/19/08 13:37:14 (17 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/game/PlayerDump.cpp
r102 r112 27 27 28 28 // Character Dump tables 29 #define DUMP_TABLE_COUNT 2029 #define DUMP_TABLE_COUNT 19 30 30 31 31 struct DumpTable … … 259 259 260 260 // 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 261 void PlayerDumpWriter::DumpTable(std::string& dump, uint32 guid, char const*tableFrom, char const*tableTo, DumpTableType type) 262 { 266 263 GUIDs const* guids = NULL; 267 264 char const* fieldname = NULL; … … 281 278 // for guid set stop if set is empty 282 279 if(guids && guids->empty()) 283 return true; // nothing to do280 return; // nothing to do 284 281 285 282 // setup for guids case start position … … 299 296 QueryResult *result = CharacterDatabase.PQuery("SELECT * FROM %s WHERE %s", tableFrom, wherestr.c_str()); 300 297 if(!result) 301 return false;298 return; 302 299 303 300 do … … 329 326 } 330 327 while(guids && guids_itr != guids->end()); // not set case iterate single time, set case iterate for all guids 331 332 return true;333 328 } 334 329 … … 339 334 DumpTable(dump, guid, dumpTables[i].name, dumpTables[i].name, dumpTables[i].type); 340 335 341 // TODO: Add instance/group /gifts..336 // TODO: Add instance/group.. 342 337 // TODO: Add a dump level option to skip some non-important tables 343 338 … … 345 340 } 346 341 347 boolPlayerDumpWriter::WriteDump(std::string file, uint32 guid)342 DumpReturn PlayerDumpWriter::WriteDump(std::string file, uint32 guid) 348 343 { 349 344 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; 351 347 352 348 std::string dump = GetDump(guid); … … 354 350 fprintf(fout,"%s\n",dump.c_str()); 355 351 fclose(fout); 356 return true;352 return DUMP_SUCCESS; 357 353 } 358 354 359 355 // Reading - High-level functions 360 #define ROLLBACK {CharacterDatabase.RollbackTransaction(); fclose(fin); return false;}361 362 boolPlayerDumpReader::LoadDump(std::string file, uint32 account, std::string name, uint32 guid)356 #define ROLLBACK(DR) {CharacterDatabase.RollbackTransaction(); fclose(fin); return (DR);} 357 358 DumpReturn PlayerDumpReader::LoadDump(std::string file, uint32 account, std::string name, uint32 guid) 363 359 { 364 360 // check character count … … 373 369 374 370 if (charcount >= 10) 375 { 376 return false; 377 } 371 return DUMP_TOO_MANY_CHARS; 378 372 } 379 373 } 380 374 FILE *fin = fopen(file.c_str(), "r"); 381 if(!fin) return false; 375 if(!fin) 376 return DUMP_FILE_OPEN_ERROR; 382 377 383 378 QueryResult * result = NULL; … … 435 430 { 436 431 if(feof(fin)) break; 437 sLog.outError("LoadPlayerDump: File read error!"); 438 ROLLBACK; 432 ROLLBACK(DUMP_FILE_BROKEN); 439 433 } 440 434 … … 450 444 { 451 445 sLog.outError("LoadPlayerDump: Can't extract table name from line: '%s'!", line.c_str()); 452 ROLLBACK ;446 ROLLBACK(DUMP_FILE_BROKEN); 453 447 } 454 448 … … 467 461 { 468 462 sLog.outError("LoadPlayerDump: Unknown table: '%s'!", tn.c_str()); 469 ROLLBACK ;463 ROLLBACK(DUMP_FILE_BROKEN); 470 464 } 471 465 … … 474 468 { 475 469 case DTT_CHAR_TABLE: 476 if(!changenth(line, 1, newguid)) ROLLBACK; 470 if(!changenth(line, 1, newguid)) 471 ROLLBACK(DUMP_FILE_BROKEN); 477 472 break; 478 473 479 474 case DTT_CHARACTER: // character t. 480 475 { 481 if(!changenth(line, 1, newguid)) ROLLBACK; 476 if(!changenth(line, 1, newguid)) 477 ROLLBACK(DUMP_FILE_BROKEN); 482 478 483 479 // guid, data field:guid, items 484 if(!changenth(line, 2, chraccount)) ROLLBACK; 480 if(!changenth(line, 2, chraccount)) 481 ROLLBACK(DUMP_FILE_BROKEN); 482 485 483 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 487 487 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 490 494 if (name == "") 491 495 { … … 499 503 delete result; 500 504 // 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); 502 507 } 503 508 } 504 else if(!changenth(line, 4, name.c_str())) ROLLBACK; 509 else if(!changenth(line, 4, name.c_str())) 510 ROLLBACK(DUMP_FILE_BROKEN); 505 511 506 512 break; … … 508 514 case DTT_INVENTORY: // character_inventory t. 509 515 { 510 if(!changenth(line, 1, newguid)) ROLLBACK; 516 if(!changenth(line, 1, newguid)) 517 ROLLBACK(DUMP_FILE_BROKEN); 511 518 512 519 // 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); 515 524 break; 516 525 } … … 518 527 { 519 528 // 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 522 534 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); 526 541 break; 527 542 } … … 529 544 { 530 545 // 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); 533 550 break; 534 551 } … … 552 569 553 570 // 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); 556 575 557 576 break; … … 563 582 // lookup currpetid and match to new inserted pet id 564 583 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); 566 586 567 587 snprintf(newpetid, 20, "%d", petids_iter->second); 568 588 569 if(!changenth(line, 1, newpetid)) ROLLBACK; 589 if(!changenth(line, 1, newpetid)) 590 ROLLBACK(DUMP_FILE_BROKEN); 570 591 571 592 break; … … 574 595 { 575 596 // 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); 578 601 break; 579 602 } … … 581 604 { 582 605 // 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); 586 612 break; 587 613 } … … 591 617 } 592 618 593 if(!CharacterDatabase.Execute(line.c_str())) ROLLBACK; 619 if(!CharacterDatabase.Execute(line.c_str())) 620 ROLLBACK(DUMP_FILE_BROKEN); 594 621 } 595 622 … … 604 631 fclose(fin); 605 632 606 return true;607 } 633 return DUMP_SUCCESS; 634 }