Files
TCPlayerbotCore/src/server/scripts/Commands/cs_message.cpp
T

267 lines
9.3 KiB
C++
Raw Normal View History

2012-07-21 22:29:14 +02:00
/*
2020-01-02 06:44:10 +01:00
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
2012-07-21 22:29:14 +02:00
*
* 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 */
2017-05-20 00:09:37 +02:00
#include "ScriptMgr.h"
2012-07-21 22:29:14 +02:00
#include "Chat.h"
2017-05-20 00:09:37 +02:00
#include "ChatPackets.h"
2016-10-03 06:06:33 -03:00
#include "Channel.h"
2012-07-21 22:29:14 +02:00
#include "ChannelMgr.h"
2017-05-18 23:52:58 +02:00
#include "DatabaseEnv.h"
2017-06-04 01:00:45 +02:00
#include "DB2Stores.h"
#include "Language.h"
2017-06-04 01:00:45 +02:00
#include "ObjectAccessor.h"
2013-03-15 23:02:11 +01:00
#include "ObjectMgr.h"
2017-05-20 00:09:37 +02:00
#include "Player.h"
#include "RBAC.h"
2017-05-18 23:52:58 +02:00
#include "World.h"
2017-06-04 01:00:45 +02:00
#include "WorldSession.h"
2012-07-21 22:29:14 +02:00
using namespace Trinity::ChatCommands;
2012-07-21 22:29:14 +02:00
class message_commandscript : public CommandScript
{
public:
message_commandscript() : CommandScript("message_commandscript") { }
std::vector<ChatCommand> GetCommands() const override
2012-07-21 22:29:14 +02:00
{
static std::vector<ChatCommand> channelSetCommandTable =
2012-07-21 22:29:14 +02:00
{
{ "ownership", rbac::RBAC_PERM_COMMAND_CHANNEL_SET_OWNERSHIP, false, &HandleChannelSetOwnership, "" },
2012-07-21 22:29:14 +02:00
};
static std::vector<ChatCommand> channelCommandTable =
2012-07-21 22:29:14 +02:00
{
2020-08-14 17:06:03 +02:00
{ "set", rbac::RBAC_PERM_COMMAND_CHANNEL_SET, true, nullptr, "", channelSetCommandTable },
2012-07-21 22:29:14 +02:00
};
static std::vector<ChatCommand> commandTable =
2012-07-21 22:29:14 +02:00
{
2020-08-14 17:06:03 +02:00
{ "channel", rbac::RBAC_PERM_COMMAND_CHANNEL, true, nullptr, "", channelCommandTable },
{ "nameannounce", rbac::RBAC_PERM_COMMAND_NAMEANNOUNCE, true, &HandleNameAnnounceCommand, "" },
{ "gmnameannounce", rbac::RBAC_PERM_COMMAND_GMNAMEANNOUNCE, true, &HandleGMNameAnnounceCommand, "" },
{ "announce", rbac::RBAC_PERM_COMMAND_ANNOUNCE, true, &HandleAnnounceCommand, "" },
{ "gmannounce", rbac::RBAC_PERM_COMMAND_GMANNOUNCE, true, &HandleGMAnnounceCommand, "" },
{ "notify", rbac::RBAC_PERM_COMMAND_NOTIFY, true, &HandleNotifyCommand, "" },
{ "gmnotify", rbac::RBAC_PERM_COMMAND_GMNOTIFY, true, &HandleGMNotifyCommand, "" },
{ "whispers", rbac::RBAC_PERM_COMMAND_WHISPERS, false, &HandleWhispersCommand, "" },
2012-07-21 22:29:14 +02:00
};
return commandTable;
}
static bool HandleChannelSetOwnership(ChatHandler* handler, std::string channelName, bool grantOwnership)
2012-07-21 22:29:14 +02:00
{
2016-10-03 06:06:33 -03:00
uint32 channelId = 0;
for (uint32 i = 0; i < sChatChannelsStore.GetNumRows(); ++i)
{
ChatChannelsEntry const* channelEntry = sChatChannelsStore.LookupEntry(i);
if (!channelEntry)
continue;
if (StringContainsStringI(channelEntry->Name[handler->GetSessionDbcLocale()], channelName))
2016-10-03 06:06:33 -03:00
{
channelId = i;
break;
}
}
AreaTableEntry const* zoneEntry = nullptr;
for (uint32 i = 0; i < sAreaTableStore.GetNumRows(); ++i)
{
AreaTableEntry const* entry = sAreaTableStore.LookupEntry(i);
if (!entry)
continue;
if (StringContainsStringI(entry->AreaName[handler->GetSessionDbcLocale()], channelName))
2016-10-03 06:06:33 -03:00
{
zoneEntry = entry;
break;
}
}
2012-07-21 22:29:14 +02:00
Player* player = handler->GetSession()->GetPlayer();
2016-10-03 06:06:33 -03:00
Channel* channel = nullptr;
2012-07-21 22:29:14 +02:00
2014-11-23 04:25:47 +01:00
if (ChannelMgr* cMgr = ChannelMgr::ForTeam(player->GetTeam()))
channel = cMgr->GetChannel(channelId, channelName, player, false, zoneEntry);
2012-07-21 22:29:14 +02:00
if (grantOwnership)
2012-07-21 22:29:14 +02:00
{
2016-10-03 06:06:33 -03:00
if (channel)
channel->SetOwnership(true);
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHANNEL_OWNERSHIP);
2012-07-21 22:29:14 +02:00
stmt->setUInt8 (0, 1);
stmt->setString(1, channelName);
2012-07-21 22:29:14 +02:00
CharacterDatabase.Execute(stmt);
handler->PSendSysMessage(LANG_CHANNEL_ENABLE_OWNERSHIP, channelName.c_str());
2012-07-21 22:29:14 +02:00
}
else
2012-07-21 22:29:14 +02:00
{
2016-10-03 06:06:33 -03:00
if (channel)
channel->SetOwnership(false);
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHANNEL_OWNERSHIP);
2012-07-21 22:29:14 +02:00
stmt->setUInt8 (0, 0);
stmt->setString(1, channelName);
2012-07-21 22:29:14 +02:00
CharacterDatabase.Execute(stmt);
handler->PSendSysMessage(LANG_CHANNEL_DISABLE_OWNERSHIP, channelName.c_str());
2012-07-21 22:29:14 +02:00
}
return true;
}
static bool HandleNameAnnounceCommand(ChatHandler* handler, CommandArgs* args)
2012-07-21 22:29:14 +02:00
{
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->GetFullArgs());
2012-07-21 22:29:14 +02:00
return true;
}
static bool HandleGMNameAnnounceCommand(ChatHandler* handler, CommandArgs* args)
2012-07-21 22:29:14 +02:00
{
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->GetFullArgs());
2012-07-21 22:29:14 +02:00
return true;
}
2012-07-21 22:29:14 +02:00
// global announce
static bool HandleAnnounceCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
std::string str = handler->PGetParseString(LANG_SYSTEMMESSAGE, args);
sWorld->SendServerMessage(SERVER_MSG_STRING, str);
2012-07-21 22:29:14 +02:00
return true;
}
2012-07-21 22:29:14 +02:00
// announce to logged in GMs
static bool HandleGMAnnounceCommand(ChatHandler* /*handler*/, CommandArgs* args)
2012-07-21 22:29:14 +02:00
{
if (!*args)
return false;
sWorld->SendGMText(LANG_GM_BROADCAST, args->GetFullArgs());
2012-07-21 22:29:14 +02:00
return true;
}
// send on-screen notification to players
static bool HandleNotifyCommand(ChatHandler* handler, CommandArgs* args)
2012-07-21 22:29:14 +02:00
{
if (!*args)
return false;
std::string str = handler->GetTrinityString(LANG_GLOBAL_NOTIFY);
str += args->GetFullArgs();
2012-07-21 22:29:14 +02:00
2015-02-23 20:23:33 +01:00
sWorld->SendGlobalMessage(WorldPackets::Chat::PrintNotification(str).Write());
2012-07-21 22:29:14 +02:00
return true;
}
// send on-screen notification to GMs
static bool HandleGMNotifyCommand(ChatHandler* handler, CommandArgs* args)
2012-07-21 22:29:14 +02:00
{
if (!*args)
return false;
std::string str = handler->GetTrinityString(LANG_GM_NOTIFY);
str += args->GetFullArgs();
2012-07-21 22:29:14 +02:00
2015-02-23 20:23:33 +01:00
sWorld->SendGlobalGMMessage(WorldPackets::Chat::PrintNotification(str).Write());
2012-07-21 22:29:14 +02:00
return true;
}
// Enable/Disable accepting whispers (for GM)
static bool HandleWhispersCommand(ChatHandler* handler, Optional<Variant<bool, ExactSequence<'r', 'e', 'm', 'o', 'v', 'e'>>> operationArg, Optional<std::string> playerNameArg)
2012-07-21 22:29:14 +02:00
{
if (!operationArg)
2012-07-21 22:29:14 +02:00
{
handler->PSendSysMessage(LANG_COMMAND_WHISPERACCEPTING, handler->GetSession()->GetPlayer()->isAcceptWhispers() ? handler->GetTrinityString(LANG_ON) : handler->GetTrinityString(LANG_OFF));
return true;
}
if (operationArg->holds_alternative<bool>())
2012-07-21 22:29:14 +02:00
{
if (operationArg->get<bool>())
{
handler->GetSession()->GetPlayer()->SetAcceptWhispers(true);
handler->SendSysMessage(LANG_COMMAND_WHISPERON);
return true;
}
else
{
// 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;
}
2012-07-21 22:29:14 +02:00
}
if (operationArg->holds_alternative<ExactSequence<'r', 'e', 'm', 'o', 'v', 'e'>>())
2012-07-21 22:29:14 +02:00
{
if (!playerNameArg)
return false;
2012-07-21 22:29:14 +02:00
if (normalizePlayerName(*playerNameArg))
2013-03-18 23:38:07 +01:00
{
if (Player* player = ObjectAccessor::FindPlayerByName(*playerNameArg))
{
handler->GetSession()->GetPlayer()->RemoveFromWhisperWhiteList(player->GetGUID());
handler->PSendSysMessage(LANG_COMMAND_WHISPEROFFPLAYER, playerNameArg->c_str());
return true;
}
else
{
handler->PSendSysMessage(LANG_PLAYER_NOT_FOUND, playerNameArg->c_str());
handler->SetSentErrorMessage(true);
return false;
}
2013-03-18 23:38:07 +01:00
}
}
2012-07-21 22:29:14 +02:00
handler->SendSysMessage(LANG_USE_BOL);
handler->SetSentErrorMessage(true);
return false;
}
};
void AddSC_message_commandscript()
{
new message_commandscript();
}