Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
cs_character.cpp
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6/* ScriptData
7Name: character_commandscript
8%Complete: 100
9Comment: All character related commands
10Category: commandscripts
11EndScriptData */
12
13#include "AccountMgr.h"
14#include "Chat.h"
15#include "DatabaseEnv.h"
16#include "ObjectAccessor.h"
17#include "ObjectMgr.h"
18#include "Player.h"
19#include "PlayerDump.h"
20#include "ReputationMgr.h"
21#include "ScriptMgr.h"
22
24{
25public:
26 character_commandscript() : CommandScript("character_commandscript") { }
27
28 std::vector<ChatCommand> GetCommands() const OVERRIDE
29 {
30 static std::vector<ChatCommand> pdumpCommandTable =
31 {
34 };
35 static std::vector<ChatCommand> characterDeletedCommandTable =
36 {
41 };
42
43 static std::vector<ChatCommand> characterCommandTable =
44 {
48 { "deleted", rbac::RBAC_PERM_COMMAND_CHARACTER_DELETED, true, NULL, "", characterDeletedCommandTable },
54 };
55
56 static std::vector<ChatCommand> commandTable =
57 {
58 { "character", rbac::RBAC_PERM_COMMAND_CHARACTER, true, NULL, "", characterCommandTable },
59 { "levelup", rbac::RBAC_PERM_COMMAND_LEVELUP, false, &HandleLevelUpCommand, "", },
60 { "pdump", rbac::RBAC_PERM_COMMAND_PDUMP, true, NULL, "", pdumpCommandTable },
61 };
62 return commandTable;
63 }
64
65 // Stores informations about a deleted character
67 {
69 std::string name;
71 std::string accountName;
72 time_t deleteDate;
73 };
74
75 typedef std::list<DeletedInfo> DeletedInfoList;
76
84 static bool GetDeletedCharacterInfoList(DeletedInfoList& foundList, std::string searchString)
85 {
88 if (!searchString.empty())
89 {
90 // search by GUID
91 if (isNumeric(searchString.c_str()))
92 {
93 stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_DEL_INFO_BY_GUID);
94 stmt->setUInt32(0, uint32(atoi(searchString.c_str())));
95 result = CharacterDatabase.Query(stmt);
96 }
97 // search by name
98 else
99 {
100 if (!normalizePlayerName(searchString))
101 return false;
102
103 stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_DEL_INFO_BY_NAME);
104 stmt->setString(0, searchString);
105 result = CharacterDatabase.Query(stmt);
106 }
107 }
108 else
109 {
110 stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_DEL_INFO);
111 result = CharacterDatabase.Query(stmt);
112 }
113
114 if (result)
115 {
116 do
117 {
118 Field* fields = result->Fetch();
119
120 DeletedInfo info;
121
122 info.lowGuid = fields[0].GetUInt32();
123 info.name = fields[1].GetString();
124 info.accountId = fields[2].GetUInt32();
125
126 // account name will be empty for not existed account
128 info.deleteDate = time_t(fields[3].GetUInt32());
129 foundList.push_back(info);
130 } while (result->NextRow());
131 }
132
133 return true;
134 }
135
146 static void HandleCharacterDeletedListHelper(DeletedInfoList const& foundList, ChatHandler* handler)
147 {
148 if (!handler->GetSession())
149 {
153 }
154
155 for (DeletedInfoList::const_iterator itr = foundList.begin(); itr != foundList.end(); ++itr)
156 {
157 std::string dateStr = TimeToTimestampStr(itr->deleteDate);
158
159 if (!handler->GetSession())
161 itr->lowGuid, itr->name.c_str(), itr->accountName.empty() ? "<Not existed>" : itr->accountName.c_str(),
162 itr->accountId, dateStr.c_str());
163 else
165 itr->lowGuid, itr->name.c_str(), itr->accountName.empty() ? "<Not existed>" : itr->accountName.c_str(),
166 itr->accountId, dateStr.c_str());
167 }
168
169 if (!handler->GetSession())
171 }
172
183 static void HandleCharacterDeletedRestoreHelper(DeletedInfo const& delInfo, ChatHandler* handler)
184 {
185 if (delInfo.accountName.empty()) // account not exist
186 {
187 handler->PSendSysMessage(LANG_CHARACTER_DELETED_SKIP_ACCOUNT, delInfo.name.c_str(), delInfo.lowGuid, delInfo.accountId);
188 return;
189 }
190
191 // check character count
193 if (charcount >= 10)
194 {
195 handler->PSendSysMessage(LANG_CHARACTER_DELETED_SKIP_FULL, delInfo.name.c_str(), delInfo.lowGuid, delInfo.accountId);
196 return;
197 }
198
199 if (sObjectMgr->GetPlayerGUIDByName(delInfo.name))
200 {
201 handler->PSendSysMessage(LANG_CHARACTER_DELETED_SKIP_NAME, delInfo.name.c_str(), delInfo.lowGuid, delInfo.accountId);
202 return;
203 }
204
206 stmt->setString(0, delInfo.name);
207 stmt->setUInt32(1, delInfo.accountId);
208 stmt->setUInt32(2, delInfo.lowGuid);
209 CharacterDatabase.Execute(stmt);
210
211 stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHARACTER_NAME_DATA);
212 stmt->setUInt32(0, delInfo.lowGuid);
213 if (PreparedQueryResult result = CharacterDatabase.Query(stmt))
214 sWorld->AddCharacterNameData(delInfo.lowGuid, delInfo.name, (*result)[2].GetUInt8(), (*result)[0].GetUInt8(), (*result)[1].GetUInt8(), (*result)[3].GetUInt8(), (*result)[4].GetUInt32());
215 }
216
217 static void HandleCharacterLevel(Player* player, uint64 playerGuid, uint32 oldLevel, uint32 newLevel, ChatHandler* handler)
218 {
219 if (player)
220 {
221 player->GiveLevel(newLevel);
222 player->InitTalentForLevel();
224
225 if (handler->needReportToTarget(player))
226 {
227 if (oldLevel == newLevel)
229 else if (oldLevel < newLevel)
230 ChatHandler(player->GetSession()).PSendSysMessage(LANG_YOURS_LEVEL_UP, handler->GetNameLink().c_str(), newLevel);
231 else // if (oldlevel > newlevel)
232 ChatHandler(player->GetSession()).PSendSysMessage(LANG_YOURS_LEVEL_DOWN, handler->GetNameLink().c_str(), newLevel);
233 }
234 }
235 else
236 {
237 // Update level and reset XP, everything else will be updated at login
238 PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_LEVEL);
239 stmt->setUInt8(0, uint8(newLevel));
240 stmt->setUInt32(1, GUID_LOPART(playerGuid));
241 CharacterDatabase.Execute(stmt);
242 }
243 }
244
245 static bool HandleCharacterTitlesCommand(ChatHandler* handler, char const* args)
246 {
247 if (!*args)
248 return false;
249
250 Player* target;
251 if (!handler->extractPlayerTarget((char*)args, &target))
252 return false;
253
254 LocaleConstant loc = handler->GetSessionDbcLocale();
255 char const* targetName = target->GetName().c_str();
256 char const* knownStr = handler->GetSkyFireString(LANG_KNOWN);
257
258 // Search in CharTitles.dbc
259 for (uint32 id = 0; id < sCharTitlesStore.GetNumRows(); id++)
260 {
261 CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id);
262
263 if (titleInfo && target->HasTitle(titleInfo))
264 {
265 std::string name = titleInfo->name;
266 if (name.empty())
267 continue;
268
269 char const* activeStr = target->GetUInt32Value(PLAYER_FIELD_PLAYER_TITLE) == titleInfo->bit_index
270 ? handler->GetSkyFireString(LANG_ACTIVE)
271 : "";
272
273 char titleNameStr[80];
274 snprintf(titleNameStr, 80, name.c_str(), targetName);
275
276 // send title in "id (idx:idx) - [namedlink locale]" format
277 if (handler->GetSession())
278 handler->PSendSysMessage(LANG_TITLE_LIST_CHAT, id, titleInfo->bit_index, id, titleNameStr, localeNames[loc], knownStr, activeStr);
279 else
280 handler->PSendSysMessage(LANG_TITLE_LIST_CONSOLE, id, titleInfo->bit_index, name.c_str(), localeNames[loc], knownStr, activeStr);
281 }
282 }
283
284 return true;
285 }
286
287 //rename characters
288 static bool HandleCharacterRenameCommand(ChatHandler* handler, char const* args)
289 {
290 Player* target;
291 uint64 targetGuid;
292 std::string targetName;
293 if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid, &targetName))
294 return false;
295
296 char const* newNameStr = strtok(NULL, " ");
297
298 if (newNameStr)
299 {
300 std::string playerOldName;
301 std::string newName = newNameStr;
302
303 if (target)
304 {
305 // check online security
306 if (handler->HasLowerSecurity(target, 0))
307 return false;
308
309 playerOldName = target->GetName();
310 }
311 else
312 {
313 // check offline security
314 if (handler->HasLowerSecurity(NULL, targetGuid))
315 return false;
316
317 sObjectMgr->GetPlayerNameByGUID(targetGuid, playerOldName);
318 }
319
320 if (!normalizePlayerName(newName))
321 {
323 handler->SetSentErrorMessage(true);
324 return false;
325 }
326
328 {
330 handler->SetSentErrorMessage(true);
331 return false;
332 }
333
334 if (WorldSession* session = handler->GetSession())
335 {
336 if (!session->HasPermission(rbac::RBAC_PERM_SKIP_CHECK_CHARACTER_CREATION_RESERVEDNAME) && sObjectMgr->IsReservedName(newName))
337 {
339 handler->SetSentErrorMessage(true);
340 return false;
341 }
342 }
343
344 PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHECK_NAME);
345 stmt->setString(0, newName);
346 PreparedQueryResult result = CharacterDatabase.Query(stmt);
347 if (result)
348 {
349 handler->PSendSysMessage(LANG_RENAME_PLAYER_ALREADY_EXISTS, newName.c_str());
350 handler->SetSentErrorMessage(true);
351 return false;
352 }
353
354 // Remove declined name from db
355 stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_DECLINED_NAME);
356 stmt->setUInt32(0, targetGuid);
357 CharacterDatabase.Execute(stmt);
358
359 if (target)
360 {
361 target->SetName(newName);
362
363 if (WorldSession* session = target->GetSession())
364 session->KickPlayer();
365 }
366 else
367 {
368 stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_NAME_BY_GUID);
369 stmt->setString(0, newName);
370 stmt->setUInt32(1, GUID_LOPART(targetGuid));
371 CharacterDatabase.Execute(stmt);
372 }
373
374 sWorld->UpdateCharacterNameData(targetGuid, newName);
375
376 handler->PSendSysMessage(LANG_RENAME_PLAYER_WITH_NEW_NAME, playerOldName.c_str(), newName.c_str());
377
378 if (WorldSession* session = handler->GetSession())
379 {
380 if (Player* player = session->GetPlayer())
381 sLog->outCommand(session->GetAccountId(), "GM %s (Account: %u) forced rename %s to player %s (Account: %u)", player->GetName().c_str(), session->GetAccountId(), newName.c_str(), playerOldName.c_str(), sObjectMgr->GetPlayerAccountIdByGUID(targetGuid));
382 }
383 else
384 sLog->outCommand(0, "CONSOLE forced rename '%s' to '%s' (GUID: %u)", playerOldName.c_str(), newName.c_str(), GUID_LOPART(targetGuid));
385 }
386 else
387 {
388 if (target)
389 {
390 // check online security
391 if (handler->HasLowerSecurity(target, 0))
392 return false;
393
394 handler->PSendSysMessage(LANG_RENAME_PLAYER, handler->GetNameLink(target).c_str());
396 }
397 else
398 {
399 // check offline security
400 if (handler->HasLowerSecurity(NULL, targetGuid))
401 return false;
402
403 std::string oldNameLink = handler->playerLink(targetName);
404 handler->PSendSysMessage(LANG_RENAME_PLAYER_GUID, oldNameLink.c_str(), GUID_LOPART(targetGuid));
405
408 stmt->setUInt32(1, GUID_LOPART(targetGuid));
409 CharacterDatabase.Execute(stmt);
410 }
411 }
412
413 return true;
414 }
415
416 static bool HandleCharacterLevelCommand(ChatHandler* handler, char const* args)
417 {
418 char* nameStr;
419 char* levelStr;
420 handler->extractOptFirstArg((char*)args, &nameStr, &levelStr);
421 if (!levelStr)
422 return false;
423
424 // exception opt second arg: .character level $name
425 if (isalpha(levelStr[0]))
426 {
427 nameStr = levelStr;
428 levelStr = NULL; // current level will used
429 }
430
431 Player* target;
432 uint64 targetGuid;
433 std::string targetName;
434 if (!handler->extractPlayerTarget(nameStr, &target, &targetGuid, &targetName))
435 return false;
436
437 int32 oldlevel = target ? target->getLevel() : Player::GetLevelFromDB(targetGuid);
438 int32 newlevel = levelStr ? atoi(levelStr) : oldlevel;
439
440 if (newlevel < 1)
441 return false; // invalid level
442
443 if (newlevel > STRONG_MAX_LEVEL) // hardcoded maximum level
444 newlevel = STRONG_MAX_LEVEL;
445
446 HandleCharacterLevel(target, targetGuid, oldlevel, newlevel, handler);
447 if (!handler->GetSession() || handler->GetSession()->GetPlayer() != target) // including player == NULL
448 {
449 std::string nameLink = handler->playerLink(targetName);
450 handler->PSendSysMessage(LANG_YOU_CHANGE_LVL, nameLink.c_str(), newlevel);
451 }
452
453 return true;
454 }
455
456 // customize characters
457 static bool HandleCharacterCustomizeCommand(ChatHandler* handler, char const* args)
458 {
459 Player* target;
460 uint64 targetGuid;
461 std::string targetName;
462 if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid, &targetName))
463 return false;
464
467 if (target)
468 {
469 handler->PSendSysMessage(LANG_CUSTOMIZE_PLAYER, handler->GetNameLink(target).c_str());
471 stmt->setUInt32(1, target->GetGUIDLow());
472 }
473 else
474 {
475 std::string oldNameLink = handler->playerLink(targetName);
476 stmt->setUInt32(1, GUID_LOPART(targetGuid));
477 handler->PSendSysMessage(LANG_CUSTOMIZE_PLAYER_GUID, oldNameLink.c_str(), GUID_LOPART(targetGuid));
478 }
479 CharacterDatabase.Execute(stmt);
480
481 return true;
482 }
483
484 static bool HandleCharacterChangeFactionCommand(ChatHandler* handler, char const* args)
485 {
486 Player* target;
487 uint64 targetGuid;
488 std::string targetName;
489
490 if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid, &targetName))
491 return false;
492
495 if (target)
496 {
497 handler->PSendSysMessage(LANG_CUSTOMIZE_PLAYER, handler->GetNameLink(target).c_str());
499 stmt->setUInt32(1, target->GetGUIDLow());
500 }
501 else
502 {
503 std::string oldNameLink = handler->playerLink(targetName);
504 handler->PSendSysMessage(LANG_CUSTOMIZE_PLAYER_GUID, oldNameLink.c_str(), GUID_LOPART(targetGuid));
505 stmt->setUInt32(1, GUID_LOPART(targetGuid));
506 }
507 CharacterDatabase.Execute(stmt);
508
509 return true;
510 }
511
512 static bool HandleCharacterChangeRaceCommand(ChatHandler* handler, char const* args)
513 {
514 Player* target;
515 uint64 targetGuid;
516 std::string targetName;
517 if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid, &targetName))
518 return false;
519
522 if (target)
523 {
525 handler->PSendSysMessage(LANG_CUSTOMIZE_PLAYER, handler->GetNameLink(target).c_str());
527 stmt->setUInt32(1, target->GetGUIDLow());
528 }
529 else
530 {
531 std::string oldNameLink = handler->playerLink(targetName);
533 handler->PSendSysMessage(LANG_CUSTOMIZE_PLAYER_GUID, oldNameLink.c_str(), GUID_LOPART(targetGuid));
534 stmt->setUInt32(1, GUID_LOPART(targetGuid));
535 }
536 CharacterDatabase.Execute(stmt);
537
538 return true;
539 }
540
541 static bool HandleCharacterReputationCommand(ChatHandler* handler, char const* args)
542 {
543 Player* target;
544 if (!handler->extractPlayerTarget((char*)args, &target))
545 return false;
546
547 LocaleConstant loc = handler->GetSessionDbcLocale();
548
549 FactionStateList const& targetFSL = target->GetReputationMgr().GetStateList();
550 for (FactionStateList::const_iterator itr = targetFSL.begin(); itr != targetFSL.end(); ++itr)
551 {
552 FactionState const& faction = itr->second;
553 FactionEntry const* factionEntry = sFactionStore.LookupEntry(faction.ID);
554 char const* factionName = factionEntry ? factionEntry->name : "#Not found#";
555 ReputationRank rank = target->GetReputationMgr().GetRank(factionEntry);
556 std::string rankName = handler->GetSkyFireString(ReputationRankStrIndex[rank]);
557 std::ostringstream ss;
558 if (handler->GetSession())
559 ss << faction.ID << " - |cffffffff|Hfaction:" << faction.ID << "|h[" << factionName << ' ' << localeNames[loc] << "]|h|r";
560 else
561 ss << faction.ID << " - " << factionName << ' ' << localeNames[loc];
562
563 ss << ' ' << rankName << " (" << target->GetReputationMgr().GetReputation(factionEntry) << ')';
564
565 if (faction.Flags & FACTION_FLAG_VISIBLE)
567 if (faction.Flags & FACTION_FLAG_AT_WAR)
568 ss << handler->GetSkyFireString(LANG_FACTION_ATWAR);
569 if (faction.Flags & FACTION_FLAG_PEACE_FORCED)
571 if (faction.Flags & FACTION_FLAG_HIDDEN)
575 if (faction.Flags & FACTION_FLAG_INACTIVE)
577
578 handler->SendSysMessage(ss.str().c_str());
579 }
580
581 return true;
582 }
583
594 static bool HandleCharacterDeletedListCommand(ChatHandler* handler, char const* args)
595 {
596 DeletedInfoList foundList;
597 if (!GetDeletedCharacterInfoList(foundList, args))
598 return false;
599
600 // if no characters have been found, output a warning
601 if (foundList.empty())
602 {
604 return false;
605 }
606
607 HandleCharacterDeletedListHelper(foundList, handler);
608
609 return true;
610 }
611
623 static bool HandleCharacterDeletedRestoreCommand(ChatHandler* handler, char const* args)
624 {
625 // It is required to submit at least one argument
626 if (!*args)
627 return false;
628
629 std::string searchString;
630 std::string newCharName;
631 uint32 newAccount = 0;
632
633 // GCC by some strange reason fail build code without temporary variable
634 std::istringstream params(args);
635 params >> searchString >> newCharName >> newAccount;
636
637 DeletedInfoList foundList;
638 if (!GetDeletedCharacterInfoList(foundList, searchString))
639 return false;
640
641 if (foundList.empty())
642 {
644 return false;
645 }
646
648 HandleCharacterDeletedListHelper(foundList, handler);
649
650 if (newCharName.empty())
651 {
652 // Drop not existed account cases
653 for (DeletedInfoList::iterator itr = foundList.begin(); itr != foundList.end(); ++itr)
655 }
656 else if (foundList.size() == 1 && normalizePlayerName(newCharName))
657 {
658 DeletedInfo delInfo = foundList.front();
659
660 // update name
661 delInfo.name = newCharName;
662
663 // if new account provided update deleted info
664 if (newAccount && newAccount != delInfo.accountId)
665 {
666 delInfo.accountId = newAccount;
667 AccountMgr::GetName(newAccount, delInfo.accountName);
668 }
669
670 HandleCharacterDeletedRestoreHelper(delInfo, handler);
671 }
672 else
674
675 return true;
676 }
677
688 static bool HandleCharacterDeletedDeleteCommand(ChatHandler* handler, char const* args)
689 {
690 // It is required to submit at least one argument
691 if (!*args)
692 return false;
693
694 DeletedInfoList foundList;
695 if (!GetDeletedCharacterInfoList(foundList, args))
696 return false;
697
698 if (foundList.empty())
699 {
701 return false;
702 }
703
705 HandleCharacterDeletedListHelper(foundList, handler);
706
707 // Call the appropriate function to delete them (current account for deleted characters is 0)
708 for (DeletedInfoList::const_iterator itr = foundList.begin(); itr != foundList.end(); ++itr)
709 Player::DeleteFromDB(itr->lowGuid, 0, false, true);
710
711 return true;
712 }
713
725 static bool HandleCharacterDeletedOldCommand(ChatHandler* /*handler*/, char const* args)
726 {
728
729 char* daysStr = strtok((char*)args, " ");
730 if (daysStr)
731 {
732 if (!isNumeric(daysStr))
733 return false;
734
735 keepDays = atoi(daysStr);
736 if (keepDays < 0)
737 return false;
738 }
739 // config option value 0 -> disabled and can't be used
740 else if (keepDays <= 0)
741 return false;
742
744
745 return true;
746 }
747
748 static bool HandleCharacterEraseCommand(ChatHandler* handler, char const* args)
749 {
750 if (!*args)
751 return false;
752
753 char* characterName_str = strtok((char*)args, " ");
754 if (!characterName_str)
755 return false;
756
757 std::string characterName = characterName_str;
758 if (!normalizePlayerName(characterName))
759 return false;
760
761 uint64 characterGuid;
762 uint32 accountId;
763
764 Player* player = sObjectAccessor->FindPlayerByName(characterName);
765 if (player)
766 {
767 characterGuid = player->GetGUID();
768 accountId = player->GetSession()->GetAccountId();
769 player->GetSession()->KickPlayer();
770 }
771 else
772 {
773 characterGuid = sObjectMgr->GetPlayerGUIDByName(characterName);
774 if (!characterGuid)
775 {
776 handler->PSendSysMessage(LANG_NO_PLAYER, characterName.c_str());
777 handler->SetSentErrorMessage(true);
778 return false;
779 }
780 accountId = sObjectMgr->GetPlayerAccountIdByGUID(characterGuid);
781 }
782
783 std::string accountName;
784 AccountMgr::GetName(accountId, accountName);
785
786 Player::DeleteFromDB(characterGuid, accountId, true, true);
787 handler->PSendSysMessage(LANG_CHARACTER_DELETED, characterName.c_str(), GUID_LOPART(characterGuid), accountName.c_str(), accountId);
788
789 return true;
790 }
791
792 static bool HandleLevelUpCommand(ChatHandler* handler, char const* args)
793 {
794 char* nameStr;
795 char* levelStr;
796 handler->extractOptFirstArg((char*)args, &nameStr, &levelStr);
797
798 // exception opt second arg: .character level $name
799 if (levelStr && isalpha(levelStr[0]))
800 {
801 nameStr = levelStr;
802 levelStr = NULL; // current level will used
803 }
804
805 Player* target;
806 uint64 targetGuid;
807 std::string targetName;
808 if (!handler->extractPlayerTarget(nameStr, &target, &targetGuid, &targetName))
809 return false;
810
811 int32 oldlevel = target ? target->getLevel() : Player::GetLevelFromDB(targetGuid);
812 int32 addlevel = levelStr ? atoi(levelStr) : 1;
813 int32 newlevel = oldlevel + addlevel;
814
815 if (newlevel < 1)
816 newlevel = 1;
817
818 if (newlevel > STRONG_MAX_LEVEL) // hardcoded maximum level
819 newlevel = STRONG_MAX_LEVEL;
820
821 HandleCharacterLevel(target, targetGuid, oldlevel, newlevel, handler);
822
823 if (!handler->GetSession() || handler->GetSession()->GetPlayer() != target) // including chr == NULL
824 {
825 std::string nameLink = handler->playerLink(targetName);
826 handler->PSendSysMessage(LANG_YOU_CHANGE_LVL, nameLink.c_str(), newlevel);
827 }
828
829 return true;
830 }
831
832 static bool HandlePDumpLoadCommand(ChatHandler* handler, char const* args)
833 {
834 if (!*args)
835 return false;
836
837 char* fileStr = strtok((char*)args, " ");
838 if (!fileStr)
839 return false;
840
841 char* accountStr = strtok(NULL, " ");
842 if (!accountStr)
843 return false;
844
845 std::string accountName = accountStr;
846 if (!AccountMgr::normalizeString(accountName))
847 {
848 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
849 handler->SetSentErrorMessage(true);
850 return false;
851 }
852
853 uint32 accountId = AccountMgr::GetId(accountName);
854 if (!accountId)
855 {
856 accountId = atoi(accountStr); // use original string
857 if (!accountId)
858 {
859 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
860 handler->SetSentErrorMessage(true);
861 return false;
862 }
863 }
864
865 if (!AccountMgr::GetName(accountId, accountName))
866 {
867 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
868 handler->SetSentErrorMessage(true);
869 return false;
870 }
871
872 char* guidStr = NULL;
873 char* nameStr = strtok(NULL, " ");
874
875 std::string name;
876 if (nameStr)
877 {
878 name = nameStr;
879 // normalize the name if specified and check if it exists
880 if (!normalizePlayerName(name))
881 {
883 handler->SetSentErrorMessage(true);
884 return false;
885 }
886
888 {
890 handler->SetSentErrorMessage(true);
891 return false;
892 }
893
894 guidStr = strtok(NULL, " ");
895 }
896
897 uint32 guid = 0;
898
899 if (guidStr)
900 {
901 guid = uint32(atoi(guidStr));
902 if (!guid)
903 {
905 handler->SetSentErrorMessage(true);
906 return false;
907 }
908
909 if (sObjectMgr->GetPlayerAccountIdByGUID(guid))
910 {
912 handler->SetSentErrorMessage(true);
913 return false;
914 }
915 }
916
917 switch (PlayerDumpReader().LoadDump(fileStr, accountId, name, guid))
918 {
919 case DUMP_SUCCESS:
921 break;
923 handler->PSendSysMessage(LANG_FILE_OPEN_FAIL, fileStr);
924 handler->SetSentErrorMessage(true);
925 return false;
926 case DUMP_FILE_BROKEN:
927 handler->PSendSysMessage(LANG_DUMP_BROKEN, fileStr);
928 handler->SetSentErrorMessage(true);
929 return false;
931 handler->PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL, accountName.c_str(), accountId);
932 handler->SetSentErrorMessage(true);
933 return false;
934 default:
936 handler->SetSentErrorMessage(true);
937 return false;
938 }
939
940 return true;
941 }
942
943 static bool HandlePDumpWriteCommand(ChatHandler* handler, char const* args)
944 {
945 if (!*args)
946 return false;
947
948 char* fileStr = strtok((char*)args, " ");
949 char* playerStr = strtok(NULL, " ");
950
951 if (!fileStr || !playerStr)
952 return false;
953
954 uint64 guid;
955 // character name can't start from number
956 if (isNumeric(playerStr))
957 guid = MAKE_NEW_GUID(atoi(playerStr), 0, HIGHGUID_PLAYER);
958 else
959 {
960 std::string name = handler->extractPlayerNameFromLink(playerStr);
961 if (name.empty())
962 {
964 handler->SetSentErrorMessage(true);
965 return false;
966 }
967
968 guid = sObjectMgr->GetPlayerGUIDByName(name);
969 }
970
971 if (!sObjectMgr->GetPlayerAccountIdByGUID(guid))
972 {
974 handler->SetSentErrorMessage(true);
975 return false;
976 }
977
978 sObjectAccessor->SaveAllPlayers();
979 CharacterDatabase.Wait();
980
981 switch (PlayerDumpWriter().WriteDump(fileStr, uint32(guid)))
982 {
983 case DUMP_SUCCESS:
985 break;
987 handler->PSendSysMessage(LANG_FILE_OPEN_FAIL, fileStr);
988 handler->SetSentErrorMessage(true);
989 return false;
992 handler->SetSentErrorMessage(true);
993 return false;
994 default:
996 handler->SetSentErrorMessage(true);
997 return false;
998 }
999
1000 return true;
1001 }
1002};
1003
@ CHAR_SEL_CHECK_NAME
@ CHAR_UPD_LEVEL
@ CHAR_DEL_DECLINED_NAME
@ CHAR_SEL_CHAR_DEL_INFO_BY_NAME
@ CHAR_SEL_CHAR_DEL_INFO
@ CHAR_UPD_NAME_BY_GUID
@ CHAR_UDP_RESTORE_DELETE_INFO
@ CHAR_SEL_CHAR_DEL_INFO_BY_GUID
@ CHAR_SEL_CHARACTER_NAME_DATA
@ CHAR_UPD_ADD_AT_LOGIN_FLAG
char const * localeNames[TOTAL_LOCALES]
Definition Common.cpp:8
LocaleConstant
Definition Common.h:138
@ STRONG_MAX_LEVEL
Definition DBCEnums.h:24
DBCStorage< CharTitlesEntry > sCharTitlesStore(CharTitlesEntryfmt)
DBCStorage< FactionEntry > sFactionStore(FactionEntryfmt)
std::int32_t int32
Definition Define.h:73
std::uint8_t uint8
Definition Define.h:79
std::uint32_t uint32
Definition Define.h:77
#define OVERRIDE
Definition Define.h:60
std::uint64_t uint64
Definition Define.h:76
std::uint16_t uint16
Definition Define.h:78
@ LANG_FACTION_PEACE_FORCED
Definition Language.h:321
@ LANG_CHARACTER_DELETED_SKIP_NAME
Definition Language.h:883
@ LANG_CHARACTER_DELETED_LIST_LINE_CHAT
Definition Language.h:884
@ LANG_RENAME_PLAYER
Definition Language.h:257
@ LANG_FACTION_ATWAR
Definition Language.h:320
@ LANG_CHARACTER_DELETED_ERR_RENAME
Definition Language.h:880
@ LANG_CHARACTER_DELETED_LIST_HEADER
Definition Language.h:874
@ LANG_KNOWN
Definition Language.h:44
@ LANG_DUMP_BROKEN
Definition Language.h:904
@ LANG_CHARACTER_DELETED_LIST_LINE_CONSOLE
Definition Language.h:875
@ LANG_FACTION_INVISIBLE_FORCED
Definition Language.h:323
@ LANG_COMMAND_EXPORT_DELETED_CHAR
Definition Language.h:920
@ LANG_FILE_OPEN_FAIL
Definition Language.h:902
@ LANG_CHARACTER_GUID_IN_USE
Definition Language.h:907
@ LANG_CUSTOMIZE_PLAYER_GUID
Definition Language.h:353
@ LANG_ACCOUNT_CHARACTER_LIST_FULL
Definition Language.h:903
@ LANG_RENAME_PLAYER_WITH_NEW_NAME
Definition Language.h:99
@ LANG_YOU_CHANGE_LVL
Definition Language.h:131
@ LANG_TITLE_LIST_CHAT
Definition Language.h:356
@ LANG_NO_PLAYER
Definition Language.h:114
@ LANG_CHARACTER_DELETED_RESTORE
Definition Language.h:878
@ LANG_CHARACTER_DELETED
Definition Language.h:867
@ LANG_COMMAND_EXPORT_SUCCESS
Definition Language.h:465
@ LANG_FACTION_HIDDEN
Definition Language.h:322
@ LANG_CUSTOMIZE_PLAYER
Definition Language.h:352
@ LANG_ACTIVE
Definition Language.h:48
@ LANG_PLAYER_NOT_FOUND
Definition Language.h:487
@ LANG_CHARACTER_DELETED_SKIP_FULL
Definition Language.h:882
@ LANG_CHARACTER_DELETED_LIST_EMPTY
Definition Language.h:877
@ LANG_CHARACTER_DELETED_LIST_BAR
Definition Language.h:876
@ LANG_BAD_VALUE
Definition Language.h:117
@ LANG_TITLE_LIST_CONSOLE
Definition Language.h:357
@ LANG_COMMAND_IMPORT_FAILED
Definition Language.h:464
@ LANG_YOURS_LEVEL_UP
Definition Language.h:558
@ LANG_YOURS_LEVEL_PROGRESS_RESET
Definition Language.h:560
@ LANG_ACCOUNT_NOT_EXIST
Definition Language.h:390
@ LANG_RESERVED_NAME
Definition Language.h:176
@ LANG_COMMAND_EXPORT_FAILED
Definition Language.h:466
@ LANG_FACTION_INACTIVE
Definition Language.h:324
@ LANG_RENAME_PLAYER_ALREADY_EXISTS
Definition Language.h:98
@ LANG_CHARACTER_DELETED_SKIP_ACCOUNT
Definition Language.h:881
@ LANG_INVALID_CHARACTER_GUID
Definition Language.h:906
@ LANG_RENAME_PLAYER_GUID
Definition Language.h:258
@ LANG_FACTION_VISIBLE
Definition Language.h:319
@ LANG_YOURS_LEVEL_DOWN
Definition Language.h:559
@ LANG_INVALID_CHARACTER_NAME
Definition Language.h:905
@ LANG_COMMAND_IMPORT_SUCCESS
Definition Language.h:463
@ LANG_CHARACTER_DELETED_DELETE
Definition Language.h:879
#define sLog
Definition Log.h:106
#define sObjectAccessor
uint32 GUID_LOPART(uint64 x)
@ HIGHGUID_PLAYER
uint64 MAKE_NEW_GUID(uint32 l, uint32 e, uint32 h)
bool normalizePlayerName(std::string &name)
#define sObjectMgr
Definition ObjectMgr.h:1617
@ AT_LOGIN_CUSTOMIZE
Definition Player.h:620
@ AT_LOGIN_RENAME
Definition Player.h:617
@ AT_LOGIN_CHANGE_RACE
Definition Player.h:624
@ AT_LOGIN_CHANGE_FACTION
Definition Player.h:623
@ DUMP_FILE_OPEN_ERROR
Definition PlayerDump.h:81
@ DUMP_CHARACTER_DELETED
Definition PlayerDump.h:85
@ DUMP_SUCCESS
Definition PlayerDump.h:80
@ DUMP_TOO_MANY_CHARS
Definition PlayerDump.h:82
@ DUMP_FILE_BROKEN
Definition PlayerDump.h:84
Skyfire::AutoPtr< PreparedResultSet, Skyfire::Mutex > PreparedQueryResult
Definition QueryResult.h:94
static uint32 ReputationRankStrIndex[MAX_REPUTATION_RANK]
@ FACTION_FLAG_INACTIVE
@ FACTION_FLAG_PEACE_FORCED
@ FACTION_FLAG_INVISIBLE_FORCED
@ FACTION_FLAG_HIDDEN
@ FACTION_FLAG_VISIBLE
@ FACTION_FLAG_AT_WAR
std::map< RepListID, FactionState > FactionStateList
ReputationRank
@ PLAYER_FIELD_XP
@ PLAYER_FIELD_PLAYER_TITLE
std::string TimeToTimestampStr(time_t t)
Definition Util.cpp:213
bool isNumeric(wchar_t wchar)
Definition Util.h:202
static uint32 GetCharactersCount(uint32 accountId)
static bool normalizeString(std::string &utf8String)
static uint32 GetId(std::string const &username)
static bool GetName(uint32 accountId, std::string &name)
virtual std::string GetNameLink() const
Definition Chat.h:79
bool HasLowerSecurity(Player *target, uint64 guid, bool strong=false)
Definition Chat.cpp:78
void extractOptFirstArg(char *args, char **arg1, char **arg2)
Definition Chat.cpp:1237
std::string playerLink(std::string const &name) const
Definition Chat.h:108
WorldSession * GetSession()
Definition Chat.h:43
virtual LocaleConstant GetSessionDbcLocale() const
Definition Chat.cpp:1277
void PSendSysMessage(const char *format,...) ATTR_PRINTF(2
Definition Chat.cpp:221
void SetSentErrorMessage(bool val)
Definition Chat.h:114
bool extractPlayerTarget(char *args, Player **player, uint64 *player_guid=NULL, std::string *player_name=NULL)
Definition Chat.cpp:1184
virtual bool needReportToTarget(Player *chr) const
Definition Chat.cpp:1271
virtual void SendSysMessage(const char *str)
Definition Chat.cpp:153
virtual const char * GetSkyFireString(int32 entry) const
Definition Chat.cpp:68
std::string extractPlayerNameFromLink(char *text)
Definition Chat.cpp:1170
CommandScript(const char *name)
Definition Field.h:16
std::string GetString() const
Definition Field.h:228
uint32 GetUInt32() const
Definition Field.h:105
uint64 GetGUID() const
Definition Object.h:119
uint32 GetUInt32Value(uint16 index) const
Definition Object.cpp:325
uint32 GetGUIDLow() const
Definition Object.h:120
void SetUInt32Value(uint16 index, uint32 value)
Definition Object.cpp:1038
static ResponseCodes CheckPlayerName(std::string const &name, bool create=false)
bool HasTitle(uint32 bitIndex)
Definition Player.cpp:20424
void InitTalentForLevel()
Definition Player.cpp:3283
static void DeleteOldCharacters()
Definition Player.cpp:5113
void GiveLevel(uint8 level)
Definition Player.cpp:3166
static uint32 GetLevelFromDB(uint64 guid)
Definition Player.cpp:8086
void SetAtLoginFlag(AtLoginFlags f)
Definition Player.h:2880
WorldSession * GetSession() const
Definition Player.h:2417
static void DeleteFromDB(uint64 playerguid, uint32 accountId, bool updateRealmChars=true, bool deleteFinally=false)
Definition Player.cpp:4775
ReputationMgr & GetReputationMgr()
Definition Player.h:2555
void setString(const uint8 index, const std::string &value)
void setUInt16(const uint8 index, const uint16 value)
void setUInt32(const uint8 index, const uint32 value)
void setUInt8(const uint8 index, const uint8 value)
FactionStateList const & GetStateList() const
int32 GetReputation(uint32 faction_id) const
ReputationRank GetRank(FactionEntry const *factionEntry) const
uint8 getLevel() const
Definition Unit.h:1528
static Player * GetPlayer(WorldObject &object, uint64 guid)
Definition Unit.cpp:4900
void SetName(std::string const &newname)
Definition Object.h:665
std::string const & GetName() const
Definition Object.h:664
Player session in the World.
void KickPlayer()
Kick a player out of the World.
Player * GetPlayer() const
uint32 GetAccountId() const
static bool HandleCharacterDeletedListCommand(ChatHandler *handler, char const *args)
static bool HandlePDumpWriteCommand(ChatHandler *handler, char const *args)
static void HandleCharacterLevel(Player *player, uint64 playerGuid, uint32 oldLevel, uint32 newLevel, ChatHandler *handler)
static bool HandleCharacterRenameCommand(ChatHandler *handler, char const *args)
static bool GetDeletedCharacterInfoList(DeletedInfoList &foundList, std::string searchString)
static bool HandleCharacterDeletedDeleteCommand(ChatHandler *handler, char const *args)
static void HandleCharacterDeletedRestoreHelper(DeletedInfo const &delInfo, ChatHandler *handler)
static bool HandleCharacterEraseCommand(ChatHandler *handler, char const *args)
static bool HandleLevelUpCommand(ChatHandler *handler, char const *args)
static bool HandleCharacterDeletedRestoreCommand(ChatHandler *handler, char const *args)
static bool HandleCharacterChangeRaceCommand(ChatHandler *handler, char const *args)
std::vector< ChatCommand > GetCommands() const OVERRIDE
static bool HandlePDumpLoadCommand(ChatHandler *handler, char const *args)
static bool HandleCharacterDeletedOldCommand(ChatHandler *, char const *args)
static bool HandleCharacterReputationCommand(ChatHandler *handler, char const *args)
static void HandleCharacterDeletedListHelper(DeletedInfoList const &foundList, ChatHandler *handler)
static bool HandleCharacterCustomizeCommand(ChatHandler *handler, char const *args)
static bool HandleCharacterLevelCommand(ChatHandler *handler, char const *args)
static bool HandleCharacterChangeFactionCommand(ChatHandler *handler, char const *args)
static bool HandleCharacterTitlesCommand(ChatHandler *handler, char const *args)
std::list< DeletedInfo > DeletedInfoList
void AddSC_character_commandscript()
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition Main.cpp:41
#define sWorld
Definition World.h:910
@ CONFIG_CHARDELETE_KEEP_DAYS
Definition World.h:321
@ RBAC_PERM_COMMAND_CHARACTER_CHANGERACE
Definition RBAC.h:164
@ RBAC_PERM_COMMAND_CHARACTER_DELETED_OLD
Definition RBAC.h:169
@ RBAC_PERM_COMMAND_CHARACTER
Definition RBAC.h:161
@ RBAC_PERM_COMMAND_LEVELUP
Definition RBAC.h:175
@ RBAC_PERM_COMMAND_CHARACTER_LEVEL
Definition RBAC.h:171
@ RBAC_PERM_COMMAND_CHARACTER_DELETED
Definition RBAC.h:165
@ RBAC_PERM_COMMAND_CHARACTER_DELETED_DELETE
Definition RBAC.h:166
@ RBAC_PERM_SKIP_CHECK_CHARACTER_CREATION_RESERVEDNAME
Definition RBAC.h:57
@ RBAC_PERM_COMMAND_CHARACTER_CHANGEFACTION
Definition RBAC.h:163
@ RBAC_PERM_COMMAND_CHARACTER_TITLES
Definition RBAC.h:174
@ RBAC_PERM_COMMAND_CHARACTER_CUSTOMIZE
Definition RBAC.h:162
@ RBAC_PERM_COMMAND_CHARACTER_RENAME
Definition RBAC.h:172
@ RBAC_PERM_COMMAND_CHARACTER_ERASE
Definition RBAC.h:170
@ RBAC_PERM_COMMAND_PDUMP
Definition RBAC.h:176
@ RBAC_PERM_COMMAND_PDUMP_LOAD
Definition RBAC.h:177
@ RBAC_PERM_COMMAND_CHARACTER_REPUTATION
Definition RBAC.h:173
@ RBAC_PERM_COMMAND_CHARACTER_DELETED_LIST
Definition RBAC.h:167
@ RBAC_PERM_COMMAND_CHARACTER_DELETED_RESTORE
Definition RBAC.h:168
@ RBAC_PERM_COMMAND_PDUMP_WRITE
Definition RBAC.h:178
uint32 bit_index
char * name
char * name
std::string name
the character name
std::string accountName
the account name
time_t deleteDate
the date at which the character has been deleted
uint32 lowGuid
the low GUID from the character