First Commit

For Azeroth!
This commit is contained in:
Yehonal
2016-06-26 10:39:44 +02:00
commit e8e94a0a66
3777 changed files with 1419268 additions and 0 deletions
+111
View File
@@ -0,0 +1,111 @@
# Copyright (C)
#
# This file is free software; as a special exception the author gives
# unlimited permission to copy and/or distribute it, with or without
# modifications, as long as this notice is preserved.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
set(scripts_STAT_SRCS
${scripts_STAT_SRCS}
Commands/cs_account.cpp
Commands/cs_achievement.cpp
Commands/cs_ban.cpp
Commands/cs_bf.cpp
Commands/cs_cast.cpp
Commands/cs_character.cpp
Commands/cs_debug.cpp
Commands/cs_event.cpp
Commands/cs_gm.cpp
Commands/cs_go.cpp
Commands/cs_gobject.cpp
Commands/cs_guild.cpp
Commands/cs_honor.cpp
Commands/cs_instance.cpp
Commands/cs_learn.cpp
Commands/cs_lfg.cpp
Commands/cs_list.cpp
Commands/cs_lookup.cpp
Commands/cs_message.cpp
Commands/cs_misc.cpp
Commands/cs_modify.cpp
Commands/cs_npc.cpp
Commands/cs_quest.cpp
Commands/cs_reload.cpp
Commands/cs_reset.cpp
Commands/cs_tele.cpp
Commands/cs_server.cpp
Commands/cs_ticket.cpp
Commands/cs_titles.cpp
Commands/cs_wp.cpp
Commands/cs_spectator.cpp
# Commands/cs_pdump.cpp
# Commands/cs_channel.cpp
# Commands/cs_pet.cpp
# Commands/cs_aura.cpp
# Commands/cs_unaura.cpp
# Commands/cs_nameannounce.cpp
# Commands/cs_gmnameannounce.cpp
# Commands/cs_announce.cpp
# Commands/cs_gmannounce.cpp
# Commands/cs_notify.cpp
# Commands/cs_gmnotify.cpp
# Commands/cs_appear.cpp
# Commands/cs_summon.cpp
# Commands/cs_groupsummon.cpp
# Commands/cs_commands.cpp
# Commands/cs_demorph.cpp
# Commands/cs_die.cpp
# Commands/cs_revive.cpp
# Commands/cs_dismount.cpp
# Commands/cs_guid.cpp
# Commands/cs_help.cpp
# Commands/cs_itemmove.cpp
# Commands/cs_cooldown.cpp
# Commands/cs_unlearn.cpp
# Commands/cs_distance.cpp
# Commands/cs_recall.cpp
# Commands/cs_save.cpp
# Commands/cs_saveall.cpp
# Commands/cs_kick.cpp
# Commands/cs_start.cpp
# Commands/cs_taxicheat.cpp
# Commands/cs_linkgrave.cpp
# Commands/cs_neargrave.cpp
# Commands/cs_explorecheat.cpp
# Commands/cs_hover.cpp
# Commands/cs_levelup.cpp
# Commands/cs_showarea.cpp
# Commands/cs_hidearea.cpp
# Commands/cs_additem.cpp
# Commands/cs_additemset.cpp
# Commands/cs_bank.cpp
# Commands/cs_wchange.cpp
# Commands/cs_maxskill.cpp
# Commands/cs_setskill.cpp
# Commands/cs_whispers.cpp
# Commands/cs_pinfo.cpp
# Commands/cs_respawn.cpp
# Commands/cs_send.cpp
# Commands/cs_mute.cpp
# Commands/cs_unmute.cpp
# Commands/cs_movegens.cpp
# Commands/cs_cometome.cpp
# Commands/cs_damage.cpp
# Commands/cs_combatstop.cpp
# Commands/cs_flusharenapoints.cpp
# Commands/cs_repairitems.cpp
# Commands/cs_waterwalk.cpp
# Commands/cs_freeze.cpp
# Commands/cs_unfreeze.cpp
# Commands/cs_listfreeze.cpp
# Commands/cs_possess.cpp
# Commands/cs_unpossess.cpp
# Commands/cs_bindsight.cpp
# Commands/cs_unbindsight.cpp
# Commands/cs_playall.cpp
)
message(" -> Prepared: Commands")
@@ -0,0 +1,57 @@
/*
* Copyright (C)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* ScriptData
Name: account_commandscript
%Complete: 100
Comment: All account related commands
Category: commandscripts
EndScriptData */
#include "AccountMgr.h"
#include "Chat.h"
#include "Language.h"
#include "Player.h"
#include "ScriptMgr.h"
class account_commandscript : public CommandScript
{
public:
account_commandscript() : CommandScript("account_commandscript") { }
ChatCommand* GetCommands() const
{
static ChatCommand commandTable[] =
{
{ "account", SEC_PLAYER, false, &HandleAccountCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}
static bool HandleAccountCommand(ChatHandler* handler, char const* /*args*/)
{
AccountTypes gmLevel = handler->GetSession()->GetSecurity();
handler->PSendSysMessage(LANG_ACCOUNT_LEVEL, uint32(gmLevel));
return true;
}
};
void AddSC_account_commandscript()
{
new account_commandscript();
}
@@ -0,0 +1,97 @@
/*
* Copyright (C)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* ScriptData
Name: achievement_commandscript
%Complete: 100
Comment: All achievement related commands
Category: commandscripts
EndScriptData */
#include "Chat.h"
#include "Language.h"
#include "Player.h"
#include "ScriptMgr.h"
class achievement_commandscript : public CommandScript
{
public:
achievement_commandscript() : CommandScript("achievement_commandscript") { }
ChatCommand* GetCommands() const
{
static ChatCommand achievementCommandTable[] =
{
{ "add", SEC_ADMINISTRATOR, false, &HandleAchievementAddCommand, "", NULL },
{ "checkall", SEC_ADMINISTRATOR, false, &HandleAchievementCheckAllCommand, "", 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, char const* args)
{
if (!*args)
return false;
uint32 achievementId = atoi((char*)args);
if (!achievementId)
{
if (char* id = handler->extractKeyFromLink((char*)args, "Hachievement"))
achievementId = atoi(id);
if (!achievementId)
return false;
}
Player* target = handler->getSelectedPlayer();
if (!target)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
if (AchievementEntry const* achievementEntry = sAchievementStore.LookupEntry(achievementId))
target->CompletedAchievement(achievementEntry);
return true;
}
static bool HandleAchievementCheckAllCommand(ChatHandler* handler, char const* args)
{
Player* target = handler->getSelectedPlayer();
if (!target)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
target->CheckAllAchievementCriteria();
return true;
}
};
void AddSC_achievement_commandscript()
{
new achievement_commandscript();
}
+724
View File
@@ -0,0 +1,724 @@
/*
* Copyright (C)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* ScriptData
Name: ban_commandscript
%Complete: 100
Comment: All ban related commands
Category: commandscripts
EndScriptData */
#include "AccountMgr.h"
#include "Chat.h"
#include "Language.h"
#include "ObjectAccessor.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "ScriptMgr.h"
class ban_commandscript : public CommandScript
{
public:
ban_commandscript() : CommandScript("ban_commandscript") { }
ChatCommand* GetCommands() const
{
static ChatCommand unbanCommandTable[] =
{
{ "account", SEC_ADMINISTRATOR, true, &HandleUnBanAccountCommand, "", NULL },
{ "character", SEC_ADMINISTRATOR, true, &HandleUnBanCharacterCommand, "", NULL },
{ "playeraccount", SEC_ADMINISTRATOR, true, &HandleUnBanAccountByCharCommand, "", NULL },
{ "ip", SEC_ADMINISTRATOR, true, &HandleUnBanIPCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand banlistCommandTable[] =
{
{ "account", SEC_ADMINISTRATOR, true, &HandleBanListAccountCommand, "", NULL },
{ "character", SEC_ADMINISTRATOR, true, &HandleBanListCharacterCommand, "", NULL },
{ "ip", SEC_ADMINISTRATOR, true, &HandleBanListIPCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand baninfoCommandTable[] =
{
{ "account", SEC_ADMINISTRATOR, true, &HandleBanInfoAccountCommand, "", NULL },
{ "character", SEC_ADMINISTRATOR, true, &HandleBanInfoCharacterCommand, "", NULL },
{ "ip", SEC_ADMINISTRATOR, true, &HandleBanInfoIPCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand banCommandTable[] =
{
{ "account", SEC_ADMINISTRATOR, true, &HandleBanAccountCommand, "", NULL },
{ "character", SEC_ADMINISTRATOR, true, &HandleBanCharacterCommand, "", NULL },
{ "playeraccount", SEC_ADMINISTRATOR, true, &HandleBanAccountByCharCommand, "", NULL },
{ "ip", SEC_ADMINISTRATOR, true, &HandleBanIPCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "ban", SEC_ADMINISTRATOR, true, NULL, "", banCommandTable },
{ "baninfo", SEC_ADMINISTRATOR, true, NULL, "", baninfoCommandTable },
{ "banlist", SEC_ADMINISTRATOR, true, NULL, "", banlistCommandTable },
{ "unban", SEC_ADMINISTRATOR, true, NULL, "", unbanCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}
static bool HandleBanAccountCommand(ChatHandler* handler, char const* args)
{
return HandleBanHelper(BAN_ACCOUNT, args, handler);
}
static bool HandleBanCharacterCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
char* nameStr = strtok((char*)args, " ");
if (!nameStr)
return false;
std::string name = nameStr;
char* durationStr = strtok(NULL, " ");
if (!durationStr || !atoi(durationStr))
return false;
char* reasonStr = strtok(NULL, "");
if (!reasonStr)
return false;
if (!normalizePlayerName(name))
{
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
handler->SetSentErrorMessage(true);
return false;
}
switch (sWorld->BanCharacter(name, durationStr, reasonStr, handler->GetSession() ? handler->GetSession()->GetPlayerName() : ""))
{
case BAN_SUCCESS:
{
if (atoi(durationStr) > 0)
handler->PSendSysMessage(LANG_BAN_YOUBANNED, name.c_str(), secsToTimeString(TimeStringToSecs(durationStr), true).c_str(), reasonStr);
else
handler->PSendSysMessage(LANG_BAN_YOUPERMBANNED, name.c_str(), reasonStr);
break;
}
case BAN_NOTFOUND:
{
handler->PSendSysMessage(LANG_BAN_NOTFOUND, "character", name.c_str());
handler->SetSentErrorMessage(true);
return false;
}
default:
break;
}
return true;
}
static bool HandleBanAccountByCharCommand(ChatHandler* handler, char const* args)
{
return HandleBanHelper(BAN_CHARACTER, args, handler);
}
static bool HandleBanIPCommand(ChatHandler* handler, char const* args)
{
return HandleBanHelper(BAN_IP, args, handler);
}
static bool HandleBanHelper(BanMode mode, char const* args, ChatHandler* handler)
{
if (!*args)
return false;
char* cnameOrIP = strtok((char*)args, " ");
if (!cnameOrIP)
return false;
std::string nameOrIP = cnameOrIP;
char* durationStr = strtok(NULL, " ");
if (!durationStr || !atoi(durationStr))
return false;
char* reasonStr = strtok(NULL, "");
if (!reasonStr)
return false;
switch (mode)
{
case BAN_ACCOUNT:
if (!AccountMgr::normalizeString(nameOrIP))
{
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, nameOrIP.c_str());
handler->SetSentErrorMessage(true);
return false;
}
break;
case BAN_CHARACTER:
if (!normalizePlayerName(nameOrIP))
{
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
handler->SetSentErrorMessage(true);
return false;
}
break;
case BAN_IP:
if (!IsIPAddress(nameOrIP.c_str()))
return false;
break;
}
switch (sWorld->BanAccount(mode, nameOrIP, durationStr, reasonStr, handler->GetSession() ? handler->GetSession()->GetPlayerName() : ""))
{
case BAN_SUCCESS:
if (atoi(durationStr) > 0)
handler->PSendSysMessage(LANG_BAN_YOUBANNED, nameOrIP.c_str(), secsToTimeString(TimeStringToSecs(durationStr), true).c_str(), reasonStr);
else
handler->PSendSysMessage(LANG_BAN_YOUPERMBANNED, nameOrIP.c_str(), reasonStr);
break;
case BAN_SYNTAX_ERROR:
return false;
case BAN_NOTFOUND:
switch (mode)
{
default:
handler->PSendSysMessage(LANG_BAN_NOTFOUND, "account", nameOrIP.c_str());
break;
case BAN_CHARACTER:
handler->PSendSysMessage(LANG_BAN_NOTFOUND, "character", nameOrIP.c_str());
break;
case BAN_IP:
handler->PSendSysMessage(LANG_BAN_NOTFOUND, "ip", nameOrIP.c_str());
break;
}
handler->SetSentErrorMessage(true);
return false;
case BAN_LONGER_EXISTS:
handler->PSendSysMessage("Unsuccessful! A longer ban is already present on this account!");
break;
}
return true;
}
static bool HandleBanInfoAccountCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
char* nameStr = strtok((char*)args, "");
if (!nameStr)
return false;
std::string accountName = nameStr;
if (!AccountMgr::normalizeString(accountName))
{
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
handler->SetSentErrorMessage(true);
return false;
}
uint32 accountId = AccountMgr::GetId(accountName);
if (!accountId)
{
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
return true;
}
return HandleBanInfoHelper(accountId, accountName.c_str(), handler);
}
static bool HandleBanInfoHelper(uint32 accountId, char const* accountName, ChatHandler* handler)
{
QueryResult result = LoginDatabase.PQuery("SELECT FROM_UNIXTIME(bandate, '%%Y-%%m-%%d..%%H:%%I:%%s') as bandate, unbandate-bandate, active, unbandate, banreason, bannedby FROM account_banned WHERE id = '%u' ORDER BY bandate ASC", accountId);
if (!result)
{
handler->PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN, accountName);
return true;
}
handler->PSendSysMessage(LANG_BANINFO_BANHISTORY, accountName);
do
{
Field* fields = result->Fetch();
time_t unbanDate = time_t(fields[3].GetUInt32());
bool active = false;
if (fields[2].GetBool() && (fields[1].GetUInt64() == uint64(0) || unbanDate >= time(NULL)))
active = true;
bool permanent = (fields[1].GetUInt64() == uint64(0));
std::string banTime = permanent ? handler->GetTrinityString(LANG_BANINFO_INFINITE) : secsToTimeString(fields[1].GetUInt64(), true);
handler->PSendSysMessage(LANG_BANINFO_HISTORYENTRY,
fields[0].GetCString(), banTime.c_str(), active ? handler->GetTrinityString(LANG_BANINFO_YES) : handler->GetTrinityString(LANG_BANINFO_NO), fields[4].GetCString(), fields[5].GetCString());
}
while (result->NextRow());
return true;
}
static bool HandleBanInfoCharacterCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
Player* target = ObjectAccessor::FindPlayerByName(args, false);
uint32 targetGuid = 0;
std::string name(args);
if (!target)
{
targetGuid = sWorld->GetGlobalPlayerGUID(name);
if (!targetGuid)
{
handler->PSendSysMessage(LANG_BANINFO_NOCHARACTER);
return false;
}
}
else
targetGuid = target->GetGUIDLow();
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_BANINFO);
stmt->setUInt32(0, targetGuid);
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (!result)
{
handler->PSendSysMessage(LANG_CHAR_NOT_BANNED, name.c_str());
return true;
}
handler->PSendSysMessage(LANG_BANINFO_BANHISTORY, name.c_str());
do
{
Field* fields = result->Fetch();
time_t unbanDate = time_t(fields[3].GetUInt32());
bool active = false;
if (fields[2].GetUInt8() && (!fields[1].GetUInt32() || unbanDate >= time(NULL)))
active = true;
bool permanent = (fields[1].GetUInt32() == uint32(0));
std::string banTime = permanent ? handler->GetTrinityString(LANG_BANINFO_INFINITE) : secsToTimeString(fields[1].GetUInt64(), true);
handler->PSendSysMessage(LANG_BANINFO_HISTORYENTRY,
fields[0].GetCString(), banTime.c_str(), active ? handler->GetTrinityString(LANG_BANINFO_YES) : handler->GetTrinityString(LANG_BANINFO_NO), fields[4].GetCString(), fields[5].GetCString());
}
while (result->NextRow());
return true;
}
static bool HandleBanInfoIPCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
char* ipStr = strtok((char*)args, "");
if (!ipStr)
return false;
if (!IsIPAddress(ipStr))
return false;
std::string IP = ipStr;
LoginDatabase.EscapeString(IP);
QueryResult result = LoginDatabase.PQuery("SELECT ip, FROM_UNIXTIME(bandate), FROM_UNIXTIME(unbandate), unbandate-UNIX_TIMESTAMP(), banreason, bannedby, unbandate-bandate FROM ip_banned WHERE ip = '%s'", IP.c_str());
if (!result)
{
handler->PSendSysMessage(LANG_BANINFO_NOIP);
return true;
}
Field* fields = result->Fetch();
bool permanent = !fields[6].GetUInt64();
handler->PSendSysMessage(LANG_BANINFO_IPENTRY,
fields[0].GetCString(), fields[1].GetCString(), permanent ? handler->GetTrinityString(LANG_BANINFO_NEVER) : fields[2].GetCString(),
permanent ? handler->GetTrinityString(LANG_BANINFO_INFINITE) : secsToTimeString(fields[3].GetUInt64(), true).c_str(), fields[4].GetCString(), fields[5].GetCString());
return true;
}
static bool HandleBanListAccountCommand(ChatHandler* handler, char const* args)
{
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_EXPIRED_IP_BANS);
LoginDatabase.Execute(stmt);
char* filterStr = strtok((char*)args, " ");
std::string filter = filterStr ? filterStr : "";
PreparedQueryResult result;
if (filter.empty())
{
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_BANNED_ALL);
result = LoginDatabase.Query(stmt);
}
else
{
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_BANNED_BY_USERNAME);
stmt->setString(0, filter);
result = LoginDatabase.Query(stmt);
}
if (!result)
{
handler->PSendSysMessage(LANG_BANLIST_NOACCOUNT);
return true;
}
return HandleBanListHelper(result, handler);
}
static bool HandleBanListHelper(PreparedQueryResult result, ChatHandler* handler)
{
handler->PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT);
// Chat short output
if (handler->GetSession())
{
do
{
Field* fields = result->Fetch();
uint32 accountid = fields[0].GetUInt32();
QueryResult banResult = LoginDatabase.PQuery("SELECT account.username FROM account, account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id", accountid);
if (banResult)
{
Field* fields2 = banResult->Fetch();
handler->PSendSysMessage("%s", fields2[0].GetCString());
}
}
while (result->NextRow());
}
// Console wide output
else
{
handler->SendSysMessage(LANG_BANLIST_ACCOUNTS);
handler->SendSysMessage(" ===============================================================================");
handler->SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER);
do
{
handler->SendSysMessage("-------------------------------------------------------------------------------");
Field* fields = result->Fetch();
uint32 accountId = fields[0].GetUInt32();
std::string accountName;
// "account" case, name can be get in same query
if (result->GetFieldCount() > 1)
accountName = fields[1].GetString();
// "character" case, name need extract from another DB
else
AccountMgr::GetName(accountId, accountName);
// No SQL injection. id is uint32.
QueryResult banInfo = LoginDatabase.PQuery("SELECT bandate, unbandate, bannedby, banreason FROM account_banned WHERE id = %u ORDER BY unbandate", accountId);
if (banInfo)
{
Field* fields2 = banInfo->Fetch();
do
{
time_t timeBan = time_t(fields2[0].GetUInt32());
tm tmBan;
ACE_OS::localtime_r(&timeBan, &tmBan);
if (fields2[0].GetUInt32() == fields2[1].GetUInt32())
{
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
accountName.c_str(), tmBan.tm_year%100, tmBan.tm_mon+1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min,
fields2[2].GetCString(), fields2[3].GetCString());
}
else
{
time_t timeUnban = time_t(fields2[1].GetUInt32());
tm tmUnban;
ACE_OS::localtime_r(&timeUnban, &tmUnban);
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
accountName.c_str(), tmBan.tm_year%100, tmBan.tm_mon+1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min,
tmUnban.tm_year%100, tmUnban.tm_mon+1, tmUnban.tm_mday, tmUnban.tm_hour, tmUnban.tm_min,
fields2[2].GetCString(), fields2[3].GetCString());
}
}
while (banInfo->NextRow());
}
}
while (result->NextRow());
handler->SendSysMessage(" ===============================================================================");
}
return true;
}
static bool HandleBanListCharacterCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
char* filterStr = strtok((char*)args, " ");
if (!filterStr)
return false;
std::string filter(filterStr);
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GUID_BY_NAME_FILTER);
stmt->setString(0, filter);
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (!result)
{
handler->PSendSysMessage(LANG_BANLIST_NOCHARACTER);
return true;
}
handler->PSendSysMessage(LANG_BANLIST_MATCHINGCHARACTER);
// Chat short output
if (handler->GetSession())
{
do
{
Field* fields = result->Fetch();
PreparedStatement* stmt2 = CharacterDatabase.GetPreparedStatement(CHAR_SEL_BANNED_NAME);
stmt2->setUInt32(0, fields[0].GetUInt32());
PreparedQueryResult banResult = CharacterDatabase.Query(stmt2);
if (banResult)
handler->PSendSysMessage("%s", (*banResult)[0].GetCString());
}
while (result->NextRow());
}
// Console wide output
else
{
handler->SendSysMessage(LANG_BANLIST_CHARACTERS);
handler->SendSysMessage(" =============================================================================== ");
handler->SendSysMessage(LANG_BANLIST_CHARACTERS_HEADER);
do
{
handler->SendSysMessage("-------------------------------------------------------------------------------");
Field* fields = result->Fetch();
std::string char_name = fields[1].GetString();
PreparedStatement* stmt2 = CharacterDatabase.GetPreparedStatement(CHAR_SEL_BANINFO_LIST);
stmt2->setUInt32(0, fields[0].GetUInt32());
PreparedQueryResult banInfo = CharacterDatabase.Query(stmt2);
if (banInfo)
{
Field* banFields = banInfo->Fetch();
do
{
time_t timeBan = time_t(banFields[0].GetUInt32());
tm tmBan;
ACE_OS::localtime_r(&timeBan, &tmBan);
if (banFields[0].GetUInt32() == banFields[1].GetUInt32())
{
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
char_name.c_str(), tmBan.tm_year%100, tmBan.tm_mon+1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min,
banFields[2].GetCString(), banFields[3].GetCString());
}
else
{
time_t timeUnban = time_t(banFields[1].GetUInt32());
tm tmUnban;
ACE_OS::localtime_r(&timeUnban, &tmUnban);
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
char_name.c_str(), tmBan.tm_year%100, tmBan.tm_mon+1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min,
tmUnban.tm_year%100, tmUnban.tm_mon+1, tmUnban.tm_mday, tmUnban.tm_hour, tmUnban.tm_min,
banFields[2].GetCString(), banFields[3].GetCString());
}
}
while (banInfo->NextRow());
}
}
while (result->NextRow());
handler->SendSysMessage(" =============================================================================== ");
}
return true;
}
static bool HandleBanListIPCommand(ChatHandler* handler, char const* args)
{
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_EXPIRED_IP_BANS);
LoginDatabase.Execute(stmt);
char* filterStr = strtok((char*)args, " ");
std::string filter = filterStr ? filterStr : "";
LoginDatabase.EscapeString(filter);
PreparedQueryResult result;
if (filter.empty())
{
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_IP_BANNED_ALL);
result = LoginDatabase.Query(stmt);
}
else
{
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_IP_BANNED_BY_IP);
stmt->setString(0, filter);
result = LoginDatabase.Query(stmt);
}
if (!result)
{
handler->PSendSysMessage(LANG_BANLIST_NOIP);
return true;
}
handler->PSendSysMessage(LANG_BANLIST_MATCHINGIP);
// Chat short output
if (handler->GetSession())
{
do
{
Field* fields = result->Fetch();
handler->PSendSysMessage("%s", fields[0].GetCString());
}
while (result->NextRow());
}
// Console wide output
else
{
handler->SendSysMessage(LANG_BANLIST_IPS);
handler->SendSysMessage(" ===============================================================================");
handler->SendSysMessage(LANG_BANLIST_IPS_HEADER);
do
{
handler->SendSysMessage("-------------------------------------------------------------------------------");
Field* fields = result->Fetch();
time_t timeBan = time_t(fields[1].GetUInt32());
tm tmBan;
ACE_OS::localtime_r(&timeBan, &tmBan);
if (fields[1].GetUInt32() == fields[2].GetUInt32())
{
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
fields[0].GetCString(), tmBan.tm_year%100, tmBan.tm_mon+1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min,
fields[3].GetCString(), fields[4].GetCString());
}
else
{
time_t timeUnban = time_t(fields[2].GetUInt32());
tm tmUnban;
ACE_OS::localtime_r(&timeUnban, &tmUnban);
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
fields[0].GetCString(), tmBan.tm_year%100, tmBan.tm_mon+1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min,
tmUnban.tm_year%100, tmUnban.tm_mon+1, tmUnban.tm_mday, tmUnban.tm_hour, tmUnban.tm_min,
fields[3].GetCString(), fields[4].GetCString());
}
}
while (result->NextRow());
handler->SendSysMessage(" ===============================================================================");
}
return true;
}
static bool HandleUnBanAccountCommand(ChatHandler* handler, char const* args)
{
return HandleUnBanHelper(BAN_ACCOUNT, args, handler);
}
static bool HandleUnBanCharacterCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
char* nameStr = strtok((char*)args, " ");
if (!nameStr)
return false;
std::string name = nameStr;
if (!normalizePlayerName(name))
{
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
handler->SetSentErrorMessage(true);
return false;
}
if (!sWorld->RemoveBanCharacter(name))
{
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
handler->SetSentErrorMessage(true);
return false;
}
return true;
}
static bool HandleUnBanAccountByCharCommand(ChatHandler* handler, char const* args)
{
return HandleUnBanHelper(BAN_CHARACTER, args, handler);
}
static bool HandleUnBanIPCommand(ChatHandler* handler, char const* args)
{
return HandleUnBanHelper(BAN_IP, args, handler);
}
static bool HandleUnBanHelper(BanMode mode, char const* args, ChatHandler* handler)
{
if (!*args)
return false;
char* nameOrIPStr = strtok((char*)args, " ");
if (!nameOrIPStr)
return false;
std::string nameOrIP = nameOrIPStr;
switch (mode)
{
case BAN_ACCOUNT:
if (!AccountMgr::normalizeString(nameOrIP))
{
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, nameOrIP.c_str());
handler->SetSentErrorMessage(true);
return false;
}
break;
case BAN_CHARACTER:
if (!normalizePlayerName(nameOrIP))
{
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
handler->SetSentErrorMessage(true);
return false;
}
break;
case BAN_IP:
if (!IsIPAddress(nameOrIP.c_str()))
return false;
break;
}
if (sWorld->RemoveBanAccount(mode, nameOrIP))
handler->PSendSysMessage(LANG_UNBAN_UNBANNED, nameOrIP.c_str());
else
handler->PSendSysMessage(LANG_UNBAN_ERROR, nameOrIP.c_str());
return true;
}
};
void AddSC_ban_commandscript()
{
new ban_commandscript();
}
+180
View File
@@ -0,0 +1,180 @@
/*
* Copyright (C)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* ScriptData
Name: bf_commandscript
%Complete: 100
Comment: All bf related commands
Category: commandscripts
EndScriptData */
#include "ScriptMgr.h"
#include "Chat.h"
#include "BattlefieldMgr.h"
class bf_commandscript : public CommandScript
{
public:
bf_commandscript() : CommandScript("bf_commandscript") { }
ChatCommand* GetCommands() const
{
static ChatCommand battlefieldcommandTable[] =
{
{ "start", SEC_ADMINISTRATOR, false, &HandleBattlefieldStart, "", NULL },
{ "stop", SEC_ADMINISTRATOR, false, &HandleBattlefieldEnd, "", NULL },
{ "switch", SEC_ADMINISTRATOR, false, &HandleBattlefieldSwitch, "", NULL },
{ "timer", SEC_ADMINISTRATOR, false, &HandleBattlefieldTimer, "", NULL },
{ "enable", SEC_ADMINISTRATOR, false, &HandleBattlefieldEnable, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "bf", SEC_ADMINISTRATOR, false, NULL, "", battlefieldcommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}
static bool HandleBattlefieldStart(ChatHandler* handler, const char* args)
{
uint32 battleid = 0;
char* battleid_str = strtok((char*)args, " ");
if (!battleid_str)
return false;
battleid = atoi(battleid_str);
Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleid);
if (!bf)
return false;
bf->StartBattle();
if (battleid == 1)
handler->SendGlobalGMSysMessage("Wintergrasp (Command start used)");
return true;
}
static bool HandleBattlefieldEnd(ChatHandler* handler, const char* args)
{
uint32 battleid = 0;
char* battleid_str = strtok((char*)args, " ");
if (!battleid_str)
return false;
battleid = atoi(battleid_str);
Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleid);
if (!bf)
return false;
bf->EndBattle(true);
if (battleid == 1)
handler->SendGlobalGMSysMessage("Wintergrasp (Command stop used)");
return true;
}
static bool HandleBattlefieldEnable(ChatHandler* handler, const char* args)
{
uint32 battleid = 0;
char* battleid_str = strtok((char*)args, " ");
if (!battleid_str)
return false;
battleid = atoi(battleid_str);
Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleid);
if (!bf)
return false;
if (bf->IsEnabled())
{
bf->ToggleBattlefield(false);
if (battleid == 1)
handler->SendGlobalGMSysMessage("Wintergrasp is disabled");
}
else
{
bf->ToggleBattlefield(true);
if (battleid == 1)
handler->SendGlobalGMSysMessage("Wintergrasp is enabled");
}
return true;
}
static bool HandleBattlefieldSwitch(ChatHandler* handler, const char* args)
{
uint32 battleid = 0;
char* battleid_str = strtok((char*)args, " ");
if (!battleid_str)
return false;
battleid = atoi(battleid_str);
Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleid);
if (!bf)
return false;
bf->EndBattle(false);
if (battleid == 1)
handler->SendGlobalGMSysMessage("Wintergrasp (Command switch used)");
return true;
}
static bool HandleBattlefieldTimer(ChatHandler* handler, const char* args)
{
uint32 battleid = 0;
uint32 time = 0;
char* battleid_str = strtok((char*)args, " ");
if (!battleid_str)
return false;
char* time_str = strtok(NULL, " ");
if (!time_str)
return false;
battleid = atoi(battleid_str);
time = atoi(time_str);
Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleid);
if (!bf)
return false;
bf->SetTimer(time * IN_MILLISECONDS);
bf->SendInitWorldStatesToAll();
if (battleid == 1)
handler->SendGlobalGMSysMessage("Wintergrasp (Command timer used)");
return true;
}
};
void AddSC_bf_commandscript()
{
new bf_commandscript();
}
+414
View File
@@ -0,0 +1,414 @@
/*
* Copyright (C)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* ScriptData
Name: cast_commandscript
%Complete: 100
Comment: All cast related commands
Category: commandscripts
EndScriptData */
#include "ScriptMgr.h"
#include "Chat.h"
#include "Creature.h"
#include "Language.h"
#include "Player.h"
class cast_commandscript : public CommandScript
{
public:
cast_commandscript() : CommandScript("cast_commandscript") { }
ChatCommand* GetCommands() const
{
static ChatCommand castCommandTable[] =
{
{ "back", SEC_ADMINISTRATOR, false, &HandleCastBackCommand, "", NULL },
{ "dist", SEC_ADMINISTRATOR, false, &HandleCastDistCommand, "", NULL },
{ "self", SEC_ADMINISTRATOR, false, &HandleCastSelfCommand, "", NULL },
{ "target", SEC_ADMINISTRATOR, false, &HandleCastTargetCommad, "", NULL },
{ "dest", SEC_ADMINISTRATOR, false, &HandleCastDestCommand, "", NULL },
{ "", SEC_ADMINISTRATOR, false, &HandleCastCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "cast", SEC_ADMINISTRATOR, false, NULL, "", castCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}
static bool HandleCastCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
Unit* target = handler->getSelectedUnit();
if (!target)
{
handler->SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
handler->SetSentErrorMessage(true);
return false;
}
// number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
uint32 spellId = handler->extractSpellIdFromLink((char*)args);
if (!spellId)
return false;
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
if (!spellInfo)
{
handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND);
handler->SetSentErrorMessage(true);
return false;
}
if (!SpellMgr::IsSpellValid(spellInfo))
{
handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spellId);
handler->SetSentErrorMessage(true);
return false;
}
SpellScriptsBounds bounds = sObjectMgr->GetSpellScriptsBounds(spellId);
uint32 spellDifficultyId = sSpellMgr->GetSpellDifficultyId(spellId);
if (handler->GetSession()->GetSecurity() < SEC_CONSOLE && (bounds.first != bounds.second || spellDifficultyId || spellInfo->HasEffect(SPELL_EFFECT_SKILL_STEP) || spellInfo->HasEffect(SPELL_EFFECT_TRADE_SKILL)))
{
handler->PSendSysMessage("Spell %u cannot be casted using a command!", spellId);
handler->SetSentErrorMessage(true);
return false;
}
char* triggeredStr = strtok(NULL, " ");
if (triggeredStr)
{
int l = strlen(triggeredStr);
if (strncmp(triggeredStr, "triggered", l) != 0)
return false;
}
bool triggered = (triggeredStr != NULL);
handler->GetSession()->GetPlayer()->CastSpell(target, spellId, triggered);
return true;
}
static bool HandleCastBackCommand(ChatHandler* handler, char const* args)
{
Creature* caster = handler->getSelectedCreature();
if (!caster)
{
handler->SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
handler->SetSentErrorMessage(true);
return false;
}
// number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
// number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
uint32 spellId = handler->extractSpellIdFromLink((char*)args);
if (!spellId)
return false;
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
if (!spellInfo)
{
handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND);
handler->SetSentErrorMessage(true);
return false;
}
if (!SpellMgr::IsSpellValid(spellInfo))
{
handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spellId);
handler->SetSentErrorMessage(true);
return false;
}
SpellScriptsBounds bounds = sObjectMgr->GetSpellScriptsBounds(spellId);
uint32 spellDifficultyId = sSpellMgr->GetSpellDifficultyId(spellId);
if (handler->GetSession()->GetSecurity() < SEC_CONSOLE && (bounds.first != bounds.second || spellDifficultyId || spellInfo->HasEffect(SPELL_EFFECT_SKILL_STEP) || spellInfo->HasEffect(SPELL_EFFECT_TRADE_SKILL)))
{
handler->PSendSysMessage("Spell %u cannot be casted using a command!", spellId);
handler->SetSentErrorMessage(true);
return false;
}
char* triggeredStr = strtok(NULL, " ");
if (triggeredStr)
{
int l = strlen(triggeredStr);
if (strncmp(triggeredStr, "triggered", l) != 0)
return false;
}
bool triggered = (triggeredStr != NULL);
caster->CastSpell(handler->GetSession()->GetPlayer(), spellId, triggered);
return true;
}
static bool HandleCastDistCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
// number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
uint32 spellId = handler->extractSpellIdFromLink((char*)args);
if (!spellId)
return false;
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
if (!spellInfo)
{
handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND);
handler->SetSentErrorMessage(true);
return false;
}
if (!SpellMgr::IsSpellValid(spellInfo))
{
handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spellId);
handler->SetSentErrorMessage(true);
return false;
}
SpellScriptsBounds bounds = sObjectMgr->GetSpellScriptsBounds(spellId);
uint32 spellDifficultyId = sSpellMgr->GetSpellDifficultyId(spellId);
if (handler->GetSession()->GetSecurity() < SEC_CONSOLE && (bounds.first != bounds.second || spellDifficultyId || spellInfo->HasEffect(SPELL_EFFECT_SKILL_STEP) || spellInfo->HasEffect(SPELL_EFFECT_TRADE_SKILL)))
{
handler->PSendSysMessage("Spell %u cannot be casted using a command!", spellId);
handler->SetSentErrorMessage(true);
return false;
}
char* distStr = strtok(NULL, " ");
float dist = 0;
if (distStr)
sscanf(distStr, "%f", &dist);
char* triggeredStr = strtok(NULL, " ");
if (triggeredStr)
{
int l = strlen(triggeredStr);
if (strncmp(triggeredStr, "triggered", l) != 0)
return false;
}
bool triggered = (triggeredStr != NULL);
float x, y, z;
handler->GetSession()->GetPlayer()->GetClosePoint(x, y, z, dist);
handler->GetSession()->GetPlayer()->CastSpell(x, y, z, spellId, triggered);
return true;
}
static bool HandleCastSelfCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
Unit* target = handler->getSelectedUnit();
if (!target)
{
handler->SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
handler->SetSentErrorMessage(true);
return false;
}
// number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
uint32 spellId = handler->extractSpellIdFromLink((char*)args);
if (!spellId)
return false;
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
if (!spellInfo)
{
handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND);
handler->SetSentErrorMessage(true);
return false;
}
if (!SpellMgr::IsSpellValid(spellInfo))
{
handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spellId);
handler->SetSentErrorMessage(true);
return false;
}
SpellScriptsBounds bounds = sObjectMgr->GetSpellScriptsBounds(spellId);
uint32 spellDifficultyId = sSpellMgr->GetSpellDifficultyId(spellId);
if (handler->GetSession()->GetSecurity() < SEC_CONSOLE && (bounds.first != bounds.second || spellDifficultyId || spellInfo->HasEffect(SPELL_EFFECT_SKILL_STEP) || spellInfo->HasEffect(SPELL_EFFECT_TRADE_SKILL)))
{
handler->PSendSysMessage("Spell %u cannot be casted using a command!", spellId);
handler->SetSentErrorMessage(true);
return false;
}
char* triggeredStr = strtok(NULL, " ");
if (triggeredStr)
{
int l = strlen(triggeredStr);
if (strncmp(triggeredStr, "triggered", l) != 0)
return false;
}
bool triggered = (triggeredStr != NULL);
target->CastSpell(target, spellId, triggered);
return true;
}
static bool HandleCastTargetCommad(ChatHandler* handler, char const* args)
{
Creature* caster = handler->getSelectedCreature();
if (!caster)
{
handler->SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
handler->SetSentErrorMessage(true);
return false;
}
if (!caster->GetVictim())
{
handler->SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM);
handler->SetSentErrorMessage(true);
return false;
}
// number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
uint32 spellId = handler->extractSpellIdFromLink((char*)args);
if (!spellId)
return false;
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
if (!spellInfo)
{
handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND);
handler->SetSentErrorMessage(true);
return false;
}
if (!SpellMgr::IsSpellValid(spellInfo))
{
handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spellId);
handler->SetSentErrorMessage(true);
return false;
}
SpellScriptsBounds bounds = sObjectMgr->GetSpellScriptsBounds(spellId);
uint32 spellDifficultyId = sSpellMgr->GetSpellDifficultyId(spellId);
if (handler->GetSession()->GetSecurity() < SEC_CONSOLE && (bounds.first != bounds.second || spellDifficultyId || spellInfo->HasEffect(SPELL_EFFECT_SKILL_STEP) || spellInfo->HasEffect(SPELL_EFFECT_TRADE_SKILL)))
{
handler->PSendSysMessage("Spell %u cannot be casted using a command!", spellId);
handler->SetSentErrorMessage(true);
return false;
}
char* triggeredStr = strtok(NULL, " ");
if (triggeredStr)
{
int l = strlen(triggeredStr);
if (strncmp(triggeredStr, "triggered", l) != 0)
return false;
}
bool triggered = (triggeredStr != NULL);
caster->CastSpell(caster->GetVictim(), spellId, triggered);
return true;
}
static bool HandleCastDestCommand(ChatHandler* handler, char const* args)
{
Unit* caster = handler->getSelectedUnit();
if (!caster)
{
handler->SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
handler->SetSentErrorMessage(true);
return false;
}
// number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
uint32 spellId = handler->extractSpellIdFromLink((char*)args);
if (!spellId)
return false;
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
if (!spellInfo)
{
handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND);
handler->SetSentErrorMessage(true);
return false;
}
if (!SpellMgr::IsSpellValid(spellInfo))
{
handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spellId);
handler->SetSentErrorMessage(true);
return false;
}
SpellScriptsBounds bounds = sObjectMgr->GetSpellScriptsBounds(spellId);
uint32 spellDifficultyId = sSpellMgr->GetSpellDifficultyId(spellId);
if (handler->GetSession()->GetSecurity() < SEC_CONSOLE && (bounds.first != bounds.second || spellDifficultyId || spellInfo->HasEffect(SPELL_EFFECT_SKILL_STEP) || spellInfo->HasEffect(SPELL_EFFECT_TRADE_SKILL)))
{
handler->PSendSysMessage("Spell %u cannot be casted using a command!", spellId);
handler->SetSentErrorMessage(true);
return false;
}
char* posX = strtok(NULL, " ");
char* posY = strtok(NULL, " ");
char* posZ = strtok(NULL, " ");
if (!posX || !posY || !posZ)
return false;
float x = float(atof(posX));
float y = float(atof(posY));
float z = float(atof(posZ));
char* triggeredStr = strtok(NULL, " ");
if (triggeredStr)
{
int l = strlen(triggeredStr);
if (strncmp(triggeredStr, "triggered", l) != 0)
return false;
}
bool triggered = (triggeredStr != NULL);
caster->CastSpell(x, y, z, spellId, triggered);
return true;
}
};
void AddSC_cast_commandscript()
{
new cast_commandscript();
}
@@ -0,0 +1,598 @@
/*
* Copyright (C)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* ScriptData
Name: character_commandscript
%Complete: 100
Comment: All character related commands
Category: commandscripts
EndScriptData */
#include "AccountMgr.h"
#include "Chat.h"
#include "ObjectMgr.h"
#include "PlayerDump.h"
#include "Player.h"
#include "ReputationMgr.h"
#include "ScriptMgr.h"
class character_commandscript : public CommandScript
{
public:
character_commandscript() : CommandScript("character_commandscript") { }
ChatCommand* GetCommands() const
{
static ChatCommand pdumpCommandTable[] =
{
{ "load", SEC_ADMINISTRATOR, true, &HandlePDumpLoadCommand, "", NULL },
{ "write", SEC_ADMINISTRATOR, true, &HandlePDumpWriteCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand characterCommandTable[] =
{
{ "customize", SEC_GAMEMASTER, true, &HandleCharacterCustomizeCommand, "", NULL },
{ "changefaction", SEC_GAMEMASTER, true, &HandleCharacterChangeFactionCommand, "", NULL },
{ "changerace", SEC_GAMEMASTER, true, &HandleCharacterChangeRaceCommand, "", NULL },
{ "level", SEC_ADMINISTRATOR, true, &HandleCharacterLevelCommand, "", NULL },
{ "rename", SEC_GAMEMASTER, true, &HandleCharacterRenameCommand, "", NULL },
{ "reputation", SEC_GAMEMASTER, true, &HandleCharacterReputationCommand, "", NULL },
{ "titles", SEC_GAMEMASTER, true, &HandleCharacterTitlesCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "character", SEC_GAMEMASTER, true, NULL, "", characterCommandTable },
{ "levelup", SEC_ADMINISTRATOR, false, &HandleLevelUpCommand, "", NULL },
{ "pdump", SEC_ADMINISTRATOR, true, NULL, "", pdumpCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}
// Stores informations about a deleted character
struct DeletedInfo
{
uint32 lowGuid; ///< the low GUID from the character
std::string name; ///< the character name
uint32 accountId; ///< the account id
std::string accountName; ///< the account name
time_t deleteDate; ///< the date at which the character has been deleted
};
static void HandleCharacterLevel(Player* player, uint64 playerGuid, uint32 oldLevel, uint32 newLevel, ChatHandler* handler)
{
if (player)
{
player->GiveLevel(newLevel);
player->InitTalentForLevel();
player->SetUInt32Value(PLAYER_XP, 0);
if (handler->needReportToTarget(player))
{
if (oldLevel == newLevel)
ChatHandler(player->GetSession()).PSendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET, handler->GetNameLink().c_str());
else if (oldLevel < newLevel)
ChatHandler(player->GetSession()).PSendSysMessage(LANG_YOURS_LEVEL_UP, handler->GetNameLink().c_str(), newLevel);
else // if (oldlevel > newlevel)
ChatHandler(player->GetSession()).PSendSysMessage(LANG_YOURS_LEVEL_DOWN, handler->GetNameLink().c_str(), newLevel);
}
}
else
{
// Update level and reset XP, everything else will be updated at login
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_LEVEL);
stmt->setUInt8(0, uint8(newLevel));
stmt->setUInt32(1, GUID_LOPART(playerGuid));
CharacterDatabase.Execute(stmt);
// xinef: update global storage
sWorld->UpdateGlobalPlayerData(GUID_LOPART(playerGuid), PLAYER_UPDATE_DATA_LEVEL, "", newLevel);
}
}
static bool HandleCharacterTitlesCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
Player* target;
if (!handler->extractPlayerTarget((char*)args, &target))
return false;
LocaleConstant loc = handler->GetSessionDbcLocale();
char const* targetName = target->GetName().c_str();
char const* knownStr = handler->GetTrinityString(LANG_KNOWN);
// Search in CharTitles.dbc
for (uint32 id = 0; id < sCharTitlesStore.GetNumRows(); id++)
{
CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id);
if (titleInfo && target->HasTitle(titleInfo))
{
std::string name = target->getGender() == GENDER_MALE ? titleInfo->nameMale[loc] : titleInfo->nameFemale[loc];
if (name.empty())
continue;
char const* activeStr = target && target->GetUInt32Value(PLAYER_CHOSEN_TITLE) == titleInfo->bit_index
? handler->GetTrinityString(LANG_ACTIVE)
: "";
char titleNameStr[80];
snprintf(titleNameStr, 80, name.c_str(), targetName);
// send title in "id (idx:idx) - [namedlink locale]" format
if (handler->GetSession())
handler->PSendSysMessage(LANG_TITLE_LIST_CHAT, id, titleInfo->bit_index, id, titleNameStr, localeNames[loc], knownStr, activeStr);
else
handler->PSendSysMessage(LANG_TITLE_LIST_CONSOLE, id, titleInfo->bit_index, name.c_str(), localeNames[loc], knownStr, activeStr);
}
}
return true;
}
//rename characters
static bool HandleCharacterRenameCommand(ChatHandler* handler, char const* args)
{
Player* target;
uint64 targetGuid;
std::string targetName;
if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid, &targetName))
return false;
if (target)
{
// check online security
if (handler->HasLowerSecurity(target, 0))
return false;
handler->PSendSysMessage(LANG_RENAME_PLAYER, handler->GetNameLink(target).c_str());
target->SetAtLoginFlag(AT_LOGIN_RENAME);
}
else
{
// check offline security
if (handler->HasLowerSecurity(NULL, targetGuid))
return false;
std::string oldNameLink = handler->playerLink(targetName);
handler->PSendSysMessage(LANG_RENAME_PLAYER_GUID, oldNameLink.c_str(), GUID_LOPART(targetGuid));
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ADD_AT_LOGIN_FLAG);
stmt->setUInt16(0, uint16(AT_LOGIN_RENAME));
stmt->setUInt32(1, GUID_LOPART(targetGuid));
CharacterDatabase.Execute(stmt);
}
return true;
}
static bool HandleCharacterLevelCommand(ChatHandler* handler, char const* args)
{
char* nameStr;
char* levelStr;
handler->extractOptFirstArg((char*)args, &nameStr, &levelStr);
if (!levelStr)
return false;
// exception opt second arg: .character level $name
if (isalpha(levelStr[0]))
{
nameStr = levelStr;
levelStr = NULL; // current level will used
}
Player* target;
uint64 targetGuid;
std::string targetName;
if (!handler->extractPlayerTarget(nameStr, &target, &targetGuid, &targetName))
return false;
int32 oldlevel = target ? target->getLevel() : Player::GetLevelFromStorage(targetGuid);
int32 newlevel = levelStr ? atoi(levelStr) : oldlevel;
if (newlevel < 1)
return false; // invalid level
if (newlevel > STRONG_MAX_LEVEL) // hardcoded maximum level
newlevel = STRONG_MAX_LEVEL;
HandleCharacterLevel(target, targetGuid, oldlevel, newlevel, handler);
if (!handler->GetSession() || handler->GetSession()->GetPlayer() != target) // including player == NULL
{
std::string nameLink = handler->playerLink(targetName);
handler->PSendSysMessage(LANG_YOU_CHANGE_LVL, nameLink.c_str(), newlevel);
}
return true;
}
// customize characters
static bool HandleCharacterCustomizeCommand(ChatHandler* handler, char const* args)
{
Player* target;
uint64 targetGuid;
std::string targetName;
if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid, &targetName))
return false;
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ADD_AT_LOGIN_FLAG);
stmt->setUInt16(0, uint16(AT_LOGIN_CUSTOMIZE));
if (target)
{
handler->PSendSysMessage(LANG_CUSTOMIZE_PLAYER, handler->GetNameLink(target).c_str());
target->SetAtLoginFlag(AT_LOGIN_CUSTOMIZE);
stmt->setUInt32(1, target->GetGUIDLow());
}
else
{
std::string oldNameLink = handler->playerLink(targetName);
stmt->setUInt32(1, GUID_LOPART(targetGuid));
handler->PSendSysMessage(LANG_CUSTOMIZE_PLAYER_GUID, oldNameLink.c_str(), GUID_LOPART(targetGuid));
}
CharacterDatabase.Execute(stmt);
return true;
}
static bool HandleCharacterChangeFactionCommand(ChatHandler* handler, char const* args)
{
Player* target;
uint64 targetGuid;
std::string targetName;
if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid, &targetName))
return false;
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ADD_AT_LOGIN_FLAG);
stmt->setUInt16(0, uint16(AT_LOGIN_CHANGE_FACTION));
if (target)
{
handler->PSendSysMessage(LANG_CUSTOMIZE_PLAYER, handler->GetNameLink(target).c_str());
target->SetAtLoginFlag(AT_LOGIN_CHANGE_FACTION);
stmt->setUInt32(1, target->GetGUIDLow());
}
else
{
std::string oldNameLink = handler->playerLink(targetName);
handler->PSendSysMessage(LANG_CUSTOMIZE_PLAYER_GUID, oldNameLink.c_str(), GUID_LOPART(targetGuid));
stmt->setUInt32(1, GUID_LOPART(targetGuid));
}
CharacterDatabase.Execute(stmt);
return true;
}
static bool HandleCharacterChangeRaceCommand(ChatHandler* handler, char const* args)
{
Player* target;
uint64 targetGuid;
std::string targetName;
if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid, &targetName))
return false;
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ADD_AT_LOGIN_FLAG);
stmt->setUInt16(0, uint16(AT_LOGIN_CHANGE_RACE));
if (target)
{
// TODO : add text into database
handler->PSendSysMessage(LANG_CUSTOMIZE_PLAYER, handler->GetNameLink(target).c_str());
target->SetAtLoginFlag(AT_LOGIN_CHANGE_RACE);
stmt->setUInt32(1, target->GetGUIDLow());
}
else
{
std::string oldNameLink = handler->playerLink(targetName);
// TODO : add text into database
handler->PSendSysMessage(LANG_CUSTOMIZE_PLAYER_GUID, oldNameLink.c_str(), GUID_LOPART(targetGuid));
stmt->setUInt32(1, GUID_LOPART(targetGuid));
}
CharacterDatabase.Execute(stmt);
return true;
}
static bool HandleCharacterReputationCommand(ChatHandler* handler, char const* args)
{
Player* target;
if (!handler->extractPlayerTarget((char*)args, &target))
return false;
LocaleConstant loc = handler->GetSessionDbcLocale();
FactionStateList const& targetFSL = target->GetReputationMgr().GetStateList();
for (FactionStateList::const_iterator itr = targetFSL.begin(); itr != targetFSL.end(); ++itr)
{
FactionState const& faction = itr->second;
FactionEntry const* factionEntry = sFactionStore.LookupEntry(faction.ID);
char const* factionName = factionEntry ? factionEntry->name[loc] : "#Not found#";
ReputationRank rank = target->GetReputationMgr().GetRank(factionEntry);
std::string rankName = handler->GetTrinityString(ReputationRankStrIndex[rank]);
std::ostringstream ss;
if (handler->GetSession())
ss << faction.ID << " - |cffffffff|Hfaction:" << faction.ID << "|h[" << factionName << ' ' << localeNames[loc] << "]|h|r";
else
ss << faction.ID << " - " << factionName << ' ' << localeNames[loc];
ss << ' ' << rankName << " (" << target->GetReputationMgr().GetReputation(factionEntry) << ')';
if (faction.Flags & FACTION_FLAG_VISIBLE)
ss << handler->GetTrinityString(LANG_FACTION_VISIBLE);
if (faction.Flags & FACTION_FLAG_AT_WAR)
ss << handler->GetTrinityString(LANG_FACTION_ATWAR);
if (faction.Flags & FACTION_FLAG_PEACE_FORCED)
ss << handler->GetTrinityString(LANG_FACTION_PEACE_FORCED);
if (faction.Flags & FACTION_FLAG_HIDDEN)
ss << handler->GetTrinityString(LANG_FACTION_HIDDEN);
if (faction.Flags & FACTION_FLAG_INVISIBLE_FORCED)
ss << handler->GetTrinityString(LANG_FACTION_INVISIBLE_FORCED);
if (faction.Flags & FACTION_FLAG_INACTIVE)
ss << handler->GetTrinityString(LANG_FACTION_INACTIVE);
handler->SendSysMessage(ss.str().c_str());
}
return true;
}
static bool HandleLevelUpCommand(ChatHandler* handler, char const* args)
{
char* nameStr;
char* levelStr;
handler->extractOptFirstArg((char*)args, &nameStr, &levelStr);
// exception opt second arg: .character level $name
if (levelStr && isalpha(levelStr[0]))
{
nameStr = levelStr;
levelStr = NULL; // current level will used
}
Player* target;
uint64 targetGuid;
std::string targetName;
if (!handler->extractPlayerTarget(nameStr, &target, &targetGuid, &targetName))
return false;
int32 oldlevel = target ? target->getLevel() : Player::GetLevelFromStorage(targetGuid);
int32 addlevel = levelStr ? atoi(levelStr) : 1;
int32 newlevel = oldlevel + addlevel;
if (newlevel < 1)
newlevel = 1;
if (newlevel > STRONG_MAX_LEVEL) // hardcoded maximum level
newlevel = STRONG_MAX_LEVEL;
HandleCharacterLevel(target, targetGuid, oldlevel, newlevel, handler);
if (!handler->GetSession() || handler->GetSession()->GetPlayer() != target) // including chr == NULL
{
std::string nameLink = handler->playerLink(targetName);
handler->PSendSysMessage(LANG_YOU_CHANGE_LVL, nameLink.c_str(), newlevel);
}
return true;
}
static bool HandlePDumpLoadCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
char* fileStr = strtok((char*)args, " ");
if (!fileStr)
return false;
char* accountStr = strtok(NULL, " ");
if (!accountStr)
return false;
std::string accountName = accountStr;
if (!AccountMgr::normalizeString(accountName))
{
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
handler->SetSentErrorMessage(true);
return false;
}
uint32 accountId = AccountMgr::GetId(accountName);
if (!accountId)
{
accountId = atoi(accountStr); // use original string
if (!accountId)
{
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
handler->SetSentErrorMessage(true);
return false;
}
}
if (!AccountMgr::GetName(accountId, accountName))
{
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
handler->SetSentErrorMessage(true);
return false;
}
char* guidStr = NULL;
char* nameStr = strtok(NULL, " ");
std::string name;
if (nameStr)
{
name = nameStr;
// normalize the name if specified and check if it exists
if (!normalizePlayerName(name))
{
handler->PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
handler->SetSentErrorMessage(true);
return false;
}
if (ObjectMgr::CheckPlayerName(name, true) != CHAR_NAME_SUCCESS)
{
handler->PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
handler->SetSentErrorMessage(true);
return false;
}
guidStr = strtok(NULL, " ");
}
uint32 guid = 0;
if (guidStr)
{
guid = uint32(atoi(guidStr));
if (!guid)
{
handler->PSendSysMessage(LANG_INVALID_CHARACTER_GUID);
handler->SetSentErrorMessage(true);
return false;
}
if (sObjectMgr->GetPlayerAccountIdByGUID(guid))
{
handler->PSendSysMessage(LANG_CHARACTER_GUID_IN_USE, guid);
handler->SetSentErrorMessage(true);
return false;
}
}
switch (PlayerDumpReader().LoadDump(fileStr, accountId, name, guid))
{
case DUMP_SUCCESS:
handler->PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS);
break;
case DUMP_FILE_OPEN_ERROR:
handler->PSendSysMessage(LANG_FILE_OPEN_FAIL, fileStr);
handler->SetSentErrorMessage(true);
return false;
case DUMP_FILE_BROKEN:
handler->PSendSysMessage(LANG_DUMP_BROKEN, fileStr);
handler->SetSentErrorMessage(true);
return false;
case DUMP_TOO_MANY_CHARS:
handler->PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL, accountName.c_str(), accountId);
handler->SetSentErrorMessage(true);
return false;
default:
handler->PSendSysMessage(LANG_COMMAND_IMPORT_FAILED);
handler->SetSentErrorMessage(true);
return false;
}
return true;
}
static bool HandlePDumpWriteCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
char* fileStr = strtok((char*)args, " ");
char* playerStr = strtok(NULL, " ");
if (!fileStr && !playerStr)
{
QueryResult result = CharacterDatabase.PQuery("SELECT guid FROM characters");
if (!result)
return true;
do{
uint64 _guid = result->Fetch()[0].GetUInt64();
char buff[20];
sprintf(buff,"%u.dump", _guid);
switch(PlayerDumpWriter().WriteDump(buff, uint32(_guid)))
{
case DUMP_SUCCESS:
handler->PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS);
break;
case DUMP_FILE_OPEN_ERROR:
handler->PSendSysMessage(LANG_FILE_OPEN_FAIL, buff);
handler->SetSentErrorMessage(true);
return false;
case DUMP_CHARACTER_DELETED:
handler->PSendSysMessage(LANG_COMMAND_EXPORT_DELETED_CHAR);
handler->SetSentErrorMessage(true);
return false;
default:
handler->PSendSysMessage(LANG_COMMAND_EXPORT_FAILED);
handler->SetSentErrorMessage(true);
return false;
}
}while(result->NextRow());
}
if (!fileStr || !playerStr)
return false;
uint64 guid;
// character name can't start from number
if (isNumeric(playerStr))
guid = MAKE_NEW_GUID(atoi(playerStr), 0, HIGHGUID_PLAYER);
else
{
std::string name = handler->extractPlayerNameFromLink(playerStr);
if (name.empty())
{
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
handler->SetSentErrorMessage(true);
return false;
}
guid = sObjectMgr->GetPlayerGUIDByName(name);
}
if (!sObjectMgr->GetPlayerAccountIdByGUID(guid))
{
handler->PSendSysMessage(LANG_PLAYER_NOT_FOUND);
handler->SetSentErrorMessage(true);
return false;
}
switch (PlayerDumpWriter().WriteDump(fileStr, uint32(guid)))
{
case DUMP_SUCCESS:
handler->PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS);
break;
case DUMP_FILE_OPEN_ERROR:
handler->PSendSysMessage(LANG_FILE_OPEN_FAIL, fileStr);
handler->SetSentErrorMessage(true);
return false;
case DUMP_CHARACTER_DELETED:
handler->PSendSysMessage(LANG_COMMAND_EXPORT_DELETED_CHAR);
handler->SetSentErrorMessage(true);
return false;
default:
handler->PSendSysMessage(LANG_COMMAND_EXPORT_FAILED);
handler->SetSentErrorMessage(true);
return false;
}
return true;
}
};
void AddSC_character_commandscript()
{
new character_commandscript();
}
File diff suppressed because it is too large Load Diff
+219
View File
@@ -0,0 +1,219 @@
/*
* Copyright (C)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* ScriptData
Name: event_commandscript
%Complete: 100
Comment: All event related commands
Category: commandscripts
EndScriptData */
#include "Chat.h"
#include "GameEventMgr.h"
#include "Language.h"
#include "Player.h"
#include "ScriptMgr.h"
class event_commandscript : public CommandScript
{
public:
event_commandscript() : CommandScript("event_commandscript") { }
ChatCommand* GetCommands() const
{
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, char const* /*args*/)
{
uint32 counter = 0;
GameEventMgr::GameEventDataMap const& events = sGameEventMgr->GetEventMap();
GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
char const* active = handler->GetTrinityString(LANG_ACTIVE);
for (GameEventMgr::ActiveEvents::const_iterator itr = activeEvents.begin(); itr != activeEvents.end(); ++itr)
{
uint32 eventId = *itr;
GameEventData const& eventData = events[eventId];
if (handler->GetSession())
handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CHAT, eventId, eventId, eventData.description.c_str(), active);
else
handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CONSOLE, eventId, eventData.description.c_str(), active);
++counter;
}
if (counter == 0)
handler->SendSysMessage(LANG_NOEVENTFOUND);
handler->SetSentErrorMessage(true);
return true;
}
static bool HandleEventInfoCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
// id or [name] Shift-click form |color|Hgameevent:id|h[name]|h|r
char* id = handler->extractKeyFromLink((char*)args, "Hgameevent");
if (!id)
return false;
uint32 eventId = atoi(id);
GameEventMgr::GameEventDataMap const& events = sGameEventMgr->GetEventMap();
if (eventId >= events.size())
{
handler->SendSysMessage(LANG_EVENT_NOT_EXIST);
handler->SetSentErrorMessage(true);
return false;
}
GameEventData const& eventData = events[eventId];
if (!eventData.isValid())
{
handler->SendSysMessage(LANG_EVENT_NOT_EXIST);
handler->SetSentErrorMessage(true);
return false;
}
GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
bool active = activeEvents.find(eventId) != 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(eventId);
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, true);
std::string lengthStr = secsToTimeString(eventData.length * MINUTE, true);
handler->PSendSysMessage(LANG_EVENT_INFO, eventId, 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, char const* args)
{
if (!*args)
return false;
// id or [name] Shift-click form |color|Hgameevent:id|h[name]|h|r
char* id = handler->extractKeyFromLink((char*)args, "Hgameevent");
if (!id)
return false;
int32 eventId = atoi(id);
GameEventMgr::GameEventDataMap const& events = sGameEventMgr->GetEventMap();
if (eventId < 1 || uint32(eventId) >= events.size())
{
handler->SendSysMessage(LANG_EVENT_NOT_EXIST);
handler->SetSentErrorMessage(true);
return false;
}
GameEventData const& eventData = events[eventId];
if (!eventData.isValid())
{
handler->SendSysMessage(LANG_EVENT_NOT_EXIST);
handler->SetSentErrorMessage(true);
return false;
}
GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
if (activeEvents.find(eventId) != activeEvents.end())
{
handler->PSendSysMessage(LANG_EVENT_ALREADY_ACTIVE, eventId);
handler->SetSentErrorMessage(true);
return false;
}
sGameEventMgr->StartEvent(eventId, true);
return true;
}
static bool HandleEventStopCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
// id or [name] Shift-click form |color|Hgameevent:id|h[name]|h|r
char* id = handler->extractKeyFromLink((char*)args, "Hgameevent");
if (!id)
return false;
int32 eventId = atoi(id);
GameEventMgr::GameEventDataMap const& events = sGameEventMgr->GetEventMap();
if (eventId < 1 || uint32(eventId) >= events.size())
{
handler->SendSysMessage(LANG_EVENT_NOT_EXIST);
handler->SetSentErrorMessage(true);
return false;
}
GameEventData const& eventData = events[eventId];
if (!eventData.isValid())
{
handler->SendSysMessage(LANG_EVENT_NOT_EXIST);
handler->SetSentErrorMessage(true);
return false;
}
GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
if (activeEvents.find(eventId) == activeEvents.end())
{
handler->PSendSysMessage(LANG_EVENT_NOT_ACTIVE, eventId);
handler->SetSentErrorMessage(true);
return false;
}
sGameEventMgr->StopEvent(eventId, true);
return true;
}
};
void AddSC_event_commandscript()
{
new event_commandscript();
}
+278
View File
@@ -0,0 +1,278 @@
/*
* Copyright (C)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* ScriptData
Name: gm_commandscript
%Complete: 100
Comment: All gm related commands
Category: commandscripts
EndScriptData */
#include "ScriptMgr.h"
#include "ObjectMgr.h"
#include "Chat.h"
#include "AccountMgr.h"
#include "Language.h"
#include "World.h"
#include "Player.h"
#include "Opcodes.h"
class gm_commandscript : public CommandScript
{
public:
gm_commandscript() : CommandScript("gm_commandscript") { }
ChatCommand* GetCommands() const
{
static ChatCommand gmCommandTable[] =
{
{ "chat", SEC_GAMEMASTER, false, &HandleGMChatCommand, "", NULL },
{ "fly", SEC_ADMINISTRATOR, false, &HandleGMFlyCommand, "", NULL },
//{ "ingame", SEC_PLAYER, true, &HandleGMListIngameCommand, "", NULL },
{ "list", SEC_ADMINISTRATOR, true, &HandleGMListFullCommand, "", NULL },
{ "visible", SEC_GAMEMASTER, false, &HandleGMVisibleCommand, "", NULL },
{ "", SEC_GAMEMASTER, false, &HandleGMCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "gm", SEC_GAMEMASTER, false, NULL, "", gmCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}
// Enables or disables hiding of the staff badge
static bool HandleGMChatCommand(ChatHandler* handler, char const* args)
{
if (!*args)
{
WorldSession* session = handler->GetSession();
if (!AccountMgr::IsPlayerAccount(session->GetSecurity()) && session->GetPlayer()->isGMChat())
session->SendNotification(LANG_GM_CHAT_ON);
else
session->SendNotification(LANG_GM_CHAT_OFF);
return true;
}
std::string param = (char*)args;
if (param == "on")
{
handler->GetSession()->GetPlayer()->SetGMChat(true);
handler->GetSession()->SendNotification(LANG_GM_CHAT_ON);
return true;
}
if (param == "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, char const* args)
{
if (!*args)
return false;
Player* target = handler->getSelectedPlayer();
if (!target || handler->GetSession()->GetSecurity() < SEC_GAMEMASTER)
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);
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);
handler->SetSentErrorMessage(true);
return false;
}
static bool HandleGMListIngameCommand(ChatHandler* handler, char const* /*args*/)
{
bool first = true;
bool footer = false;
TRINITY_READ_GUARD(HashMapHolder<Player>::LockType, *HashMapHolder<Player>::GetLock());
HashMapHolder<Player>::MapType const& m = sObjectAccessor->GetPlayers();
for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
{
AccountTypes itrSec = itr->second->GetSession()->GetSecurity();
if ((itr->second->IsGameMaster() || (!AccountMgr::IsPlayerAccount(itrSec) && itrSec <= AccountTypes(sWorld->getIntConfig(CONFIG_GM_LEVEL_IN_GM_LIST)))) &&
(!handler->GetSession() || itr->second->IsVisibleGloballyFor(handler->GetSession()->GetPlayer())))
{
if (first)
{
first = false;
footer = true;
handler->SendSysMessage(LANG_GMS_ON_SRV);
handler->SendSysMessage("========================");
}
std::string const& name = itr->second->GetName();
uint8 size = name.size();
uint8 security = itrSec;
uint8 max = ((16 - size) / 2);
uint8 max2 = max;
if ((max + max2 + size) == 16)
max2 = max - 1;
if (handler->GetSession())
handler->PSendSysMessage("| %s GMLevel %u", name.c_str(), security);
else
handler->PSendSysMessage("|%*s%s%*s| %u |", max, " ", name.c_str(), max2, " ", security);
}
}
if (footer)
handler->SendSysMessage("========================");
if (first)
handler->SendSysMessage(LANG_GMS_NOT_LOGGED);
return true;
}
/// Display the list of GMs
static bool HandleGMListFullCommand(ChatHandler* handler, char const* /*args*/)
{
///- Get the accounts with GM Level >0
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_GM_ACCOUNTS);
stmt->setUInt8(0, uint8(SEC_MODERATOR));
stmt->setInt32(1, int32(realmID));
PreparedQueryResult result = LoginDatabase.Query(stmt);
if (result)
{
handler->SendSysMessage(LANG_GMLIST);
handler->SendSysMessage("========================");
///- Cycle through them. Display username and GM level
do
{
Field* fields = result->Fetch();
char const* 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, char const* args)
{
Player* _player = handler->GetSession()->GetPlayer();
if (!*args)
{
handler->PSendSysMessage(LANG_YOU_ARE, _player->isGMVisible() ? handler->GetTrinityString(LANG_VISIBLE) : handler->GetTrinityString(LANG_INVISIBLE));
handler->SetSentErrorMessage(true);
return false;
}
const uint32 VISUAL_AURA = 37800;
std::string param = (char*)args;
if (param == "on")
{
if (_player->HasAura(VISUAL_AURA, 0))
_player->RemoveAurasDueToSpell(VISUAL_AURA);
_player->SetGMVisible(true);
//_player->UpdateObjectVisibility();
handler->GetSession()->SendNotification(LANG_INVISIBLE_VISIBLE);
handler->SetSentErrorMessage(true);
return false;
}
if (param == "off")
{
_player->AddAura(VISUAL_AURA, _player);
_player->SetGMVisible(false);
//_player->UpdateObjectVisibility();
handler->GetSession()->SendNotification(LANG_INVISIBLE_INVISIBLE);
handler->SetSentErrorMessage(true);
return false;
}
handler->SendSysMessage(LANG_USE_BOL);
handler->SetSentErrorMessage(true);
return false;
}
//Enable\Disable GM Mode
static bool HandleGMCommand(ChatHandler* handler, char const* args)
{
Player* _player = handler->GetSession()->GetPlayer();
if (!*args)
{
handler->GetSession()->SendNotification(_player->IsGameMaster() ? LANG_GM_ON : LANG_GM_OFF);
handler->SetSentErrorMessage(true);
return false;
}
std::string param = (char*)args;
if (param == "on")
{
_player->SetGameMaster(true);
handler->GetSession()->SendNotification(LANG_GM_ON);
_player->UpdateTriggerVisibility();
handler->SetSentErrorMessage(true);
return false;
}
if (param == "off")
{
_player->SetGameMaster(false);
handler->GetSession()->SendNotification(LANG_GM_OFF);
_player->UpdateTriggerVisibility();
handler->SetSentErrorMessage(true);
return false;
}
handler->SendSysMessage(LANG_USE_BOL);
handler->SetSentErrorMessage(true);
return false;
}
};
void AddSC_gm_commandscript()
{
new gm_commandscript();
}
+575
View File
@@ -0,0 +1,575 @@
/*
* Copyright (C)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* ScriptData
Name: go_commandscript
%Complete: 100
Comment: All go related commands
Category: commandscripts
EndScriptData */
#include "ScriptMgr.h"
#include "ObjectMgr.h"
#include "MapManager.h"
#include "TicketMgr.h"
#include "Chat.h"
#include "Language.h"
#include "Player.h"
class go_commandscript : public CommandScript
{
public:
go_commandscript() : CommandScript("go_commandscript") { }
ChatCommand* GetCommands() const
{
static ChatCommand goCommandTable[] =
{
{ "creature", SEC_GAMEMASTER, false, &HandleGoCreatureCommand, "", NULL },
{ "graveyard", SEC_GAMEMASTER, false, &HandleGoGraveyardCommand, "", NULL },
{ "grid", SEC_GAMEMASTER, false, &HandleGoGridCommand, "", NULL },
{ "object", SEC_GAMEMASTER, false, &HandleGoObjectCommand, "", NULL },
{ "taxinode", SEC_GAMEMASTER, false, &HandleGoTaxinodeCommand, "", NULL },
{ "trigger", SEC_GAMEMASTER, false, &HandleGoTriggerCommand, "", NULL },
{ "zonexy", SEC_GAMEMASTER, false, &HandleGoZoneXYCommand, "", NULL },
{ "xyz", SEC_GAMEMASTER, false, &HandleGoXYZCommand, "", NULL },
{ "ticket", SEC_GAMEMASTER, false, &HandleGoTicketCommand, "", NULL },
{ "", SEC_GAMEMASTER, false, &HandleGoXYZCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "go", SEC_GAMEMASTER, false, NULL, "", goCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}
/** \brief Teleport the GM to the specified creature
*
* .gocreature <GUID> --> TP using creature.guid
* .gocreature azuregos --> TP player to the mob with this name
* Warning: If there is more than one mob with this name
* you will be teleported to the first one that is found.
* .gocreature id 6109 --> TP player to the mob, that has this creature_template.entry
* Warning: If there is more than one mob with this "id"
* you will be teleported to the first one that is found.
*/
//teleport to creature
static bool HandleGoCreatureCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
Player* player = handler->GetSession()->GetPlayer();
// "id" or number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
char* param1 = handler->extractKeyFromLink((char*)args, "Hcreature");
if (!param1)
return false;
std::ostringstream whereClause;
// User wants to teleport to the NPC's template entry
if (strcmp(param1, "id") == 0)
{
// Get the "creature_template.entry"
// number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
char* tail = strtok(NULL, "");
if (!tail)
return false;
char* id = handler->extractKeyFromLink(tail, "Hcreature_entry");
if (!id)
return false;
int32 entry = atoi(id);
if (!entry)
return false;
whereClause << "WHERE id = '" << entry << '\'';
}
else
{
int32 guid = atoi(param1);
// Number is invalid - maybe the user specified the mob's name
if (!guid)
{
std::string name = param1;
WorldDatabase.EscapeString(name);
whereClause << ", creature_template WHERE creature.id = creature_template.entry AND creature_template.name " _LIKE_" '" << name << '\'';
}
else
whereClause << "WHERE guid = '" << guid << '\'';
}
QueryResult result = WorldDatabase.PQuery("SELECT position_x, position_y, position_z, orientation, map, guid, id FROM creature %s", whereClause.str().c_str());
if (!result)
{
handler->SendSysMessage(LANG_COMMAND_GOCREATNOTFOUND);
handler->SetSentErrorMessage(true);
return false;
}
if (result->GetRowCount() > 1)
handler->SendSysMessage(LANG_COMMAND_GOCREATMULTIPLE);
Field* fields = result->Fetch();
float x = fields[0].GetFloat();
float y = fields[1].GetFloat();
float z = fields[2].GetFloat();
float ort = fields[3].GetFloat();
int mapId = fields[4].GetUInt16();
uint32 guid = fields[5].GetUInt32();
uint32 id = fields[6].GetUInt32();
// if creature is in same map with caster go at its current location
if (Creature* creature = ObjectAccessor::GetCreature(*player, MAKE_NEW_GUID(guid, id, HIGHGUID_UNIT)))
{
x = creature->GetPositionX();
y = creature->GetPositionY();
z = creature->GetPositionZ();
ort = creature->GetOrientation();
}
if (!MapManager::IsValidMapCoord(mapId, x, y, z, ort))
{
handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, x, y, mapId);
handler->SetSentErrorMessage(true);
return false;
}
// stop flight if need
if (player->IsInFlight())
{
player->GetMotionMaster()->MovementExpired();
player->CleanupAfterTaxiFlight();
}
// save only in non-flight case
else
player->SaveRecallPosition();
player->TeleportTo(mapId, x, y, z, ort);
return true;
}
static bool HandleGoGraveyardCommand(ChatHandler* handler, char const* args)
{
Player* player = handler->GetSession()->GetPlayer();
if (!*args)
return false;
char* gyId = strtok((char*)args, " ");
if (!gyId)
return false;
int32 graveyardId = atoi(gyId);
if (!graveyardId)
return false;
WorldSafeLocsEntry const* gy = sWorldSafeLocsStore.LookupEntry(graveyardId);
if (!gy)
{
handler->PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST, graveyardId);
handler->SetSentErrorMessage(true);
return false;
}
if (!MapManager::IsValidMapCoord(gy->map_id, gy->x, gy->y, gy->z))
{
handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, gy->x, gy->y, gy->map_id);
handler->SetSentErrorMessage(true);
return false;
}
// stop flight if need
if (player->IsInFlight())
{
player->GetMotionMaster()->MovementExpired();
player->CleanupAfterTaxiFlight();
}
// save only in non-flight case
else
player->SaveRecallPosition();
player->TeleportTo(gy->map_id, gy->x, gy->y, gy->z, player->GetOrientation());
return true;
}
//teleport to grid
static bool HandleGoGridCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
Player* player = handler->GetSession()->GetPlayer();
char* gridX = strtok((char*)args, " ");
char* gridY = strtok(NULL, " ");
char* id = strtok(NULL, " ");
if (!gridX || !gridY)
return false;
uint32 mapId = id ? (uint32)atoi(id) : player->GetMapId();
// center of grid
float x = ((float)atof(gridX) - CENTER_GRID_ID + 0.5f) * SIZE_OF_GRIDS;
float y = ((float)atof(gridY) - CENTER_GRID_ID + 0.5f) * SIZE_OF_GRIDS;
if (!MapManager::IsValidMapCoord(mapId, x, y))
{
handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, x, y, mapId);
handler->SetSentErrorMessage(true);
return false;
}
// stop flight if need
if (player->IsInFlight())
{
player->GetMotionMaster()->MovementExpired();
player->CleanupAfterTaxiFlight();
}
// save only in non-flight case
else
player->SaveRecallPosition();
Map const* map = sMapMgr->CreateBaseMap(mapId);
float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
player->TeleportTo(mapId, x, y, z, player->GetOrientation());
return true;
}
//teleport to gameobject
static bool HandleGoObjectCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
Player* player = handler->GetSession()->GetPlayer();
// number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r
char* id = handler->extractKeyFromLink((char*)args, "Hgameobject");
if (!id)
return false;
int32 guid = atoi(id);
if (!guid)
return false;
float x, y, z, ort;
int mapId;
// by DB guid
if (GameObjectData const* goData = sObjectMgr->GetGOData(guid))
{
x = goData->posX;
y = goData->posY;
z = goData->posZ;
ort = goData->orientation;
mapId = goData->mapid;
}
else
{
handler->SendSysMessage(LANG_COMMAND_GOOBJNOTFOUND);
handler->SetSentErrorMessage(true);
return false;
}
if (!MapManager::IsValidMapCoord(mapId, x, y, z, ort))
{
handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, x, y, mapId);
handler->SetSentErrorMessage(true);
return false;
}
// stop flight if need
if (player->IsInFlight())
{
player->GetMotionMaster()->MovementExpired();
player->CleanupAfterTaxiFlight();
}
// save only in non-flight case
else
player->SaveRecallPosition();
player->TeleportTo(mapId, x, y, z, ort);
return true;
}
static bool HandleGoTaxinodeCommand(ChatHandler* handler, char const* args)
{
Player* player = handler->GetSession()->GetPlayer();
if (!*args)
return false;
char* id = handler->extractKeyFromLink((char*)args, "Htaxinode");
if (!id)
return false;
int32 nodeId = atoi(id);
if (!nodeId)
return false;
TaxiNodesEntry const* node = sTaxiNodesStore.LookupEntry(nodeId);
if (!node)
{
handler->PSendSysMessage(LANG_COMMAND_GOTAXINODENOTFOUND, nodeId);
handler->SetSentErrorMessage(true);
return false;
}
if ((node->x == 0.0f && node->y == 0.0f && node->z == 0.0f) ||
!MapManager::IsValidMapCoord(node->map_id, node->x, node->y, node->z))
{
handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, node->x, node->y, node->map_id);
handler->SetSentErrorMessage(true);
return false;
}
// stop flight if need
if (player->IsInFlight())
{
player->GetMotionMaster()->MovementExpired();
player->CleanupAfterTaxiFlight();
}
// save only in non-flight case
else
player->SaveRecallPosition();
player->TeleportTo(node->map_id, node->x, node->y, node->z, player->GetOrientation());
return true;
}
static bool HandleGoTriggerCommand(ChatHandler* handler, char const* args)
{
Player* player = handler->GetSession()->GetPlayer();
if (!*args)
return false;
char* id = strtok((char*)args, " ");
if (!id)
return false;
int32 areaTriggerId = atoi(id);
if (!areaTriggerId)
return false;
AreaTriggerEntry const* at = sAreaTriggerStore.LookupEntry(areaTriggerId);
if (!at)
{
handler->PSendSysMessage(LANG_COMMAND_GOAREATRNOTFOUND, areaTriggerId);
handler->SetSentErrorMessage(true);
return false;
}
if (!MapManager::IsValidMapCoord(at->mapid, at->x, at->y, at->z))
{
handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, at->x, at->y, at->mapid);
handler->SetSentErrorMessage(true);
return false;
}
// stop flight if need
if (player->IsInFlight())
{
player->GetMotionMaster()->MovementExpired();
player->CleanupAfterTaxiFlight();
}
// save only in non-flight case
else
player->SaveRecallPosition();
player->TeleportTo(at->mapid, at->x, at->y, at->z, player->GetOrientation());
return true;
}
//teleport at coordinates
static bool HandleGoZoneXYCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
Player* player = handler->GetSession()->GetPlayer();
char* zoneX = strtok((char*)args, " ");
char* zoneY = strtok(NULL, " ");
char* tail = strtok(NULL, "");
char* id = handler->extractKeyFromLink(tail, "Harea"); // string or [name] Shift-click form |color|Harea:area_id|h[name]|h|r
if (!zoneX || !zoneY)
return false;
float x = (float)atof(zoneX);
float y = (float)atof(zoneY);
// prevent accept wrong numeric args
if ((x == 0.0f && *zoneX != '0') || (y == 0.0f && *zoneY != '0'))
return false;
uint32 areaId = id ? (uint32)atoi(id) : player->GetZoneId();
AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(areaId);
if (x < 0 || x > 100 || y < 0 || y > 100 || !areaEntry)
{
handler->PSendSysMessage(LANG_INVALID_ZONE_COORD, x, y, areaId);
handler->SetSentErrorMessage(true);
return false;
}
// update to parent zone if exist (client map show only zones without parents)
AreaTableEntry const* zoneEntry = areaEntry->zone ? GetAreaEntryByAreaID(areaEntry->zone) : areaEntry;
Map const* map = sMapMgr->CreateBaseMap(zoneEntry->mapid);
if (map->Instanceable())
{
handler->PSendSysMessage(LANG_INVALID_ZONE_MAP, areaEntry->ID, areaEntry->area_name[handler->GetSessionDbcLocale()], map->GetId(), map->GetMapName());
handler->SetSentErrorMessage(true);
return false;
}
Zone2MapCoordinates(x, y, zoneEntry->ID);
if (!MapManager::IsValidMapCoord(zoneEntry->mapid, x, y))
{
handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, x, y, zoneEntry->mapid);
handler->SetSentErrorMessage(true);
return false;
}
// stop flight if need
if (player->IsInFlight())
{
player->GetMotionMaster()->MovementExpired();
player->CleanupAfterTaxiFlight();
}
// save only in non-flight case
else
player->SaveRecallPosition();
float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
player->TeleportTo(zoneEntry->mapid, x, y, z, player->GetOrientation());
return true;
}
//teleport at coordinates, including Z and orientation
static bool HandleGoXYZCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
Player* player = handler->GetSession()->GetPlayer();
char* goX = strtok((char*)args, " ");
char* goY = strtok(NULL, " ");
char* goZ = strtok(NULL, " ");
char* id = strtok(NULL, " ");
char* port = strtok(NULL, " ");
if (!goX || !goY)
return false;
float x = (float)atof(goX);
float y = (float)atof(goY);
float z;
float ort = port ? (float)atof(port) : player->GetOrientation();
uint32 mapId = id ? (uint32)atoi(id) : player->GetMapId();
if (goZ)
{
z = (float)atof(goZ);
if (!MapManager::IsValidMapCoord(mapId, x, y, z))
{
handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, x, y, mapId);
handler->SetSentErrorMessage(true);
return false;
}
}
else
{
if (!MapManager::IsValidMapCoord(mapId, x, y))
{
handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, x, y, mapId);
handler->SetSentErrorMessage(true);
return false;
}
Map const* map = sMapMgr->CreateBaseMap(mapId);
z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
}
// stop flight if need
if (player->IsInFlight())
{
player->GetMotionMaster()->MovementExpired();
player->CleanupAfterTaxiFlight();
}
// save only in non-flight case
else
player->SaveRecallPosition();
player->TeleportTo(mapId, x, y, z, ort);
return true;
}
static bool HandleGoTicketCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
char* id = strtok((char*)args, " ");
if (!id)
return false;
uint32 ticketId = atoi(id);
if (!ticketId)
return false;
GmTicket* ticket = sTicketMgr->GetTicket(ticketId);
if (!ticket)
{
handler->SendSysMessage(LANG_COMMAND_TICKETNOTEXIST);
return true;
}
Player* player = handler->GetSession()->GetPlayer();
if (player->IsInFlight())
{
player->GetMotionMaster()->MovementExpired();
player->CleanupAfterTaxiFlight();
}
else
player->SaveRecallPosition();
ticket->TeleportTo(player);
return true;
}
};
void AddSC_go_commandscript()
{
new go_commandscript();
}
+720
View File
@@ -0,0 +1,720 @@
/*
* Copyright (C)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* ScriptData
Name: gobject_commandscript
%Complete: 100
Comment: All gobject related commands
Category: commandscripts
EndScriptData */
#include "ScriptMgr.h"
#include "GameEventMgr.h"
#include "ObjectMgr.h"
#include "PoolMgr.h"
#include "MapManager.h"
#include "Chat.h"
#include "Language.h"
#include "Player.h"
#include "Opcodes.h"
#include "Transport.h"
#include "GameObject.h"
class gobject_commandscript : public CommandScript
{
public:
gobject_commandscript() : CommandScript("gobject_commandscript") { }
ChatCommand* GetCommands() const
{
static ChatCommand gobjectAddCommandTable[] =
{
{ "temp", SEC_GAMEMASTER, false, &HandleGameObjectAddTempCommand, "", NULL },
{ "", SEC_GAMEMASTER, false, &HandleGameObjectAddCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand gobjectSetCommandTable[] =
{
{ "phase", SEC_GAMEMASTER, false, &HandleGameObjectSetPhaseCommand, "", NULL },
{ "state", SEC_GAMEMASTER, false, &HandleGameObjectSetStateCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand gobjectCommandTable[] =
{
{ "activate", SEC_GAMEMASTER, false, &HandleGameObjectActivateCommand, "", NULL },
{ "delete", SEC_GAMEMASTER, false, &HandleGameObjectDeleteCommand, "", NULL },
{ "info", SEC_GAMEMASTER, false, &HandleGameObjectInfoCommand, "", NULL },
{ "move", SEC_GAMEMASTER, false, &HandleGameObjectMoveCommand, "", NULL },
{ "near", SEC_GAMEMASTER, false, &HandleGameObjectNearCommand, "", NULL },
{ "target", SEC_GAMEMASTER, false, &HandleGameObjectTargetCommand, "", NULL },
{ "turn", SEC_GAMEMASTER, false, &HandleGameObjectTurnCommand, "", NULL },
{ "add", SEC_GAMEMASTER, false, NULL, "", gobjectAddCommandTable },
{ "set", SEC_GAMEMASTER, false, NULL, "", gobjectSetCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "gobject", SEC_GAMEMASTER, false, NULL, "", gobjectCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}
static bool HandleGameObjectActivateCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
char* id = handler->extractKeyFromLink((char*)args, "Hgameobject");
if (!id)
return false;
uint32 guidLow = atoi(id);
if (!guidLow)
return false;
GameObject* object = NULL;
// by DB guid
if (GameObjectData const* goData = sObjectMgr->GetGOData(guidLow))
object = handler->GetObjectGlobalyWithGuidOrNearWithDbGuid(guidLow, goData->id);
if (!object)
{
handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, guidLow);
handler->SetSentErrorMessage(true);
return false;
}
// Activate
object->SetLootState(GO_READY);
object->UseDoorOrButton(10000, false, handler->GetSession()->GetPlayer());
handler->PSendSysMessage("Object activated!");
return true;
}
//spawn go
static bool HandleGameObjectAddCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
// number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
char* id = handler->extractKeyFromLink((char*)args, "Hgameobject_entry");
if (!id)
return false;
uint32 objectId = atol(id);
if (!objectId)
return false;
char* spawntimeSecs = strtok(NULL, " ");
const GameObjectTemplate* objectInfo = sObjectMgr->GetGameObjectTemplate(objectId);
if (!objectInfo)
{
handler->PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST, objectId);
handler->SetSentErrorMessage(true);
return false;
}
if (objectInfo->displayId && !sGameObjectDisplayInfoStore.LookupEntry(objectInfo->displayId))
{
// report to DB errors log as in loading case
sLog->outErrorDb("Gameobject (Entry %u GoType: %u) have invalid displayId (%u), not spawned.", objectId, objectInfo->type, objectInfo->displayId);
handler->PSendSysMessage(LANG_GAMEOBJECT_HAVE_INVALID_DATA, objectId);
handler->SetSentErrorMessage(true);
return false;
}
Player* player = handler->GetSession()->GetPlayer();
float x = float(player->GetPositionX());
float y = float(player->GetPositionY());
float z = float(player->GetPositionZ());
float o = float(player->GetOrientation());
Map* map = player->GetMap();
GameObject* object = sObjectMgr->IsGameObjectStaticTransport(objectInfo->entry) ? new StaticTransport() : new GameObject();
uint32 guidLow = sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT);
if (!object->Create(guidLow, objectInfo->entry, map, player->GetPhaseMaskForSpawn(), x, y, z, o, G3D::Quat(), 0, GO_STATE_READY))
{
delete object;
return false;
}
if (spawntimeSecs)
{
uint32 value = atoi((char*)spawntimeSecs);
object->SetRespawnTime(value);
}
// fill the gameobject data and save to the db
object->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), player->GetPhaseMaskForSpawn());
// delete the old object and do a clean load from DB with a fresh new GameObject instance.
// this is required to avoid weird behavior and memory leaks
delete object;
object = sObjectMgr->IsGameObjectStaticTransport(objectInfo->entry) ? new StaticTransport() : new GameObject();
// this will generate a new guid if the object is in an instance
if (!object->LoadGameObjectFromDB(guidLow, map))
{
delete object;
return false;
}
// TODO: is it really necessary to add both the real and DB table guid here ?
sObjectMgr->AddGameobjectToGrid(guidLow, sObjectMgr->GetGOData(guidLow));
handler->PSendSysMessage(LANG_GAMEOBJECT_ADD, objectId, objectInfo->name.c_str(), guidLow, x, y, z);
return true;
}
// add go, temp only
static bool HandleGameObjectAddTempCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
char* id = strtok((char*)args, " ");
if (!id)
return false;
Player* player = handler->GetSession()->GetPlayer();
char* spawntime = strtok(NULL, " ");
uint32 spawntm = 300;
if (spawntime)
spawntm = atoi((char*)spawntime);
float x = player->GetPositionX();
float y = player->GetPositionY();
float z = player->GetPositionZ();
float ang = player->GetOrientation();
float rot2 = sin(ang/2);
float rot3 = cos(ang/2);
uint32 objectId = atoi(id);
player->SummonGameObject(objectId, x, y, z, ang, 0, 0, rot2, rot3, spawntm);
return true;
}
static bool HandleGameObjectTargetCommand(ChatHandler* handler, char const* args)
{
Player* player = handler->GetSession()->GetPlayer();
QueryResult result;
GameEventMgr::ActiveEvents const& activeEventsList = sGameEventMgr->GetActiveEventList();
if (*args)
{
// number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
char* id = handler->extractKeyFromLink((char*)args, "Hgameobject_entry");
if (!id)
return false;
uint32 objectId = atol(id);
if (objectId)
result = WorldDatabase.PQuery("SELECT guid, id, position_x, position_y, position_z, orientation, map, phaseMask, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM gameobject WHERE map = '%i' AND id = '%u' ORDER BY order_ ASC LIMIT 1",
player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetMapId(), objectId);
else
{
std::string name = id;
WorldDatabase.EscapeString(name);
result = WorldDatabase.PQuery(
"SELECT guid, id, position_x, position_y, position_z, orientation, map, phaseMask, (POW(position_x - %f, 2) + POW(position_y - %f, 2) + POW(position_z - %f, 2)) AS order_ "
"FROM gameobject, gameobject_template WHERE gameobject_template.entry = gameobject.id AND map = %i AND name " _LIKE_" " _CONCAT3_("'%%'", "'%s'", "'%%'")" ORDER BY order_ ASC LIMIT 1",
player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetMapId(), name.c_str());
}
}
else
{
std::ostringstream eventFilter;
eventFilter << " AND (eventEntry IS NULL ";
bool initString = true;
for (GameEventMgr::ActiveEvents::const_iterator itr = activeEventsList.begin(); itr != activeEventsList.end(); ++itr)
{
if (initString)
{
eventFilter << "OR eventEntry IN (" << *itr;
initString = false;
}
else
eventFilter << ',' << *itr;
}
if (!initString)
eventFilter << "))";
else
eventFilter << ')';
result = WorldDatabase.PQuery("SELECT gameobject.guid, id, position_x, position_y, position_z, orientation, map, phaseMask, "
"(POW(position_x - %f, 2) + POW(position_y - %f, 2) + POW(position_z - %f, 2)) AS order_ FROM gameobject "
"LEFT OUTER JOIN game_event_gameobject on gameobject.guid = game_event_gameobject.guid WHERE map = '%i' %s ORDER BY order_ ASC LIMIT 10",
handler->GetSession()->GetPlayer()->GetPositionX(), handler->GetSession()->GetPlayer()->GetPositionY(), handler->GetSession()->GetPlayer()->GetPositionZ(),
handler->GetSession()->GetPlayer()->GetMapId(), eventFilter.str().c_str());
}
if (!result)
{
handler->SendSysMessage(LANG_COMMAND_TARGETOBJNOTFOUND);
return true;
}
bool found = false;
float x, y, z, o;
uint32 guidLow, id, phase;
uint16 mapId;
uint32 poolId;
do
{
Field* fields = result->Fetch();
guidLow = fields[0].GetUInt32();
id = fields[1].GetUInt32();
x = fields[2].GetFloat();
y = fields[3].GetFloat();
z = fields[4].GetFloat();
o = fields[5].GetFloat();
mapId = fields[6].GetUInt16();
phase = fields[7].GetUInt32();
poolId = sPoolMgr->IsPartOfAPool<GameObject>(guidLow);
if (!poolId || sPoolMgr->IsSpawnedObject<GameObject>(guidLow))
found = true;
} while (result->NextRow() && !found);
if (!found)
{
handler->PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST, id);
return false;
}
GameObjectTemplate const* objectInfo = sObjectMgr->GetGameObjectTemplate(id);
if (!objectInfo)
{
handler->PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST, id);
return false;
}
GameObject* target = handler->GetSession()->GetPlayer()->GetMap()->GetGameObject(MAKE_NEW_GUID(guidLow, id, HIGHGUID_GAMEOBJECT));
handler->PSendSysMessage(LANG_GAMEOBJECT_DETAIL, guidLow, objectInfo->name.c_str(), guidLow, id, x, y, z, mapId, o, phase);
if (target)
{
int32 curRespawnDelay = int32(target->GetRespawnTimeEx() - time(NULL));
if (curRespawnDelay < 0)
curRespawnDelay = 0;
std::string curRespawnDelayStr = secsToTimeString(curRespawnDelay, true);
std::string defRespawnDelayStr = secsToTimeString(target->GetRespawnDelay(), true);
handler->PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES, defRespawnDelayStr.c_str(), curRespawnDelayStr.c_str());
}
return true;
}
//delete object by selection or guid
static bool HandleGameObjectDeleteCommand(ChatHandler* handler, char const* args)
{
// number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r
char* id = handler->extractKeyFromLink((char*)args, "Hgameobject");
if (!id)
return false;
uint32 guidLow = atoi(id);
if (!guidLow)
return false;
GameObject* object = NULL;
// by DB guid
if (GameObjectData const* gameObjectData = sObjectMgr->GetGOData(guidLow))
object = handler->GetObjectGlobalyWithGuidOrNearWithDbGuid(guidLow, gameObjectData->id);
if (!object)
{
handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, guidLow);
handler->SetSentErrorMessage(true);
return false;
}
uint64 ownerGuid = object->GetOwnerGUID();
if (ownerGuid)
{
Unit* owner = ObjectAccessor::GetUnit(*handler->GetSession()->GetPlayer(), ownerGuid);
if (!owner || !IS_PLAYER_GUID(ownerGuid))
{
handler->PSendSysMessage(LANG_COMMAND_DELOBJREFERCREATURE, GUID_LOPART(ownerGuid), object->GetGUIDLow());
handler->SetSentErrorMessage(true);
return false;
}
owner->RemoveGameObject(object, false);
}
object->SetRespawnTime(0); // not save respawn time
object->Delete();
object->DeleteFromDB();
handler->PSendSysMessage(LANG_COMMAND_DELOBJMESSAGE, object->GetGUIDLow());
return true;
}
//turn selected object
static bool HandleGameObjectTurnCommand(ChatHandler* handler, char const* args)
{
// number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r
char* id = handler->extractKeyFromLink((char*)args, "Hgameobject");
if (!id)
return false;
uint32 guidLow = atoi(id);
if (!guidLow)
return false;
GameObject* object = NULL;
// by DB guid
if (GameObjectData const* gameObjectData = sObjectMgr->GetGOData(guidLow))
object = handler->GetObjectGlobalyWithGuidOrNearWithDbGuid(guidLow, gameObjectData->id);
if (!object)
{
handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, guidLow);
handler->SetSentErrorMessage(true);
return false;
}
char* orientation = strtok(NULL, " ");
float oz = 0.f, oy = 0.f, ox = 0.f;
if (orientation)
{
oz = float(atof(orientation));
orientation = strtok(NULL, " ");
if (orientation)
{
oy = float(atof(orientation));
orientation = strtok(NULL, " ");
if (orientation)
ox = float(atof(orientation));
}
}
else
{
Player* player = handler->GetSession()->GetPlayer();
oz = player->GetOrientation();
}
object->SetWorldRotationAngles(oz, oy, ox);
object->DestroyForNearbyPlayers();
object->UpdateObjectVisibility();
object->SaveToDB();
object->Refresh();
handler->PSendSysMessage(LANG_COMMAND_TURNOBJMESSAGE, object->GetGUIDLow(), object->GetGOInfo()->name.c_str(), object->GetGUIDLow(), oz, oy, ox);
return true;
}
//move selected object
static bool HandleGameObjectMoveCommand(ChatHandler* handler, char const* args)
{
// number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r
char* id = handler->extractKeyFromLink((char*)args, "Hgameobject");
if (!id)
return false;
uint32 guidLow = atoi(id);
if (!guidLow)
return false;
GameObject* object = NULL;
// by DB guid
if (GameObjectData const* gameObjectData = sObjectMgr->GetGOData(guidLow))
object = handler->GetObjectGlobalyWithGuidOrNearWithDbGuid(guidLow, gameObjectData->id);
if (!object)
{
handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, guidLow);
handler->SetSentErrorMessage(true);
return false;
}
char* toX = strtok(NULL, " ");
char* toY = strtok(NULL, " ");
char* toZ = strtok(NULL, " ");
if (!toX)
{
Player* player = handler->GetSession()->GetPlayer();
object->GetMap()->GameObjectRelocation(object, player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), object->GetOrientation());
object->DestroyForNearbyPlayers();
object->UpdateObjectVisibility();
}
else
{
if (!toY || !toZ)
return false;
float x = (float)atof(toX);
float y = (float)atof(toY);
float z = (float)atof(toZ);
if (!MapManager::IsValidMapCoord(object->GetMapId(), x, y, z))
{
handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, x, y, object->GetMapId());
handler->SetSentErrorMessage(true);
return false;
}
object->GetMap()->GameObjectRelocation(object, x, y, z, object->GetOrientation());
object->DestroyForNearbyPlayers();
object->UpdateObjectVisibility();
}
object->SaveToDB();
object->Refresh();
handler->PSendSysMessage(LANG_COMMAND_MOVEOBJMESSAGE, object->GetGUIDLow(), object->GetGOInfo()->name.c_str(), object->GetGUIDLow());
return true;
}
//set phasemask for selected object
static bool HandleGameObjectSetPhaseCommand(ChatHandler* handler, char const* args)
{
// number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r
char* id = handler->extractKeyFromLink((char*)args, "Hgameobject");
if (!id)
return false;
uint32 guidLow = atoi(id);
if (!guidLow)
return false;
GameObject* object = NULL;
// by DB guid
if (GameObjectData const* gameObjectData = sObjectMgr->GetGOData(guidLow))
object = handler->GetObjectGlobalyWithGuidOrNearWithDbGuid(guidLow, gameObjectData->id);
if (!object)
{
handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, guidLow);
handler->SetSentErrorMessage(true);
return false;
}
char* phase = strtok (NULL, " ");
uint32 phaseMask = phase ? atoi(phase) : 0;
if (phaseMask == 0)
{
handler->SendSysMessage(LANG_BAD_VALUE);
handler->SetSentErrorMessage(true);
return false;
}
object->SetPhaseMask(phaseMask, true);
object->SaveToDB();
return true;
}
static bool HandleGameObjectNearCommand(ChatHandler* handler, char const* args)
{
float distance = (!*args) ? 10.0f : (float)(atof(args));
uint32 count = 0;
Player* player = handler->GetSession()->GetPlayer();
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_GAMEOBJECT_NEAREST);
stmt->setFloat(0, player->GetPositionX());
stmt->setFloat(1, player->GetPositionY());
stmt->setFloat(2, player->GetPositionZ());
stmt->setUInt32(3, player->GetMapId());
stmt->setFloat(4, player->GetPositionX());
stmt->setFloat(5, player->GetPositionY());
stmt->setFloat(6, player->GetPositionZ());
stmt->setFloat(7, distance * distance);
PreparedQueryResult result = WorldDatabase.Query(stmt);
if (result)
{
do
{
Field* fields = result->Fetch();
uint32 guid = fields[0].GetUInt32();
uint32 entry = fields[1].GetUInt32();
float x = fields[2].GetFloat();
float y = fields[3].GetFloat();
float z = fields[4].GetFloat();
uint16 mapId = fields[5].GetUInt16();
GameObjectTemplate const* gameObjectInfo = sObjectMgr->GetGameObjectTemplate(entry);
if (!gameObjectInfo)
continue;
handler->PSendSysMessage(LANG_GO_LIST_CHAT, guid, entry, guid, gameObjectInfo->name.c_str(), x, y, z, mapId);
++count;
} while (result->NextRow());
}
handler->PSendSysMessage(LANG_COMMAND_NEAROBJMESSAGE, distance, count);
return true;
}
//show info of gameobject
static bool HandleGameObjectInfoCommand(ChatHandler* handler, char const* args)
{
uint32 entry = 0;
uint32 type = 0;
uint32 displayId = 0;
std::string name;
uint32 lootId = 0;
GameObject* gameObject = NULL;
if (!*args)
{
if (WorldObject* object = handler->getSelectedObject())
{
entry = object->GetEntry();
if (object->GetTypeId() == TYPEID_GAMEOBJECT)
gameObject = object->ToGameObject();
}
}
else
entry = atoi((char*)args);
GameObjectTemplate const* gameObjectInfo = sObjectMgr->GetGameObjectTemplate(entry);
if (!gameObjectInfo)
return false;
type = gameObjectInfo->type;
displayId = gameObjectInfo->displayId;
name = gameObjectInfo->name;
if (type == GAMEOBJECT_TYPE_CHEST)
lootId = gameObjectInfo->chest.lootId;
else if (type == GAMEOBJECT_TYPE_FISHINGHOLE)
lootId = gameObjectInfo->fishinghole.lootId;
handler->PSendSysMessage(LANG_GOINFO_ENTRY, entry);
handler->PSendSysMessage(LANG_GOINFO_TYPE, type);
handler->PSendSysMessage(LANG_GOINFO_LOOTID, lootId);
handler->PSendSysMessage(LANG_GOINFO_DISPLAYID, displayId);
if (gameObject)
{
handler->PSendSysMessage("LootMode: %u", gameObject->GetLootMode());
handler->PSendSysMessage("LootState: %u", gameObject->getLootState());
handler->PSendSysMessage("GOState: %u", gameObject->GetGoState());
handler->PSendSysMessage("PhaseMask: %u", gameObject->GetPhaseMask());
handler->PSendSysMessage("IsLootEmpty: %u", gameObject->loot.empty());
handler->PSendSysMessage("IsLootLooted: %u", gameObject->loot.isLooted());
}
handler->PSendSysMessage(LANG_GOINFO_NAME, name.c_str());
return true;
}
static bool HandleGameObjectSetStateCommand(ChatHandler* handler, char const* args)
{
// number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r
char* id = handler->extractKeyFromLink((char*)args, "Hgameobject");
if (!id)
return false;
int32 guidLow = atoi(id);
if (!guidLow)
return false;
GameObject* object = NULL;
if (guidLow > 0)
{
if (GameObjectData const* gameObjectData = sObjectMgr->GetGOData(guidLow))
object = handler->GetObjectGlobalyWithGuidOrNearWithDbGuid(guidLow, gameObjectData->id);
}
else
object = handler->GetSession()->GetPlayer()->FindNearestGameObject(-guidLow, 30.0f);
if (!object)
{
handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, abs(guidLow));
handler->SetSentErrorMessage(true);
return false;
}
char* type = strtok(NULL, " ");
if (!type)
return false;
int32 objectType = atoi(type);
if (objectType < 0)
{
if (objectType == -1)
object->SendObjectDeSpawnAnim(object->GetGUID());
else if (objectType == -2)
return false;
return true;
}
char* state = strtok(NULL, " ");
if (!state)
return false;
int32 objectState = atoi(state);
if (objectType < 4)
object->SetByteValue(GAMEOBJECT_BYTES_1, objectType, objectState);
else if (objectType == 4)
{
WorldPacket data(SMSG_GAMEOBJECT_CUSTOM_ANIM, 8+4);
data << object->GetGUID();
data << (uint32)(objectState);
object->SendMessageToSet(&data, true);
}
else if (objectType == 5)
object->SetUInt32Value(GAMEOBJECT_FLAGS, (uint32)(objectState));
else if (objectType == 6)
object->SetGoArtKit((uint32)(objectState));
handler->PSendSysMessage("Set gobject type %d state %d", objectType, objectState);
return true;
}
};
void AddSC_gobject_commandscript()
{
new gobject_commandscript();
}
+201
View File
@@ -0,0 +1,201 @@
/*
* Copyright (C)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* ScriptData
Name: guild_commandscript
%Complete: 100
Comment: All guild related commands
Category: commandscripts
EndScriptData */
#include "Chat.h"
#include "Language.h"
#include "Guild.h"
#include "GuildMgr.h"
#include "ObjectAccessor.h"
#include "ScriptMgr.h"
class guild_commandscript : public CommandScript
{
public:
guild_commandscript() : CommandScript("guild_commandscript") { }
ChatCommand* GetCommands() const
{
static ChatCommand guildCommandTable[] =
{
{ "create", SEC_GAMEMASTER, true, &HandleGuildCreateCommand, "", NULL },
{ "delete", SEC_GAMEMASTER, true, &HandleGuildDeleteCommand, "", NULL },
{ "invite", SEC_GAMEMASTER, true, &HandleGuildInviteCommand, "", NULL },
{ "uninvite", SEC_GAMEMASTER, true, &HandleGuildUninviteCommand, "", NULL },
{ "rank", SEC_GAMEMASTER, true, &HandleGuildRankCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "guild", SEC_ADMINISTRATOR, true, NULL, "", guildCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}
/** \brief GM command level 3 - Create a guild.
*
* This command allows a GM (level 3) to create a guild.
*
* The "args" parameter contains the name of the guild leader
* and then the name of the guild.
*
*/
static bool HandleGuildCreateCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
// if not guild name only (in "") then player name
Player* target;
if (!handler->extractPlayerTarget(*args != '"' ? (char*)args : NULL, &target))
return false;
char* tailStr = *args != '"' ? strtok(NULL, "") : (char*)args;
if (!tailStr)
return false;
char* guildStr = handler->extractQuotedArg(tailStr);
if (!guildStr)
return false;
std::string guildName = guildStr;
if (target->GetGuildId())
{
handler->SendSysMessage(LANG_PLAYER_IN_GUILD);
return true;
}
Guild* guild = new Guild;
if (!guild->Create(target, guildName))
{
delete guild;
handler->SendSysMessage(LANG_GUILD_NOT_CREATED);
handler->SetSentErrorMessage(true);
return false;
}
sGuildMgr->AddGuild(guild);
return true;
}
static bool HandleGuildDeleteCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
char* guildStr = handler->extractQuotedArg((char*)args);
if (!guildStr)
return false;
std::string guildName = guildStr;
Guild* targetGuild = sGuildMgr->GetGuildByName(guildName);
if (!targetGuild)
return false;
targetGuild->Disband();
delete targetGuild;
return true;
}
static bool HandleGuildInviteCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
// if not guild name only (in "") then player name
uint64 targetGuid;
if (!handler->extractPlayerTarget(*args != '"' ? (char*)args : NULL, NULL, &targetGuid))
return false;
char* tailStr = *args != '"' ? strtok(NULL, "") : (char*)args;
if (!tailStr)
return false;
char* guildStr = handler->extractQuotedArg(tailStr);
if (!guildStr)
return false;
std::string guildName = guildStr;
Guild* targetGuild = sGuildMgr->GetGuildByName(guildName);
if (!targetGuild)
return false;
// player's guild membership checked in AddMember before add
return targetGuild->AddMember(targetGuid);
}
static bool HandleGuildUninviteCommand(ChatHandler* handler, char const* args)
{
Player* target;
uint64 targetGuid;
if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid))
return false;
uint32 guildId = target ? target->GetGuildId() : Player::GetGuildIdFromStorage(GUID_LOPART(targetGuid));
if (!guildId)
return false;
Guild* targetGuild = sGuildMgr->GetGuildById(guildId);
if (!targetGuild)
return false;
targetGuild->DeleteMember(targetGuid, false, true, true);
return true;
}
static bool HandleGuildRankCommand(ChatHandler* handler, char const* args)
{
char* nameStr;
char* rankStr;
handler->extractOptFirstArg((char*)args, &nameStr, &rankStr);
if (!rankStr)
return false;
Player* target;
uint64 targetGuid;
std::string target_name;
if (!handler->extractPlayerTarget(nameStr, &target, &targetGuid, &target_name))
return false;
uint32 guildId = target ? target->GetGuildId() : Player::GetGuildIdFromStorage(GUID_LOPART(targetGuid));
if (!guildId)
return false;
Guild* targetGuild = sGuildMgr->GetGuildById(guildId);
if (!targetGuild)
return false;
uint8 newRank = uint8(atoi(rankStr));
return targetGuild->ChangeMemberRank(targetGuid, newRank);
}
};
void AddSC_guild_commandscript()
{
new guild_commandscript();
}
+122
View File
@@ -0,0 +1,122 @@
/*
* Copyright (C)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* ScriptData
Name: honor_commandscript
%Complete: 100
Comment: All honor related commands
Category: commandscripts
EndScriptData */
#include "Chat.h"
#include "Language.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "ScriptMgr.h"
class honor_commandscript : public CommandScript
{
public:
honor_commandscript() : CommandScript("honor_commandscript") { }
ChatCommand* GetCommands() const
{
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;
}
static bool HandleHonorAddCommand(ChatHandler* handler, char const* args)
{
if (!*args)
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;
uint32 amount = (uint32)atoi(args);
target->RewardHonor(NULL, 1, amount);
return true;
}
static bool HandleHonorAddKillCommand(ChatHandler* handler, char const* /*args*/)
{
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(target->ToPlayer(), 0))
return false;
handler->GetSession()->GetPlayer()->RewardHonor(target, 1);
return true;
}
static bool HandleHonorUpdateCommand(ChatHandler* handler, char const* /*args*/)
{
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;
}
};
void AddSC_honor_commandscript()
{
new honor_commandscript();
}
+184
View File
@@ -0,0 +1,184 @@
/*
* Copyright (C)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* ScriptData
Name: instance_commandscript
%Complete: 100
Comment: All instance related commands
Category: commandscripts
EndScriptData */
#include "ScriptMgr.h"
#include "Chat.h"
#include "Group.h"
#include "InstanceSaveMgr.h"
#include "InstanceScript.h"
#include "MapManager.h"
#include "Player.h"
class instance_commandscript : public CommandScript
{
public:
instance_commandscript() : CommandScript("instance_commandscript") { }
ChatCommand* GetCommands() const
{
static ChatCommand instanceCommandTable[] =
{
{ "listbinds", SEC_ADMINISTRATOR, false, &HandleInstanceListBindsCommand, "", NULL },
{ "unbind", SEC_ADMINISTRATOR, false, &HandleInstanceUnbindCommand, "", NULL },
{ "stats", SEC_ADMINISTRATOR, true, &HandleInstanceStatsCommand, "", NULL },
{ "savedata", SEC_ADMINISTRATOR, false, &HandleInstanceSaveDataCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "instance", SEC_ADMINISTRATOR, true, NULL, "", instanceCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}
static std::string GetTimeString(uint64 time)
{
uint64 days = time / DAY, hours = (time % DAY) / HOUR, minute = (time % HOUR) / MINUTE;
std::ostringstream ss;
if (days)
ss << days << "d ";
if (hours)
ss << hours << "h ";
ss << minute << 'm';
return ss.str();
}
static bool HandleInstanceListBindsCommand(ChatHandler* handler, char const* /*args*/)
{
Player* player = handler->getSelectedPlayer();
if (!player)
player = handler->GetSession()->GetPlayer();
uint32 counter = 0;
for (uint8 i = 0; i < MAX_DIFFICULTY; ++i)
{
BoundInstancesMap const& m_boundInstances = sInstanceSaveMgr->PlayerGetBoundInstances(player->GetGUIDLow(), Difficulty(i));
for (BoundInstancesMap::const_iterator itr = m_boundInstances.begin(); itr != m_boundInstances.end(); ++itr)
{
InstanceSave* save = itr->second.save;
uint32 resetTime = itr->second.extended ? save->GetExtendedResetTime() : save->GetResetTime();
uint32 ttr = (resetTime >= time(NULL) ? resetTime - time(NULL) : 0);
std::string timeleft = GetTimeString(ttr);
handler->PSendSysMessage("map: %d, inst: %d, perm: %s, diff: %d, canReset: %s, TTR: %s%s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty(), save->CanReset() ? "yes" : "no", timeleft.c_str(), (itr->second.extended ? " (extended)" : ""));
counter++;
}
}
handler->PSendSysMessage("player binds: %d", counter);
return true;
}
static bool HandleInstanceUnbindCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
Player* player = handler->getSelectedPlayer();
if (!player)
player = handler->GetSession()->GetPlayer();
char* map = strtok((char*)args, " ");
char* pDiff = strtok(NULL, " ");
int8 diff = -1;
if (pDiff)
diff = atoi(pDiff);
uint16 counter = 0;
uint16 MapId = 0;
if (strcmp(map, "all"))
{
MapId = uint16(atoi(map));
if (!MapId)
return false;
}
for (uint8 i = 0; i < MAX_DIFFICULTY; ++i)
{
BoundInstancesMap const& m_boundInstances = sInstanceSaveMgr->PlayerGetBoundInstances(player->GetGUIDLow(), Difficulty(i));
for (BoundInstancesMap::const_iterator itr = m_boundInstances.begin(); itr != m_boundInstances.end();)
{
InstanceSave* save = itr->second.save;
if (itr->first != player->GetMapId() && (!MapId || MapId == itr->first) && (diff == -1 || diff == save->GetDifficulty()))
{
uint32 resetTime = itr->second.extended ? save->GetExtendedResetTime() : save->GetResetTime();
uint32 ttr = (resetTime >= time(NULL) ? resetTime - time(NULL) : 0);
std::string timeleft = GetTimeString(ttr);
handler->PSendSysMessage("unbinding map: %d, inst: %d, perm: %s, diff: %d, canReset: %s, TTR: %s%s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty(), save->CanReset() ? "yes" : "no", timeleft.c_str(), (itr->second.extended ? " (extended)" : ""));
sInstanceSaveMgr->PlayerUnbindInstance(player->GetGUIDLow(), itr->first, Difficulty(i), true, player);
itr = m_boundInstances.begin();
counter++;
}
else
++itr;
}
}
handler->PSendSysMessage("instances unbound: %d", counter);
return true;
}
static bool HandleInstanceStatsCommand(ChatHandler* handler, char const* /*args*/)
{
uint32 dungeon = 0, battleground = 0, arena = 0, spectators = 0;
sMapMgr->GetNumInstances(dungeon, battleground, arena);
handler->PSendSysMessage("instances loaded: dungeons (%d), battlegrounds (%d), arenas (%d)", dungeon, battleground, arena);
dungeon = 0; battleground = 0; arena = 0; spectators = 0;
sMapMgr->GetNumPlayersInInstances(dungeon, battleground, arena, spectators);
handler->PSendSysMessage("players in instances: dungeons (%d), battlegrounds (%d), arenas (%d + %d spect)", dungeon, battleground, arena, spectators);
handler->SetSentErrorMessage(true);
return false;
}
static bool HandleInstanceSaveDataCommand(ChatHandler* handler, char const* /*args*/)
{
Player* player = handler->GetSession()->GetPlayer();
Map* map = player->GetMap();
if (!map->IsDungeon())
{
handler->PSendSysMessage("Map is not a dungeon.");
handler->SetSentErrorMessage(true);
return false;
}
if (!map->ToInstanceMap()->GetInstanceScript())
{
handler->PSendSysMessage("Map has no instance data.");
handler->SetSentErrorMessage(true);
return false;
}
map->ToInstanceMap()->GetInstanceScript()->SaveToDB();
return true;
}
};
void AddSC_instance_commandscript()
{
new instance_commandscript();
}
+528
View File
@@ -0,0 +1,528 @@
/*
* Copyright (C)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* ScriptData
Name: learn_commandscript
%Complete: 100
Comment: All learn related commands
Category: commandscripts
EndScriptData */
#include "Chat.h"
#include "ScriptMgr.h"
#include "ObjectMgr.h"
#include "Language.h"
#include "SpellMgr.h"
#include "SpellInfo.h"
#include "Player.h"
#include "Pet.h"
class learn_commandscript : public CommandScript
{
public:
learn_commandscript() : CommandScript("learn_commandscript") { }
ChatCommand* GetCommands() const
{
static ChatCommand learnAllMyCommandTable[] =
{
{ "class", SEC_ADMINISTRATOR, false, &HandleLearnAllMyClassCommand, "", NULL },
{ "pettalents", SEC_ADMINISTRATOR, false, &HandleLearnAllMyPetTalentsCommand, "", NULL },
{ "spells", SEC_ADMINISTRATOR, false, &HandleLearnAllMySpellsCommand, "", NULL },
{ "talents", SEC_ADMINISTRATOR, false, &HandleLearnAllMyTalentsCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand learnAllCommandTable[] =
{
{ "my", SEC_ADMINISTRATOR, false, NULL, "", learnAllMyCommandTable },
{ "gm", SEC_GAMEMASTER, false, &HandleLearnAllGMCommand, "", NULL },
{ "crafts", SEC_GAMEMASTER, false, &HandleLearnAllCraftsCommand, "", NULL },
{ "default", SEC_GAMEMASTER, false, &HandleLearnAllDefaultCommand, "", NULL },
{ "lang", SEC_GAMEMASTER, false, &HandleLearnAllLangCommand, "", NULL },
{ "recipes", SEC_GAMEMASTER, false, &HandleLearnAllRecipesCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand learnCommandTable[] =
{
{ "all", SEC_ADMINISTRATOR, false, NULL, "", learnAllCommandTable },
{ "", SEC_ADMINISTRATOR, false, &HandleLearnCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "learn", SEC_GAMEMASTER, false, NULL, "", learnCommandTable },
{ "unlearn", SEC_ADMINISTRATOR, false, &HandleUnLearnCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}
static bool HandleLearnCommand(ChatHandler* handler, char const* args)
{
Player* targetPlayer = handler->getSelectedPlayer();
if (!targetPlayer)
{
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
handler->SetSentErrorMessage(true);
return false;
}
// number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
uint32 spell = handler->extractSpellIdFromLink((char*)args);
if (!spell)
return false;
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spell);
if (!spellInfo)
{
handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND);
handler->SetSentErrorMessage(true);
return false;
}
if (!SpellMgr::IsSpellValid(spellInfo))
{
handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spell);
handler->SetSentErrorMessage(true);
return false;
}
SpellScriptsBounds bounds = sObjectMgr->GetSpellScriptsBounds(spell);
uint32 spellDifficultyId = sSpellMgr->GetSpellDifficultyId(spell);
if (handler->GetSession()->GetSecurity() < SEC_CONSOLE && (bounds.first != bounds.second || spellDifficultyId))
{
handler->PSendSysMessage("Spell %u cannot be learnt using a command!", spell);
handler->SetSentErrorMessage(true);
return false;
}
char const* all = strtok(NULL, " ");
bool allRanks = all ? (strncmp(all, "all", strlen(all)) == 0) : false;
if (!allRanks && targetPlayer->HasSpell(spell))
{
if (targetPlayer == handler->GetSession()->GetPlayer())
handler->SendSysMessage(LANG_YOU_KNOWN_SPELL);
else
handler->PSendSysMessage(LANG_TARGET_KNOWN_SPELL, handler->GetNameLink(targetPlayer).c_str());
handler->SetSentErrorMessage(true);
return false;
}
if (allRanks)
targetPlayer->learnSpellHighRank(spell);
else
targetPlayer->learnSpell(spell);
uint32 firstSpell = sSpellMgr->GetFirstSpellInChain(spell);
if (GetTalentSpellCost(firstSpell))
targetPlayer->SendTalentsInfoData(false);
return true;
}
static bool HandleLearnAllGMCommand(ChatHandler* handler, char const* /*args*/)
{
for (uint32 i = 0; i < sSpellMgr->GetSpellInfoStoreSize(); ++i)
{
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(i);
if (!spellInfo || !SpellMgr::IsSpellValid(spellInfo))
continue;
if (!spellInfo->IsAbilityOfSkillType(SKILL_INTERNAL))
continue;
handler->GetSession()->GetPlayer()->learnSpell(i);
}
handler->SendSysMessage(LANG_LEARNING_GM_SKILLS);
return true;
}
static bool HandleLearnAllMyClassCommand(ChatHandler* handler, char const* /*args*/)
{
HandleLearnAllMySpellsCommand(handler, "");
HandleLearnAllMyTalentsCommand(handler, "");
return true;
}
static bool HandleLearnAllMySpellsCommand(ChatHandler* handler, char const* /*args*/)
{
ChrClassesEntry const* classEntry = sChrClassesStore.LookupEntry(handler->GetSession()->GetPlayer()->getClass());
if (!classEntry)
return true;
uint32 family = classEntry->spellfamily;
for (uint32 i = 0; i < sSkillLineAbilityStore.GetNumRows(); ++i)
{
SkillLineAbilityEntry const* entry = sSkillLineAbilityStore.LookupEntry(i);
if (!entry)
continue;
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(entry->spellId);
if (!spellInfo)
continue;
// skip server-side/triggered spells
if (spellInfo->SpellLevel == 0)
continue;
// skip wrong class/race skills
if (!handler->GetSession()->GetPlayer()->IsSpellFitByClassAndRace(spellInfo->Id))
continue;
// skip other spell families
if (spellInfo->SpellFamilyName != family)
continue;
// skip spells with first rank learned as talent (and all talents then also)
uint32 firstRank = sSpellMgr->GetFirstSpellInChain(spellInfo->Id);
if (GetTalentSpellCost(firstRank) > 0)
continue;
// skip broken spells
if (!SpellMgr::IsSpellValid(spellInfo))
continue;
handler->GetSession()->GetPlayer()->learnSpell(spellInfo->Id);
}
handler->SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS);
return true;
}
static bool HandleLearnAllMyTalentsCommand(ChatHandler* handler, char const* /*args*/)
{
Player* player = handler->GetSession()->GetPlayer();
uint32 classMask = player->getClassMask();
for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i)
{
TalentEntry const* talentInfo = sTalentStore.LookupEntry(i);
if (!talentInfo)
continue;
TalentTabEntry const* talentTabInfo = sTalentTabStore.LookupEntry(talentInfo->TalentTab);
if (!talentTabInfo)
continue;
if ((classMask & talentTabInfo->ClassMask) == 0)
continue;
// xinef: search highest talent rank
uint32 spellId = 0;
uint8 rankId = MAX_TALENT_RANK;
for (int8 rank = MAX_TALENT_RANK - 1; rank >= 0; --rank)
{
if (talentInfo->RankID[rank] != 0)
{
rankId = rank;
spellId = talentInfo->RankID[rank];
break;
}
}
// xinef: some errors?
if (!spellId || rankId == MAX_TALENT_RANK)
continue;
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
if (!spellInfo || !SpellMgr::IsSpellValid(spellInfo))
continue;
player->LearnTalent(talentInfo->TalentID, rankId);
}
handler->SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS);
return true;
}
static bool HandleLearnAllMyPetTalentsCommand(ChatHandler* handler, char const* /*args*/)
{
Player* player = handler->GetSession()->GetPlayer();
Pet* pet = player->GetPet();
if (!pet)
{
handler->SendSysMessage(LANG_NO_PET_FOUND);
handler->SetSentErrorMessage(true);
return false;
}
CreatureTemplate const* creatureInfo = pet->GetCreatureTemplate();
if (!creatureInfo)
{
handler->SendSysMessage(LANG_WRONG_PET_TYPE);
handler->SetSentErrorMessage(true);
return false;
}
CreatureFamilyEntry const* petFamily = sCreatureFamilyStore.LookupEntry(creatureInfo->family);
if (!petFamily)
{
handler->SendSysMessage(LANG_WRONG_PET_TYPE);
handler->SetSentErrorMessage(true);
return false;
}
if (petFamily->petTalentType < 0) // not hunter pet
{
handler->SendSysMessage(LANG_WRONG_PET_TYPE);
handler->SetSentErrorMessage(true);
return false;
}
for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i)
{
TalentEntry const* talentInfo = sTalentStore.LookupEntry(i);
if (!talentInfo)
continue;
TalentTabEntry const* talentTabInfo = sTalentTabStore.LookupEntry(talentInfo->TalentTab);
if (!talentTabInfo)
continue;
// prevent learn talent for different family (cheating)
if (((1 << petFamily->petTalentType) & talentTabInfo->petTalentMask) == 0)
continue;
// search highest talent rank
uint32 spellId = 0;
for (int8 rank = MAX_TALENT_RANK-1; rank >= 0; --rank)
{
if (talentInfo->RankID[rank] != 0)
{
spellId = talentInfo->RankID[rank];
break;
}
}
if (!spellId) // ??? none spells in talent
continue;
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
if (!spellInfo || !SpellMgr::IsSpellValid(spellInfo))
continue;
// learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
pet->learnSpellHighRank(spellId);
}
pet->SetFreeTalentPoints(0);
handler->SendSysMessage(LANG_COMMAND_LEARN_PET_TALENTS);
return true;
}
static bool HandleLearnAllLangCommand(ChatHandler* handler, char const* /*args*/)
{
// skipping UNIVERSAL language (0)
for (uint8 i = 1; i < LANGUAGES_COUNT; ++i)
handler->GetSession()->GetPlayer()->learnSpell(lang_description[i].spell_id);
handler->SendSysMessage(LANG_COMMAND_LEARN_ALL_LANG);
return true;
}
static bool HandleLearnAllDefaultCommand(ChatHandler* handler, char const* args)
{
Player* target;
if (!handler->extractPlayerTarget((char*)args, &target))
return false;
target->learnDefaultSpells();
target->learnQuestRewardedSpells();
handler->PSendSysMessage(LANG_COMMAND_LEARN_ALL_DEFAULT_AND_QUEST, handler->GetNameLink(target).c_str());
return true;
}
static bool HandleLearnAllCraftsCommand(ChatHandler* handler, char const* /*args*/)
{
for (uint32 i = 0; i < sSkillLineStore.GetNumRows(); ++i)
{
SkillLineEntry const* skillInfo = sSkillLineStore.LookupEntry(i);
if (!skillInfo)
continue;
if ((skillInfo->categoryId == SKILL_CATEGORY_PROFESSION || skillInfo->categoryId == SKILL_CATEGORY_SECONDARY) &&
skillInfo->canLink) // only prof. with recipes have
{
HandleLearnSkillRecipesHelper(handler->GetSession()->GetPlayer(), skillInfo->id);
}
}
handler->SendSysMessage(LANG_COMMAND_LEARN_ALL_CRAFT);
return true;
}
static bool HandleLearnAllRecipesCommand(ChatHandler* handler, char const* args)
{
// Learns all recipes of specified profession and sets skill to max
// Example: .learn all_recipes enchanting
Player* target = handler->getSelectedPlayer();
if (!target)
{
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
return false;
}
if (!*args)
return false;
std::wstring namePart;
if (!Utf8toWStr(args, namePart))
return false;
// converting string that we try to find to lower case
wstrToLower(namePart);
std::string name;
SkillLineEntry const* targetSkillInfo = NULL;
for (uint32 i = 1; i < sSkillLineStore.GetNumRows(); ++i)
{
SkillLineEntry const* skillInfo = sSkillLineStore.LookupEntry(i);
if (!skillInfo)
continue;
if ((skillInfo->categoryId != SKILL_CATEGORY_PROFESSION &&
skillInfo->categoryId != SKILL_CATEGORY_SECONDARY) ||
!skillInfo->canLink) // only prof with recipes have set
continue;
int locale = handler->GetSessionDbcLocale();
name = skillInfo->name[locale];
if (name.empty())
continue;
if (!Utf8FitTo(name, namePart))
{
locale = 0;
for (; locale < TOTAL_LOCALES; ++locale)
{
if (locale == handler->GetSessionDbcLocale())
continue;
name = skillInfo->name[locale];
if (name.empty())
continue;
if (Utf8FitTo(name, namePart))
break;
}
}
if (locale < TOTAL_LOCALES)
{
targetSkillInfo = skillInfo;
break;
}
}
if (!targetSkillInfo)
return false;
HandleLearnSkillRecipesHelper(target, targetSkillInfo->id);
uint16 maxLevel = target->GetPureMaxSkillValue(targetSkillInfo->id);
target->SetSkill(targetSkillInfo->id, target->GetSkillStep(targetSkillInfo->id), maxLevel, maxLevel);
handler->PSendSysMessage(LANG_COMMAND_LEARN_ALL_RECIPES, name.c_str());
return true;
}
static void HandleLearnSkillRecipesHelper(Player* player, uint32 skillId)
{
uint32 classmask = player->getClassMask();
for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j)
{
SkillLineAbilityEntry const* skillLine = sSkillLineAbilityStore.LookupEntry(j);
if (!skillLine)
continue;
// wrong skill
if (skillLine->skillId != skillId)
continue;
// not high rank
if (skillLine->forward_spellid)
continue;
// skip racial skills
if (skillLine->racemask != 0)
continue;
// skip wrong class skills
if (skillLine->classmask && (skillLine->classmask & classmask) == 0)
continue;
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(skillLine->spellId);
if (!spellInfo || !SpellMgr::IsSpellValid(spellInfo))
continue;
player->learnSpell(skillLine->spellId);
}
}
static bool HandleUnLearnCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
// number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
uint32 spellId = handler->extractSpellIdFromLink((char*)args);
if (!spellId)
return false;
char const* allStr = strtok(NULL, " ");
bool allRanks = allStr ? (strncmp(allStr, "all", strlen(allStr)) == 0) : false;
Player* target = handler->getSelectedPlayer();
if (!target)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
if (allRanks)
spellId = sSpellMgr->GetFirstSpellInChain (spellId);
if (target->HasSpell(spellId))
target->removeSpell(spellId, SPEC_MASK_ALL, false);
else
handler->SendSysMessage(LANG_FORGET_SPELL);
if (GetTalentSpellCost(spellId))
target->SendTalentsInfoData(false);
return true;
}
};
void AddSC_learn_commandscript()
{
new learn_commandscript();
}
+135
View File
@@ -0,0 +1,135 @@
/*
* Copyright (C)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ScriptMgr.h"
#include "Chat.h"
#include "Language.h"
#include "LFGMgr.h"
#include "Group.h"
#include "Player.h"
void GetPlayerInfo(ChatHandler* handler, Player* player)
{
if (!player)
return;
uint64 guid = player->GetGUID();
lfg::LfgDungeonSet dungeons = sLFGMgr->GetSelectedDungeons(guid);
/*std::string const& state = lfg::GetStateString(sLFGMgr->GetState(guid));
handler->PSendSysMessage(LANG_LFG_PLAYER_INFO, player->GetName().c_str(),
state.c_str(), uint8(dungeons.size()), lfg::ConcatenateDungeons(dungeons).c_str(),
lfg::GetRolesString(sLFGMgr->GetRoles(guid)).c_str(), sLFGMgr->GetComment(guid).c_str());*/
}
class lfg_commandscript : public CommandScript
{
public:
lfg_commandscript() : CommandScript("lfg_commandscript") { }
ChatCommand* GetCommands() const
{
static ChatCommand lfgCommandTable[] =
{
{ "player", SEC_GAMEMASTER, false, &HandleLfgPlayerInfoCommand, "", NULL },
{ "group", SEC_GAMEMASTER, false, &HandleLfgGroupInfoCommand, "", NULL },
{ "queue", SEC_GAMEMASTER, false, &HandleLfgQueueInfoCommand, "", NULL },
{ "clean", SEC_ADMINISTRATOR, false, &HandleLfgCleanCommand, "", NULL },
{ "options", SEC_ADMINISTRATOR, false, &HandleLfgOptionsCommand, "", NULL },
{ NULL, SEC_PLAYER, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "lfg", SEC_GAMEMASTER, false, NULL, "", lfgCommandTable },
{ NULL, SEC_PLAYER, false, NULL, "", NULL }
};
return commandTable;
}
static bool HandleLfgPlayerInfoCommand(ChatHandler* handler, char const* args)
{
Player* target = NULL;
std::string playerName;
if (!handler->extractPlayerTarget((char*)args, &target, NULL, &playerName))
return false;
GetPlayerInfo(handler, target);
return true;
}
static bool HandleLfgGroupInfoCommand(ChatHandler* handler, char const* args)
{
Player* target = NULL;
std::string playerName;
if (!handler->extractPlayerTarget((char*)args, &target, NULL, &playerName))
return false;
Group* grp = target->GetGroup();
if (!grp)
{
handler->PSendSysMessage(LANG_LFG_NOT_IN_GROUP, playerName.c_str());
return true;
}
/*
uint64 guid = grp->GetGUID();
std::string const& state = lfg::GetStateString(sLFGMgr->GetState(guid));
handler->PSendSysMessage(LANG_LFG_GROUP_INFO, grp->isLFGGroup(),
state.c_str(), sLFGMgr->GetDungeon(guid));
for (GroupReference* itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
GetPlayerInfo(handler, itr->GetSource());
*/
return true;
}
static bool HandleLfgOptionsCommand(ChatHandler* handler, char const* args)
{
int32 options = -1;
if (char* str = strtok((char*)args, " "))
{
int32 tmp = atoi(str);
if (tmp > -1)
options = tmp;
}
if (options != -1)
{
sLFGMgr->SetOptions(options);
handler->PSendSysMessage(LANG_LFG_OPTIONS_CHANGED);
}
handler->PSendSysMessage(LANG_LFG_OPTIONS, sLFGMgr->GetOptions());
return true;
}
static bool HandleLfgQueueInfoCommand(ChatHandler* handler, char const* args)
{
return true;
}
static bool HandleLfgCleanCommand(ChatHandler* handler, char const* /*args*/)
{
handler->PSendSysMessage(LANG_LFG_CLEAN);
sLFGMgr->Clean();
return true;
}
};
void AddSC_lfg_commandscript()
{
new lfg_commandscript();
}
+474
View File
@@ -0,0 +1,474 @@
/*
* Copyright (C)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* ScriptData
Name: list_commandscript
%Complete: 100
Comment: All list related commands
Category: commandscripts
EndScriptData */
#include "ScriptMgr.h"
#include "Chat.h"
#include "SpellAuraEffects.h"
#include "Language.h"
#include "ObjectAccessor.h"
#include "ObjectMgr.h"
#include "Player.h"
class list_commandscript : public CommandScript
{
public:
list_commandscript() : CommandScript("list_commandscript") { }
ChatCommand* GetCommands() const
{
static ChatCommand listCommandTable[] =
{
{ "creature", SEC_ADMINISTRATOR, true, &HandleListCreatureCommand, "", NULL },
{ "item", SEC_ADMINISTRATOR, true, &HandleListItemCommand, "", NULL },
{ "object", SEC_ADMINISTRATOR, true, &HandleListObjectCommand, "", NULL },
{ "auras", SEC_ADMINISTRATOR, false, &HandleListAurasCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "list", SEC_ADMINISTRATOR, true, NULL, "", listCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}
static bool HandleListCreatureCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
// number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
char* id = handler->extractKeyFromLink((char*)args, "Hcreature_entry");
if (!id)
return false;
uint32 creatureId = atol(id);
if (!creatureId)
{
handler->PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, creatureId);
handler->SetSentErrorMessage(true);
return false;
}
CreatureTemplate const* cInfo = sObjectMgr->GetCreatureTemplate(creatureId);
if (!cInfo)
{
handler->PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, creatureId);
handler->SetSentErrorMessage(true);
return false;
}
char* countStr = strtok(NULL, " ");
uint32 count = countStr ? atol(countStr) : 10;
if (count == 0)
return false;
QueryResult result;
uint32 creatureCount = 0;
result = WorldDatabase.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'", creatureId);
if (result)
creatureCount = (*result)[0].GetUInt64();
if (handler->GetSession())
{
Player* player = handler->GetSession()->GetPlayer();
result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM creature WHERE id = '%u' ORDER BY order_ ASC LIMIT %u",
player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), creatureId, count);
}
else
result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
creatureId, count);
if (result)
{
do
{
Field* fields = result->Fetch();
uint32 guid = fields[0].GetUInt32();
float x = fields[1].GetFloat();
float y = fields[2].GetFloat();
float z = fields[3].GetFloat();
uint16 mapId = fields[4].GetUInt16();
if (handler->GetSession())
handler->PSendSysMessage(LANG_CREATURE_LIST_CHAT, guid, guid, cInfo->Name.c_str(), x, y, z, mapId);
else
handler->PSendSysMessage(LANG_CREATURE_LIST_CONSOLE, guid, cInfo->Name.c_str(), x, y, z, mapId);
}
while (result->NextRow());
}
handler->PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE, creatureId, creatureCount);
return true;
}
static bool HandleListItemCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
char* id = handler->extractKeyFromLink((char*)args, "Hitem");
if (!id)
return false;
uint32 itemId = atol(id);
if (!itemId)
{
handler->PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, itemId);
handler->SetSentErrorMessage(true);
return false;
}
ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(itemId);
if (!itemTemplate)
{
handler->PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, itemId);
handler->SetSentErrorMessage(true);
return false;
}
char* countStr = strtok(NULL, " ");
uint32 count = countStr ? atol(countStr) : 10;
if (count == 0)
return false;
PreparedQueryResult result;
// inventory case
uint32 inventoryCount = 0;
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_INVENTORY_COUNT_ITEM);
stmt->setUInt32(0, itemId);
result = CharacterDatabase.Query(stmt);
if (result)
inventoryCount = (*result)[0].GetUInt64();
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_INVENTORY_ITEM_BY_ENTRY);
stmt->setUInt32(0, itemId);
stmt->setUInt32(1, count);
result = CharacterDatabase.Query(stmt);
if (result)
{
do
{
Field* fields = result->Fetch();
uint32 itemGuid = fields[0].GetUInt32();
uint32 itemBag = fields[1].GetUInt32();
uint8 itemSlot = fields[2].GetUInt8();
uint32 ownerGuid = fields[3].GetUInt32();
uint32 ownerAccountId = fields[4].GetUInt32();
std::string ownerName = fields[5].GetString();
char const* itemPos = 0;
if (Player::IsEquipmentPos(itemBag, itemSlot))
itemPos = "[equipped]";
else if (Player::IsInventoryPos(itemBag, itemSlot))
itemPos = "[in inventory]";
else if (Player::IsBankPos(itemBag, itemSlot))
itemPos = "[in bank]";
else
itemPos = "";
handler->PSendSysMessage(LANG_ITEMLIST_SLOT, itemGuid, ownerName.c_str(), ownerGuid, ownerAccountId, itemPos);
}
while (result->NextRow());
uint32 resultCount = uint32(result->GetRowCount());
if (count > resultCount)
count -= resultCount;
else if (count)
count = 0;
}
// mail case
uint32 mailCount = 0;
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_MAIL_COUNT_ITEM);
stmt->setUInt32(0, itemId);
result = CharacterDatabase.Query(stmt);
if (result)
mailCount = (*result)[0].GetUInt64();
if (count > 0)
{
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_MAIL_ITEMS_BY_ENTRY);
stmt->setUInt32(0, itemId);
stmt->setUInt32(1, count);
result = CharacterDatabase.Query(stmt);
}
else
result = PreparedQueryResult(NULL);
if (result)
{
do
{
Field* fields = result->Fetch();
uint32 itemGuid = fields[0].GetUInt32();
uint32 itemSender = fields[1].GetUInt32();
uint32 itemReceiver = fields[2].GetUInt32();
uint32 itemSenderAccountId = fields[3].GetUInt32();
std::string itemSenderName = fields[4].GetString();
uint32 itemReceiverAccount = fields[5].GetUInt32();
std::string itemReceiverName = fields[6].GetString();
char const* itemPos = "[in mail]";
handler->PSendSysMessage(LANG_ITEMLIST_MAIL, itemGuid, itemSenderName.c_str(), itemSender, itemSenderAccountId, itemReceiverName.c_str(), itemReceiver, itemReceiverAccount, itemPos);
}
while (result->NextRow());
uint32 resultCount = uint32(result->GetRowCount());
if (count > resultCount)
count -= resultCount;
else if (count)
count = 0;
}
// auction case
uint32 auctionCount = 0;
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_AUCTIONHOUSE_COUNT_ITEM);
stmt->setUInt32(0, itemId);
result = CharacterDatabase.Query(stmt);
if (result)
auctionCount = (*result)[0].GetUInt64();
if (count > 0)
{
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_AUCTIONHOUSE_ITEM_BY_ENTRY);
stmt->setUInt32(0, itemId);
stmt->setUInt32(1, count);
result = CharacterDatabase.Query(stmt);
}
else
result = PreparedQueryResult(NULL);
if (result)
{
do
{
Field* fields = result->Fetch();
uint32 itemGuid = fields[0].GetUInt32();
uint32 owner = fields[1].GetUInt32();
uint32 ownerAccountId = fields[2].GetUInt32();
std::string ownerName = fields[3].GetString();
char const* itemPos = "[in auction]";
handler->PSendSysMessage(LANG_ITEMLIST_AUCTION, itemGuid, ownerName.c_str(), owner, ownerAccountId, itemPos);
}
while (result->NextRow());
}
// guild bank case
uint32 guildCount = 0;
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GUILD_BANK_COUNT_ITEM);
stmt->setUInt32(0, itemId);
result = CharacterDatabase.Query(stmt);
if (result)
guildCount = (*result)[0].GetUInt64();
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GUILD_BANK_ITEM_BY_ENTRY);
stmt->setUInt32(0, itemId);
stmt->setUInt32(1, count);
result = CharacterDatabase.Query(stmt);
if (result)
{
do
{
Field* fields = result->Fetch();
uint32 itemGuid = fields[0].GetUInt32();
uint32 guildGuid = fields[1].GetUInt32();
std::string guildName = fields[2].GetString();
char const* itemPos = "[in guild bank]";
handler->PSendSysMessage(LANG_ITEMLIST_GUILD, itemGuid, guildName.c_str(), guildGuid, itemPos);
}
while (result->NextRow());
uint32 resultCount = uint32(result->GetRowCount());
if (count > resultCount)
count -= resultCount;
else if (count)
count = 0;
}
if (inventoryCount + mailCount + auctionCount + guildCount == 0)
{
handler->SendSysMessage(LANG_COMMAND_NOITEMFOUND);
handler->SetSentErrorMessage(true);
return false;
}
handler->PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE, itemId, inventoryCount + mailCount + auctionCount + guildCount, inventoryCount, mailCount, auctionCount, guildCount);
return true;
}
static bool HandleListObjectCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
// number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
char* id = handler->extractKeyFromLink((char*)args, "Hgameobject_entry");
if (!id)
return false;
uint32 gameObjectId = atol(id);
if (!gameObjectId)
{
handler->PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, gameObjectId);
handler->SetSentErrorMessage(true);
return false;
}
GameObjectTemplate const* gInfo = sObjectMgr->GetGameObjectTemplate(gameObjectId);
if (!gInfo)
{
handler->PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, gameObjectId);
handler->SetSentErrorMessage(true);
return false;
}
char* countStr = strtok(NULL, " ");
uint32 count = countStr ? atol(countStr) : 10;
if (count == 0)
return false;
QueryResult result;
uint32 objectCount = 0;
result = WorldDatabase.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'", gameObjectId);
if (result)
objectCount = (*result)[0].GetUInt64();
if (handler->GetSession())
{
Player* player = handler->GetSession()->GetPlayer();
result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map, id, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM gameobject WHERE id = '%u' ORDER BY order_ ASC LIMIT %u",
player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), gameObjectId, count);
}
else
result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map, id FROM gameobject WHERE id = '%u' LIMIT %u",
gameObjectId, count);
if (result)
{
do
{
Field* fields = result->Fetch();
uint32 guid = fields[0].GetUInt32();
float x = fields[1].GetFloat();
float y = fields[2].GetFloat();
float z = fields[3].GetFloat();
uint16 mapId = fields[4].GetUInt16();
uint32 entry = fields[5].GetUInt32();
if (handler->GetSession())
handler->PSendSysMessage(LANG_GO_LIST_CHAT, guid, entry, guid, gInfo->name.c_str(), x, y, z, mapId);
else
handler->PSendSysMessage(LANG_GO_LIST_CONSOLE, guid, gInfo->name.c_str(), x, y, z, mapId);
}
while (result->NextRow());
}
handler->PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE, gameObjectId, objectCount);
return true;
}
static bool HandleListAurasCommand(ChatHandler* handler, char const* args)
{
Unit* unit = handler->getSelectedUnit();
if (!unit)
{
handler->SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
handler->SetSentErrorMessage(true);
return false;
}
char const* talentStr = handler->GetTrinityString(LANG_TALENT);
char const* passiveStr = handler->GetTrinityString(LANG_PASSIVE);
Unit::AuraApplicationMap const& auras = unit->GetAppliedAuras();
handler->PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS, auras.size());
for (Unit::AuraApplicationMap::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
{
bool talent = GetTalentSpellCost(itr->second->GetBase()->GetId()) > 0;
AuraApplication const* aurApp = itr->second;
Aura const* aura = aurApp->GetBase();
char const* name = aura->GetSpellInfo()->SpellName[handler->GetSessionDbcLocale()];
std::ostringstream ss_name;
ss_name << "|cffffffff|Hspell:" << aura->GetId() << "|h[" << name << "]|h|r";
handler->PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL, aura->GetId(), (handler->GetSession() ? ss_name.str().c_str() : name),
aurApp->GetEffectMask(), aura->GetCharges(), aura->GetStackAmount(), aurApp->GetSlot(),
aura->GetDuration(), aura->GetMaxDuration(), (aura->IsPassive() ? passiveStr : ""),
(talent ? talentStr : ""), IS_PLAYER_GUID(aura->GetCasterGUID()) ? "player" : "creature",
GUID_LOPART(aura->GetCasterGUID()));
}
if (!args || std::string(args) != "all")
return true;
for (uint16 i = 0; i < TOTAL_AURAS; ++i)
{
Unit::AuraEffectList const& auraList = unit->GetAuraEffectsByType(AuraType(i));
if (auraList.empty())
continue;
handler->PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE, auraList.size(), i);
for (Unit::AuraEffectList::const_iterator itr = auraList.begin(); itr != auraList.end(); ++itr)
handler->PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE, (*itr)->GetId(), (*itr)->GetEffIndex(), (*itr)->GetAmount());
}
return true;
}
};
void AddSC_list_commandscript()
{
new list_commandscript();
}
File diff suppressed because it is too large Load Diff
+164
View File
@@ -0,0 +1,164 @@
/*
* Copyright (C)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* ScriptData
Name: message_commandscript
%Complete: 100
Comment: All message related commands
Category: commandscripts
EndScriptData */
#include "ScriptMgr.h"
#include "Chat.h"
#include "ChannelMgr.h"
#include "Language.h"
#include "Player.h"
class message_commandscript : public CommandScript
{
public:
message_commandscript() : CommandScript("message_commandscript") { }
ChatCommand* GetCommands() const
{
static ChatCommand commandTable[] =
{
{ "nameannounce", SEC_GAMEMASTER, true, &HandleNameAnnounceCommand, "", NULL },
{ "gmnameannounce", SEC_GAMEMASTER, true, &HandleGMNameAnnounceCommand, "", NULL },
{ "announce", SEC_GAMEMASTER, true, &HandleAnnounceCommand, "", NULL },
{ "gmannounce", SEC_GAMEMASTER, true, &HandleGMAnnounceCommand, "", NULL },
{ "notify", SEC_GAMEMASTER, true, &HandleNotifyCommand, "", NULL },
{ "gmnotify", SEC_GAMEMASTER, true, &HandleGMNotifyCommand, "", NULL },
{ "whispers", SEC_GAMEMASTER, false, &HandleWhispersCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}
static bool HandleNameAnnounceCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
std::string name("Console");
if (WorldSession* session = handler->GetSession())
name = session->GetPlayer()->GetName();
sWorld->SendWorldText(LANG_ANNOUNCE_COLOR, name.c_str(), args);
return true;
}
static bool HandleGMNameAnnounceCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
std::string name("Console");
if (WorldSession* session = handler->GetSession())
name = session->GetPlayer()->GetName();
sWorld->SendGMText(LANG_GM_ANNOUNCE_COLOR, name.c_str(), args);
return true;
}
// global announce
static bool HandleAnnounceCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
char buff[2048];
sprintf(buff, handler->GetTrinityString(LANG_SYSTEMMESSAGE), args);
sWorld->SendServerMessage(SERVER_MSG_STRING, buff);
return true;
}
// announce to logged in GMs
static bool HandleGMAnnounceCommand(ChatHandler* /*handler*/, char const* args)
{
if (!*args)
return false;
sWorld->SendGMText(LANG_GM_BROADCAST, args);
return true;
}
// notification player at the screen
static bool HandleNotifyCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
std::string str = handler->GetTrinityString(LANG_GLOBAL_NOTIFY);
str += args;
WorldPacket data(SMSG_NOTIFICATION, (str.size()+1));
data << str;
sWorld->SendGlobalMessage(&data);
return true;
}
// notification GM at the screen
static bool HandleGMNotifyCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
std::string str = handler->GetTrinityString(LANG_GM_NOTIFY);
str += args;
WorldPacket data(SMSG_NOTIFICATION, (str.size()+1));
data << str;
sWorld->SendGlobalGMMessage(&data);
return true;
}
// Enable\Dissable accept whispers (for GM)
static bool HandleWhispersCommand(ChatHandler* handler, char const* args)
{
if (!*args)
{
handler->PSendSysMessage(LANG_COMMAND_WHISPERACCEPTING, handler->GetSession()->GetPlayer()->isAcceptWhispers() ? handler->GetTrinityString(LANG_ON) : handler->GetTrinityString(LANG_OFF));
return true;
}
std::string argStr = (char*)args;
// whisper on
if (argStr == "on")
{
handler->GetSession()->GetPlayer()->SetAcceptWhispers(true);
handler->SendSysMessage(LANG_COMMAND_WHISPERON);
return true;
}
// whisper off
if (argStr == "off")
{
// Remove all players from the Gamemaster's whisper whitelist
handler->GetSession()->GetPlayer()->ClearWhisperWhiteList();
handler->GetSession()->GetPlayer()->SetAcceptWhispers(false);
handler->SendSysMessage(LANG_COMMAND_WHISPEROFF);
return true;
}
handler->SendSysMessage(LANG_USE_BOL);
handler->SetSentErrorMessage(true);
return false;
}
};
void AddSC_message_commandscript()
{
new message_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
+281
View File
@@ -0,0 +1,281 @@
/*
* Copyright (C)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* ScriptData
Name: quest_commandscript
%Complete: 100
Comment: All quest related commands
Category: commandscripts
EndScriptData */
#include "Chat.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "ReputationMgr.h"
#include "ScriptMgr.h"
class quest_commandscript : public 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 },
{ "reward", SEC_ADMINISTRATOR, false, &HandleQuestReward, "", NULL },
{ NULL, SEC_PLAYER, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "quest", SEC_ADMINISTRATOR, false, NULL, "", questCommandTable },
{ NULL, SEC_PLAYER, false, NULL, "", NULL }
};
return commandTable;
}
static bool HandleQuestAdd(ChatHandler* handler, const char* args)
{
Player* player = handler->getSelectedPlayer();
if (!player)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
// .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* quest = sObjectMgr->GetQuestTemplate(entry);
if (!quest)
{
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)
ItemTemplateContainer const* itc = sObjectMgr->GetItemTemplateStore();
ItemTemplateContainer::const_iterator result = find_if(itc->begin(), itc->end(), Finder<uint32, ItemTemplate>(entry, &ItemTemplate::StartQuest));
if (result != itc->end())
{
handler->PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry, result->second.ItemId);
handler->SetSentErrorMessage(true);
return false;
}
// ok, normal (creature/GO starting) quest
if (player->CanAddQuest(quest, true))
player->AddQuestAndCheckCompletion(quest, NULL);
return true;
}
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* quest = sObjectMgr->GetQuestTemplate(entry);
if (!quest)
{
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 logQuest = player->GetQuestSlotQuestId(slot);
if (logQuest == entry)
{
player->SetQuestSlot(slot, 0);
// we ignore unequippable quest items in this case, its' still be equipped
player->TakeQuestSourceItem(logQuest, false);
if (quest->HasFlag(QUEST_FLAGS_FLAGS_PVP))
{
player->pvpInfo.IsHostile = player->pvpInfo.IsInHostileArea || player->HasPvPForcingQuest();
player->UpdatePvPState();
}
}
}
player->RemoveRewardedQuest(entry);
player->RemoveActiveQuest(entry, 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* quest = sObjectMgr->GetQuestTemplate(entry);
// If player doesn't have the quest
if (!quest || 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 = quest->RequiredItemId[x];
uint32 count = quest->RequiredItemCount[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 = quest->RequiredNpcOrGo[i];
uint32 creatureCount = quest->RequiredNpcOrGoCount[i];
if (creature > 0)
{
if (CreatureTemplate const* creatureInfo = sObjectMgr->GetCreatureTemplate(creature))
for (uint16 z = 0; z < creatureCount; ++z)
player->KilledMonster(creatureInfo, 0);
}
else if (creature < 0)
for (uint16 z = 0; z < creatureCount; ++z)
player->KillCreditGO(creature, 0);
}
// If the quest requires reputation to complete
if (uint32 repFaction = quest->GetRepObjectiveFaction())
{
uint32 repValue = quest->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 = quest->GetRepObjectiveFaction2())
{
uint32 repValue2 = quest->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 = quest->GetRewOrReqMoney();
if (ReqOrRewMoney < 0)
player->ModifyMoney(-ReqOrRewMoney);
player->CompleteQuest(entry);
return true;
}
static bool HandleQuestReward(ChatHandler* handler, char const* args)
{
Player* player = handler->getSelectedPlayer();
if (!player)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
// .quest reward #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* quest = sObjectMgr->GetQuestTemplate(entry);
// If player doesn't have the quest
if (!quest || player->GetQuestStatus(entry) != QUEST_STATUS_COMPLETE)
{
handler->PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
handler->SetSentErrorMessage(true);
return false;
}
player->RewardQuest(quest, 0, player);
return true;
}
};
void AddSC_quest_commandscript()
{
new quest_commandscript();
}
File diff suppressed because it is too large Load Diff
+312
View File
@@ -0,0 +1,312 @@
/*
* Copyright (C)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* ScriptData
Name: reset_commandscript
%Complete: 100
Comment: All reset related commands
Category: commandscripts
EndScriptData */
#include "AchievementMgr.h"
#include "Chat.h"
#include "Language.h"
#include "ObjectAccessor.h"
#include "Player.h"
#include "Pet.h"
#include "ScriptMgr.h"
class reset_commandscript : public CommandScript
{
public:
reset_commandscript() : CommandScript("reset_commandscript") { }
ChatCommand* GetCommands() const
{
static ChatCommand resetCommandTable[] =
{
{ "achievements", SEC_ADMINISTRATOR, true, &HandleResetAchievementsCommand, "", NULL },
{ "honor", SEC_ADMINISTRATOR, true, &HandleResetHonorCommand, "", NULL },
{ "level", SEC_ADMINISTRATOR, true, &HandleResetLevelCommand, "", NULL },
{ "spells", SEC_ADMINISTRATOR, true, &HandleResetSpellsCommand, "", NULL },
{ "stats", SEC_ADMINISTRATOR, true, &HandleResetStatsCommand, "", NULL },
{ "talents", SEC_ADMINISTRATOR, true, &HandleResetTalentsCommand, "", NULL },
{ "all", SEC_ADMINISTRATOR, true, &HandleResetAllCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "reset", SEC_ADMINISTRATOR, true, NULL, "", resetCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}
static bool HandleResetAchievementsCommand(ChatHandler* handler, char const* args)
{
Player* target;
uint64 targetGuid;
if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid))
return false;
if (target)
target->ResetAchievements();
else
AchievementMgr::DeleteFromDB(GUID_LOPART(targetGuid));
return true;
}
static bool HandleResetHonorCommand(ChatHandler* handler, char const* args)
{
Player* target;
if (!handler->extractPlayerTarget((char*)args, &target))
return false;
target->SetHonorPoints(0);
target->SetUInt32Value(PLAYER_FIELD_KILLS, 0);
target->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS, 0);
target->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION, 0);
target->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION, 0);
target->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EARN_HONORABLE_KILL);
return true;
}
static bool HandleResetStatsOrLevelHelper(Player* player)
{
ChrClassesEntry const* classEntry = sChrClassesStore.LookupEntry(player->getClass());
if (!classEntry)
{
sLog->outError("Class %u not found in DBC (Wrong DBC files?)", player->getClass());
return false;
}
uint8 powerType = classEntry->powerType;
// reset m_form if no aura
if (!player->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT))
player->SetShapeshiftForm(FORM_NONE);
player->setFactionForRace(player->getRace());
player->SetUInt32Value(UNIT_FIELD_BYTES_0, ((player->getRace()) | (player->getClass() << 8) | (player->getGender() << 16) | (powerType << 24)));
// reset only if player not in some form;
if (player->GetShapeshiftForm() == FORM_NONE)
player->InitDisplayIds();
player->SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_PVP);
player->SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
//-1 is default value
player->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX, uint32(-1));
return true;
}
static bool HandleResetLevelCommand(ChatHandler* handler, char const* args)
{
Player* target;
if (!handler->extractPlayerTarget((char*)args, &target))
return false;
if (!HandleResetStatsOrLevelHelper(target))
return false;
uint8 oldLevel = target->getLevel();
// set starting level
uint32 startLevel = target->getClass() != CLASS_DEATH_KNIGHT
? sWorld->getIntConfig(CONFIG_START_PLAYER_LEVEL)
: sWorld->getIntConfig(CONFIG_START_HEROIC_PLAYER_LEVEL);
target->_ApplyAllLevelScaleItemMods(false);
target->SetLevel(startLevel);
target->InitRunes();
target->InitStatsForLevel(true);
target->InitTaxiNodesForLevel();
target->InitGlyphsForLevel();
target->InitTalentForLevel();
target->SetUInt32Value(PLAYER_XP, 0);
target->_ApplyAllLevelScaleItemMods(true);
// reset level for pet
if (Pet* pet = target->GetPet())
pet->SynchronizeLevelWithOwner();
sScriptMgr->OnPlayerLevelChanged(target, oldLevel);
return true;
}
static bool HandleResetSpellsCommand(ChatHandler* handler, char const* args)
{
Player* target;
uint64 targetGuid;
std::string targetName;
if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid, &targetName))
return false;
if (target)
{
target->resetSpells(/* bool myClassOnly */);
ChatHandler(target->GetSession()).SendSysMessage(LANG_RESET_SPELLS);
if (!handler->GetSession() || handler->GetSession()->GetPlayer() != target)
handler->PSendSysMessage(LANG_RESET_SPELLS_ONLINE, handler->GetNameLink(target).c_str());
}
else
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ADD_AT_LOGIN_FLAG);
stmt->setUInt16(0, uint16(AT_LOGIN_RESET_SPELLS));
stmt->setUInt32(1, GUID_LOPART(targetGuid));
CharacterDatabase.Execute(stmt);
handler->PSendSysMessage(LANG_RESET_SPELLS_OFFLINE, targetName.c_str());
}
return true;
}
static bool HandleResetStatsCommand(ChatHandler* handler, char const* args)
{
Player* target;
if (!handler->extractPlayerTarget((char*)args, &target))
return false;
if (!HandleResetStatsOrLevelHelper(target))
return false;
target->InitRunes();
target->InitStatsForLevel(true);
target->InitTaxiNodesForLevel();
target->InitGlyphsForLevel();
target->InitTalentForLevel();
return true;
}
static bool HandleResetTalentsCommand(ChatHandler* handler, char const* args)
{
Player* target;
uint64 targetGuid;
std::string targetName;
if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid, &targetName))
{
// Try reset talents as Hunter Pet
Creature* creature = handler->getSelectedCreature();
if (!*args && creature && creature->IsPet())
{
Unit* owner = creature->GetOwner();
if (owner && owner->GetTypeId() == TYPEID_PLAYER && creature->ToPet()->IsPermanentPetFor(owner->ToPlayer()))
{
creature->ToPet()->resetTalents();
owner->ToPlayer()->SendTalentsInfoData(true);
ChatHandler(owner->ToPlayer()->GetSession()).SendSysMessage(LANG_RESET_PET_TALENTS);
if (!handler->GetSession() || handler->GetSession()->GetPlayer() != owner->ToPlayer())
handler->PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE, handler->GetNameLink(owner->ToPlayer()).c_str());
}
return true;
}
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
if (target)
{
target->resetTalents(true);
target->SendTalentsInfoData(false);
ChatHandler(target->GetSession()).SendSysMessage(LANG_RESET_TALENTS);
if (!handler->GetSession() || handler->GetSession()->GetPlayer() != target)
handler->PSendSysMessage(LANG_RESET_TALENTS_ONLINE, handler->GetNameLink(target).c_str());
Pet* pet = target->GetPet();
Pet::resetTalentsForAllPetsOf(target, pet);
if (pet)
target->SendTalentsInfoData(true);
return true;
}
else if (targetGuid)
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ADD_AT_LOGIN_FLAG);
stmt->setUInt16(0, uint16(AT_LOGIN_NONE | AT_LOGIN_RESET_PET_TALENTS));
stmt->setUInt32(1, GUID_LOPART(targetGuid));
CharacterDatabase.Execute(stmt);
std::string nameLink = handler->playerLink(targetName);
handler->PSendSysMessage(LANG_RESET_TALENTS_OFFLINE, nameLink.c_str());
return true;
}
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
static bool HandleResetAllCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
std::string caseName = args;
AtLoginFlags atLogin;
// Command specially created as single command to prevent using short case names
if (caseName == "spells")
{
atLogin = AT_LOGIN_RESET_SPELLS;
sWorld->SendWorldText(LANG_RESETALL_SPELLS);
if (!handler->GetSession())
handler->SendSysMessage(LANG_RESETALL_SPELLS);
}
else if (caseName == "talents")
{
atLogin = AtLoginFlags(AT_LOGIN_RESET_TALENTS | AT_LOGIN_RESET_PET_TALENTS);
sWorld->SendWorldText(LANG_RESETALL_TALENTS);
if (!handler->GetSession())
handler->SendSysMessage(LANG_RESETALL_TALENTS);
}
else
{
handler->PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE, args);
handler->SetSentErrorMessage(true);
return false;
}
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ALL_AT_LOGIN_FLAGS);
stmt->setUInt16(0, uint16(atLogin));
CharacterDatabase.Execute(stmt);
TRINITY_READ_GUARD(HashMapHolder<Player>::LockType, *HashMapHolder<Player>::GetLock());
HashMapHolder<Player>::MapType const& plist = sObjectAccessor->GetPlayers();
for (HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
itr->second->SetAtLoginFlag(atLogin);
return true;
}
};
void AddSC_reset_commandscript()
{
new reset_commandscript();
}
+398
View File
@@ -0,0 +1,398 @@
/*
* Copyright (C)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* ScriptData
Name: server_commandscript
%Complete: 100
Comment: All server related commands
Category: commandscripts
EndScriptData */
#include "Chat.h"
#include "Config.h"
#include "Language.h"
#include "ObjectAccessor.h"
#include "Player.h"
#include "ScriptMgr.h"
#include "SystemConfig.h"
#include "AvgDiffTracker.h"
class server_commandscript : public CommandScript
{
public:
server_commandscript() : CommandScript("server_commandscript") { }
ChatCommand* GetCommands() const
{
static ChatCommand serverIdleRestartCommandTable[] =
{
{ "cancel", SEC_ADMINISTRATOR, true, &HandleServerShutDownCancelCommand, "", NULL },
{ "" , SEC_ADMINISTRATOR, true, &HandleServerIdleRestartCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand serverIdleShutdownCommandTable[] =
{
{ "cancel", SEC_ADMINISTRATOR, true, &HandleServerShutDownCancelCommand, "", NULL },
{ "" , SEC_ADMINISTRATOR, true, &HandleServerIdleShutDownCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand serverRestartCommandTable[] =
{
{ "cancel", SEC_ADMINISTRATOR, true, &HandleServerShutDownCancelCommand, "", NULL },
{ "" , SEC_ADMINISTRATOR, true, &HandleServerRestartCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand serverShutdownCommandTable[] =
{
{ "cancel", SEC_ADMINISTRATOR, true, &HandleServerShutDownCancelCommand, "", NULL },
{ "" , SEC_ADMINISTRATOR, true, &HandleServerShutDownCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand serverSetCommandTable[] =
{
{ "difftime", SEC_CONSOLE, true, &HandleServerSetDiffTimeCommand, "", NULL },
{ "loglevel", SEC_CONSOLE, true, &HandleServerSetLogLevelCommand, "", NULL },
{ "logfilelevel", SEC_CONSOLE, true, &HandleServerSetLogFileLevelCommand, "", NULL },
{ "motd", SEC_ADMINISTRATOR, true, &HandleServerSetMotdCommand, "", NULL },
{ "closed", SEC_ADMINISTRATOR, true, &HandleServerSetClosedCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand serverCommandTable[] =
{
{ "corpses", SEC_GAMEMASTER, true, &HandleServerCorpsesCommand, "", NULL },
{ "exit", SEC_CONSOLE, true, &HandleServerExitCommand, "", NULL },
{ "idlerestart", SEC_ADMINISTRATOR, true, NULL, "", serverIdleRestartCommandTable },
{ "idleshutdown", SEC_ADMINISTRATOR, true, NULL, "", serverIdleShutdownCommandTable },
{ "info", SEC_PLAYER, true, &HandleServerInfoCommand, "", NULL },
{ "motd", SEC_PLAYER, true, &HandleServerMotdCommand, "", NULL },
{ "restart", SEC_ADMINISTRATOR, true, NULL, "", serverRestartCommandTable },
{ "shutdown", SEC_ADMINISTRATOR, true, NULL, "", serverShutdownCommandTable },
{ "set", SEC_ADMINISTRATOR, true, NULL, "", serverSetCommandTable },
{ "togglequerylog", SEC_CONSOLE, true, &HandleServerToggleQueryLogging, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "server", SEC_ADMINISTRATOR, true, NULL, "", serverCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}
// Triggering corpses expire check in world
static bool HandleServerCorpsesCommand(ChatHandler* /*handler*/, char const* /*args*/)
{
sObjectAccessor->RemoveOldCorpses();
return true;
}
static bool HandleServerInfoCommand(ChatHandler* handler, char const* /*args*/)
{
std::string realmName = sWorld->GetRealmName();
uint32 playerCount = sWorld->GetPlayerCount();
uint32 activeSessionCount = sWorld->GetActiveSessionCount();
uint32 queuedSessionCount = sWorld->GetQueuedSessionCount();
uint32 connPeak = sWorld->GetMaxActiveSessionCount();
std::string uptime = secsToTimeString(sWorld->GetUptime()).append(".");
uint32 updateTime = sWorld->GetUpdateTime();
uint32 avgUpdateTime = avgDiffTracker.getAverage();
handler->PSendSysMessage("%s Realm, revision: %s.", realmName.c_str(), _REVISION);
handler->PSendSysMessage("This server runs on SunwellCore.");
if (!queuedSessionCount)
handler->PSendSysMessage("Connected players: %u. Characters in world: %u.", activeSessionCount, playerCount);
else
handler->PSendSysMessage("Connected players: %u. Characters in world: %u. Queue: %u.", activeSessionCount, playerCount, queuedSessionCount);
//handler->PSendSysMessage("Connection peak: %u.", connPeak);
handler->PSendSysMessage(LANG_UPTIME, uptime.c_str());
handler->PSendSysMessage("Update time diff: %ums, average: %ums.", updateTime, avgUpdateTime);
if (handler->GetSession())
if (Player* p = handler->GetSession()->GetPlayer())
if (p->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_DEVELOPER))
handler->PSendSysMessage("DEV wavg: %ums, nsmax: %ums, nsavg: %ums. LFG avg: %ums, max: %ums.", avgDiffTracker.getTimeWeightedAverage(), devDiffTracker.getMax(), devDiffTracker.getAverage(), lfgDiffTracker.getAverage(), lfgDiffTracker.getMax());
//! Can't use sWorld->ShutdownMsg here in case of console command
if (sWorld->IsShuttingDown())
handler->PSendSysMessage(LANG_SHUTDOWN_TIMELEFT, secsToTimeString(sWorld->GetShutDownTimeLeft()).append(".").c_str());
return true;
}
// Display the 'Message of the day' for the realm
static bool HandleServerMotdCommand(ChatHandler* handler, char const* /*args*/)
{
handler->PSendSysMessage(LANG_MOTD_CURRENT, sWorld->GetMotd());
return true;
}
static bool HandleServerShutDownCancelCommand(ChatHandler* handler, char const* /*args*/)
{
sWorld->ShutdownCancel();
return true;
}
static bool HandleServerShutDownCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
char* timeStr = strtok((char*) args, " ");
char* exitCodeStr = strtok(NULL, "");
int32 time = atoi(timeStr);
// Prevent interpret wrong arg value as 0 secs shutdown time
if ((time == 0 && (timeStr[0] != '0' || timeStr[1] != '\0')) || time < 0)
return false;
if (exitCodeStr)
{
int32 exitCode = atoi(exitCodeStr);
// Handle atoi() errors
if (exitCode == 0 && (exitCodeStr[0] != '0' || exitCodeStr[1] != '\0'))
return false;
// Exit code should be in range of 0-125, 126-255 is used
// in many shells for their own return codes and code > 255
// is not supported in many others
if (exitCode < 0 || exitCode > 125)
return false;
sWorld->ShutdownServ(time, 0, exitCode);
}
else
sWorld->ShutdownServ(time, 0, SHUTDOWN_EXIT_CODE);
return true;
}
static bool HandleServerRestartCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
char* timeStr = strtok((char*) args, " ");
char* exitCodeStr = strtok(NULL, "");
int32 time = atoi(timeStr);
// Prevent interpret wrong arg value as 0 secs shutdown time
if ((time == 0 && (timeStr[0] != '0' || timeStr[1] != '\0')) || time < 0)
return false;
if (exitCodeStr)
{
int32 exitCode = atoi(exitCodeStr);
// Handle atoi() errors
if (exitCode == 0 && (exitCodeStr[0] != '0' || exitCodeStr[1] != '\0'))
return false;
// Exit code should be in range of 0-125, 126-255 is used
// in many shells for their own return codes and code > 255
// is not supported in many others
if (exitCode < 0 || exitCode > 125)
return false;
sWorld->ShutdownServ(time, SHUTDOWN_MASK_RESTART, exitCode);
}
else
sWorld->ShutdownServ(time, SHUTDOWN_MASK_RESTART, RESTART_EXIT_CODE);
return true;
}
static bool HandleServerIdleRestartCommand(ChatHandler* /*handler*/, char const* args)
{
if (!*args)
return false;
char* timeStr = strtok((char*) args, " ");
char* exitCodeStr = strtok(NULL, "");
int32 time = atoi(timeStr);
// Prevent interpret wrong arg value as 0 secs shutdown time
if ((time == 0 && (timeStr[0] != '0' || timeStr[1] != '\0')) || time < 0)
return false;
if (exitCodeStr)
{
int32 exitCode = atoi(exitCodeStr);
// Handle atoi() errors
if (exitCode == 0 && (exitCodeStr[0] != '0' || exitCodeStr[1] != '\0'))
return false;
// Exit code should be in range of 0-125, 126-255 is used
// in many shells for their own return codes and code > 255
// is not supported in many others
if (exitCode < 0 || exitCode > 125)
return false;
sWorld->ShutdownServ(time, SHUTDOWN_MASK_RESTART | SHUTDOWN_MASK_IDLE, exitCode);
}
else
sWorld->ShutdownServ(time, SHUTDOWN_MASK_RESTART | SHUTDOWN_MASK_IDLE, RESTART_EXIT_CODE);
return true;
}
static bool HandleServerIdleShutDownCommand(ChatHandler* /*handler*/, char const* args)
{
if (!*args)
return false;
char* timeStr = strtok((char*) args, " ");
char* exitCodeStr = strtok(NULL, "");
int32 time = atoi(timeStr);
// Prevent interpret wrong arg value as 0 secs shutdown time
if ((time == 0 && (timeStr[0] != '0' || timeStr[1] != '\0')) || time < 0)
return false;
if (exitCodeStr)
{
int32 exitCode = atoi(exitCodeStr);
// Handle atoi() errors
if (exitCode == 0 && (exitCodeStr[0] != '0' || exitCodeStr[1] != '\0'))
return false;
// Exit code should be in range of 0-125, 126-255 is used
// in many shells for their own return codes and code > 255
// is not supported in many others
if (exitCode < 0 || exitCode > 125)
return false;
sWorld->ShutdownServ(time, SHUTDOWN_MASK_IDLE, exitCode);
}
else
sWorld->ShutdownServ(time, SHUTDOWN_MASK_IDLE, SHUTDOWN_EXIT_CODE);
return true;
}
// Exit the realm
static bool HandleServerExitCommand(ChatHandler* handler, char const* /*args*/)
{
handler->SendSysMessage(LANG_COMMAND_EXIT);
World::StopNow(SHUTDOWN_EXIT_CODE);
return true;
}
// Define the 'Message of the day' for the realm
static bool HandleServerSetMotdCommand(ChatHandler* handler, char const* args)
{
sWorld->SetMotd(args);
handler->PSendSysMessage(LANG_MOTD_NEW, args);
return true;
}
// Set whether we accept new clients
static bool HandleServerSetClosedCommand(ChatHandler* handler, char const* args)
{
if (strncmp(args, "on", 3) == 0)
{
handler->SendSysMessage(LANG_WORLD_CLOSED);
sWorld->SetClosed(true);
return true;
}
else if (strncmp(args, "off", 4) == 0)
{
handler->SendSysMessage(LANG_WORLD_OPENED);
sWorld->SetClosed(false);
return true;
}
handler->SendSysMessage(LANG_USE_BOL);
handler->SetSentErrorMessage(true);
return false;
}
// Set the level of logging
static bool HandleServerSetLogFileLevelCommand(ChatHandler* /*handler*/, char const* args)
{
if (!*args)
return false;
char* newLevel = strtok((char*)args, " ");
if (!newLevel)
return false;
sLog->SetLogFileLevel(newLevel);
return true;
}
// Set the level of logging
static bool HandleServerSetLogLevelCommand(ChatHandler* /*handler*/, char const* args)
{
if (!*args)
return false;
char* newLevel = strtok((char*)args, " ");
if (!newLevel)
return false;
sLog->SetLogLevel(newLevel);
return true;
}
// set diff time record interval
static bool HandleServerSetDiffTimeCommand(ChatHandler* /*handler*/, char const* args)
{
if (!*args)
return false;
char* newTimeStr = strtok((char*)args, " ");
if (!newTimeStr)
return false;
int32 newTime = atoi(newTimeStr);
if (newTime < 0)
return false;
sWorld->SetRecordDiffInterval(newTime);
printf("Record diff every %u ms\n", newTime);
return true;
}
// toggle sql driver query logging
static bool HandleServerToggleQueryLogging(ChatHandler* handler, char const* /*args*/)
{
sLog->SetSQLDriverQueryLogging(!sLog->GetSQLDriverQueryLogging());
if (sLog->GetSQLDriverQueryLogging())
handler->PSendSysMessage(LANG_SQLDRIVER_QUERY_LOGGING_ENABLED);
else
handler->PSendSysMessage(LANG_SQLDRIVER_QUERY_LOGGING_DISABLED);
return true;
}
};
void AddSC_server_commandscript()
{
new server_commandscript();
}
@@ -0,0 +1,257 @@
#include "ScriptMgr.h"
#include "ObjectMgr.h"
#include "Chat.h"
#include "AccountMgr.h"
#include "Language.h"
#include "World.h"
#include "Player.h"
#include "Opcodes.h"
#include "ArenaSpectator.h"
#include "LFGMgr.h"
#include "BattlegroundMgr.h"
class spectator_commandscript : public CommandScript
{
public:
spectator_commandscript() : CommandScript("spectator_commandscript") { }
ChatCommand* GetCommands() const
{
static ChatCommand spectatorCommandTable[] =
{
{ "version", SEC_CONSOLE, false, &HandleSpectatorVersionCommand, "", NULL },
{ "reset", SEC_CONSOLE, false, &HandleSpectatorResetCommand, "", NULL },
{ "spectate", SEC_CONSOLE, false, &ArenaSpectator::HandleSpectatorSpectateCommand, "", NULL },
{ "watch", SEC_CONSOLE, false, &ArenaSpectator::HandleSpectatorWatchCommand, "", NULL },
{ "leave", SEC_CONSOLE, false, &HandleSpectatorLeaveCommand, "", NULL },
{ "", SEC_CONSOLE, false, &HandleSpectatorCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "spect", SEC_CONSOLE, false, NULL, "", spectatorCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}
static bool HandleSpectatorCommand(ChatHandler* handler, char const* args)
{
handler->PSendSysMessage("Incorrect syntax.");
handler->PSendSysMessage("Command has subcommands:");
handler->PSendSysMessage(" spectate");
handler->PSendSysMessage(" leave");
return true;
}
static bool HandleSpectatorVersionCommand(ChatHandler* handler, char const* args)
{
if (atoi(args) < SPECTATOR_ADDON_VERSION)
ArenaSpectator::SendCommand(handler->GetSession()->GetPlayer(), "%sOUTDATED", SPECTATOR_ADDON_PREFIX);
return true;
}
static bool HandleSpectatorResetCommand(ChatHandler* handler, char const* args)
{
Player* p = handler->GetSession()->GetPlayer();
if (!p->IsSpectator())
return true;
ArenaSpectator::HandleResetCommand(p);
return true;
}
static bool HandleSpectatorLeaveCommand(ChatHandler* handler, char const* args)
{
Player* player = handler->GetSession()->GetPlayer();
if (!player->IsSpectator() || !player->FindMap() || !player->FindMap()->IsBattleArena())
{
handler->SendSysMessage("You are not a spectator.");
return true;
}
//player->SetIsSpectator(false);
player->TeleportToEntryPoint();
return true;
}
};
bool ArenaSpectator::HandleSpectatorSpectateCommand(ChatHandler* handler, char const* args)
{
Player* player = handler->GetSession()->GetPlayer();
std::list<std::string> errors;
if (!*args)
{
handler->SendSysMessage("Missing player name.");
return true;
}
if (player->IsSpectator())
{
if (player->FindMap() && player->FindMap()->IsBattleArena())
{
HandleSpectatorWatchCommand(handler, args);
return true;
}
handler->PSendSysMessage("You are already spectacting arena.");
return true;
}
if (player->getClass() == CLASS_DEATH_KNIGHT && player->GetMapId() == 609)
{
handler->PSendSysMessage("Death Knights can't spectate before finishing questline.");
return true;
}
std::string name = std::string(args);
Player* spectate = ObjectAccessor::FindPlayerByName(name);
if (!spectate)
{
handler->SendSysMessage("Requested player not found.");
return true;
}
if (spectate->IsSpectator())
{
handler->SendSysMessage("Requested player is a spectator.");
return true;
}
if (!spectate->FindMap() || !spectate->FindMap()->IsBattleArena())
{
handler->SendSysMessage("Requested player is not in arena.");
return true;
}
BattlegroundMap* bgmap = ((BattlegroundMap*)spectate->FindMap());
if (!bgmap->GetBG() || bgmap->GetBG()->GetStatus() == STATUS_WAIT_LEAVE)
{
handler->SendSysMessage("This arena battle has finished.");
return true;
}
if (player->IsBeingTeleported() || !player->IsInWorld())
errors.push_back("Can't use while being teleported.");
if (!player->FindMap() || player->FindMap()->Instanceable())
errors.push_back("Can't use while in instance, bg or arena.");
if (player->GetVehicle())
errors.push_back("Can't be on a vehicle.");
if (player->IsInCombat())
errors.push_back("Can't be in combat.");
if (player->isUsingLfg())
errors.push_back("Can't spectate while using LFG system.");
if (player->InBattlegroundQueue())
errors.push_back("Can't be queued for arena or bg.");
if (player->GetGroup())
errors.push_back("Can't be in a group.");
if (player->HasUnitState(UNIT_STATE_ISOLATED))
errors.push_back("Can't be isolated.");
if (player->m_mover != player)
errors.push_back("You must control yourself.");
if (player->IsInFlight())
errors.push_back("Can't be in flight.");
if (player->IsMounted())
errors.push_back("Dismount before spectating.");
if (!player->IsAlive())
errors.push_back("Must be alive.");
if (!player->m_Controlled.empty())
errors.push_back("Can't be controlling creatures.");
const Unit::VisibleAuraMap* va = player->GetVisibleAuras();
for (Unit::VisibleAuraMap::const_iterator itr = va->begin(); itr != va->end(); ++itr)
if (Aura* aura = itr->second->GetBase())
if (!itr->second->IsPositive() && !aura->IsPermanent() && aura->GetDuration() < HOUR*IN_MILLISECONDS)
{
switch (aura->GetSpellInfo()->Id)
{
case lfg::LFG_SPELL_DUNGEON_DESERTER:
case lfg::LFG_SPELL_DUNGEON_COOLDOWN:
case 26013: // bg deserter
case 57724: // sated
case 57723: // exhaustion
case 25771: // forbearance
case 15007: // resurrection sickness
case 24755: // Tricked or Treated (z eventu)
continue;
}
errors.push_back("Can't have negative auras.");
break;
}
if (uint32 inviteInstanceId = player->GetPendingSpectatorInviteInstanceId())
{
if (Battleground* tbg = sBattlegroundMgr->GetBattleground(inviteInstanceId))
tbg->RemoveToBeTeleported(player->GetGUID());
player->SetPendingSpectatorInviteInstanceId(0);
}
bool bgPreparation = false;
if (!handler->GetSession()->GetSecurity() && bgmap->GetBG()->GetStatus() != STATUS_IN_PROGRESS ||
handler->GetSession()->GetSecurity() && bgmap->GetBG()->GetStatus() != STATUS_WAIT_JOIN && bgmap->GetBG()->GetStatus() != STATUS_IN_PROGRESS)
{
bgPreparation = true;
handler->SendSysMessage("Arena is not in progress yet. You will be invited as soon as it starts.");
bgmap->GetBG()->AddToBeTeleported(player->GetGUID(), spectate->GetGUID());
player->SetPendingSpectatorInviteInstanceId(spectate->GetBattlegroundId());
}
if (!errors.empty())
{
handler->PSendSysMessage("To spectate, please fix the following:");
for (std::list<std::string>::const_iterator itr = errors.begin(); itr != errors.end(); ++itr)
handler->PSendSysMessage(("- "+(*itr)).c_str());
return true;
}
if (bgPreparation)
return true;
player->SetPendingSpectatorForBG(spectate->GetBattlegroundId());
player->SetBattlegroundId(spectate->GetBattlegroundId(), spectate->GetBattlegroundTypeId(), PLAYER_MAX_BATTLEGROUND_QUEUES, false, false, TEAM_NEUTRAL);
player->SetEntryPoint();
float z = spectate->GetMapId() == 618 ? std::max(28.27f, spectate->GetPositionZ()+0.25f) : spectate->GetPositionZ()+0.25f;
player->TeleportTo(spectate->GetMapId(), spectate->GetPositionX(), spectate->GetPositionY(), z, spectate->GetOrientation(), TELE_TO_GM_MODE);
return true;
}
bool ArenaSpectator::HandleSpectatorWatchCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return true;
Player* player = handler->GetSession()->GetPlayer();
if (!player->IsSpectator())
return true;
if (!player->FindMap() || !player->FindMap()->IsBattleArena())
return true;
Battleground* bg = ((BattlegroundMap*)player->FindMap())->GetBG();
if (!bg || bg->GetStatus() != STATUS_IN_PROGRESS)
return true;
std::string name = std::string(args);
Player* spectate = ObjectAccessor::FindPlayerByName(name);
if (!spectate || !spectate->IsAlive() || spectate->IsSpectator() || spectate->GetGUID() == player->GetGUID() || !spectate->IsInWorld() || !spectate->FindMap() || spectate->IsBeingTeleported() || spectate->FindMap() != player->FindMap() || !bg->IsPlayerInBattleground(spectate->GetGUID()))
return true;
if (WorldObject* o = player->GetViewpoint())
if (Unit* u = o->ToUnit())
{
u->RemoveAurasByType(SPELL_AURA_BIND_SIGHT, player->GetGUID());
player->RemoveAurasDueToSpell(SPECTATOR_SPELL_BINDSIGHT, player->GetGUID(), (1 << EFFECT_1));
if (u->GetGUID() == spectate->GetGUID())
return true;
}
if (player->GetUInt64Value(PLAYER_FARSIGHT) || player->m_seer != player) // pussywizard: below this point we must not have a viewpoint!
return true;
if (player->HaveAtClient(spectate))
player->CastSpell(spectate, SPECTATOR_SPELL_BINDSIGHT, true);
return true;
}
void AddSC_spectator_commandscript()
{
new spectator_commandscript();
}
+348
View File
@@ -0,0 +1,348 @@
/*
* Copyright (C)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* ScriptData
Name: tele_commandscript
%Complete: 100
Comment: All tele related commands
Category: commandscripts
EndScriptData */
#include "Chat.h"
#include "Group.h"
#include "Language.h"
#include "MapManager.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "ScriptMgr.h"
class tele_commandscript : public CommandScript
{
public:
tele_commandscript() : CommandScript("tele_commandscript") { }
ChatCommand* GetCommands() const
{
static ChatCommand teleCommandTable[] =
{
{ "add", SEC_ADMINISTRATOR, false, &HandleTeleAddCommand, "", NULL },
{ "del", SEC_ADMINISTRATOR, true, &HandleTeleDelCommand, "", NULL },
{ "name", SEC_GAMEMASTER, true, &HandleTeleNameCommand, "", NULL },
{ "group", SEC_GAMEMASTER, false, &HandleTeleGroupCommand, "", NULL },
{ "", SEC_GAMEMASTER, false, &HandleTeleCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "tele", SEC_GAMEMASTER, 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;
}
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;
}
static bool HandleTeleDelCommand(ChatHandler* handler, const char* args)
{
if (!*args)
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;
}
std::string name = tele->name;
sObjectMgr->DeleteGameTele(name);
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;
if (strcmp(teleStr, "$home") == 0) // References target's homebind
{
if (target)
target->TeleportTo(target->m_homebindMapId, target->m_homebindX, target->m_homebindY, target->m_homebindZ, target->GetOrientation());
/* xinef: optimization, not needed function
else
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_HOMEBIND);
stmt->setUInt32(0, target_guid);
PreparedQueryResult resultDB = CharacterDatabase.Query(stmt);
if (resultDB)
{
Field* fieldsDB = resultDB->Fetch();
uint32 mapId = fieldsDB[0].GetUInt16();
uint32 zoneId = fieldsDB[1].GetUInt16();
float posX = fieldsDB[2].GetFloat();
float posY = fieldsDB[3].GetFloat();
float posZ = fieldsDB[4].GetFloat();
Player::SavePositionInDB(mapId, posX, posY, posZ, 0, zoneId, target_guid);
}
}*/
return true;
}
// 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->GetSession())).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;
}
//Teleport group to given game_tele.entry
static bool HandleTeleGroupCommand(ChatHandler* handler, const char* args)
{
if (!*args)
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;
// 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(target);
Group* grp = target->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* player = itr->GetSource();
if (!player || !player->GetSession())
continue;
// check online security
if (handler->HasLowerSecurity(player, 0))
return false;
std::string plNameLink = handler->GetNameLink(player);
if (player->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(player))
(ChatHandler(player->GetSession())).PSendSysMessage(LANG_TELEPORTED_TO_BY, nameLink.c_str());
// stop flight if need
if (player->IsInFlight())
{
player->GetMotionMaster()->MovementExpired();
player->CleanupAfterTaxiFlight();
}
// save only in non-flight case
else
player->SaveRecallPosition();
player->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()
{
new tele_commandscript();
}
+509
View File
@@ -0,0 +1,509 @@
/*
* Copyright (C)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* ScriptData
Name: ticket_commandscript
%Complete: 100
Comment: All ticket related commands
Category: commandscripts
EndScriptData */
#include "AccountMgr.h"
#include "Chat.h"
#include "Language.h"
#include "ObjectMgr.h"
#include "Opcodes.h"
#include "Player.h"
#include "TicketMgr.h"
#include "ScriptMgr.h"
class ticket_commandscript : public CommandScript
{
public:
ticket_commandscript() : CommandScript("ticket_commandscript") { }
ChatCommand* GetCommands() const
{
static ChatCommand ticketResponseCommandTable[] =
{
{ "append", SEC_GAMEMASTER, true, &HandleGMTicketResponseAppendCommand, "", NULL },
{ "appendln", SEC_GAMEMASTER, true, &HandleGMTicketResponseAppendLnCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand ticketCommandTable[] =
{
{ "assign", SEC_GAMEMASTER, true, &HandleGMTicketAssignToCommand, "", NULL },
{ "close", SEC_GAMEMASTER, true, &HandleGMTicketCloseByIdCommand, "", NULL },
{ "closedlist", SEC_GAMEMASTER, true, &HandleGMTicketListClosedCommand, "", NULL },
{ "comment", SEC_GAMEMASTER, true, &HandleGMTicketCommentCommand, "", NULL },
{ "complete", SEC_GAMEMASTER, true, &HandleGMTicketCompleteCommand, "", NULL },
{ "delete", SEC_ADMINISTRATOR, true, &HandleGMTicketDeleteByIdCommand, "", NULL },
{ "escalate", SEC_GAMEMASTER, true, &HandleGMTicketEscalateCommand, "", NULL },
{ "escalatedlist", SEC_GAMEMASTER, true, &HandleGMTicketListEscalatedCommand, "", NULL },
{ "list", SEC_GAMEMASTER, true, &HandleGMTicketListCommand, "", NULL },
{ "onlinelist", SEC_GAMEMASTER, true, &HandleGMTicketListOnlineCommand, "", NULL },
{ "reset", SEC_ADMINISTRATOR, true, &HandleGMTicketResetCommand, "", NULL },
{ "response", SEC_GAMEMASTER, true, NULL, "", ticketResponseCommandTable },
{ "togglesystem", SEC_ADMINISTRATOR, true, &HandleToggleGMTicketSystem, "", NULL },
{ "unassign", SEC_GAMEMASTER, true, &HandleGMTicketUnAssignCommand, "", NULL },
{ "viewid", SEC_GAMEMASTER, true, &HandleGMTicketGetByIdCommand, "", NULL },
{ "viewname", SEC_GAMEMASTER, true, &HandleGMTicketGetByNameCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "ticket", SEC_GAMEMASTER, false, NULL, "", ticketCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}
static bool HandleGMTicketAssignToCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
char* ticketIdStr = strtok((char*)args, " ");
uint32 ticketId = atoi(ticketIdStr);
char* targetStr = strtok(NULL, " ");
if (!targetStr)
return false;
std::string target(targetStr);
if (!normalizePlayerName(target))
return false;
GmTicket* ticket = sTicketMgr->GetTicket(ticketId);
if (!ticket || ticket->IsClosed())
{
handler->SendSysMessage(LANG_COMMAND_TICKETNOTEXIST);
return true;
}
// Get target information
uint64 targetGuid = sObjectMgr->GetPlayerGUIDByName(target.c_str());
uint64 targetAccountId = sObjectMgr->GetPlayerAccountIdByGUID(targetGuid);
uint32 targetGmLevel = AccountMgr::GetSecurity(targetAccountId, realmID);
// Target must exist and have administrative rights
if (!targetGuid || AccountMgr::IsPlayerAccount(targetGmLevel))
{
handler->SendSysMessage(LANG_COMMAND_TICKETASSIGNERROR_A);
return true;
}
// If already assigned, leave
if (ticket->IsAssignedTo(targetGuid))
{
handler->PSendSysMessage(LANG_COMMAND_TICKETASSIGNERROR_B, ticket->GetId());
return true;
}
// If assigned to different player other than current, leave
//! Console can override though
Player* player = handler->GetSession() ? handler->GetSession()->GetPlayer() : NULL;
if (player && ticket->IsAssignedNotTo(player->GetGUID()))
{
handler->PSendSysMessage(LANG_COMMAND_TICKETALREADYASSIGNED, ticket->GetId(), target.c_str());
return true;
}
// Assign ticket
SQLTransaction trans = SQLTransaction(NULL);
ticket->SetAssignedTo(targetGuid, AccountMgr::IsAdminAccount(targetGmLevel));
ticket->SaveToDB(trans);
sTicketMgr->UpdateLastChange();
std::string msg = ticket->FormatMessageString(*handler, NULL, target.c_str(), NULL, NULL);
handler->SendGlobalGMSysMessage(msg.c_str());
return true;
}
static bool HandleGMTicketCloseByIdCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
uint32 ticketId = atoi(args);
GmTicket* ticket = sTicketMgr->GetTicket(ticketId);
if (!ticket || ticket->IsClosed() || ticket->IsCompleted())
{
handler->SendSysMessage(LANG_COMMAND_TICKETNOTEXIST);
return true;
}
// Ticket should be assigned to the player who tries to close it.
// Console can override though
Player* player = handler->GetSession() ? handler->GetSession()->GetPlayer() : NULL;
if (player && ticket->IsAssignedNotTo(player->GetGUID()))
{
handler->PSendSysMessage(LANG_COMMAND_TICKETCANNOTCLOSE, ticket->GetId());
return true;
}
sTicketMgr->CloseTicket(ticket->GetId(), player ? player->GetGUID() : -1);
sTicketMgr->UpdateLastChange();
std::string msg = ticket->FormatMessageString(*handler, player ? player->GetName().c_str() : "Console", NULL, NULL, NULL);
handler->SendGlobalGMSysMessage(msg.c_str());
// Inform player, who submitted this ticket, that it is closed
if (Player* submitter = ticket->GetPlayer())
{
WorldPacket data(SMSG_GMTICKET_DELETETICKET, 4);
data << uint32(GMTICKET_RESPONSE_TICKET_DELETED);
submitter->GetSession()->SendPacket(&data);
}
return true;
}
static bool HandleGMTicketCommentCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
char* ticketIdStr = strtok((char*)args, " ");
uint32 ticketId = atoi(ticketIdStr);
char* comment = strtok(NULL, "\n");
if (!comment)
return false;
GmTicket* ticket = sTicketMgr->GetTicket(ticketId);
if (!ticket || ticket->IsClosed())
{
handler->PSendSysMessage(LANG_COMMAND_TICKETNOTEXIST);
return true;
}
// Cannot comment ticket assigned to someone else
//! Console excluded
Player* player = handler->GetSession() ? handler->GetSession()->GetPlayer() : NULL;
if (player && ticket->IsAssignedNotTo(player->GetGUID()))
{
handler->PSendSysMessage(LANG_COMMAND_TICKETALREADYASSIGNED, ticket->GetId());
return true;
}
SQLTransaction trans = SQLTransaction(NULL);
ticket->SetComment(comment);
ticket->SaveToDB(trans);
sTicketMgr->UpdateLastChange();
std::string msg = ticket->FormatMessageString(*handler, NULL, ticket->GetAssignedToName().c_str(), NULL, NULL);
msg += handler->PGetParseString(LANG_COMMAND_TICKETLISTADDCOMMENT, player ? player->GetName().c_str() : "Console", comment);
handler->SendGlobalGMSysMessage(msg.c_str());
return true;
}
static bool HandleGMTicketListClosedCommand(ChatHandler* handler, char const* /*args*/)
{
sTicketMgr->ShowClosedList(*handler);
return true;
}
static bool HandleGMTicketCompleteCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
uint32 ticketId = atoi(args);
GmTicket* ticket = sTicketMgr->GetTicket(ticketId);
if (!ticket || ticket->IsClosed() || ticket->IsCompleted())
{
handler->SendSysMessage(LANG_COMMAND_TICKETNOTEXIST);
return true;
}
if (Player* player = ticket->GetPlayer())
ticket->SendResponse(player->GetSession());
SQLTransaction trans = SQLTransaction(NULL);
ticket->SetCompleted();
ticket->SaveToDB(trans);
sTicketMgr->UpdateLastChange();
return true;
}
static bool HandleGMTicketDeleteByIdCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
uint32 ticketId = atoi(args);
GmTicket* ticket = sTicketMgr->GetTicket(ticketId);
if (!ticket)
{
handler->SendSysMessage(LANG_COMMAND_TICKETNOTEXIST);
return true;
}
if (!ticket->IsClosed())
{
handler->SendSysMessage(LANG_COMMAND_TICKETCLOSEFIRST);
return true;
}
std::string msg = ticket->FormatMessageString(*handler, NULL, NULL, NULL, handler->GetSession() ? handler->GetSession()->GetPlayer()->GetName().c_str() : "Console");
handler->SendGlobalGMSysMessage(msg.c_str());
sTicketMgr->RemoveTicket(ticket->GetId());
sTicketMgr->UpdateLastChange();
if (Player* player = ticket->GetPlayer())
{
// Force abandon ticket
WorldPacket data(SMSG_GMTICKET_DELETETICKET, 4);
data << uint32(GMTICKET_RESPONSE_TICKET_DELETED);
player->GetSession()->SendPacket(&data);
}
return true;
}
static bool HandleGMTicketEscalateCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
uint32 ticketId = atoi(args);
GmTicket* ticket = sTicketMgr->GetTicket(ticketId);
if (!ticket || ticket->IsClosed() || ticket->IsCompleted() || ticket->GetEscalatedStatus() != TICKET_UNASSIGNED)
{
handler->SendSysMessage(LANG_COMMAND_TICKETNOTEXIST);
return true;
}
ticket->SetEscalatedStatus(TICKET_IN_ESCALATION_QUEUE);
if (Player* player = ticket->GetPlayer())
sTicketMgr->SendTicket(player->GetSession(), ticket);
sTicketMgr->UpdateLastChange();
return true;
}
static bool HandleGMTicketListEscalatedCommand(ChatHandler* handler, char const* /*args*/)
{
sTicketMgr->ShowEscalatedList(*handler);
return true;
}
static bool HandleGMTicketListCommand(ChatHandler* handler, char const* /*args*/)
{
sTicketMgr->ShowList(*handler, false);
return true;
}
static bool HandleGMTicketListOnlineCommand(ChatHandler* handler, char const* /*args*/)
{
sTicketMgr->ShowList(*handler, true);
return true;
}
static bool HandleGMTicketResetCommand(ChatHandler* handler, char const* /*args*/)
{
if (sTicketMgr->GetOpenTicketCount())
{
handler->SendSysMessage(LANG_COMMAND_TICKETPENDING);
return true;
}
else
{
sTicketMgr->ResetTickets();
handler->SendSysMessage(LANG_COMMAND_TICKETRESET);
}
return true;
}
static bool HandleToggleGMTicketSystem(ChatHandler* handler, char const* /*args*/)
{
bool status = !sTicketMgr->GetStatus();
sTicketMgr->SetStatus(status);
handler->PSendSysMessage(status ? LANG_ALLOW_TICKETS : LANG_DISALLOW_TICKETS);
return true;
}
static bool HandleGMTicketUnAssignCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
uint32 ticketId = atoi(args);
GmTicket* ticket = sTicketMgr->GetTicket(ticketId);
if (!ticket || ticket->IsClosed())
{
handler->SendSysMessage(LANG_COMMAND_TICKETNOTEXIST);
return true;
}
// Ticket must be assigned
if (!ticket->IsAssigned())
{
handler->PSendSysMessage(LANG_COMMAND_TICKETNOTASSIGNED, ticket->GetId());
return true;
}
// Get security level of player, whom this ticket is assigned to
uint32 security = SEC_PLAYER;
Player* assignedPlayer = ticket->GetAssignedPlayer();
if (assignedPlayer)
security = assignedPlayer->GetSession()->GetSecurity();
else
{
uint64 guid = ticket->GetAssignedToGUID();
uint32 accountId = sObjectMgr->GetPlayerAccountIdByGUID(guid);
security = AccountMgr::GetSecurity(accountId, realmID);
}
// Check security
//! If no m_session present it means we're issuing this command from the console
uint32 mySecurity = handler->GetSession() ? handler->GetSession()->GetSecurity() : SEC_CONSOLE;
if (security > mySecurity)
{
handler->SendSysMessage(LANG_COMMAND_TICKETUNASSIGNSECURITY);
return true;
}
std::string assignedTo = ticket->GetAssignedToName(); // copy assignedto name because we need it after the ticket has been unnassigned
SQLTransaction trans = SQLTransaction(NULL);
ticket->SetUnassigned();
ticket->SaveToDB(trans);
sTicketMgr->UpdateLastChange();
std::string msg = ticket->FormatMessageString(*handler, NULL, assignedTo.c_str(),
handler->GetSession() ? handler->GetSession()->GetPlayer()->GetName().c_str() : "Console", NULL);
handler->SendGlobalGMSysMessage(msg.c_str());
return true;
}
static bool HandleGMTicketGetByIdCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
uint32 ticketId = atoi(args);
GmTicket* ticket = sTicketMgr->GetTicket(ticketId);
if (!ticket || ticket->IsClosed() || ticket->IsCompleted())
{
handler->SendSysMessage(LANG_COMMAND_TICKETNOTEXIST);
return true;
}
SQLTransaction trans = SQLTransaction(NULL);
ticket->SetViewed();
ticket->SaveToDB(trans);
handler->SendSysMessage(ticket->FormatMessageString(*handler, true).c_str());
return true;
}
static bool HandleGMTicketGetByNameCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
std::string name(args);
if (!normalizePlayerName(name))
return false;
// Detect target's GUID
uint64 guid = 0;
if (Player* player = ObjectAccessor::FindPlayerByName(name, false))
guid = player->GetGUID();
else
guid = sObjectMgr->GetPlayerGUIDByName(name);
// Target must exist
if (!guid)
{
handler->SendSysMessage(LANG_NO_PLAYERS_FOUND);
return true;
}
// Ticket must exist
GmTicket* ticket = sTicketMgr->GetTicketByPlayer(guid);
if (!ticket)
{
handler->SendSysMessage(LANG_COMMAND_TICKETNOTEXIST);
return true;
}
SQLTransaction trans = SQLTransaction(NULL);
ticket->SetViewed();
ticket->SaveToDB(trans);
handler->SendSysMessage(ticket->FormatMessageString(*handler, true).c_str());
return true;
}
static bool _HandleGMTicketResponseAppendCommand(char const* args, bool newLine, ChatHandler* handler)
{
if (!*args)
return false;
char* ticketIdStr = strtok((char*)args, " ");
uint32 ticketId = atoi(ticketIdStr);
char* response = strtok(NULL, "\n");
if (!response)
return false;
GmTicket* ticket = sTicketMgr->GetTicket(ticketId);
if (!ticket || ticket->IsClosed())
{
handler->PSendSysMessage(LANG_COMMAND_TICKETNOTEXIST);
return true;
}
// Cannot add response to ticket, assigned to someone else
//! Console excluded
Player* player = handler->GetSession() ? handler->GetSession()->GetPlayer() : NULL;
if (player && ticket->IsAssignedNotTo(player->GetGUID()))
{
handler->PSendSysMessage(LANG_COMMAND_TICKETALREADYASSIGNED, ticket->GetId());
return true;
}
SQLTransaction trans = SQLTransaction(NULL);
ticket->AppendResponse(response);
if (newLine)
ticket->AppendResponse("\n");
ticket->SaveToDB(trans);
return true;
}
static bool HandleGMTicketResponseAppendCommand(ChatHandler* handler, char const* args)
{
return _HandleGMTicketResponseAppendCommand(args, false, handler);
}
static bool HandleGMTicketResponseAppendLnCommand(ChatHandler* handler, char const* args)
{
return _HandleGMTicketResponseAppendCommand(args, true, handler);
}
};
void AddSC_ticket_commandscript()
{
new ticket_commandscript();
}
+249
View File
@@ -0,0 +1,249 @@
/*
* Copyright (C)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* ScriptData
Name: titles_commandscript
%Complete: 100
Comment: All titles related commands
Category: commandscripts
EndScriptData */
#include "Chat.h"
#include "Language.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "ScriptMgr.h"
class titles_commandscript : public CommandScript
{
public:
titles_commandscript() : CommandScript("titles_commandscript") { }
ChatCommand* GetCommands() const
{
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;
}
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;
}
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);
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, target->getGender() == GENDER_MALE ? titleInfo->nameMale[handler->GetSessionDbcLocale()] : titleInfo->nameFemale[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)
{
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 titleNameStr[80];
snprintf(titleNameStr, 80, target->getGender() == GENDER_MALE ? titleInfo->nameMale[handler->GetSessionDbcLocale()] : titleInfo->nameFemale[handler->GetSessionDbcLocale()], target->GetName().c_str());
target->SetTitle(titleInfo);
handler->PSendSysMessage(LANG_TITLE_ADD_RES, id, titleNameStr, tNameLink.c_str());
return true;
}
static bool HandleTitlesRemoveCommand(ChatHandler* handler, char const* 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 titleNameStr[80];
snprintf(titleNameStr, 80, target->getGender() == GENDER_MALE ? titleInfo->nameMale[handler->GetSessionDbcLocale()] : titleInfo->nameFemale[handler->GetSessionDbcLocale()], target->GetName().c_str());
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, char const* 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()
{
new titles_commandscript();
}
File diff suppressed because it is too large Load Diff