mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Chat/Commands: Eradicate ChatHandler::extractOptFirstArg
(cherry picked from commit 4f636b80e4)
This commit is contained in:
@@ -797,21 +797,6 @@ uint32 ChatHandler::extractSpellIdFromLink(char* text)
|
||||
return 0;
|
||||
}
|
||||
|
||||
GameTele const* ChatHandler::extractGameTeleFromLink(char* text)
|
||||
{
|
||||
// id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
|
||||
char* cId = extractKeyFromLink(text, "Htele");
|
||||
if (!cId)
|
||||
return nullptr;
|
||||
|
||||
// id case (explicit or from shift link)
|
||||
if (cId[0] >= '0' && cId[0] <= '9')
|
||||
if (uint32 id = atoi(cId))
|
||||
return sObjectMgr->GetGameTele(id);
|
||||
|
||||
return sObjectMgr->GetGameTele(cId);
|
||||
}
|
||||
|
||||
enum GuidLinkType
|
||||
{
|
||||
GUID_LINK_PLAYER = 0, // must be first for selection in not link case
|
||||
@@ -941,24 +926,6 @@ bool ChatHandler::extractPlayerTarget(char* args, Player** player, ObjectGuid* p
|
||||
return true;
|
||||
}
|
||||
|
||||
void ChatHandler::extractOptFirstArg(char* args, char** arg1, char** arg2)
|
||||
{
|
||||
char* p1 = strtok(args, " ");
|
||||
char* p2 = strtok(nullptr, " ");
|
||||
|
||||
if (!p2)
|
||||
{
|
||||
p2 = p1;
|
||||
p1 = nullptr;
|
||||
}
|
||||
|
||||
if (arg1)
|
||||
*arg1 = p1;
|
||||
|
||||
if (arg2)
|
||||
*arg2 = p2;
|
||||
}
|
||||
|
||||
char* ChatHandler::extractQuotedArg(char* args)
|
||||
{
|
||||
if (!args || !*args)
|
||||
|
||||
@@ -104,14 +104,9 @@ class TC_GAME_API ChatHandler
|
||||
|
||||
char* extractKeyFromLink(char* text, char const* linkType, char** something1 = nullptr);
|
||||
char* extractKeyFromLink(char* text, char const* const* linkTypes, int* found_idx, char** something1 = nullptr);
|
||||
|
||||
// if args have single value then it return in arg2 and arg1 == nullptr
|
||||
void extractOptFirstArg(char* args, char** arg1, char** arg2);
|
||||
char* extractQuotedArg(char* args);
|
||||
|
||||
uint32 extractSpellIdFromLink(char* text);
|
||||
ObjectGuid::LowType extractLowGuidFromLink(char* text, HighGuid& guidHigh);
|
||||
GameTele const* extractGameTeleFromLink(char* text);
|
||||
bool GetPlayerGroupAndGUIDByName(const char* cname, Player*& player, Group*& group, ObjectGuid& guid, bool offline = false);
|
||||
std::string extractPlayerNameFromLink(char* text);
|
||||
// select by arg (name/link) or in-game selection online/offline player or self if a creature is selected
|
||||
|
||||
@@ -35,8 +35,9 @@ Optional<std::string_view> Trinity::Impl::ChatCommands::ArgInfo<AchievementEntry
|
||||
Variant<Hyperlink<achievement>, uint32> val;
|
||||
Optional<std::string_view> next = SingleConsumer<decltype(val)>::TryConsumeTo(val, args);
|
||||
if (next)
|
||||
data = val.visit(AchievementVisitor());
|
||||
return next;
|
||||
if ((data = val.visit(AchievementVisitor())))
|
||||
return next;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
struct CurrencyTypesVisitor
|
||||
@@ -50,8 +51,9 @@ Optional<std::string_view> Trinity::Impl::ChatCommands::ArgInfo<CurrencyTypesEnt
|
||||
Variant<Hyperlink<currency>, uint32> val;
|
||||
Optional<std::string_view> next = SingleConsumer<decltype(val)>::TryConsumeTo(val, args);
|
||||
if (next)
|
||||
data = val.visit(CurrencyTypesVisitor());
|
||||
return next;
|
||||
if ((data = val.visit(CurrencyTypesVisitor())))
|
||||
return next;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
struct GameTeleVisitor
|
||||
@@ -65,8 +67,9 @@ Optional<std::string_view> Trinity::Impl::ChatCommands::ArgInfo<GameTele const*>
|
||||
Variant<Hyperlink<tele>, std::string> val;
|
||||
Optional<std::string_view> next = SingleConsumer<decltype(val)>::TryConsumeTo(val, args);
|
||||
if (next)
|
||||
data = val.visit(GameTeleVisitor());
|
||||
return next;
|
||||
if ((data = val.visit(GameTeleVisitor())))
|
||||
return next;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
struct ItemTemplateVisitor
|
||||
@@ -80,8 +83,9 @@ Optional<std::string_view> Trinity::Impl::ChatCommands::ArgInfo<ItemTemplate con
|
||||
Variant<Hyperlink<item>, uint32> val;
|
||||
Optional<std::string_view> next = SingleConsumer<decltype(val)>::TryConsumeTo(val, args);
|
||||
if (next)
|
||||
data = val.visit(ItemTemplateVisitor());
|
||||
return next;
|
||||
if ((data = val.visit(ItemTemplateVisitor())))
|
||||
return next;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
struct SpellInfoVisitor
|
||||
@@ -104,6 +108,7 @@ Optional<std::string_view> Trinity::Impl::ChatCommands::ArgInfo<SpellInfo const*
|
||||
Variant<Hyperlink<apower>, Hyperlink<conduit>, Hyperlink<enchant>, Hyperlink<mawpower>, Hyperlink<pvptal>, Hyperlink<spell>, Hyperlink<talent>, Hyperlink<trade>, uint32> val;
|
||||
Optional<std::string_view> next = SingleConsumer<decltype(val)>::TryConsumeTo(val, args);
|
||||
if (next)
|
||||
data = val.visit(SpellInfoVisitor());
|
||||
return next;
|
||||
if ((data = val.visit(SpellInfoVisitor())))
|
||||
return next;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
@@ -93,6 +93,8 @@ namespace Trinity::ChatCommands
|
||||
{
|
||||
using value_type = std::string_view;
|
||||
|
||||
using std::string_view::operator=;
|
||||
|
||||
Optional<std::string_view> TryConsume(std::string_view args)
|
||||
{
|
||||
std::string_view::operator=(args);
|
||||
@@ -104,6 +106,8 @@ namespace Trinity::ChatCommands
|
||||
{
|
||||
using value_type = std::wstring;
|
||||
|
||||
using std::wstring::operator=;
|
||||
|
||||
Optional<std::string_view> TryConsume(std::string_view args)
|
||||
{
|
||||
if (Utf8toWStr(args, *this))
|
||||
|
||||
@@ -582,7 +582,7 @@ void Guild::Member::SetOfficerNote(std::string const& officerNote)
|
||||
CharacterDatabase.Execute(stmt);
|
||||
}
|
||||
|
||||
void Guild::Member::ChangeRank(CharacterDatabaseTransaction& trans, GuildRankId newRank)
|
||||
void Guild::Member::ChangeRank(CharacterDatabaseTransaction trans, GuildRankId newRank)
|
||||
{
|
||||
m_rankId = newRank;
|
||||
|
||||
@@ -2911,7 +2911,7 @@ void Guild::DeleteMember(CharacterDatabaseTransaction& trans, ObjectGuid guid, b
|
||||
_UpdateAccountsNumber();
|
||||
}
|
||||
|
||||
bool Guild::ChangeMemberRank(CharacterDatabaseTransaction& trans, ObjectGuid guid, GuildRankId newRank)
|
||||
bool Guild::ChangeMemberRank(CharacterDatabaseTransaction trans, ObjectGuid guid, GuildRankId newRank)
|
||||
{
|
||||
if (GetRankInfo(newRank)) // Validate rank (allow only existing ranks)
|
||||
{
|
||||
|
||||
@@ -351,7 +351,7 @@ class TC_GAME_API Guild
|
||||
|
||||
bool IsOnline() const { return (m_flags & GUILDMEMBER_STATUS_ONLINE); }
|
||||
|
||||
void ChangeRank(CharacterDatabaseTransaction& trans, GuildRankId newRank);
|
||||
void ChangeRank(CharacterDatabaseTransaction trans, GuildRankId newRank);
|
||||
|
||||
inline void UpdateLogoutTime();
|
||||
inline bool IsRank(GuildRankId rankId) const { return m_rankId == rankId; }
|
||||
@@ -820,7 +820,7 @@ class TC_GAME_API Guild
|
||||
// Adds member to guild. If rankId == GUILD_RANK_NONE, lowest rank is assigned.
|
||||
bool AddMember(CharacterDatabaseTransaction& trans, ObjectGuid guid, Optional<GuildRankId> rankId = {});
|
||||
void DeleteMember(CharacterDatabaseTransaction& trans, ObjectGuid guid, bool isDisbanding = false, bool isKicked = false, bool canDeleteGuild = false);
|
||||
bool ChangeMemberRank(CharacterDatabaseTransaction& trans, ObjectGuid guid, GuildRankId newRank);
|
||||
bool ChangeMemberRank(CharacterDatabaseTransaction trans, ObjectGuid guid, GuildRankId newRank);
|
||||
bool IsMember(ObjectGuid guid) const;
|
||||
uint32 GetMembersCount() const { return uint32(m_members.size()); }
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ EndScriptData */
|
||||
#include "RBAC.h"
|
||||
#include <iomanip>
|
||||
|
||||
using namespace Trinity::ChatCommands;
|
||||
class guild_commandscript : public CommandScript
|
||||
{
|
||||
public:
|
||||
@@ -191,21 +192,14 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleGuildRankCommand(ChatHandler* handler, char const* args)
|
||||
static bool HandleGuildRankCommand(ChatHandler* handler, Optional<PlayerIdentifier> player, uint8 rank)
|
||||
{
|
||||
char* nameStr;
|
||||
char* rankStr;
|
||||
handler->extractOptFirstArg((char*)args, &nameStr, &rankStr);
|
||||
if (!rankStr)
|
||||
if (!player)
|
||||
player = PlayerIdentifier::FromTargetOrSelf(handler);
|
||||
if (!player)
|
||||
return false;
|
||||
|
||||
Player* target;
|
||||
ObjectGuid targetGuid;
|
||||
std::string target_name;
|
||||
if (!handler->extractPlayerTarget(nameStr, &target, &targetGuid, &target_name))
|
||||
return false;
|
||||
|
||||
ObjectGuid::LowType guildId = target ? target->GetGuildId() : sCharacterCache->GetCharacterGuildIdByGuid(targetGuid);
|
||||
ObjectGuid::LowType guildId = player->IsConnected() ? player->GetConnectedPlayer()->GetGuildId() : sCharacterCache->GetCharacterGuildIdByGuid(*player);
|
||||
if (!guildId)
|
||||
return false;
|
||||
|
||||
@@ -213,9 +207,7 @@ public:
|
||||
if (!targetGuild)
|
||||
return false;
|
||||
|
||||
uint8 newRank = uint8(atoi(rankStr));
|
||||
CharacterDatabaseTransaction trans(nullptr);
|
||||
return targetGuild->ChangeMemberRank(trans, targetGuid, GuildRankId(newRank));
|
||||
return targetGuild->ChangeMemberRank(nullptr, *player, GuildRankId(rank));
|
||||
}
|
||||
|
||||
static bool HandleGuildRenameCommand(ChatHandler* handler, char const* _args)
|
||||
|
||||
@@ -1913,63 +1913,51 @@ public:
|
||||
}
|
||||
|
||||
// mute player for the specified duration
|
||||
static bool HandleMuteCommand(ChatHandler* handler, char const* args)
|
||||
static bool HandleMuteCommand(ChatHandler* handler, Optional<PlayerIdentifier> player, uint32 muteTime, Tail muteReason)
|
||||
{
|
||||
char* nameStr;
|
||||
char* delayStr;
|
||||
handler->extractOptFirstArg((char*)args, &nameStr, &delayStr);
|
||||
if (!delayStr)
|
||||
std::string muteReasonStr{ muteReason };
|
||||
if (muteReason.empty())
|
||||
muteReasonStr = handler->GetTrinityString(LANG_NO_REASON);
|
||||
|
||||
if (!player)
|
||||
player = PlayerIdentifier::FromTarget(handler);
|
||||
if (!player)
|
||||
{
|
||||
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
char const* muteReason = strtok(nullptr, "\r");
|
||||
std::string muteReasonStr = handler->GetTrinityString(LANG_NO_REASON);
|
||||
if (muteReason != nullptr)
|
||||
muteReasonStr = muteReason;
|
||||
|
||||
Player* target;
|
||||
ObjectGuid targetGuid;
|
||||
std::string targetName;
|
||||
if (!handler->extractPlayerTarget(nameStr, &target, &targetGuid, &targetName))
|
||||
return false;
|
||||
|
||||
uint32 accountId = target ? target->GetSession()->GetAccountId() : sCharacterCache->GetCharacterAccountIdByGuid(targetGuid);
|
||||
Player* target = player->GetConnectedPlayer();
|
||||
uint32 accountId = target ? target->GetSession()->GetAccountId() : sCharacterCache->GetCharacterAccountIdByGuid(*player);
|
||||
|
||||
// find only player from same account if any
|
||||
if (!target)
|
||||
if (WorldSession* session = sWorld->FindSession(accountId))
|
||||
target = session->GetPlayer();
|
||||
|
||||
uint32 notSpeakTime = uint32(atoi(delayStr));
|
||||
|
||||
// must have strong lesser security level
|
||||
if (handler->HasLowerSecurity (target, targetGuid, true))
|
||||
if (handler->HasLowerSecurity(target, player->GetGUID(), true))
|
||||
return false;
|
||||
|
||||
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_MUTE_TIME);
|
||||
std::string muteBy = "";
|
||||
if (handler->GetSession())
|
||||
muteBy = handler->GetSession()->GetPlayerName();
|
||||
if (Player* gmPlayer = handler->GetPlayer())
|
||||
muteBy = gmPlayer->GetName();
|
||||
else
|
||||
muteBy = handler->GetTrinityString(LANG_CONSOLE);
|
||||
|
||||
if (target)
|
||||
{
|
||||
// Target is online, mute will be in effect right away.
|
||||
int64 muteTime = GameTime::GetGameTime() + notSpeakTime * MINUTE;
|
||||
target->GetSession()->m_muteTime = muteTime;
|
||||
stmt->setInt64(0, muteTime);
|
||||
std::string nameLink = handler->playerLink(targetName);
|
||||
|
||||
if (sWorld->getBoolConfig(CONFIG_SHOW_MUTE_IN_WORLD))
|
||||
sWorld->SendWorldText(LANG_COMMAND_MUTEMESSAGE_WORLD, muteBy.c_str(), nameLink.c_str(), notSpeakTime, muteReasonStr.c_str());
|
||||
|
||||
ChatHandler(target->GetSession()).PSendSysMessage(LANG_YOUR_CHAT_DISABLED, notSpeakTime, muteBy.c_str(), muteReasonStr.c_str());
|
||||
int64 mutedUntil = GameTime::GetGameTime() + static_cast<int64>(muteTime) * MINUTE;
|
||||
target->GetSession()->m_muteTime = mutedUntil;
|
||||
stmt->setInt64(0, mutedUntil);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Target is offline, mute will be in effect starting from the next login.
|
||||
int32 muteTime = -int32(notSpeakTime * MINUTE);
|
||||
stmt->setInt64(0, muteTime);
|
||||
stmt->setInt64(0, -static_cast<int64>(muteTime) * MINUTE);
|
||||
}
|
||||
|
||||
stmt->setString(1, muteReasonStr);
|
||||
@@ -1978,16 +1966,23 @@ public:
|
||||
LoginDatabase.Execute(stmt);
|
||||
stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_ACCOUNT_MUTE);
|
||||
stmt->setUInt32(0, accountId);
|
||||
stmt->setUInt32(1, notSpeakTime);
|
||||
stmt->setUInt32(1, muteTime);
|
||||
stmt->setString(2, muteBy);
|
||||
stmt->setString(3, muteReasonStr);
|
||||
LoginDatabase.Execute(stmt);
|
||||
std::string nameLink = handler->playerLink(targetName);
|
||||
|
||||
if (sWorld->getBoolConfig(CONFIG_SHOW_MUTE_IN_WORLD) && !target)
|
||||
sWorld->SendWorldText(LANG_COMMAND_MUTEMESSAGE_WORLD, muteBy.c_str(), nameLink.c_str(), notSpeakTime, muteReasonStr.c_str());
|
||||
std::string nameLink = handler->playerLink(player->GetName());
|
||||
if (sWorld->getBoolConfig(CONFIG_SHOW_MUTE_IN_WORLD))
|
||||
sWorld->SendWorldText(LANG_COMMAND_MUTEMESSAGE_WORLD, muteBy.c_str(), nameLink.c_str(), muteTime, muteReasonStr.c_str());
|
||||
if (target)
|
||||
{
|
||||
ChatHandler(target->GetSession()).PSendSysMessage(LANG_YOUR_CHAT_DISABLED, muteTime, muteBy.c_str(), muteReasonStr.c_str());
|
||||
handler->PSendSysMessage(LANG_YOU_DISABLE_CHAT, nameLink.c_str(), muteTime, muteReasonStr.c_str());
|
||||
}
|
||||
else
|
||||
handler->PSendSysMessage(target ? LANG_YOU_DISABLE_CHAT : LANG_COMMAND_DISABLE_CHAT_DELAYED, nameLink.c_str(), notSpeakTime, muteReasonStr.c_str());
|
||||
{
|
||||
handler->PSendSysMessage(LANG_COMMAND_DISABLE_CHAT_DELAYED, nameLink.c_str(), muteTime, muteReasonStr.c_str());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -109,28 +109,21 @@ public:
|
||||
}
|
||||
|
||||
// teleport player to given game_tele.entry
|
||||
static bool HandleTeleNameCommand(ChatHandler* handler, char const* args)
|
||||
static bool HandleTeleNameCommand(ChatHandler* handler, Optional<PlayerIdentifier> player, Variant<GameTele const*, ExactSequence<'$','h','o','m','e'>> where)
|
||||
{
|
||||
char* nameStr;
|
||||
char* teleStr;
|
||||
handler->extractOptFirstArg((char*)args, &nameStr, &teleStr);
|
||||
if (!teleStr)
|
||||
if (!player)
|
||||
player = PlayerIdentifier::FromTargetOrSelf(handler);
|
||||
if (!player)
|
||||
return false;
|
||||
|
||||
Player* target;
|
||||
ObjectGuid 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 (where.index() == 1) // References target's homebind
|
||||
{
|
||||
if (target)
|
||||
if (Player* target = player->GetConnectedPlayer())
|
||||
target->TeleportTo(target->m_homebind);
|
||||
else
|
||||
{
|
||||
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_HOMEBIND);
|
||||
stmt->setUInt64(0, target_guid.GetCounter());
|
||||
stmt->setUInt64(0, player->GetGUID().GetCounter());
|
||||
PreparedQueryResult resultDB = CharacterDatabase.Query(stmt);
|
||||
|
||||
if (resultDB)
|
||||
@@ -140,7 +133,7 @@ public:
|
||||
uint32 zoneId = fieldsDB[1].GetUInt16();
|
||||
|
||||
CharacterDatabaseTransaction dummy;
|
||||
Player::SavePositionInDB(loc, zoneId, target_guid, dummy);
|
||||
Player::SavePositionInDB(loc, zoneId, player->GetGUID(), dummy);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,21 +141,14 @@ public:
|
||||
}
|
||||
|
||||
// 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)
|
||||
GameTele const* tele = where.get<GameTele const*>();
|
||||
if (Player* target = player->GetConnectedPlayer())
|
||||
{
|
||||
// check online security
|
||||
if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
|
||||
return false;
|
||||
|
||||
std::string chrNameLink = handler->playerLink(target_name);
|
||||
std::string chrNameLink = handler->playerLink(target->GetName());
|
||||
|
||||
if (target->IsBeingTeleported() == true)
|
||||
{
|
||||
@@ -186,16 +172,16 @@ public:
|
||||
else
|
||||
{
|
||||
// check offline security
|
||||
if (handler->HasLowerSecurity(nullptr, target_guid))
|
||||
if (handler->HasLowerSecurity(nullptr, player->GetGUID()))
|
||||
return false;
|
||||
|
||||
std::string nameLink = handler->playerLink(target_name);
|
||||
std::string nameLink = handler->playerLink(player->GetName());
|
||||
|
||||
handler->PSendSysMessage(LANG_TELEPORTING_TO, nameLink.c_str(), handler->GetTrinityString(LANG_OFFLINE), tele->name.c_str());
|
||||
|
||||
CharacterDatabaseTransaction dummy;
|
||||
Player::SavePositionInDB(WorldLocation(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation),
|
||||
sMapMgr->GetZoneId(PhasingHandler::GetEmptyPhaseShift(), tele->mapId, tele->position_x, tele->position_y, tele->position_z), target_guid, dummy);
|
||||
sMapMgr->GetZoneId(PhasingHandler::GetEmptyPhaseShift(), tele->mapId, tele->position_x, tele->position_y, tele->position_z), player->GetGUID(), dummy);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user