Core/Scripts: Reinstate commandscripts, now with extra bling and working commands (and yes, we did test it thoroughly this time)

Thanks to Paradox for sorting the commandscripts and chanhandlers out to work as they were intentionally ment to be like.

--HG--
branch : trunk
This commit is contained in:
click
2010-11-12 20:47:03 +01:00
parent 43d8a64232
commit e22426c7c0
14 changed files with 105 additions and 6487 deletions
@@ -117,63 +117,6 @@ void commandFinished(void*, bool /*success*/)
printf("TC> ");
fflush(stdout);
}
/// Delete a user account and all associated characters in this realm
/// \todo This function has to be enhanced to respect the login/realm split (delete char, delete account chars in realm, delete account chars in realm then delete account
bool ChatHandler::HandleAccountDeleteCommand(const char* args)
{
if (!*args)
return false;
///- Get the account name from the command line
char *account_name_str=strtok ((char*)args," ");
if (!account_name_str)
return false;
std::string account_name = account_name_str;
if (!AccountMgr::normalizeString(account_name))
{
PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
SetSentErrorMessage(true);
return false;
}
uint32 account_id = sAccountMgr.GetId(account_name);
if (!account_id)
{
PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
SetSentErrorMessage(true);
return false;
}
/// Commands not recommended call from chat, but support anyway
/// can delete only for account with less security
/// This is also reject self apply in fact
if (HasLowerSecurityAccount (NULL,account_id,true))
return false;
AccountOpResult result = sAccountMgr.DeleteAccount(account_id);
switch(result)
{
case AOR_OK:
PSendSysMessage(LANG_ACCOUNT_DELETED,account_name.c_str());
break;
case AOR_NAME_NOT_EXIST:
PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
SetSentErrorMessage(true);
return false;
case AOR_DB_INTERNAL_ERROR:
PSendSysMessage(LANG_ACCOUNT_NOT_DELETED_SQL_ERROR,account_name.c_str());
SetSentErrorMessage(true);
return false;
default:
PSendSysMessage(LANG_ACCOUNT_NOT_DELETED,account_name.c_str());
SetSentErrorMessage(true);
return false;
}
return true;
}
/**
* Collects all GUIDs (and related info) from deleted characters which are still in the database.
*
@@ -540,95 +483,6 @@ bool ChatHandler::HandleServerExitCommand(const char* /*args*/)
return true;
}
/// Display info on users currently in the realm
bool ChatHandler::HandleAccountOnlineListCommand(const char* /*args*/)
{
///- Get the list of accounts ID logged to the realm
QueryResult resultDB = CharacterDatabase.Query("SELECT name,account,map,zone FROM characters WHERE online > 0");
if (!resultDB)
{
SendSysMessage(LANG_ACCOUNT_LIST_EMPTY);
return true;
}
///- Display the list of account/characters online
SendSysMessage(LANG_ACCOUNT_LIST_BAR_HEADER);
SendSysMessage(LANG_ACCOUNT_LIST_HEADER);
SendSysMessage(LANG_ACCOUNT_LIST_BAR);
///- Circle through accounts
do
{
Field *fieldsDB = resultDB->Fetch();
std::string name = fieldsDB[0].GetString();
uint32 account = fieldsDB[1].GetUInt32();
///- Get the username, last IP and GM level of each account
// No SQL injection. account is uint32.
QueryResult resultLogin =
LoginDatabase.PQuery("SELECT a.username, a.last_ip, aa.gmlevel, a.expansion "
"FROM account a "
"LEFT JOIN account_access aa "
"ON (a.id = aa.id) "
"WHERE a.id = '%u'", account);
if (resultLogin)
{
Field *fieldsLogin = resultLogin->Fetch();
PSendSysMessage(LANG_ACCOUNT_LIST_LINE,
fieldsLogin[0].GetCString(),name.c_str(),fieldsLogin[1].GetCString(),fieldsDB[2].GetInt32(),fieldsDB[3].GetInt32(),fieldsLogin[3].GetUInt32(),fieldsLogin[2].GetUInt32());
}
else
PSendSysMessage(LANG_ACCOUNT_LIST_ERROR,name.c_str());
}while (resultDB->NextRow());
SendSysMessage(LANG_ACCOUNT_LIST_BAR);
return true;
}
/// Create an account
bool ChatHandler::HandleAccountCreateCommand(const char* args)
{
if (!*args)
return false;
///- %Parse the command line arguments
char *szAcc = strtok((char*)args, " ");
char *szPassword = strtok(NULL, " ");
if (!szAcc || !szPassword)
return false;
// normalized in sAccountMgr.CreateAccount
std::string account_name = szAcc;
std::string password = szPassword;
AccountOpResult result = sAccountMgr.CreateAccount(account_name, password);
switch(result)
{
case AOR_OK:
PSendSysMessage(LANG_ACCOUNT_CREATED,account_name.c_str());
break;
case AOR_NAME_TOO_LONG:
SendSysMessage(LANG_ACCOUNT_TOO_LONG);
SetSentErrorMessage(true);
return false;
case AOR_NAME_ALREDY_EXIST:
SendSysMessage(LANG_ACCOUNT_ALREADY_EXIST);
SetSentErrorMessage(true);
return false;
case AOR_DB_INTERNAL_ERROR:
PSendSysMessage(LANG_ACCOUNT_NOT_CREATED_SQL_ERROR,account_name.c_str());
SetSentErrorMessage(true);
return false;
default:
PSendSysMessage(LANG_ACCOUNT_NOT_CREATED,account_name.c_str());
SetSentErrorMessage(true);
return false;
}
return true;
}
/// Set the level of logging
bool ChatHandler::HandleServerSetLogFileLevelCommand(const char *args)
{