aboutsummaryrefslogtreecommitdiff
path: root/src/server/scripts/Commands
diff options
context:
space:
mode:
authorGiacomo Pozzoni <giacomopoz@gmail.com>2020-09-17 21:49:52 +0200
committerShauren <shauren.trinity@gmail.com>2022-02-27 00:28:25 +0100
commitd02ee9de378a1f9c800b629c0117a03764592c72 (patch)
treecfc408fdac6ca61579a193274c9a47b73ddfd45b /src/server/scripts/Commands
parentcec71e83017bd22036a80c7747535ac3c9ee60d4 (diff)
Script/Commands: Add ".pdump copy" command (#25455)
* Script/Commands: Add ".pdump copy" command Syntax: .pdump copy $playerNameOrGUID $account [$newname] [$newguid] Copy character with name/guid $playerNameOrGUID into character list of $account with $newname, with first free or $newguid guid. * Add missing return * Restore eof check * Fix sql * Use forward declaration header Co-authored-by: Shauren <shauren.trinity@gmail.com> * Remove buffer when reading a line * Rename sql files Co-authored-by: Shauren <shauren.trinity@gmail.com> (cherry picked from commit 6215da0d640bd86a7c2bc144859c1542f09fc1a6)
Diffstat (limited to 'src/server/scripts/Commands')
-rw-r--r--src/server/scripts/Commands/cs_character.cpp93
1 files changed, 73 insertions, 20 deletions
diff --git a/src/server/scripts/Commands/cs_character.cpp b/src/server/scripts/Commands/cs_character.cpp
index a604764c667..4a6d872886f 100644
--- a/src/server/scripts/Commands/cs_character.cpp
+++ b/src/server/scripts/Commands/cs_character.cpp
@@ -48,6 +48,7 @@ public:
{
static std::vector<ChatCommand> pdumpCommandTable =
{
+ { "copy", rbac::RBAC_PERM_COMMAND_PDUMP_COPY, true, &HandlePDumpCopyCommand, "" },
{ "load", rbac::RBAC_PERM_COMMAND_PDUMP_LOAD, true, &HandlePDumpLoadCommand, "" },
{ "write", rbac::RBAC_PERM_COMMAND_PDUMP_WRITE, true, &HandlePDumpWriteCommand, "" },
};
@@ -776,39 +777,57 @@ public:
return true;
}
- static bool HandlePDumpLoadCommand(ChatHandler* handler, std::string fileName, AccountIdentifier account, Optional<std::string_view> characterName, Optional<ObjectGuid::LowType> characterGUID)
+ static bool HandlePDumpCopyCommand(ChatHandler* handler, PlayerIdentifier player, AccountIdentifier account, Optional<std::string_view> characterName, Optional<ObjectGuid::LowType> characterGUID)
{
std::string name;
- if (characterName)
+ if (!ValidatePDumpTarget(handler, name, characterName, characterGUID))
+ return false;
+
+ std::string dump;
+ switch (PlayerDumpWriter().WriteDumpToString(dump, player.GetGUID().GetCounter()))
{
- name.assign(*characterName);
- // normalize the name if specified and check if it exists
- if (!normalizePlayerName(name))
- {
- handler->PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
+ case DUMP_SUCCESS:
+ break;
+ case DUMP_CHARACTER_DELETED:
+ handler->PSendSysMessage(LANG_COMMAND_EXPORT_DELETED_CHAR);
handler->SetSentErrorMessage(true);
return false;
- }
-
- if (ObjectMgr::CheckPlayerName(name, sWorld->GetDefaultDbcLocale(), true) != CHAR_NAME_SUCCESS)
- {
- handler->PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
+ case DUMP_FILE_OPEN_ERROR: // this error code should not happen
+ default:
+ handler->PSendSysMessage(LANG_COMMAND_EXPORT_FAILED);
handler->SetSentErrorMessage(true);
return false;
- }
}
- if (characterGUID)
+ switch (PlayerDumpReader().LoadDumpFromString(dump, account, name, characterGUID.value_or(0)))
{
- if (sCharacterCache->GetCharacterCacheByGuid(ObjectGuid::Create<HighGuid::Player>(*characterGUID)))
- {
- handler->PSendSysMessage(LANG_CHARACTER_GUID_IN_USE, *characterGUID);
+ case DUMP_SUCCESS:
+ break;
+ case DUMP_TOO_MANY_CHARS:
+ handler->PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL, account.GetName().c_str(), account.GetID());
+ handler->SetSentErrorMessage(true);
+ return false;
+ case DUMP_FILE_OPEN_ERROR: // this error code should not happen
+ case DUMP_FILE_BROKEN: // this error code should not happen
+ default:
+ handler->PSendSysMessage(LANG_COMMAND_IMPORT_FAILED);
handler->SetSentErrorMessage(true);
return false;
- }
}
- switch (PlayerDumpReader().LoadDump(fileName, account, name, characterGUID.value_or(0)))
+ // ToDo: use a new trinity_string for this commands
+ handler->PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS);
+
+ return true;
+ }
+
+ static bool HandlePDumpLoadCommand(ChatHandler* handler, std::string fileName, AccountIdentifier account, Optional<std::string_view> characterName, Optional<ObjectGuid::LowType> characterGUID)
+ {
+ std::string name;
+ if (!ValidatePDumpTarget(handler, name, characterName, characterGUID))
+ return false;
+
+ switch (PlayerDumpReader().LoadDumpFromFile(fileName, account, name, characterGUID.value_or(0)))
{
case DUMP_SUCCESS:
handler->PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS);
@@ -834,9 +853,43 @@ public:
return true;
}
+ static bool ValidatePDumpTarget(ChatHandler* handler, std::string& name, Optional<std::string_view> characterName, Optional<ObjectGuid::LowType> characterGUID)
+ {
+ if (characterName)
+ {
+ name.assign(*characterName);
+ // normalize the name if specified and check if it exists
+ if (!normalizePlayerName(name))
+ {
+ handler->PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
+ handler->SetSentErrorMessage(true);
+ return false;
+ }
+
+ if (ObjectMgr::CheckPlayerName(name, sWorld->GetDefaultDbcLocale(), true) != CHAR_NAME_SUCCESS)
+ {
+ handler->PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
+ handler->SetSentErrorMessage(true);
+ return false;
+ }
+ }
+
+ if (characterGUID)
+ {
+ if (sCharacterCache->GetCharacterCacheByGuid(ObjectGuid::Create<HighGuid::Player>(*characterGUID)))
+ {
+ handler->PSendSysMessage(LANG_CHARACTER_GUID_IN_USE, *characterGUID);
+ handler->SetSentErrorMessage(true);
+ return false;
+ }
+ }
+
+ return true;
+ }
+
static bool HandlePDumpWriteCommand(ChatHandler* handler, std::string fileName, PlayerIdentifier player)
{
- switch (PlayerDumpWriter().WriteDump(fileName, player.GetGUID().GetCounter()))
+ switch (PlayerDumpWriter().WriteDumpToFile(fileName, player.GetGUID().GetCounter()))
{
case DUMP_SUCCESS:
handler->PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS);