Core/Commands: Convert more misc commands in commandscript
This commit is contained in:
@@ -26,6 +26,7 @@ EndScriptData */
|
||||
#include "Chat.h"
|
||||
#include "AccountMgr.h"
|
||||
#include "ObjectMgr.h"
|
||||
#include "PlayerDump.h"
|
||||
|
||||
class character_commandscript : public CommandScript
|
||||
{
|
||||
@@ -34,6 +35,12 @@ public:
|
||||
|
||||
ChatCommand* GetCommands() const
|
||||
{
|
||||
static ChatCommand pdumpCommandTable[] =
|
||||
{
|
||||
{ "load", SEC_ADMINISTRATOR, true, &HandlePDumpLoadCommand, "", NULL },
|
||||
{ "write", SEC_ADMINISTRATOR, true, &HandlePDumpWriteCommand, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
static ChatCommand characterDeletedCommandTable[] =
|
||||
{
|
||||
{ "delete", SEC_CONSOLE, true, &HandleCharacterDeletedDeleteCommand, "", NULL },
|
||||
@@ -48,7 +55,7 @@ public:
|
||||
{ "customize", SEC_GAMEMASTER, true, &HandleCharacterCustomizeCommand, "", NULL },
|
||||
{ "changefaction", SEC_GAMEMASTER, true, &HandleCharacterChangeFactionCommand, "", NULL },
|
||||
{ "changerace", SEC_GAMEMASTER, true, &HandleCharacterChangeRaceCommand, "", NULL },
|
||||
{ "deleted", SEC_GAMEMASTER, true, NULL, "", characterDeletedCommandTable},
|
||||
{ "deleted", SEC_GAMEMASTER, true, NULL, "", characterDeletedCommandTable },
|
||||
{ "erase", SEC_CONSOLE, true, &HandleCharacterEraseCommand, "", NULL },
|
||||
{ "level", SEC_ADMINISTRATOR, true, &HandleCharacterLevelCommand, "", NULL },
|
||||
{ "rename", SEC_GAMEMASTER, true, &HandleCharacterRenameCommand, "", NULL },
|
||||
@@ -59,8 +66,9 @@ public:
|
||||
|
||||
static ChatCommand commandTable[] =
|
||||
{
|
||||
{ "character", SEC_GAMEMASTER, true, NULL, "", characterCommandTable},
|
||||
{ "character", SEC_GAMEMASTER, true, NULL, "", characterCommandTable },
|
||||
{ "levelup", SEC_ADMINISTRATOR, false, &HandleLevelUpCommand, "", NULL },
|
||||
{ "pdump", SEC_ADMINISTRATOR, true, NULL, "", pdumpCommandTable },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
return commandTable;
|
||||
@@ -740,6 +748,174 @@ public:
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandlePDumpLoadCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
char* fileStr = strtok((char*)args, " ");
|
||||
if (!fileStr)
|
||||
return false;
|
||||
|
||||
char* accountStr = strtok(NULL, " ");
|
||||
if (!accountStr)
|
||||
return false;
|
||||
|
||||
std::string accountName = accountStr;
|
||||
if (!AccountMgr::normalizeString(accountName))
|
||||
{
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32 accountId = AccountMgr::GetId(accountName);
|
||||
if (!accountId)
|
||||
{
|
||||
accountId = atoi(accountStr); // use original string
|
||||
if (!accountId)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!AccountMgr::GetName(accountId, accountName))
|
||||
{
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
char* guidStr = NULL;
|
||||
char* nameStr = strtok(NULL, " ");
|
||||
|
||||
std::string name;
|
||||
if (nameStr)
|
||||
{
|
||||
name = nameStr;
|
||||
// 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, true) != CHAR_NAME_SUCCESS)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
guidStr = strtok(NULL, " ");
|
||||
}
|
||||
|
||||
uint32 guid = 0;
|
||||
|
||||
if (guidStr)
|
||||
{
|
||||
guid = uint32(atoi(guidStr));
|
||||
if (!guid)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_INVALID_CHARACTER_GUID);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (sObjectMgr->GetPlayerAccountIdByGUID(guid))
|
||||
{
|
||||
handler->PSendSysMessage(LANG_CHARACTER_GUID_IN_USE, guid);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
switch (PlayerDumpReader().LoadDump(fileStr, accountId, name, guid))
|
||||
{
|
||||
case DUMP_SUCCESS:
|
||||
handler->PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS);
|
||||
break;
|
||||
case DUMP_FILE_OPEN_ERROR:
|
||||
handler->PSendSysMessage(LANG_FILE_OPEN_FAIL, fileStr);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
case DUMP_FILE_BROKEN:
|
||||
handler->PSendSysMessage(LANG_DUMP_BROKEN, fileStr);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
case DUMP_TOO_MANY_CHARS:
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL, accountName.c_str(), accountId);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
default:
|
||||
handler->PSendSysMessage(LANG_COMMAND_IMPORT_FAILED);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandlePDumpWriteCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
char* fileStr = strtok((char*)args, " ");
|
||||
char* playerStr = strtok(NULL, " ");
|
||||
|
||||
if (!fileStr || !playerStr)
|
||||
return false;
|
||||
|
||||
uint64 guid;
|
||||
// character name can't start from number
|
||||
if (isNumeric(playerStr))
|
||||
guid = MAKE_NEW_GUID(atoi(playerStr), 0, HIGHGUID_PLAYER);
|
||||
else
|
||||
{
|
||||
std::string name = handler->extractPlayerNameFromLink(playerStr);
|
||||
if (name.empty())
|
||||
{
|
||||
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
guid = sObjectMgr->GetPlayerGUIDByName(name);
|
||||
}
|
||||
|
||||
if (!sObjectMgr->GetPlayerAccountIdByGUID(guid))
|
||||
{
|
||||
handler->PSendSysMessage(LANG_PLAYER_NOT_FOUND);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (PlayerDumpWriter().WriteDump(fileStr, uint32(guid)))
|
||||
{
|
||||
case DUMP_SUCCESS:
|
||||
handler->PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS);
|
||||
break;
|
||||
case DUMP_FILE_OPEN_ERROR:
|
||||
handler->PSendSysMessage(LANG_FILE_OPEN_FAIL, fileStr);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
case DUMP_CHARACTER_DELETED:
|
||||
handler->PSendSysMessage(LANG_COMMAND_EXPORT_DELETED_CHAR);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
default:
|
||||
handler->PSendSysMessage(LANG_COMMAND_EXPORT_FAILED);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
void AddSC_character_commandscript()
|
||||
|
||||
Reference in New Issue
Block a user