mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-18 08:28:32 +01:00
Core/ChatCommands: AccountIdentifier from current target
This commit is contained in:
committed by
Peter Keresztes Schmidt
parent
e14a0c197c
commit
8ee92147a5
@@ -24,6 +24,8 @@
|
||||
#include "ObjectAccessor.h"
|
||||
#include "ObjectMgr.h"
|
||||
#include "Player.h"
|
||||
#include "World.h"
|
||||
#include "WorldSession.h"
|
||||
|
||||
using namespace Trinity::Impl::ChatCommands;
|
||||
|
||||
@@ -58,6 +60,9 @@ ChatCommandResult Trinity::ChatCommands::QuotedString::TryConsume(ChatHandler co
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
Trinity::ChatCommands::AccountIdentifier::AccountIdentifier(WorldSession& session)
|
||||
: _id(session.GetAccountId()), _name(session.GetAccountName()), _session(&session) {}
|
||||
|
||||
ChatCommandResult Trinity::ChatCommands::AccountIdentifier::TryConsume(ChatHandler const* handler, std::string_view args)
|
||||
{
|
||||
std::string_view text;
|
||||
@@ -70,6 +75,7 @@ ChatCommandResult Trinity::ChatCommands::AccountIdentifier::TryConsume(ChatHandl
|
||||
if (!Utf8ToUpperOnlyLatin(_name))
|
||||
return GetTrinityString(handler, LANG_CMDPARSER_INVALID_UTF8);
|
||||
_id = AccountMgr::GetId(_name);
|
||||
_session = sWorld->FindSession(_id);
|
||||
if (_id) // account with name exists, we are done
|
||||
return next;
|
||||
|
||||
@@ -78,6 +84,7 @@ ChatCommandResult Trinity::ChatCommands::AccountIdentifier::TryConsume(ChatHandl
|
||||
if (!id)
|
||||
return FormatTrinityString(handler, LANG_CMDPARSER_ACCOUNT_NAME_NO_EXIST, STRING_VIEW_FMT_ARG(_name));
|
||||
_id = *id;
|
||||
_session = sWorld->FindSession(_id);
|
||||
|
||||
if (AccountMgr::GetName(_id, _name))
|
||||
return next;
|
||||
@@ -85,6 +92,15 @@ ChatCommandResult Trinity::ChatCommands::AccountIdentifier::TryConsume(ChatHandl
|
||||
return FormatTrinityString(handler, LANG_CMDPARSER_ACCOUNT_ID_NO_EXIST, _id);
|
||||
}
|
||||
|
||||
Optional<Trinity::ChatCommands::AccountIdentifier> Trinity::ChatCommands::AccountIdentifier::FromTarget(ChatHandler* handler)
|
||||
{
|
||||
if (Player* player = handler->GetPlayer())
|
||||
if (Player* target = player->GetSelectedPlayer())
|
||||
if (WorldSession* session = target->GetSession())
|
||||
return { *session };
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
ChatCommandResult Trinity::ChatCommands::PlayerIdentifier::TryConsume(ChatHandler const* handler, std::string_view args)
|
||||
{
|
||||
Variant<Hyperlink<player>, ObjectGuid::LowType, std::string_view> val;
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
|
||||
class ChatHandler;
|
||||
class Player;
|
||||
class WorldSession;
|
||||
|
||||
namespace Trinity::Impl::ChatCommands
|
||||
{
|
||||
@@ -152,18 +153,26 @@ namespace Trinity::ChatCommands
|
||||
{
|
||||
using value_type = uint32;
|
||||
|
||||
AccountIdentifier() : _id(), _name(), _session(nullptr) {}
|
||||
AccountIdentifier(WorldSession& session);
|
||||
|
||||
operator uint32() const { return _id; }
|
||||
operator std::string const& () const { return _name; }
|
||||
operator std::string_view() const { return { _name }; }
|
||||
|
||||
uint32 GetID() const { return _id; }
|
||||
std::string const& GetName() const { return _name; }
|
||||
bool IsConnected() { return _session != nullptr; }
|
||||
WorldSession* GetConnectedSession() { return _session; }
|
||||
|
||||
ChatCommandResult TryConsume(ChatHandler const* handler, std::string_view args);
|
||||
|
||||
static Optional<AccountIdentifier> FromTarget(ChatHandler* handler);
|
||||
|
||||
private:
|
||||
uint32 _id;
|
||||
std::string _name;
|
||||
WorldSession* _session;
|
||||
};
|
||||
|
||||
struct TC_GAME_API PlayerIdentifier : Trinity::Impl::ChatCommands::ContainerTag
|
||||
|
||||
@@ -438,6 +438,7 @@ class TC_GAME_API WorldSession
|
||||
|
||||
AccountTypes GetSecurity() const { return _security; }
|
||||
uint32 GetAccountId() const { return _accountId; }
|
||||
std::string const& GetAccountName() const { return _accountName; }
|
||||
Player* GetPlayer() const { return _player; }
|
||||
std::string const& GetPlayerName() const;
|
||||
std::string GetPlayerInfo() const;
|
||||
|
||||
Reference in New Issue
Block a user