Core/Scripts: Tidy up commandscripts to adhere to scripting-standards and fix some minor typos (fix by Paradox)

Closes issue #4859.

--HG--
branch : trunk
This commit is contained in:
click
2010-11-19 14:04:21 +01:00
parent 0fb06f63e5
commit 3e27be7501
16 changed files with 9505 additions and 9534 deletions
+456 -457
View File
@@ -28,121 +28,331 @@ EndScriptData */
class account_commandscript : public CommandScript
{
public:
account_commandscript() : CommandScript("account_commandscript") { }
public:
account_commandscript() : CommandScript("account_commandscript") { }
ChatCommand* GetCommands() const
ChatCommand* GetCommands() const
{
static ChatCommand accountSetCommandTable[] =
{
static ChatCommand accountSetCommandTable[] =
{
{ "addon", SEC_ADMINISTRATOR, true, &HandleAccountSetAddonCommand, "", NULL },
{ "gmlevel", SEC_CONSOLE, true, &HandleAccountSetGmLevelCommand, "", NULL },
{ "password", SEC_CONSOLE, true, &HandleAccountSetPasswordCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand accountCommandTable[] =
{
{ "addon", SEC_MODERATOR, false, &HandleAccountAddonCommand, "", NULL },
{ "create", SEC_CONSOLE, true, &HandleAccountCreateCommand, "", NULL },
{ "delete", SEC_CONSOLE, true, &HandleAccountDeleteCommand, "", NULL },
{ "onlinelist", SEC_CONSOLE, true, &HandleAccountOnlineListCommand, "", NULL },
{ "lock", SEC_PLAYER, false, &HandleAccountLockCommand, "", NULL },
{ "set", SEC_ADMINISTRATOR, true, NULL, "", accountSetCommandTable },
{ "password", SEC_PLAYER, false, &HandleAccountPasswordCommand, "", NULL },
{ "", SEC_PLAYER, false, &HandleAccountCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "account", SEC_PLAYER, true, NULL, "", accountCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
{ "addon", SEC_ADMINISTRATOR, true, &HandleAccountSetAddonCommand, "", NULL },
{ "gmlevel", SEC_CONSOLE, true, &HandleAccountSetGmLevelCommand, "", NULL },
{ "password", SEC_CONSOLE, true, &HandleAccountSetPasswordCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand accountCommandTable[] =
{
{ "addon", SEC_MODERATOR, false, &HandleAccountAddonCommand, "", NULL },
{ "create", SEC_CONSOLE, true, &HandleAccountCreateCommand, "", NULL },
{ "delete", SEC_CONSOLE, true, &HandleAccountDeleteCommand, "", NULL },
{ "onlinelist", SEC_CONSOLE, true, &HandleAccountOnlineListCommand, "", NULL },
{ "lock", SEC_PLAYER, false, &HandleAccountLockCommand, "", NULL },
{ "set", SEC_ADMINISTRATOR, true, NULL, "", accountSetCommandTable },
{ "password", SEC_PLAYER, false, &HandleAccountPasswordCommand, "", NULL },
{ "", SEC_PLAYER, false, &HandleAccountCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "account", SEC_PLAYER, true, NULL, "", accountCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}
static bool HandleAccountAddonCommand(ChatHandler* handler, const char* args)
{
if (!*args)
{
handler->SendSysMessage(LANG_CMD_SYNTAX);
handler->SetSentErrorMessage(true);
return false;
}
static bool HandleAccountAddonCommand(ChatHandler* handler, const char* args)
char *szExp = strtok((char*)args, " ");
uint32 account_id = handler->GetSession()->GetAccountId();
int expansion = atoi(szExp); //get int anyway (0 if error)
if (expansion < 0 || uint8(expansion) > sWorld.getIntConfig(CONFIG_EXPANSION))
{
if (!*args)
{
handler->SendSysMessage(LANG_CMD_SYNTAX);
handler->SetSentErrorMessage(true);
return false;
}
handler->SendSysMessage(LANG_IMPROPER_VALUE);
handler->SetSentErrorMessage(true);
return false;
}
char *szExp = strtok((char*)args, " ");
// No SQL injection
LoginDatabase.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'", expansion, account_id);
handler->PSendSysMessage(LANG_ACCOUNT_ADDON, expansion);
return true;
}
uint32 account_id = handler->GetSession()->GetAccountId();
/// Create an account
static bool HandleAccountCreateCommand(ChatHandler* handler, const char* args)
{
if (!*args)
return false;
int expansion = atoi(szExp); //get int anyway (0 if error)
if (expansion < 0 || uint8(expansion) > sWorld.getIntConfig(CONFIG_EXPANSION))
{
handler->SendSysMessage(LANG_IMPROPER_VALUE);
handler->SetSentErrorMessage(true);
return false;
}
///- %Parse the command line arguments
char *szAcc = strtok((char*)args, " ");
char *szPassword = strtok(NULL, " ");
if (!szAcc || !szPassword)
return false;
// No SQL injection
LoginDatabase.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'", expansion, account_id);
handler->PSendSysMessage(LANG_ACCOUNT_ADDON, expansion);
// 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:
handler->PSendSysMessage(LANG_ACCOUNT_CREATED,account_name.c_str());
break;
case AOR_NAME_TOO_LONG:
handler->SendSysMessage(LANG_ACCOUNT_TOO_LONG);
handler->SetSentErrorMessage(true);
return false;
case AOR_NAME_ALREDY_EXIST:
handler->SendSysMessage(LANG_ACCOUNT_ALREADY_EXIST);
handler->SetSentErrorMessage(true);
return false;
case AOR_DB_INTERNAL_ERROR:
handler->PSendSysMessage(LANG_ACCOUNT_NOT_CREATED_SQL_ERROR,account_name.c_str());
handler->SetSentErrorMessage(true);
return false;
default:
handler->PSendSysMessage(LANG_ACCOUNT_NOT_CREATED,account_name.c_str());
handler->SetSentErrorMessage(true);
return false;
}
return true;
}
/// 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
static bool HandleAccountDeleteCommand(ChatHandler* handler, 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))
{
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
handler->SetSentErrorMessage(true);
return false;
}
uint32 account_id = sAccountMgr.GetId(account_name);
if (!account_id)
{
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
handler->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 (handler->HasLowerSecurityAccount (NULL,account_id,true))
return false;
AccountOpResult result = sAccountMgr.DeleteAccount(account_id);
switch(result)
{
case AOR_OK:
handler->PSendSysMessage(LANG_ACCOUNT_DELETED,account_name.c_str());
break;
case AOR_NAME_NOT_EXIST:
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
handler->SetSentErrorMessage(true);
return false;
case AOR_DB_INTERNAL_ERROR:
handler->PSendSysMessage(LANG_ACCOUNT_NOT_DELETED_SQL_ERROR,account_name.c_str());
handler->SetSentErrorMessage(true);
return false;
default:
handler->PSendSysMessage(LANG_ACCOUNT_NOT_DELETED,account_name.c_str());
handler->SetSentErrorMessage(true);
return false;
}
return true;
}
/// Display info on users currently in the realm
static bool HandleAccountOnlineListCommand(ChatHandler* handler, 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)
{
handler->SendSysMessage(LANG_ACCOUNT_LIST_EMPTY);
return true;
}
/// Create an account
static bool HandleAccountCreateCommand(ChatHandler* handler, const char* args)
///- Display the list of account/characters online
handler->SendSysMessage(LANG_ACCOUNT_LIST_BAR_HEADER);
handler->SendSysMessage(LANG_ACCOUNT_LIST_HEADER);
handler->SendSysMessage(LANG_ACCOUNT_LIST_BAR);
///- Cycle through accounts
do
{
if (!*args)
return false;
Field *fieldsDB = resultDB->Fetch();
std::string name = fieldsDB[0].GetString();
uint32 account = fieldsDB[1].GetUInt32();
///- %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)
///- 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)
{
case AOR_OK:
handler->PSendSysMessage(LANG_ACCOUNT_CREATED,account_name.c_str());
break;
case AOR_NAME_TOO_LONG:
handler->SendSysMessage(LANG_ACCOUNT_TOO_LONG);
handler->SetSentErrorMessage(true);
return false;
case AOR_NAME_ALREDY_EXIST:
handler->SendSysMessage(LANG_ACCOUNT_ALREADY_EXIST);
handler->SetSentErrorMessage(true);
return false;
case AOR_DB_INTERNAL_ERROR:
handler->PSendSysMessage(LANG_ACCOUNT_NOT_CREATED_SQL_ERROR,account_name.c_str());
handler->SetSentErrorMessage(true);
return false;
default:
handler->PSendSysMessage(LANG_ACCOUNT_NOT_CREATED,account_name.c_str());
handler->SetSentErrorMessage(true);
return false;
Field *fieldsLogin = resultLogin->Fetch();
handler->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
handler->PSendSysMessage(LANG_ACCOUNT_LIST_ERROR,name.c_str());
}while (resultDB->NextRow());
handler->SendSysMessage(LANG_ACCOUNT_LIST_BAR);
return true;
}
static bool HandleAccountLockCommand(ChatHandler* handler, const char* args)
{
if (!*args)
{
handler->SendSysMessage(LANG_USE_BOL);
handler->SetSentErrorMessage(true);
return false;
}
std::string argstr = (char*)args;
if (argstr == "on")
{
LoginDatabase.PExecute("UPDATE account SET locked = '1' WHERE id = '%d'",handler->GetSession()->GetAccountId());
handler->PSendSysMessage(LANG_COMMAND_ACCLOCKLOCKED);
return true;
}
/// 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
static bool HandleAccountDeleteCommand(ChatHandler* handler, const char* args)
if (argstr == "off")
{
if (!*args)
LoginDatabase.PExecute("UPDATE account SET locked = '0' WHERE id = '%d'",handler->GetSession()->GetAccountId());
handler->PSendSysMessage(LANG_COMMAND_ACCLOCKUNLOCKED);
return true;
}
handler->SendSysMessage(LANG_USE_BOL);
handler->SetSentErrorMessage(true);
return false;
}
static bool HandleAccountPasswordCommand(ChatHandler* handler, const char* args)
{
if (!*args)
{
handler->SendSysMessage(LANG_CMD_SYNTAX);
handler->SetSentErrorMessage(true);
return false;
}
char *old_pass = strtok((char*)args, " ");
char *new_pass = strtok(NULL, " ");
char *new_pass_c = strtok(NULL, " ");
if (!old_pass || !new_pass || !new_pass_c)
{
handler->SendSysMessage(LANG_CMD_SYNTAX);
handler->SetSentErrorMessage(true);
return false;
}
std::string password_old = old_pass;
std::string password_new = new_pass;
std::string password_new_c = new_pass_c;
if (!sAccountMgr.CheckPassword(handler->GetSession()->GetAccountId(), password_old))
{
handler->SendSysMessage(LANG_COMMAND_WRONGOLDPASSWORD);
handler->SetSentErrorMessage(true);
return false;
}
if (strcmp(new_pass, new_pass_c) != 0)
{
handler->SendSysMessage(LANG_NEW_PASSWORDS_NOT_MATCH);
handler->SetSentErrorMessage(true);
return false;
}
AccountOpResult result = sAccountMgr.ChangePassword(handler->GetSession()->GetAccountId(), password_new);
switch(result)
{
case AOR_OK:
handler->SendSysMessage(LANG_COMMAND_PASSWORD);
break;
case AOR_PASS_TOO_LONG:
handler->SendSysMessage(LANG_PASSWORD_TOO_LONG);
handler->SetSentErrorMessage(true);
return false;
default:
handler->SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD);
handler->SetSentErrorMessage(true);
return false;
}
return true;
}
static bool HandleAccountCommand(ChatHandler* handler, const char* /*args*/)
{
AccountTypes gmlevel = handler->GetSession()->GetSecurity();
handler->PSendSysMessage(LANG_ACCOUNT_LEVEL, uint32(gmlevel));
return true;
}
/// Set/Unset the expansion level for an account
static bool HandleAccountSetAddonCommand(ChatHandler* handler, const char *args)
{
///- Get the command line arguments
char *szAcc = strtok((char*)args," ");
char *szExp = strtok(NULL," ");
if (!szAcc)
return false;
std::string account_name;
uint32 account_id;
if (!szExp)
{
Player* player = handler->getSelectedPlayer();
if (!player)
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;
account_id = player->GetSession()->GetAccountId();
sAccountMgr.GetName(account_id,account_name);
szExp = szAcc;
}
else
{
///- Convert Account name to Upper Format
account_name = szAcc;
if (!AccountMgr::normalizeString(account_name))
{
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
@@ -150,7 +360,7 @@ class account_commandscript : public CommandScript
return false;
}
uint32 account_id = sAccountMgr.GetId(account_name);
account_id = sAccountMgr.GetId(account_name);
if (!account_id)
{
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
@@ -158,396 +368,185 @@ class account_commandscript : public CommandScript
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 (handler->HasLowerSecurityAccount (NULL,account_id,true))
}
// Let set addon state only for lesser (strong) security level
// or to self account
if (handler->GetSession() && handler->GetSession()->GetAccountId () != account_id &&
handler->HasLowerSecurityAccount (NULL,account_id,true))
return false;
int expansion = atoi(szExp); //get int anyway (0 if error)
if (expansion < 0 || uint8(expansion) > sWorld.getIntConfig(CONFIG_EXPANSION))
return false;
// No SQL injection
LoginDatabase.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",expansion,account_id);
handler->PSendSysMessage(LANG_ACCOUNT_SETADDON,account_name.c_str(),account_id,expansion);
return true;
}
static bool HandleAccountSetGmLevelCommand(ChatHandler* handler, const char *args)
{
if (!*args)
return false;
std::string targetAccountName;
uint32 targetAccountId = 0;
uint32 targetSecurity = 0;
uint32 gm = 0;
char* arg1 = strtok((char*)args, " ");
char* arg2 = strtok(NULL, " ");
char* arg3 = strtok(NULL, " ");
bool isAccountNameGiven = true;
if (arg1 && !arg3)
{
if (!handler->getSelectedPlayer())
return false;
AccountOpResult result = sAccountMgr.DeleteAccount(account_id);
switch(result)
{
case AOR_OK:
handler->PSendSysMessage(LANG_ACCOUNT_DELETED,account_name.c_str());
break;
case AOR_NAME_NOT_EXIST:
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
handler->SetSentErrorMessage(true);
return false;
case AOR_DB_INTERNAL_ERROR:
handler->PSendSysMessage(LANG_ACCOUNT_NOT_DELETED_SQL_ERROR,account_name.c_str());
handler->SetSentErrorMessage(true);
return false;
default:
handler->PSendSysMessage(LANG_ACCOUNT_NOT_DELETED,account_name.c_str());
handler->SetSentErrorMessage(true);
return false;
}
return true;
isAccountNameGiven = false;
}
/// Display info on users currently in the realm
static bool HandleAccountOnlineListCommand(ChatHandler* handler, const char* /*args*/)
// Check for second parameter
if (!isAccountNameGiven && !arg2)
return false;
// Check for account
if (isAccountNameGiven)
{
///- 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)
targetAccountName = arg1;
if (!AccountMgr::normalizeString(targetAccountName))
{
handler->SendSysMessage(LANG_ACCOUNT_LIST_EMPTY);
return true;
}
///- Display the list of account/characters online
handler->SendSysMessage(LANG_ACCOUNT_LIST_BAR_HEADER);
handler->SendSysMessage(LANG_ACCOUNT_LIST_HEADER);
handler->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();
handler->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
handler->PSendSysMessage(LANG_ACCOUNT_LIST_ERROR,name.c_str());
}while (resultDB->NextRow());
handler->SendSysMessage(LANG_ACCOUNT_LIST_BAR);
return true;
}
static bool HandleAccountLockCommand(ChatHandler* handler, const char* args)
{
if (!*args)
{
handler->SendSysMessage(LANG_USE_BOL);
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,targetAccountName.c_str());
handler->SetSentErrorMessage(true);
return false;
}
}
std::string argstr = (char*)args;
if (argstr == "on")
{
LoginDatabase.PExecute("UPDATE account SET locked = '1' WHERE id = '%d'",handler->GetSession()->GetAccountId());
handler->PSendSysMessage(LANG_COMMAND_ACCLOCKLOCKED);
return true;
}
if (argstr == "off")
{
LoginDatabase.PExecute("UPDATE account SET locked = '0' WHERE id = '%d'",handler->GetSession()->GetAccountId());
handler->PSendSysMessage(LANG_COMMAND_ACCLOCKUNLOCKED);
return true;
}
handler->SendSysMessage(LANG_USE_BOL);
// Check for invalid specified GM level.
gm = (isAccountNameGiven) ? atoi(arg2) : atoi(arg1);
if (gm > SEC_CONSOLE)
{
handler->SendSysMessage(LANG_BAD_VALUE);
handler->SetSentErrorMessage(true);
return false;
}
static bool HandleAccountPasswordCommand(ChatHandler* handler, const char* args)
// handler->getSession() == NULL only for console
targetAccountId = (isAccountNameGiven) ? sAccountMgr.GetId(targetAccountName) : handler->getSelectedPlayer()->GetSession()->GetAccountId();
int32 gmRealmID = (isAccountNameGiven) ? atoi(arg3) : atoi(arg2);
uint32 plSecurity;
if (handler->GetSession())
plSecurity = sAccountMgr.GetSecurity(handler->GetSession()->GetAccountId(), gmRealmID);
else
plSecurity = SEC_CONSOLE;
// can set security level only for target with less security and to less security that we have
// This is also reject self apply in fact
targetSecurity = sAccountMgr.GetSecurity(targetAccountId, gmRealmID);
if (targetSecurity >= plSecurity || gm >= plSecurity)
{
if (!*args)
{
handler->SendSysMessage(LANG_CMD_SYNTAX);
handler->SetSentErrorMessage(true);
return false;
}
char *old_pass = strtok((char*)args, " ");
char *new_pass = strtok(NULL, " ");
char *new_pass_c = strtok(NULL, " ");
if (!old_pass || !new_pass || !new_pass_c)
{
handler->SendSysMessage(LANG_CMD_SYNTAX);
handler->SetSentErrorMessage(true);
return false;
}
std::string password_old = old_pass;
std::string password_new = new_pass;
std::string password_new_c = new_pass_c;
if (!sAccountMgr.CheckPassword(handler->GetSession()->GetAccountId(), password_old))
{
handler->SendSysMessage(LANG_COMMAND_WRONGOLDPASSWORD);
handler->SetSentErrorMessage(true);
return false;
}
if (strcmp(new_pass, new_pass_c) != 0)
{
handler->SendSysMessage(LANG_NEW_PASSWORDS_NOT_MATCH);
handler->SetSentErrorMessage(true);
return false;
}
AccountOpResult result = sAccountMgr.ChangePassword(handler->GetSession()->GetAccountId(), password_new);
switch(result)
{
case AOR_OK:
handler->SendSysMessage(LANG_COMMAND_PASSWORD);
break;
case AOR_PASS_TOO_LONG:
handler->SendSysMessage(LANG_PASSWORD_TOO_LONG);
handler->SetSentErrorMessage(true);
return false;
default:
handler->SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD);
handler->SetSentErrorMessage(true);
return false;
}
return true;
handler->SendSysMessage(LANG_YOURS_SECURITY_IS_LOW);
handler->SetSentErrorMessage(true);
return false;
}
static bool HandleAccountCommand(ChatHandler* handler, const char* /*args*/)
// Check and abort if the target gm has a higher rank on one of the realms and the new realm is -1
if (gmRealmID == -1)
{
AccountTypes gmlevel = handler->GetSession()->GetSecurity();
handler->PSendSysMessage(LANG_ACCOUNT_LEVEL, uint32(gmlevel));
return true;
}
/// Set/Unset the expansion level for an account
static bool HandleAccountSetAddonCommand(ChatHandler* handler, const char *args)
{
///- Get the command line arguments
char *szAcc = strtok((char*)args," ");
char *szExp = strtok(NULL," ");
if (!szAcc)
return false;
std::string account_name;
uint32 account_id;
if (!szExp)
{
Player* player = handler->getSelectedPlayer();
if (!player)
return false;
account_id = player->GetSession()->GetAccountId();
sAccountMgr.GetName(account_id,account_name);
szExp = szAcc;
}
else
{
///- Convert Account name to Upper Format
account_name = szAcc;
if (!AccountMgr::normalizeString(account_name))
{
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
handler->SetSentErrorMessage(true);
return false;
}
account_id = sAccountMgr.GetId(account_name);
if (!account_id)
{
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
handler->SetSentErrorMessage(true);
return false;
}
}
// Let set addon state only for lesser (strong) security level
// or to self account
if (handler->GetSession() && handler->GetSession()->GetAccountId () != account_id &&
handler->HasLowerSecurityAccount (NULL,account_id,true))
return false;
int expansion = atoi(szExp); //get int anyway (0 if error)
if (expansion < 0 || uint8(expansion) > sWorld.getIntConfig(CONFIG_EXPANSION))
return false;
// No SQL injection
LoginDatabase.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",expansion,account_id);
handler->PSendSysMessage(LANG_ACCOUNT_SETADDON,account_name.c_str(),account_id,expansion);
return true;
}
static bool HandleAccountSetGmLevelCommand(ChatHandler* handler, const char *args)
{
if (!*args)
return false;
std::string targetAccountName;
uint32 targetAccountId = 0;
uint32 targetSecurity = 0;
uint32 gm = 0;
char* arg1 = strtok((char*)args, " ");
char* arg2 = strtok(NULL, " ");
char* arg3 = strtok(NULL, " ");
bool isAccountNameGiven = true;
if (arg1 && !arg3)
{
if (!handler->getSelectedPlayer())
return false;
isAccountNameGiven = false;
}
// Check for second parameter
if (!isAccountNameGiven && !arg2)
return false;
// Check for account
if (isAccountNameGiven)
{
targetAccountName = arg1;
if (!AccountMgr::normalizeString(targetAccountName))
{
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,targetAccountName.c_str());
handler->SetSentErrorMessage(true);
return false;
}
}
// Check for invalid specified GM level.
gm = (isAccountNameGiven) ? atoi(arg2) : atoi(arg1);
if (gm > SEC_CONSOLE)
{
handler->SendSysMessage(LANG_BAD_VALUE);
handler->SetSentErrorMessage(true);
return false;
}
// handler->getSession() == NULL only for console
targetAccountId = (isAccountNameGiven) ? sAccountMgr.GetId(targetAccountName) : handler->getSelectedPlayer()->GetSession()->GetAccountId();
int32 gmRealmID = (isAccountNameGiven) ? atoi(arg3) : atoi(arg2);
uint32 plSecurity;
if (handler->GetSession())
plSecurity = sAccountMgr.GetSecurity(handler->GetSession()->GetAccountId(), gmRealmID);
else
plSecurity = SEC_CONSOLE;
// can set security level only for target with less security and to less security that we have
// This is also reject self apply in fact
targetSecurity = sAccountMgr.GetSecurity(targetAccountId, gmRealmID);
if (targetSecurity >= plSecurity || gm >= plSecurity)
QueryResult result = LoginDatabase.PQuery("SELECT * FROM account_access WHERE id = '%u' AND gmlevel > '%d'", targetAccountId, gm);
if (result)
{
handler->SendSysMessage(LANG_YOURS_SECURITY_IS_LOW);
handler->SetSentErrorMessage(true);
return false;
}
// Check and abort if the target gm has a higher rank on one of the realms and the new realm is -1
if (gmRealmID == -1)
{
QueryResult result = LoginDatabase.PQuery("SELECT * FROM account_access WHERE id = '%u' AND gmlevel > '%d'", targetAccountId, gm);
if (result)
{
handler->SendSysMessage(LANG_YOURS_SECURITY_IS_LOW);
handler->SetSentErrorMessage(true);
return false;
}
}
// Check if provided realmID has a negative value other than -1
if (gmRealmID < -1)
{
handler->SendSysMessage(LANG_INVALID_REALMID);
handler->SetSentErrorMessage(true);
return false;
}
// If gmRealmID is -1, delete all values for the account id, else, insert values for the specific realmID
if (gmRealmID == -1)
LoginDatabase.PExecute("DELETE FROM account_access WHERE id = '%u'", targetAccountId);
else
LoginDatabase.PExecute("DELETE FROM account_access WHERE id = '%u' AND (RealmID = '%d' OR RealmID = '-1')", targetAccountId, realmID);
if (gm != 0)
LoginDatabase.PExecute("INSERT INTO account_access VALUES ('%u','%d','%d')", targetAccountId, gm, realmID);
handler->PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName.c_str(), gm);
return true;
}
/// Set password for account
static bool HandleAccountSetPasswordCommand(ChatHandler* handler, const char *args)
// Check if provided realmID has a negative value other than -1
if (gmRealmID < -1)
{
if (!*args)
return false;
///- Get the command line arguments
char *szAccount = strtok ((char*)args," ");
char *szPassword1 = strtok (NULL," ");
char *szPassword2 = strtok (NULL," ");
if (!szAccount||!szPassword1 || !szPassword2)
return false;
std::string account_name = szAccount;
if (!AccountMgr::normalizeString(account_name))
{
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
handler->SetSentErrorMessage(true);
return false;
}
uint32 targetAccountId = sAccountMgr.GetId(account_name);
if (!targetAccountId)
{
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
handler->SetSentErrorMessage(true);
return false;
}
/// can set password only for target with less security
/// This is also reject self apply in fact
if (handler->HasLowerSecurityAccount (NULL,targetAccountId,true))
return false;
if (strcmp(szPassword1,szPassword2))
{
handler->SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH);
handler->SetSentErrorMessage (true);
return false;
}
AccountOpResult result = sAccountMgr.ChangePassword(targetAccountId, szPassword1);
switch (result)
{
case AOR_OK:
handler->SendSysMessage(LANG_COMMAND_PASSWORD);
break;
case AOR_NAME_NOT_EXIST:
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
handler->SetSentErrorMessage(true);
return false;
case AOR_PASS_TOO_LONG:
handler->SendSysMessage(LANG_PASSWORD_TOO_LONG);
handler->SetSentErrorMessage(true);
return false;
default:
handler->SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD);
handler->SetSentErrorMessage(true);
return false;
}
return true;
handler->SendSysMessage(LANG_INVALID_REALMID);
handler->SetSentErrorMessage(true);
return false;
}
// If gmRealmID is -1, delete all values for the account id, else, insert values for the specific realmID
if (gmRealmID == -1)
LoginDatabase.PExecute("DELETE FROM account_access WHERE id = '%u'", targetAccountId);
else
LoginDatabase.PExecute("DELETE FROM account_access WHERE id = '%u' AND (RealmID = '%d' OR RealmID = '-1')", targetAccountId, realmID);
if (gm != 0)
LoginDatabase.PExecute("INSERT INTO account_access VALUES ('%u','%d','%d')", targetAccountId, gm, realmID);
handler->PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName.c_str(), gm);
return true;
}
/// Set password for account
static bool HandleAccountSetPasswordCommand(ChatHandler* handler, const char *args)
{
if (!*args)
return false;
///- Get the command line arguments
char *szAccount = strtok ((char*)args," ");
char *szPassword1 = strtok (NULL," ");
char *szPassword2 = strtok (NULL," ");
if (!szAccount||!szPassword1 || !szPassword2)
return false;
std::string account_name = szAccount;
if (!AccountMgr::normalizeString(account_name))
{
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
handler->SetSentErrorMessage(true);
return false;
}
uint32 targetAccountId = sAccountMgr.GetId(account_name);
if (!targetAccountId)
{
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
handler->SetSentErrorMessage(true);
return false;
}
/// can set password only for target with less security
/// This is also reject self apply in fact
if (handler->HasLowerSecurityAccount (NULL,targetAccountId,true))
return false;
if (strcmp(szPassword1,szPassword2))
{
handler->SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH);
handler->SetSentErrorMessage (true);
return false;
}
AccountOpResult result = sAccountMgr.ChangePassword(targetAccountId, szPassword1);
switch (result)
{
case AOR_OK:
handler->SendSysMessage(LANG_COMMAND_PASSWORD);
break;
case AOR_NAME_NOT_EXIST:
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
handler->SetSentErrorMessage(true);
return false;
case AOR_PASS_TOO_LONG:
handler->SendSysMessage(LANG_PASSWORD_TOO_LONG);
handler->SetSentErrorMessage(true);
return false;
default:
handler->SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD);
handler->SetSentErrorMessage(true);
return false;
}
return true;
}
};
void AddSC_account_commandscript()
+38 -38
View File
@@ -27,51 +27,51 @@ EndScriptData */
class achievement_commandscript : public CommandScript
{
public:
achievement_commandscript() : CommandScript("achievement_commandscript") { }
public:
achievement_commandscript() : CommandScript("achievement_commandscript") { }
ChatCommand* GetCommands() const
ChatCommand* GetCommands() const
{
static ChatCommand achievementCommandTable[] =
{
static ChatCommand achievementCommandTable[] =
{
{ "add", SEC_ADMINISTRATOR, false, &HandleAchievementAddCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "achievement", SEC_ADMINISTRATOR, false, NULL, "", achievementCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}
static bool HandleAchievementAddCommand(ChatHandler* handler, const char *args)
{ "add", SEC_ADMINISTRATOR, false, &HandleAchievementAddCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
if (!*args)
return false;
{ "achievement", SEC_ADMINISTRATOR, false, NULL, "", achievementCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}
uint32 achievementId = atoi((char*)args);
static bool HandleAchievementAddCommand(ChatHandler* handler, const char *args)
{
if (!*args)
return false;
uint32 achievementId = atoi((char*)args);
if (!achievementId)
{
if (char* cId = handler->extractKeyFromLink((char*)args, "Hachievement"))
achievementId = atoi(cId);
if (!achievementId)
{
if (char* cId = handler->extractKeyFromLink((char*)args, "Hachievement"))
achievementId = atoi(cId);
if (!achievementId)
return false;
}
Player* target = handler->getSelectedPlayer();
if (!target)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
if (AchievementEntry const* pAE = GetAchievementStore()->LookupEntry(achievementId))
target->CompletedAchievement(pAE, true);
return true;
}
Player* target = handler->getSelectedPlayer();
if (!target)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
if (AchievementEntry const* pAE = GetAchievementStore()->LookupEntry(achievementId))
target->CompletedAchievement(pAE, true);
return true;
}
};
void AddSC_achievement_commandscript()
File diff suppressed because it is too large Load Diff
+163 -163
View File
@@ -28,187 +28,187 @@ EndScriptData */
class event_commandscript : public CommandScript
{
public:
event_commandscript() : CommandScript("event_commandscript") { }
public:
event_commandscript() : CommandScript("event_commandscript") { }
ChatCommand* GetCommands() const
ChatCommand* GetCommands() const
{
static ChatCommand eventCommandTable[] =
{
static ChatCommand eventCommandTable[] =
{
{ "activelist", SEC_GAMEMASTER, true, &HandleEventActiveListCommand, "", NULL },
{ "start", SEC_GAMEMASTER, true, &HandleEventStartCommand, "", NULL },
{ "stop", SEC_GAMEMASTER, true, &HandleEventStopCommand, "", NULL },
{ "", SEC_GAMEMASTER, true, &HandleEventInfoCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "event", SEC_GAMEMASTER, false, NULL, "", eventCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}
static bool HandleEventActiveListCommand(ChatHandler* handler, const char* /*args*/)
{ "activelist", SEC_GAMEMASTER, true, &HandleEventActiveListCommand, "", NULL },
{ "start", SEC_GAMEMASTER, true, &HandleEventStartCommand, "", NULL },
{ "stop", SEC_GAMEMASTER, true, &HandleEventStopCommand, "", NULL },
{ "", SEC_GAMEMASTER, true, &HandleEventInfoCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
uint32 counter = 0;
{ "event", SEC_GAMEMASTER, false, NULL, "", eventCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}
GameEventMgr::GameEventDataMap const& events = sGameEventMgr.GetEventMap();
GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr.GetActiveEventList();
static bool HandleEventActiveListCommand(ChatHandler* handler, const char* /*args*/)
{
uint32 counter = 0;
char const* active = handler->GetTrinityString(LANG_ACTIVE);
GameEventMgr::GameEventDataMap const& events = sGameEventMgr.GetEventMap();
GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr.GetActiveEventList();
for (GameEventMgr::ActiveEvents::const_iterator itr = activeEvents.begin(); itr != activeEvents.end(); ++itr)
{
uint32 event_id = *itr;
GameEventData const& eventData = events[event_id];
char const* active = handler->GetTrinityString(LANG_ACTIVE);
if (handler->GetSession())
handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CHAT,event_id,event_id,eventData.description.c_str(),active);
else
handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CONSOLE,event_id,eventData.description.c_str(),active);
++counter;
}
if (counter == 0)
handler->SendSysMessage(LANG_NOEVENTFOUND);
handler->SetSentErrorMessage(true);
return true;
}
static bool HandleEventInfoCommand(ChatHandler* handler, const char* args)
for (GameEventMgr::ActiveEvents::const_iterator itr = activeEvents.begin(); itr != activeEvents.end(); ++itr)
{
if (!*args)
return false;
// id or [name] Shift-click form |color|Hgameevent:id|h[name]|h|r
char* cId = handler->extractKeyFromLink((char*)args,"Hgameevent");
if (!cId)
return false;
uint32 event_id = atoi(cId);
GameEventMgr::GameEventDataMap const& events = sGameEventMgr.GetEventMap();
if (event_id >=events.size())
{
handler->SendSysMessage(LANG_EVENT_NOT_EXIST);
handler->SetSentErrorMessage(true);
return false;
}
uint32 event_id = *itr;
GameEventData const& eventData = events[event_id];
if (!eventData.isValid())
{
handler->SendSysMessage(LANG_EVENT_NOT_EXIST);
handler->SetSentErrorMessage(true);
return false;
}
GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr.GetActiveEventList();
bool active = activeEvents.find(event_id) != activeEvents.end();
char const* activeStr = active ? handler->GetTrinityString(LANG_ACTIVE) : "";
if (handler->GetSession())
handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CHAT,event_id,event_id,eventData.description.c_str(),active);
else
handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CONSOLE,event_id,eventData.description.c_str(),active);
std::string startTimeStr = TimeToTimestampStr(eventData.start);
std::string endTimeStr = TimeToTimestampStr(eventData.end);
uint32 delay = sGameEventMgr.NextCheck(event_id);
time_t nextTime = time(NULL)+delay;
std::string nextStr = nextTime >= eventData.start && nextTime < eventData.end ? TimeToTimestampStr(time(NULL)+delay) : "-";
std::string occurenceStr = secsToTimeString(eventData.occurence * MINUTE);
std::string lengthStr = secsToTimeString(eventData.length * MINUTE);
handler->PSendSysMessage(LANG_EVENT_INFO,event_id,eventData.description.c_str(),activeStr,
startTimeStr.c_str(),endTimeStr.c_str(),occurenceStr.c_str(),lengthStr.c_str(),
nextStr.c_str());
return true;
++counter;
}
static bool HandleEventStartCommand(ChatHandler* handler, const char* args)
if (counter == 0)
handler->SendSysMessage(LANG_NOEVENTFOUND);
handler->SetSentErrorMessage(true);
return true;
}
static bool HandleEventInfoCommand(ChatHandler* handler, const char* args)
{
if (!*args)
return false;
// id or [name] Shift-click form |color|Hgameevent:id|h[name]|h|r
char* cId = handler->extractKeyFromLink((char*)args,"Hgameevent");
if (!cId)
return false;
uint32 event_id = atoi(cId);
GameEventMgr::GameEventDataMap const& events = sGameEventMgr.GetEventMap();
if (event_id >=events.size())
{
if (!*args)
return false;
// id or [name] Shift-click form |color|Hgameevent:id|h[name]|h|r
char* cId = handler->extractKeyFromLink((char*)args,"Hgameevent");
if (!cId)
return false;
int32 event_id = atoi(cId);
GameEventMgr::GameEventDataMap const& events = sGameEventMgr.GetEventMap();
if (event_id < 1 || uint32(event_id) >= events.size())
{
handler->SendSysMessage(LANG_EVENT_NOT_EXIST);
handler->SetSentErrorMessage(true);
return false;
}
GameEventData const& eventData = events[event_id];
if (!eventData.isValid())
{
handler->SendSysMessage(LANG_EVENT_NOT_EXIST);
handler->SetSentErrorMessage(true);
return false;
}
GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr.GetActiveEventList();
if (activeEvents.find(event_id) != activeEvents.end())
{
handler->PSendSysMessage(LANG_EVENT_ALREADY_ACTIVE,event_id);
handler->SetSentErrorMessage(true);
return false;
}
sGameEventMgr.StartEvent(event_id,true);
return true;
handler->SendSysMessage(LANG_EVENT_NOT_EXIST);
handler->SetSentErrorMessage(true);
return false;
}
static bool HandleEventStopCommand(ChatHandler* handler, const char* args)
GameEventData const& eventData = events[event_id];
if (!eventData.isValid())
{
if (!*args)
return false;
// id or [name] Shift-click form |color|Hgameevent:id|h[name]|h|r
char* cId = handler->extractKeyFromLink((char*)args,"Hgameevent");
if (!cId)
return false;
int32 event_id = atoi(cId);
GameEventMgr::GameEventDataMap const& events = sGameEventMgr.GetEventMap();
if (event_id < 1 || uint32(event_id) >= events.size())
{
handler->SendSysMessage(LANG_EVENT_NOT_EXIST);
handler->SetSentErrorMessage(true);
return false;
}
GameEventData const& eventData = events[event_id];
if (!eventData.isValid())
{
handler->SendSysMessage(LANG_EVENT_NOT_EXIST);
handler->SetSentErrorMessage(true);
return false;
}
GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr.GetActiveEventList();
if (activeEvents.find(event_id) == activeEvents.end())
{
handler->PSendSysMessage(LANG_EVENT_NOT_ACTIVE,event_id);
handler->SetSentErrorMessage(true);
return false;
}
sGameEventMgr.StopEvent(event_id,true);
return true;
handler->SendSysMessage(LANG_EVENT_NOT_EXIST);
handler->SetSentErrorMessage(true);
return false;
}
GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr.GetActiveEventList();
bool active = activeEvents.find(event_id) != activeEvents.end();
char const* activeStr = active ? handler->GetTrinityString(LANG_ACTIVE) : "";
std::string startTimeStr = TimeToTimestampStr(eventData.start);
std::string endTimeStr = TimeToTimestampStr(eventData.end);
uint32 delay = sGameEventMgr.NextCheck(event_id);
time_t nextTime = time(NULL)+delay;
std::string nextStr = nextTime >= eventData.start && nextTime < eventData.end ? TimeToTimestampStr(time(NULL)+delay) : "-";
std::string occurenceStr = secsToTimeString(eventData.occurence * MINUTE);
std::string lengthStr = secsToTimeString(eventData.length * MINUTE);
handler->PSendSysMessage(LANG_EVENT_INFO,event_id,eventData.description.c_str(),activeStr,
startTimeStr.c_str(),endTimeStr.c_str(),occurenceStr.c_str(),lengthStr.c_str(),
nextStr.c_str());
return true;
}
static bool HandleEventStartCommand(ChatHandler* handler, const char* args)
{
if (!*args)
return false;
// id or [name] Shift-click form |color|Hgameevent:id|h[name]|h|r
char* cId = handler->extractKeyFromLink((char*)args,"Hgameevent");
if (!cId)
return false;
int32 event_id = atoi(cId);
GameEventMgr::GameEventDataMap const& events = sGameEventMgr.GetEventMap();
if (event_id < 1 || uint32(event_id) >= events.size())
{
handler->SendSysMessage(LANG_EVENT_NOT_EXIST);
handler->SetSentErrorMessage(true);
return false;
}
GameEventData const& eventData = events[event_id];
if (!eventData.isValid())
{
handler->SendSysMessage(LANG_EVENT_NOT_EXIST);
handler->SetSentErrorMessage(true);
return false;
}
GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr.GetActiveEventList();
if (activeEvents.find(event_id) != activeEvents.end())
{
handler->PSendSysMessage(LANG_EVENT_ALREADY_ACTIVE,event_id);
handler->SetSentErrorMessage(true);
return false;
}
sGameEventMgr.StartEvent(event_id,true);
return true;
}
static bool HandleEventStopCommand(ChatHandler* handler, const char* args)
{
if (!*args)
return false;
// id or [name] Shift-click form |color|Hgameevent:id|h[name]|h|r
char* cId = handler->extractKeyFromLink((char*)args,"Hgameevent");
if (!cId)
return false;
int32 event_id = atoi(cId);
GameEventMgr::GameEventDataMap const& events = sGameEventMgr.GetEventMap();
if (event_id < 1 || uint32(event_id) >= events.size())
{
handler->SendSysMessage(LANG_EVENT_NOT_EXIST);
handler->SetSentErrorMessage(true);
return false;
}
GameEventData const& eventData = events[event_id];
if (!eventData.isValid())
{
handler->SendSysMessage(LANG_EVENT_NOT_EXIST);
handler->SetSentErrorMessage(true);
return false;
}
GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr.GetActiveEventList();
if (activeEvents.find(event_id) == activeEvents.end())
{
handler->PSendSysMessage(LANG_EVENT_NOT_ACTIVE,event_id);
handler->SetSentErrorMessage(true);
return false;
}
sGameEventMgr.StopEvent(event_id,true);
return true;
}
};
void AddSC_event_commandscript()
+208 -208
View File
@@ -28,232 +28,232 @@ EndScriptData */
class gm_commandscript : public CommandScript
{
public:
gm_commandscript() : CommandScript("gm_commandscript") { }
public:
gm_commandscript() : CommandScript("gm_commandscript") { }
ChatCommand* GetCommands() const
ChatCommand* GetCommands() const
{
static ChatCommand gmCommandTable[] =
{
static ChatCommand gmCommandTable[] =
{
{ "chat", SEC_MODERATOR, false, &HandleGMChatCommand, "", NULL },
{ "fly", SEC_ADMINISTRATOR, false, &HandleGMFlyCommand, "", NULL },
{ "ingame", SEC_PLAYER, true, &HandleGMListIngameCommand, "", NULL },
{ "list", SEC_ADMINISTRATOR, true, &HandleGMListFullCommand, "", NULL },
{ "visible", SEC_MODERATOR, false, &HandleGMVisibleCommand, "", NULL },
{ "", SEC_MODERATOR, false, &HandleGMCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "gm", SEC_MODERATOR, false, NULL, "", gmCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}
// Enables or disables hiding of the staff badge
static bool HandleGMChatCommand(ChatHandler* handler, const char* args)
{ "chat", SEC_MODERATOR, false, &HandleGMChatCommand, "", NULL },
{ "fly", SEC_ADMINISTRATOR, false, &HandleGMFlyCommand, "", NULL },
{ "ingame", SEC_PLAYER, true, &HandleGMListIngameCommand, "", NULL },
{ "list", SEC_ADMINISTRATOR, true, &HandleGMListFullCommand, "", NULL },
{ "visible", SEC_MODERATOR, false, &HandleGMVisibleCommand, "", NULL },
{ "", SEC_MODERATOR, false, &HandleGMCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
if (!*args)
{
if (handler->GetSession()->GetPlayer()->isGMChat())
handler->GetSession()->SendNotification(LANG_GM_CHAT_ON);
else
handler->GetSession()->SendNotification(LANG_GM_CHAT_OFF);
return true;
}
{ "gm", SEC_MODERATOR, false, NULL, "", gmCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}
std::string argstr = (char*)args;
if (argstr == "on")
{
handler->GetSession()->GetPlayer()->SetGMChat(true);
// Enables or disables hiding of the staff badge
static bool HandleGMChatCommand(ChatHandler* handler, const char* args)
{
if (!*args)
{
if (handler->GetSession()->GetPlayer()->isGMChat())
handler->GetSession()->SendNotification(LANG_GM_CHAT_ON);
return true;
}
if (argstr == "off")
{
handler->GetSession()->GetPlayer()->SetGMChat(false);
else
handler->GetSession()->SendNotification(LANG_GM_CHAT_OFF);
return true;
}
return true;
}
std::string argstr = (char*)args;
if (argstr == "on")
{
handler->GetSession()->GetPlayer()->SetGMChat(true);
handler->GetSession()->SendNotification(LANG_GM_CHAT_ON);
return true;
}
if (argstr == "off")
{
handler->GetSession()->GetPlayer()->SetGMChat(false);
handler->GetSession()->SendNotification(LANG_GM_CHAT_OFF);
return true;
}
handler->SendSysMessage(LANG_USE_BOL);
handler->SetSentErrorMessage(true);
return false;
}
static bool HandleGMFlyCommand(ChatHandler* handler, const char* args)
{
if (!*args)
return false;
Player *target = handler->getSelectedPlayer();
if (!target)
target = handler->GetSession()->GetPlayer();
WorldPacket data(12);
if (strncmp(args, "on", 3) == 0)
data.SetOpcode(SMSG_MOVE_SET_CAN_FLY);
else if (strncmp(args, "off", 4) == 0)
data.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY);
else
{
handler->SendSysMessage(LANG_USE_BOL);
handler->SetSentErrorMessage(true);
return false;
}
data.append(target->GetPackGUID());
data << uint32(0); // unknown
target->SendMessageToSet(&data, true);
handler->PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS, handler->GetNameLink(target).c_str(), args);
return true;
}
static bool HandleGMFlyCommand(ChatHandler* handler, const char* args)
static bool HandleGMListIngameCommand(ChatHandler* handler, const char* /*args*/)
{
bool first = true;
bool footer = false;
ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, *HashMapHolder<Player>::GetLock(), true);
HashMapHolder<Player>::MapType &m = sObjectAccessor.GetPlayers();
for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
{
if (!*args)
return false;
Player *target = handler->getSelectedPlayer();
if (!target)
target = handler->GetSession()->GetPlayer();
WorldPacket data(12);
if (strncmp(args, "on", 3) == 0)
data.SetOpcode(SMSG_MOVE_SET_CAN_FLY);
else if (strncmp(args, "off", 4) == 0)
data.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY);
else
AccountTypes itr_sec = itr->second->GetSession()->GetSecurity();
if ((itr->second->isGameMaster() || (itr_sec > SEC_PLAYER && itr_sec <= AccountTypes(sWorld.getIntConfig(CONFIG_GM_LEVEL_IN_GM_LIST)))) &&
(!handler->GetSession() || itr->second->IsVisibleGloballyFor(handler->GetSession()->GetPlayer())))
{
handler->SendSysMessage(LANG_USE_BOL);
return false;
}
data.append(target->GetPackGUID());
data << uint32(0); // unknown
target->SendMessageToSet(&data, true);
handler->PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS, handler->GetNameLink(target).c_str(), args);
return true;
}
static bool HandleGMListIngameCommand(ChatHandler* handler, const char* /*args*/)
{
bool first = true;
bool footer = false;
ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, *HashMapHolder<Player>::GetLock(), true);
HashMapHolder<Player>::MapType &m = sObjectAccessor.GetPlayers();
for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
{
AccountTypes itr_sec = itr->second->GetSession()->GetSecurity();
if ((itr->second->isGameMaster() || (itr_sec > SEC_PLAYER && itr_sec <= AccountTypes(sWorld.getIntConfig(CONFIG_GM_LEVEL_IN_GM_LIST)))) &&
(!handler->GetSession() || itr->second->IsVisibleGloballyFor(handler->GetSession()->GetPlayer())))
if (first)
{
if (first)
{
first = false;
footer = true;
handler->SendSysMessage(LANG_GMS_ON_SRV);
handler->SendSysMessage("========================");
}
const char* name = itr->second->GetName();
uint8 security = itr_sec;
uint8 max = ((16 - strlen(name)) / 2);
uint8 max2 = max;
if (((max)+(max2)+(strlen(name))) == 16)
max2 = ((max)-1);
if (handler->GetSession())
handler->PSendSysMessage("| %s GMLevel %u", name, security);
else
handler->PSendSysMessage("|%*s%s%*s| %u |", max, " ", name, max2, " ", security);
first = false;
footer = true;
handler->SendSysMessage(LANG_GMS_ON_SRV);
handler->SendSysMessage("========================");
}
}
if (footer)
handler->SendSysMessage("========================");
if (first)
handler->SendSysMessage(LANG_GMS_NOT_LOGGED);
return true;
}
/// Display the list of GMs
static bool HandleGMListFullCommand(ChatHandler* handler, const char* /*args*/)
{
///- Get the accounts with GM Level >0
QueryResult result = LoginDatabase.Query("SELECT a.username,aa.gmlevel FROM account a, account_access aa WHERE a.id=aa.id AND aa.gmlevel > 0");
if (result)
{
handler->SendSysMessage(LANG_GMLIST);
handler->SendSysMessage("========================");
///- Cycle through them. Display username and GM level
do
{
Field *fields = result->Fetch();
const char* name = fields[0].GetCString();
uint8 security = fields[1].GetUInt8();
uint8 max = ((16 - strlen(name)) / 2);
uint8 max2 = max;
if (((max)+(max2)+(strlen(name))) == 16)
max2 = ((max)-1);
if (handler->GetSession())
handler->PSendSysMessage("| %s GMLevel %u", name, security);
else
handler->PSendSysMessage("|%*s%s%*s| %u |", max, " ", name, max2, " ", security);
}
while (result->NextRow());
handler->SendSysMessage("========================");
}
else
handler->PSendSysMessage(LANG_GMLIST_EMPTY);
return true;
}
//Enable\Disable Invisible mode
static bool HandleGMVisibleCommand(ChatHandler* handler, const char* args)
{
if (!*args)
{
handler->PSendSysMessage(LANG_YOU_ARE, handler->GetSession()->GetPlayer()->isGMVisible() ? handler->GetTrinityString(LANG_VISIBLE) : handler->GetTrinityString(LANG_INVISIBLE));
return true;
}
std::string argstr = (char*)args;
if (argstr == "on")
{
handler->GetSession()->GetPlayer()->SetGMVisible(true);
handler->GetSession()->SendNotification(LANG_INVISIBLE_VISIBLE);
return true;
}
if (argstr == "off")
{
handler->GetSession()->SendNotification(LANG_INVISIBLE_INVISIBLE);
handler->GetSession()->GetPlayer()->SetGMVisible(false);
return true;
}
handler->SendSysMessage(LANG_USE_BOL);
handler->SetSentErrorMessage(true);
return false;
}
//Enable\Disable GM Mode
static bool HandleGMCommand(ChatHandler* handler, const char* args)
{
if (!*args)
{
if (handler->GetSession()->GetPlayer()->isGameMaster())
handler->GetSession()->SendNotification(LANG_GM_ON);
const char* name = itr->second->GetName();
uint8 security = itr_sec;
uint8 max = ((16 - strlen(name)) / 2);
uint8 max2 = max;
if (((max)+(max2)+(strlen(name))) == 16)
max2 = ((max)-1);
if (handler->GetSession())
handler->PSendSysMessage("| %s GMLevel %u", name, security);
else
handler->GetSession()->SendNotification(LANG_GM_OFF);
return true;
handler->PSendSysMessage("|%*s%s%*s| %u |", max, " ", name, max2, " ", security);
}
std::string argstr = (char*)args;
if (argstr == "on")
{
handler->GetSession()->GetPlayer()->SetGameMaster(true);
handler->GetSession()->SendNotification(LANG_GM_ON);
handler->GetSession()->GetPlayer()->UpdateTriggerVisibility();
#ifdef _DEBUG_VMAPS
VMAP::IVMapManager *vMapManager = VMAP::VMapFactory::createOrGetVMapManager();
vMapManager->processCommand("stoplog");
#endif
return true;
}
if (argstr == "off")
{
handler->GetSession()->GetPlayer()->SetGameMaster(false);
handler->GetSession()->SendNotification(LANG_GM_OFF);
handler->GetSession()->GetPlayer()->UpdateTriggerVisibility();
#ifdef _DEBUG_VMAPS
VMAP::IVMapManager *vMapManager = VMAP::VMapFactory::createOrGetVMapManager();
vMapManager->processCommand("startlog");
#endif
return true;
}
handler->SendSysMessage(LANG_USE_BOL);
handler->SetSentErrorMessage(true);
return false;
}
if (footer)
handler->SendSysMessage("========================");
if (first)
handler->SendSysMessage(LANG_GMS_NOT_LOGGED);
return true;
}
/// Display the list of GMs
static bool HandleGMListFullCommand(ChatHandler* handler, const char* /*args*/)
{
///- Get the accounts with GM Level >0
QueryResult result = LoginDatabase.Query("SELECT a.username,aa.gmlevel FROM account a, account_access aa WHERE a.id=aa.id AND aa.gmlevel > 0");
if (result)
{
handler->SendSysMessage(LANG_GMLIST);
handler->SendSysMessage("========================");
///- Cycle through them. Display username and GM level
do
{
Field *fields = result->Fetch();
const char* name = fields[0].GetCString();
uint8 security = fields[1].GetUInt8();
uint8 max = ((16 - strlen(name)) / 2);
uint8 max2 = max;
if (((max)+(max2)+(strlen(name))) == 16)
max2 = ((max)-1);
if (handler->GetSession())
handler->PSendSysMessage("| %s GMLevel %u", name, security);
else
handler->PSendSysMessage("|%*s%s%*s| %u |", max, " ", name, max2, " ", security);
}
while (result->NextRow());
handler->SendSysMessage("========================");
}
else
handler->PSendSysMessage(LANG_GMLIST_EMPTY);
return true;
}
//Enable\Disable Invisible mode
static bool HandleGMVisibleCommand(ChatHandler* handler, const char* args)
{
if (!*args)
{
handler->PSendSysMessage(LANG_YOU_ARE, handler->GetSession()->GetPlayer()->isGMVisible() ? handler->GetTrinityString(LANG_VISIBLE) : handler->GetTrinityString(LANG_INVISIBLE));
return true;
}
std::string argstr = (char*)args;
if (argstr == "on")
{
handler->GetSession()->GetPlayer()->SetGMVisible(true);
handler->GetSession()->SendNotification(LANG_INVISIBLE_VISIBLE);
return true;
}
if (argstr == "off")
{
handler->GetSession()->SendNotification(LANG_INVISIBLE_INVISIBLE);
handler->GetSession()->GetPlayer()->SetGMVisible(false);
return true;
}
handler->SendSysMessage(LANG_USE_BOL);
handler->SetSentErrorMessage(true);
return false;
}
//Enable\Disable GM Mode
static bool HandleGMCommand(ChatHandler* handler, const char* args)
{
if (!*args)
{
if (handler->GetSession()->GetPlayer()->isGameMaster())
handler->GetSession()->SendNotification(LANG_GM_ON);
else
handler->GetSession()->SendNotification(LANG_GM_OFF);
return true;
}
std::string argstr = (char*)args;
if (argstr == "on")
{
handler->GetSession()->GetPlayer()->SetGameMaster(true);
handler->GetSession()->SendNotification(LANG_GM_ON);
handler->GetSession()->GetPlayer()->UpdateTriggerVisibility();
#ifdef _DEBUG_VMAPS
VMAP::IVMapManager *vMapManager = VMAP::VMapFactory::createOrGetVMapManager();
vMapManager->processCommand("stoplog");
#endif
return true;
}
if (argstr == "off")
{
handler->GetSession()->GetPlayer()->SetGameMaster(false);
handler->GetSession()->SendNotification(LANG_GM_OFF);
handler->GetSession()->GetPlayer()->UpdateTriggerVisibility();
#ifdef _DEBUG_VMAPS
VMAP::IVMapManager *vMapManager = VMAP::VMapFactory::createOrGetVMapManager();
vMapManager->processCommand("startlog");
#endif
return true;
}
handler->SendSysMessage(LANG_USE_BOL);
handler->SetSentErrorMessage(true);
return false;
}
};
void AddSC_gm_commandscript()
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+69 -74
View File
@@ -28,90 +28,85 @@ EndScriptData */
class honor_commandscript : public CommandScript
{
public:
honor_commandscript() : CommandScript("honor_commandscript") { }
public:
honor_commandscript() : CommandScript("honor_commandscript") { }
ChatCommand* GetCommands() const
ChatCommand* GetCommands() const
{
static ChatCommand honorAddCommandTable[] =
{
static ChatCommand honorAddCommandTable[] =
{
{ "kill", SEC_GAMEMASTER, false, &HandleHonorAddKillCommand, "", NULL },
{ "", SEC_GAMEMASTER, false, &HandleHonorAddCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand honorCommandTable[] =
{
{ "add", SEC_GAMEMASTER, false, NULL, "", honorAddCommandTable },
{ "update", SEC_GAMEMASTER, false, &HandleHonorUpdateCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "honor", SEC_GAMEMASTER, false, NULL, "", honorCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
{ "kill", SEC_GAMEMASTER, false, &HandleHonorAddKillCommand, "", NULL },
{ "", SEC_GAMEMASTER, false, &HandleHonorAddCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand honorCommandTable[] =
{
{ "add", SEC_GAMEMASTER, false, NULL, "", honorAddCommandTable },
{ "update", SEC_GAMEMASTER, false, &HandleHonorUpdateCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "honor", SEC_GAMEMASTER, false, NULL, "", honorCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}
static bool HandleHonorAddCommand(ChatHandler* handler, const char* args)
{
if (!*args)
return false;
Player *target = handler->getSelectedPlayer();
if (!target)
{
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
handler->SetSentErrorMessage(true);
return false;
}
static bool HandleHonorAddCommand(ChatHandler* handler, const char* args)
{
if (!*args)
return false;
// check online security
if (handler->HasLowerSecurity(target, 0))
return false;
Player *target = handler->getSelectedPlayer();
if (!target)
{
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
handler->SetSentErrorMessage(true);
return false;
uint32 amount = (uint32)atoi(args);
target->RewardHonor(NULL, 1, amount);
return true;
}
// check online security
if (handler->HasLowerSecurity(target, 0))
return false;
uint32 amount = (uint32)atoi(args);
target->RewardHonor(NULL, 1, amount);
return true;
}
static bool HandleHonorAddKillCommand(ChatHandler* handler, const char* /*args*/)
{
Unit *target = handler->getSelectedUnit();
if (!target)
static bool HandleHonorAddKillCommand(ChatHandler* handler, const char* /*args*/)
{
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
handler->SetSentErrorMessage(true);
return false;
Unit *target = handler->getSelectedUnit();
if (!target)
{
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
handler->SetSentErrorMessage(true);
return false;
}
// check online security
if (target->GetTypeId() == TYPEID_PLAYER && handler->HasLowerSecurity((Player*)target, 0))
return false;
handler->GetSession()->GetPlayer()->RewardHonor(target, 1);
return true;
}
// check online security
if (target->GetTypeId() == TYPEID_PLAYER && handler->HasLowerSecurity((Player*)target, 0))
return false;
handler->GetSession()->GetPlayer()->RewardHonor(target, 1);
return true;
}
static bool HandleHonorUpdateCommand(ChatHandler* handler, const char* /*args*/)
{
Player *target = handler->getSelectedPlayer();
if (!target)
static bool HandleHonorUpdateCommand(ChatHandler* handler, const char* /*args*/)
{
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
handler->SetSentErrorMessage(true);
return false;
Player *target = handler->getSelectedPlayer();
if (!target)
{
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
handler->SetSentErrorMessage(true);
return false;
}
// check online security
if (handler->HasLowerSecurity(target, 0))
return false;
target->UpdateHonorFields();
return true;
}
// check online security
if (handler->HasLowerSecurity(target, 0))
return false;
target->UpdateHonorFields();
return true;
}
};
void AddSC_honor_commandscript()
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+194 -195
View File
@@ -28,230 +28,229 @@ EndScriptData */
class quest_commandscript : public CommandScript
{
public:
quest_commandscript() : CommandScript("quest_commandscript") { }
public:
quest_commandscript() : CommandScript("quest_commandscript") { }
ChatCommand* GetCommands() const
{
static ChatCommand questCommandTable[] =
{
{ "add", SEC_ADMINISTRATOR, false, &HandleQuestAdd, "", NULL },
{ "complete", SEC_ADMINISTRATOR, false, &HandleQuestComplete, "", NULL },
{ "remove", SEC_ADMINISTRATOR, false, &HandleQuestRemove, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "quest", SEC_ADMINISTRATOR, false, NULL, "", questCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}
static bool HandleQuestAdd(ChatHandler* handler, const char* args)
{
Player* player = handler->getSelectedPlayer();
if (!player)
ChatCommand* GetCommands() const
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
static ChatCommand questCommandTable[] =
{
{ "add", SEC_ADMINISTRATOR, false, &HandleQuestAdd, "", NULL },
{ "complete", SEC_ADMINISTRATOR, false, &HandleQuestComplete, "", NULL },
{ "remove", SEC_ADMINISTRATOR, false, &HandleQuestRemove, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "quest", SEC_ADMINISTRATOR, false, NULL, "", questCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}
// .addquest #entry'
// number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
char* cId = handler->extractKeyFromLink((char*)args,"Hquest");
if (!cId)
return false;
uint32 entry = atol(cId);
Quest const* pQuest = sObjectMgr.GetQuestTemplate(entry);
if (!pQuest)
static bool HandleQuestAdd(ChatHandler* handler, const char* args)
{
handler->PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND,entry);
handler->SetSentErrorMessage(true);
return false;
}
// check item starting quest (it can work incorrectly if added without item in inventory)
for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
{
ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype>(id);
if (!pProto)
continue;
if (pProto->StartQuest == entry)
Player* player = handler->getSelectedPlayer();
if (!player)
{
handler->PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry, pProto->ItemId);
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
}
// ok, normal (creature/GO starting) quest
if (player->CanAddQuest(pQuest, true))
{
player->AddQuest(pQuest, NULL);
// .addquest #entry'
// number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
char* cId = handler->extractKeyFromLink((char*)args,"Hquest");
if (!cId)
return false;
if (player->CanCompleteQuest(entry))
player->CompleteQuest(entry);
}
uint32 entry = atol(cId);
return true;
}
Quest const* pQuest = sObjectMgr.GetQuestTemplate(entry);
static bool HandleQuestRemove(ChatHandler* handler, const char* args)
{
Player* player = handler->getSelectedPlayer();
if (!player)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
// .removequest #entry'
// number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
char* cId = handler->extractKeyFromLink((char*)args,"Hquest");
if (!cId)
return false;
uint32 entry = atol(cId);
Quest const* pQuest = sObjectMgr.GetQuestTemplate(entry);
if (!pQuest)
{
handler->PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
handler->SetSentErrorMessage(true);
return false;
}
// remove all quest entries for 'entry' from quest log
for (uint8 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot)
{
uint32 quest = player->GetQuestSlotQuestId(slot);
if (quest == entry)
if (!pQuest)
{
player->SetQuestSlot(slot,0);
// we ignore unequippable quest items in this case, its' still be equipped
player->TakeQuestSourceItem(quest, false);
handler->PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND,entry);
handler->SetSentErrorMessage(true);
return false;
}
}
// set quest status to not started (will updated in DB at next save)
player->SetQuestStatus(entry, QUEST_STATUS_NONE);
// reset rewarded for restart repeatable quest
player->getQuestStatusMap()[entry].m_rewarded = false;
handler->SendSysMessage(LANG_COMMAND_QUEST_REMOVED);
return true;
}
static bool HandleQuestComplete(ChatHandler* handler, const char* args)
{
Player* player = handler->getSelectedPlayer();
if (!player)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
// .quest complete #entry
// number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
char* cId = handler->extractKeyFromLink((char*)args,"Hquest");
if (!cId)
return false;
uint32 entry = atol(cId);
Quest const* pQuest = sObjectMgr.GetQuestTemplate(entry);
// If player doesn't have the quest
if (!pQuest || player->GetQuestStatus(entry) == QUEST_STATUS_NONE)
{
handler->PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
handler->SetSentErrorMessage(true);
return false;
}
// Add quest items for quests that require items
for (uint8 x = 0; x < QUEST_ITEM_OBJECTIVES_COUNT; ++x)
{
uint32 id = pQuest->ReqItemId[x];
uint32 count = pQuest->ReqItemCount[x];
if (!id || !count)
continue;
uint32 curItemCount = player->GetItemCount(id,true);
ItemPosCountVec dest;
uint8 msg = player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, id, count-curItemCount);
if (msg == EQUIP_ERR_OK)
// check item starting quest (it can work incorrectly if added without item in inventory)
for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
{
Item* item = player->StoreNewItem(dest, id, true);
player->SendNewItem(item,count-curItemCount,true,false);
ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype>(id);
if (!pProto)
continue;
if (pProto->StartQuest == entry)
{
handler->PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry, pProto->ItemId);
handler->SetSentErrorMessage(true);
return false;
}
}
// ok, normal (creature/GO starting) quest
if (player->CanAddQuest(pQuest, true))
{
player->AddQuest(pQuest, NULL);
if (player->CanCompleteQuest(entry))
player->CompleteQuest(entry);
}
return true;
}
// All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
for (uint8 i = 0; i < QUEST_OBJECTIVES_COUNT; ++i)
static bool HandleQuestRemove(ChatHandler* handler, const char* args)
{
int32 creature = pQuest->ReqCreatureOrGOId[i];
uint32 creaturecount = pQuest->ReqCreatureOrGOCount[i];
if (uint32 spell_id = pQuest->ReqSpell[i])
Player* player = handler->getSelectedPlayer();
if (!player)
{
for (uint16 z = 0; z < creaturecount; ++z)
player->CastedCreatureOrGO(creature,0,spell_id);
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
else if (creature > 0)
// .removequest #entry'
// number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
char* cId = handler->extractKeyFromLink((char*)args,"Hquest");
if (!cId)
return false;
uint32 entry = atol(cId);
Quest const* pQuest = sObjectMgr.GetQuestTemplate(entry);
if (!pQuest)
{
if (CreatureInfo const* cInfo = sObjectMgr.GetCreatureTemplate(creature))
handler->PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
handler->SetSentErrorMessage(true);
return false;
}
// remove all quest entries for 'entry' from quest log
for (uint8 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot)
{
uint32 quest = player->GetQuestSlotQuestId(slot);
if (quest == entry)
{
player->SetQuestSlot(slot,0);
// we ignore unequippable quest items in this case, its' still be equipped
player->TakeQuestSourceItem(quest, false);
}
}
// set quest status to not started (will updated in DB at next save)
player->SetQuestStatus(entry, QUEST_STATUS_NONE);
// reset rewarded for restart repeatable quest
player->getQuestStatusMap()[entry].m_rewarded = false;
handler->SendSysMessage(LANG_COMMAND_QUEST_REMOVED);
return true;
}
static bool HandleQuestComplete(ChatHandler* handler, const char* args)
{
Player* player = handler->getSelectedPlayer();
if (!player)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
// .quest complete #entry
// number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
char* cId = handler->extractKeyFromLink((char*)args,"Hquest");
if (!cId)
return false;
uint32 entry = atol(cId);
Quest const* pQuest = sObjectMgr.GetQuestTemplate(entry);
// If player doesn't have the quest
if (!pQuest || player->GetQuestStatus(entry) == QUEST_STATUS_NONE)
{
handler->PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
handler->SetSentErrorMessage(true);
return false;
}
// Add quest items for quests that require items
for (uint8 x = 0; x < QUEST_ITEM_OBJECTIVES_COUNT; ++x)
{
uint32 id = pQuest->ReqItemId[x];
uint32 count = pQuest->ReqItemCount[x];
if (!id || !count)
continue;
uint32 curItemCount = player->GetItemCount(id,true);
ItemPosCountVec dest;
uint8 msg = player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, id, count-curItemCount);
if (msg == EQUIP_ERR_OK)
{
Item* item = player->StoreNewItem(dest, id, true);
player->SendNewItem(item,count-curItemCount,true,false);
}
}
// All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
for (uint8 i = 0; i < QUEST_OBJECTIVES_COUNT; ++i)
{
int32 creature = pQuest->ReqCreatureOrGOId[i];
uint32 creaturecount = pQuest->ReqCreatureOrGOCount[i];
if (uint32 spell_id = pQuest->ReqSpell[i])
{
for (uint16 z = 0; z < creaturecount; ++z)
player->KilledMonster(cInfo,0);
player->CastedCreatureOrGO(creature,0,spell_id);
}
else if (creature > 0)
{
if (CreatureInfo const* cInfo = sObjectMgr.GetCreatureTemplate(creature))
for (uint16 z = 0; z < creaturecount; ++z)
player->KilledMonster(cInfo,0);
}
else if (creature < 0)
{
for (uint16 z = 0; z < creaturecount; ++z)
player->CastedCreatureOrGO(creature,0,0);
}
}
else if (creature < 0)
// If the quest requires reputation to complete
if (uint32 repFaction = pQuest->GetRepObjectiveFaction())
{
for (uint16 z = 0; z < creaturecount; ++z)
player->CastedCreatureOrGO(creature,0,0);
uint32 repValue = pQuest->GetRepObjectiveValue();
uint32 curRep = player->GetReputationMgr().GetReputation(repFaction);
if (curRep < repValue)
if (FactionEntry const *factionEntry = sFactionStore.LookupEntry(repFaction))
player->GetReputationMgr().SetReputation(factionEntry,repValue);
}
// If the quest requires a SECOND reputation to complete
if (uint32 repFaction = pQuest->GetRepObjectiveFaction2())
{
uint32 repValue2 = pQuest->GetRepObjectiveValue2();
uint32 curRep = player->GetReputationMgr().GetReputation(repFaction);
if (curRep < repValue2)
if (FactionEntry const *factionEntry = sFactionStore.LookupEntry(repFaction))
player->GetReputationMgr().SetReputation(factionEntry,repValue2);
}
// If the quest requires money
int32 ReqOrRewMoney = pQuest->GetRewOrReqMoney();
if (ReqOrRewMoney < 0)
player->ModifyMoney(-ReqOrRewMoney);
player->CompleteQuest(entry);
return true;
}
// If the quest requires reputation to complete
if (uint32 repFaction = pQuest->GetRepObjectiveFaction())
{
uint32 repValue = pQuest->GetRepObjectiveValue();
uint32 curRep = player->GetReputationMgr().GetReputation(repFaction);
if (curRep < repValue)
if (FactionEntry const *factionEntry = sFactionStore.LookupEntry(repFaction))
player->GetReputationMgr().SetReputation(factionEntry,repValue);
}
// If the quest requires a SECOND reputation to complete
if (uint32 repFaction = pQuest->GetRepObjectiveFaction2())
{
uint32 repValue2 = pQuest->GetRepObjectiveValue2();
uint32 curRep = player->GetReputationMgr().GetReputation(repFaction);
if (curRep < repValue2)
if (FactionEntry const *factionEntry = sFactionStore.LookupEntry(repFaction))
player->GetReputationMgr().SetReputation(factionEntry,repValue2);
}
// If the quest requires money
int32 ReqOrRewMoney = pQuest->GetRewOrReqMoney();
if (ReqOrRewMoney < 0)
player->ModifyMoney(-ReqOrRewMoney);
player->CompleteQuest(entry);
return true;
}
};
void AddSC_quest_commandscript()
File diff suppressed because it is too large Load Diff
+250 -250
View File
@@ -29,286 +29,286 @@ EndScriptData */
class tele_commandscript : public CommandScript
{
public:
tele_commandscript() : CommandScript("tele_commandscript") { }
public:
tele_commandscript() : CommandScript("tele_commandscript") { }
ChatCommand* GetCommands() const
ChatCommand* GetCommands() const
{
static ChatCommand teleCommandTable[] =
{
static ChatCommand teleCommandTable[] =
{
{ "add", SEC_ADMINISTRATOR, false, &HandleTeleAddCommand, "", NULL },
{ "del", SEC_ADMINISTRATOR, true, &HandleTeleDelCommand, "", NULL },
{ "name", SEC_MODERATOR, true, &HandleTeleNameCommand, "", NULL },
{ "group", SEC_MODERATOR, false, &HandleTeleGroupCommand, "", NULL },
{ "", SEC_MODERATOR, false, &HandleTeleCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "tele", SEC_MODERATOR, false, NULL, "", teleCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
{ "add", SEC_ADMINISTRATOR, false, &HandleTeleAddCommand, "", NULL },
{ "del", SEC_ADMINISTRATOR, true, &HandleTeleDelCommand, "", NULL },
{ "name", SEC_MODERATOR, true, &HandleTeleNameCommand, "", NULL },
{ "group", SEC_MODERATOR, false, &HandleTeleGroupCommand, "", NULL },
{ "", SEC_MODERATOR, false, &HandleTeleCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "tele", SEC_MODERATOR, false, NULL, "", teleCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}
static bool HandleTeleAddCommand(ChatHandler* handler, const char* args)
{
if (!*args)
return false;
Player *player = handler->GetSession()->GetPlayer();
if (!player)
return false;
std::string name = args;
if (sObjectMgr.GetGameTele(name))
{
handler->SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST);
handler->SetSentErrorMessage(true);
return false;
}
static bool HandleTeleAddCommand(ChatHandler* handler, const char* args)
GameTele tele;
tele.position_x = player->GetPositionX();
tele.position_y = player->GetPositionY();
tele.position_z = player->GetPositionZ();
tele.orientation = player->GetOrientation();
tele.mapId = player->GetMapId();
tele.name = name;
if (sObjectMgr.AddGameTele(tele))
{
if (!*args)
return false;
Player *player = handler->GetSession()->GetPlayer();
if (!player)
return false;
std::string name = args;
if (sObjectMgr.GetGameTele(name))
{
handler->SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST);
handler->SetSentErrorMessage(true);
return false;
}
GameTele tele;
tele.position_x = player->GetPositionX();
tele.position_y = player->GetPositionY();
tele.position_z = player->GetPositionZ();
tele.orientation = player->GetOrientation();
tele.mapId = player->GetMapId();
tele.name = name;
if (sObjectMgr.AddGameTele(tele))
{
handler->SendSysMessage(LANG_COMMAND_TP_ADDED);
}
else
{
handler->SendSysMessage(LANG_COMMAND_TP_ADDEDERR);
handler->SetSentErrorMessage(true);
return false;
}
return true;
handler->SendSysMessage(LANG_COMMAND_TP_ADDED);
}
else
{
handler->SendSysMessage(LANG_COMMAND_TP_ADDEDERR);
handler->SetSentErrorMessage(true);
return false;
}
static bool HandleTeleDelCommand(ChatHandler* handler, const char* args)
return true;
}
static bool HandleTeleDelCommand(ChatHandler* handler, const char* args)
{
if (!*args)
return false;
std::string name = args;
if (!sObjectMgr.DeleteGameTele(name))
{
if (!*args)
return false;
std::string name = args;
if (!sObjectMgr.DeleteGameTele(name))
{
handler->SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
handler->SetSentErrorMessage(true);
return false;
}
handler->SendSysMessage(LANG_COMMAND_TP_DELETED);
return true;
handler->SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
handler->SetSentErrorMessage(true);
return false;
}
// teleport player to given game_tele.entry
static bool HandleTeleNameCommand(ChatHandler* handler, const char* args)
handler->SendSysMessage(LANG_COMMAND_TP_DELETED);
return true;
}
// teleport player to given game_tele.entry
static bool HandleTeleNameCommand(ChatHandler* handler, const char* args)
{
char* nameStr;
char* teleStr;
handler->extractOptFirstArg((char*)args,&nameStr,&teleStr);
if (!teleStr)
return false;
Player* target;
uint64 target_guid;
std::string target_name;
if (!handler->extractPlayerTarget(nameStr,&target,&target_guid,&target_name))
return false;
// id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
GameTele const* tele = handler->extractGameTeleFromLink(teleStr);
if (!tele)
{
char* nameStr;
char* teleStr;
handler->extractOptFirstArg((char*)args,&nameStr,&teleStr);
if (!teleStr)
return false;
Player* target;
uint64 target_guid;
std::string target_name;
if (!handler->extractPlayerTarget(nameStr,&target,&target_guid,&target_name))
return false;
// id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
GameTele const* tele = handler->extractGameTeleFromLink(teleStr);
if (!tele)
{
handler->SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
handler->SetSentErrorMessage(true);
return false;
}
if (target)
{
// check online security
if (handler->HasLowerSecurity(target, 0))
return false;
std::string chrNameLink = handler->playerLink(target_name);
if (target->IsBeingTeleported() == true)
{
handler->PSendSysMessage(LANG_IS_TELEPORTED, chrNameLink.c_str());
handler->SetSentErrorMessage(true);
return false;
}
handler->PSendSysMessage(LANG_TELEPORTING_TO, chrNameLink.c_str(),"", tele->name.c_str());
if (handler->needReportToTarget(target))
(ChatHandler(target)).PSendSysMessage(LANG_TELEPORTED_TO_BY, handler->GetNameLink().c_str());
// stop flight if need
if (target->isInFlight())
{
target->GetMotionMaster()->MovementExpired();
target->CleanupAfterTaxiFlight();
}
// save only in non-flight case
else
target->SaveRecallPosition();
target->TeleportTo(tele->mapId,tele->position_x,tele->position_y,tele->position_z,tele->orientation);
}
else
{
// check offline security
if (handler->HasLowerSecurity(NULL, target_guid))
return false;
std::string nameLink = handler->playerLink(target_name);
handler->PSendSysMessage(LANG_TELEPORTING_TO, nameLink.c_str(), handler->GetTrinityString(LANG_OFFLINE), tele->name.c_str());
Player::SavePositionInDB(tele->mapId,tele->position_x,tele->position_y,tele->position_z,tele->orientation,
sMapMgr.GetZoneId(tele->mapId,tele->position_x,tele->position_y,tele->position_z),target_guid);
}
return true;
handler->SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
handler->SetSentErrorMessage(true);
return false;
}
//Teleport group to given game_tele.entry
static bool HandleTeleGroupCommand(ChatHandler* handler, const char* args)
if (target)
{
if (!*args)
return false;
Player *player = handler->getSelectedPlayer();
if (!player)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
// check online security
if (handler->HasLowerSecurity(player, 0))
if (handler->HasLowerSecurity(target, 0))
return false;
// id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
GameTele const* tele = handler->extractGameTeleFromLink((char*)args);
if (!tele)
std::string chrNameLink = handler->playerLink(target_name);
if (target->IsBeingTeleported() == true)
{
handler->SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
handler->PSendSysMessage(LANG_IS_TELEPORTED, chrNameLink.c_str());
handler->SetSentErrorMessage(true);
return false;
}
MapEntry const * map = sMapStore.LookupEntry(tele->mapId);
if (!map || map->IsBattlegroundOrArena())
{
handler->SendSysMessage(LANG_CANNOT_TELE_TO_BG);
handler->SetSentErrorMessage(true);
return false;
}
std::string nameLink = handler->GetNameLink(player);
Group *grp = player->GetGroup();
if (!grp)
{
handler->PSendSysMessage(LANG_NOT_IN_GROUP,nameLink.c_str());
handler->SetSentErrorMessage(true);
return false;
}
for (GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
{
Player *pl = itr->getSource();
if (!pl || !pl->GetSession())
continue;
// check online security
if (handler->HasLowerSecurity(pl, 0))
return false;
std::string plNameLink = handler->GetNameLink(pl);
if (pl->IsBeingTeleported())
{
handler->PSendSysMessage(LANG_IS_TELEPORTED, plNameLink.c_str());
continue;
}
handler->PSendSysMessage(LANG_TELEPORTING_TO, plNameLink.c_str(),"", tele->name.c_str());
if (handler->needReportToTarget(pl))
(ChatHandler(pl)).PSendSysMessage(LANG_TELEPORTED_TO_BY, nameLink.c_str());
// stop flight if need
if (pl->isInFlight())
{
pl->GetMotionMaster()->MovementExpired();
pl->CleanupAfterTaxiFlight();
}
// save only in non-flight case
else
pl->SaveRecallPosition();
pl->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
}
return true;
}
static bool HandleTeleCommand(ChatHandler* handler, const char* args)
{
if (!*args)
return false;
Player* me = handler->GetSession()->GetPlayer();
// id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
GameTele const* tele = handler->extractGameTeleFromLink((char*)args);
if (!tele)
{
handler->SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
handler->SetSentErrorMessage(true);
return false;
}
if (me->isInCombat())
{
handler->SendSysMessage(LANG_YOU_IN_COMBAT);
handler->SetSentErrorMessage(true);
return false;
}
MapEntry const * map = sMapStore.LookupEntry(tele->mapId);
if (!map || map->IsBattlegroundOrArena())
{
handler->SendSysMessage(LANG_CANNOT_TELE_TO_BG);
handler->SetSentErrorMessage(true);
return false;
}
handler->PSendSysMessage(LANG_TELEPORTING_TO, chrNameLink.c_str(),"", tele->name.c_str());
if (handler->needReportToTarget(target))
(ChatHandler(target)).PSendSysMessage(LANG_TELEPORTED_TO_BY, handler->GetNameLink().c_str());
// stop flight if need
if (me->isInFlight())
if (target->isInFlight())
{
me->GetMotionMaster()->MovementExpired();
me->CleanupAfterTaxiFlight();
target->GetMotionMaster()->MovementExpired();
target->CleanupAfterTaxiFlight();
}
// save only in non-flight case
else
me->SaveRecallPosition();
target->SaveRecallPosition();
me->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
return true;
target->TeleportTo(tele->mapId,tele->position_x,tele->position_y,tele->position_z,tele->orientation);
}
else
{
// check offline security
if (handler->HasLowerSecurity(NULL, target_guid))
return false;
std::string nameLink = handler->playerLink(target_name);
handler->PSendSysMessage(LANG_TELEPORTING_TO, nameLink.c_str(), handler->GetTrinityString(LANG_OFFLINE), tele->name.c_str());
Player::SavePositionInDB(tele->mapId,tele->position_x,tele->position_y,tele->position_z,tele->orientation,
sMapMgr.GetZoneId(tele->mapId,tele->position_x,tele->position_y,tele->position_z),target_guid);
}
return true;
}
//Teleport group to given game_tele.entry
static bool HandleTeleGroupCommand(ChatHandler* handler, const char* args)
{
if (!*args)
return false;
Player *player = handler->getSelectedPlayer();
if (!player)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
// check online security
if (handler->HasLowerSecurity(player, 0))
return false;
// id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
GameTele const* tele = handler->extractGameTeleFromLink((char*)args);
if (!tele)
{
handler->SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
handler->SetSentErrorMessage(true);
return false;
}
MapEntry const * map = sMapStore.LookupEntry(tele->mapId);
if (!map || map->IsBattlegroundOrArena())
{
handler->SendSysMessage(LANG_CANNOT_TELE_TO_BG);
handler->SetSentErrorMessage(true);
return false;
}
std::string nameLink = handler->GetNameLink(player);
Group *grp = player->GetGroup();
if (!grp)
{
handler->PSendSysMessage(LANG_NOT_IN_GROUP,nameLink.c_str());
handler->SetSentErrorMessage(true);
return false;
}
for (GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
{
Player *pl = itr->getSource();
if (!pl || !pl->GetSession())
continue;
// check online security
if (handler->HasLowerSecurity(pl, 0))
return false;
std::string plNameLink = handler->GetNameLink(pl);
if (pl->IsBeingTeleported())
{
handler->PSendSysMessage(LANG_IS_TELEPORTED, plNameLink.c_str());
continue;
}
handler->PSendSysMessage(LANG_TELEPORTING_TO, plNameLink.c_str(),"", tele->name.c_str());
if (handler->needReportToTarget(pl))
(ChatHandler(pl)).PSendSysMessage(LANG_TELEPORTED_TO_BY, nameLink.c_str());
// stop flight if need
if (pl->isInFlight())
{
pl->GetMotionMaster()->MovementExpired();
pl->CleanupAfterTaxiFlight();
}
// save only in non-flight case
else
pl->SaveRecallPosition();
pl->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
}
return true;
}
static bool HandleTeleCommand(ChatHandler* handler, const char* args)
{
if (!*args)
return false;
Player* me = handler->GetSession()->GetPlayer();
// id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
GameTele const* tele = handler->extractGameTeleFromLink((char*)args);
if (!tele)
{
handler->SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
handler->SetSentErrorMessage(true);
return false;
}
if (me->isInCombat())
{
handler->SendSysMessage(LANG_YOU_IN_COMBAT);
handler->SetSentErrorMessage(true);
return false;
}
MapEntry const * map = sMapStore.LookupEntry(tele->mapId);
if (!map || map->IsBattlegroundOrArena())
{
handler->SendSysMessage(LANG_CANNOT_TELE_TO_BG);
handler->SetSentErrorMessage(true);
return false;
}
// stop flight if need
if (me->isInFlight())
{
me->GetMotionMaster()->MovementExpired();
me->CleanupAfterTaxiFlight();
}
// save only in non-flight case
else
me->SaveRecallPosition();
me->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
return true;
}
};
void AddSC_tele_commandscript()
+198 -199
View File
@@ -28,220 +28,219 @@ EndScriptData */
class titles_commandscript : public CommandScript
{
public:
titles_commandscript() : CommandScript("titles_commandscript") { }
public:
titles_commandscript() : CommandScript("titles_commandscript") { }
ChatCommand* GetCommands() const
ChatCommand* GetCommands() const
{
static ChatCommand titlesSetCommandTable[] =
{
static ChatCommand titlesSetCommandTable[] =
{
{ "mask", SEC_GAMEMASTER, false, &HandleTitlesSetMaskCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand titlesCommandTable[] =
{
{ "add", SEC_GAMEMASTER, false, &HandleTitlesAddCommand, "", NULL },
{ "current", SEC_GAMEMASTER, false, &HandleTitlesCurrentCommand, "", NULL },
{ "remove", SEC_GAMEMASTER, false, &HandleTitlesRemoveCommand, "", NULL },
{ "set", SEC_GAMEMASTER, false, NULL, "", titlesSetCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "titles", SEC_GAMEMASTER, false, NULL, "", titlesCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
{ "mask", SEC_GAMEMASTER, false, &HandleTitlesSetMaskCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand titlesCommandTable[] =
{
{ "add", SEC_GAMEMASTER, false, &HandleTitlesAddCommand, "", NULL },
{ "current", SEC_GAMEMASTER, false, &HandleTitlesCurrentCommand, "", NULL },
{ "remove", SEC_GAMEMASTER, false, &HandleTitlesRemoveCommand, "", NULL },
{ "set", SEC_GAMEMASTER, false, NULL, "", titlesSetCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "titles", SEC_GAMEMASTER, false, NULL, "", titlesCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}
static bool HandleTitlesCurrentCommand(ChatHandler* handler, const char* args)
{
// number or [name] Shift-click form |color|Htitle:title_id|h[name]|h|r
char* id_p = handler->extractKeyFromLink((char*)args,"Htitle");
if (!id_p)
return false;
int32 id = atoi(id_p);
if (id <= 0)
{
handler->PSendSysMessage(LANG_INVALID_TITLE_ID, id);
handler->SetSentErrorMessage(true);
return false;
}
static bool HandleTitlesCurrentCommand(ChatHandler* handler, const char* args)
{
// number or [name] Shift-click form |color|Htitle:title_id|h[name]|h|r
char* id_p = handler->extractKeyFromLink((char*)args,"Htitle");
if (!id_p)
return false;
Player * target = handler->getSelectedPlayer();
if (!target)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
int32 id = atoi(id_p);
if (id <= 0)
{
handler->PSendSysMessage(LANG_INVALID_TITLE_ID, id);
handler->SetSentErrorMessage(true);
return false;
// check online security
if (handler->HasLowerSecurity(target, 0))
return false;
CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id);
if (!titleInfo)
{
handler->PSendSysMessage(LANG_INVALID_TITLE_ID, id);
handler->SetSentErrorMessage(true);
return false;
}
std::string tNameLink = handler->GetNameLink(target);
target->SetTitle(titleInfo); // to be sure that title now known
target->SetUInt32Value(PLAYER_CHOSEN_TITLE,titleInfo->bit_index);
handler->PSendSysMessage(LANG_TITLE_CURRENT_RES, id, titleInfo->name[handler->GetSessionDbcLocale()], tNameLink.c_str());
return true;
}
Player * target = handler->getSelectedPlayer();
if (!target)
static bool HandleTitlesAddCommand(ChatHandler* handler, const char* args)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
// number or [name] Shift-click form |color|Htitle:title_id|h[name]|h|r
char* id_p = handler->extractKeyFromLink((char*)args,"Htitle");
if (!id_p)
return false;
int32 id = atoi(id_p);
if (id <= 0)
{
handler->PSendSysMessage(LANG_INVALID_TITLE_ID, id);
handler->SetSentErrorMessage(true);
return false;
}
Player * target = handler->getSelectedPlayer();
if (!target)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
// check online security
if (handler->HasLowerSecurity(target, 0))
return false;
CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id);
if (!titleInfo)
{
handler->PSendSysMessage(LANG_INVALID_TITLE_ID, id);
handler->SetSentErrorMessage(true);
return false;
}
std::string tNameLink = handler->GetNameLink(target);
char const* targetName = target->GetName();
char titleNameStr[80];
snprintf(titleNameStr,80,titleInfo->name[handler->GetSessionDbcLocale()],targetName);
target->SetTitle(titleInfo);
handler->PSendSysMessage(LANG_TITLE_ADD_RES, id, titleNameStr, tNameLink.c_str());
return true;
}
// check online security
if (handler->HasLowerSecurity(target, 0))
return false;
CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id);
if (!titleInfo)
static bool HandleTitlesRemoveCommand(ChatHandler* handler, const char* args)
{
handler->PSendSysMessage(LANG_INVALID_TITLE_ID, id);
handler->SetSentErrorMessage(true);
return false;
// number or [name] Shift-click form |color|Htitle:title_id|h[name]|h|r
char* id_p = handler->extractKeyFromLink((char*)args,"Htitle");
if (!id_p)
return false;
int32 id = atoi(id_p);
if (id <= 0)
{
handler->PSendSysMessage(LANG_INVALID_TITLE_ID, id);
handler->SetSentErrorMessage(true);
return false;
}
Player * target = handler->getSelectedPlayer();
if (!target)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
// check online security
if (handler->HasLowerSecurity(target, 0))
return false;
CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id);
if (!titleInfo)
{
handler->PSendSysMessage(LANG_INVALID_TITLE_ID, id);
handler->SetSentErrorMessage(true);
return false;
}
target->SetTitle(titleInfo,true);
std::string tNameLink = handler->GetNameLink(target);
char const* targetName = target->GetName();
char titleNameStr[80];
snprintf(titleNameStr,80,titleInfo->name[handler->GetSessionDbcLocale()],targetName);
handler->PSendSysMessage(LANG_TITLE_REMOVE_RES, id, titleNameStr, tNameLink.c_str());
if (!target->HasTitle(target->GetInt32Value(PLAYER_CHOSEN_TITLE)))
{
target->SetUInt32Value(PLAYER_CHOSEN_TITLE,0);
handler->PSendSysMessage(LANG_CURRENT_TITLE_RESET, tNameLink.c_str());
}
return true;
}
std::string tNameLink = handler->GetNameLink(target);
target->SetTitle(titleInfo); // to be sure that title now known
target->SetUInt32Value(PLAYER_CHOSEN_TITLE,titleInfo->bit_index);
handler->PSendSysMessage(LANG_TITLE_CURRENT_RES, id, titleInfo->name[handler->GetSessionDbcLocale()], tNameLink.c_str());
return true;
}
static bool HandleTitlesAddCommand(ChatHandler* handler, const char* args)
{
// number or [name] Shift-click form |color|Htitle:title_id|h[name]|h|r
char* id_p = handler->extractKeyFromLink((char*)args,"Htitle");
if (!id_p)
return false;
int32 id = atoi(id_p);
if (id <= 0)
//Edit Player KnownTitles
static bool HandleTitlesSetMaskCommand(ChatHandler* handler, const char* args)
{
handler->PSendSysMessage(LANG_INVALID_TITLE_ID, id);
handler->SetSentErrorMessage(true);
return false;
if (!*args)
return false;
uint64 titles = 0;
sscanf((char*)args, UI64FMTD, &titles);
Player *target = handler->getSelectedPlayer();
if (!target)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
// check online security
if (handler->HasLowerSecurity(target, 0))
return false;
uint64 titles2 = titles;
for (uint32 i = 1; i < sCharTitlesStore.GetNumRows(); ++i)
if (CharTitlesEntry const* tEntry = sCharTitlesStore.LookupEntry(i))
titles2 &= ~(uint64(1) << tEntry->bit_index);
titles &= ~titles2; // remove not existed titles
target->SetUInt64Value(PLAYER__FIELD_KNOWN_TITLES, titles);
handler->SendSysMessage(LANG_DONE);
if (!target->HasTitle(target->GetInt32Value(PLAYER_CHOSEN_TITLE)))
{
target->SetUInt32Value(PLAYER_CHOSEN_TITLE,0);
handler->PSendSysMessage(LANG_CURRENT_TITLE_RESET,handler->GetNameLink(target).c_str());
}
return true;
}
Player * target = handler->getSelectedPlayer();
if (!target)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
// check online security
if (handler->HasLowerSecurity(target, 0))
return false;
CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id);
if (!titleInfo)
{
handler->PSendSysMessage(LANG_INVALID_TITLE_ID, id);
handler->SetSentErrorMessage(true);
return false;
}
std::string tNameLink = handler->GetNameLink(target);
char const* targetName = target->GetName();
char titleNameStr[80];
snprintf(titleNameStr,80,titleInfo->name[handler->GetSessionDbcLocale()],targetName);
target->SetTitle(titleInfo);
handler->PSendSysMessage(LANG_TITLE_ADD_RES, id, titleNameStr, tNameLink.c_str());
return true;
}
static bool HandleTitlesRemoveCommand(ChatHandler* handler, const char* args)
{
// number or [name] Shift-click form |color|Htitle:title_id|h[name]|h|r
char* id_p = handler->extractKeyFromLink((char*)args,"Htitle");
if (!id_p)
return false;
int32 id = atoi(id_p);
if (id <= 0)
{
handler->PSendSysMessage(LANG_INVALID_TITLE_ID, id);
handler->SetSentErrorMessage(true);
return false;
}
Player * target = handler->getSelectedPlayer();
if (!target)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
// check online security
if (handler->HasLowerSecurity(target, 0))
return false;
CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id);
if (!titleInfo)
{
handler->PSendSysMessage(LANG_INVALID_TITLE_ID, id);
handler->SetSentErrorMessage(true);
return false;
}
target->SetTitle(titleInfo,true);
std::string tNameLink = handler->GetNameLink(target);
char const* targetName = target->GetName();
char titleNameStr[80];
snprintf(titleNameStr,80,titleInfo->name[handler->GetSessionDbcLocale()],targetName);
handler->PSendSysMessage(LANG_TITLE_REMOVE_RES, id, titleNameStr, tNameLink.c_str());
if (!target->HasTitle(target->GetInt32Value(PLAYER_CHOSEN_TITLE)))
{
target->SetUInt32Value(PLAYER_CHOSEN_TITLE,0);
handler->PSendSysMessage(LANG_CURRENT_TITLE_RESET, tNameLink.c_str());
}
return true;
}
//Edit Player KnownTitles
static bool HandleTitlesSetMaskCommand(ChatHandler* handler, const char* args)
{
if (!*args)
return false;
uint64 titles = 0;
sscanf((char*)args, UI64FMTD, &titles);
Player *target = handler->getSelectedPlayer();
if (!target)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
// check online security
if (handler->HasLowerSecurity(target, 0))
return false;
uint64 titles2 = titles;
for (uint32 i = 1; i < sCharTitlesStore.GetNumRows(); ++i)
if (CharTitlesEntry const* tEntry = sCharTitlesStore.LookupEntry(i))
titles2 &= ~(uint64(1) << tEntry->bit_index);
titles &= ~titles2; // remove not existed titles
target->SetUInt64Value(PLAYER__FIELD_KNOWN_TITLES, titles);
handler->SendSysMessage(LANG_DONE);
if (!target->HasTitle(target->GetInt32Value(PLAYER_CHOSEN_TITLE)))
{
target->SetUInt32Value(PLAYER_CHOSEN_TITLE,0);
handler->PSendSysMessage(LANG_CURRENT_TITLE_RESET,handler->GetNameLink(target).c_str());
}
return true;
}
};
void AddSC_titles_commandscript()
File diff suppressed because it is too large Load Diff