Core: Define helper functions to know if an account is Player, Moderator, GM, Admin or Console

This commit is contained in:
Spp-
2011-09-08 15:11:55 +02:00
parent d5cbc97373
commit 327fe7c247
23 changed files with 174 additions and 90 deletions
@@ -27,6 +27,7 @@
#include "Opcodes.h"
#include "UpdateMask.h"
#include "Util.h"
#include "AccountMgr.h"
//please DO NOT use iterator++, because it is slower than ++iterator!!!
//post-incrementation is always slower than pre-incrementation !
@@ -204,7 +205,7 @@ void WorldSession::HandleAuctionSellItem(WorldPacket & recv_data)
return;
}
if (GetSecurity() > SEC_PLAYER && sWorld->getBoolConfig(CONFIG_GM_LOG_TRADE))
if (AccountMgr::IsGMAccount(GetSecurity()) && sWorld->getBoolConfig(CONFIG_GM_LOG_TRADE))
{
sLog->outCommand(GetAccountId(), "GM %s (Account: %u) create auction: %s (Entry: %u Count: %u)",
GetPlayerName(), GetAccountId(), it->GetTemplate()->Name1.c_str(), it->GetEntry(), count);
@@ -42,6 +42,7 @@
#include "Util.h"
#include "ScriptMgr.h"
#include "Battleground.h"
#include "AccountMgr.h"
class LoginQueryHolder : public SQLQueryHolder
{
@@ -279,7 +280,7 @@ void WorldSession::HandleCharCreateOpcode(WorldPacket & recv_data)
WorldPacket data(SMSG_CHAR_CREATE, 1); // returned with diff.values in all cases
if (GetSecurity() == SEC_PLAYER)
if (AccountMgr::IsPlayerAccount(GetSecurity()))
{
if (uint32 mask = sWorld->getIntConfig(CONFIG_CHARACTER_CREATING_DISABLED))
{
@@ -337,7 +338,7 @@ void WorldSession::HandleCharCreateOpcode(WorldPacket & recv_data)
return;
}
if (GetSecurity() == SEC_PLAYER)
if (AccountMgr::IsPlayerAccount(GetSecurity()))
{
uint32 raceMaskDisabled = sWorld->getIntConfig(CONFIG_CHARACTER_CREATING_DISABLED_RACEMASK);
if ((1 << (race_ - 1)) & raceMaskDisabled)
@@ -374,7 +375,7 @@ void WorldSession::HandleCharCreateOpcode(WorldPacket & recv_data)
return;
}
if (GetSecurity() == SEC_PLAYER && sObjectMgr->IsReservedName(name))
if (AccountMgr::IsPlayerAccount(GetSecurity()) && sObjectMgr->IsReservedName(name))
{
data << (uint8)CHAR_NAME_RESERVED;
SendPacket(&data);
@@ -383,7 +384,7 @@ void WorldSession::HandleCharCreateOpcode(WorldPacket & recv_data)
// speedup check for heroic class disabled case
uint32 heroic_free_slots = sWorld->getIntConfig(CONFIG_HEROIC_CHARACTERS_PER_REALM);
if (heroic_free_slots == 0 && GetSecurity() == SEC_PLAYER && class_ == CLASS_DEATH_KNIGHT)
if (heroic_free_slots == 0 && AccountMgr::IsPlayerAccount(GetSecurity()) && class_ == CLASS_DEATH_KNIGHT)
{
data << (uint8)CHAR_CREATE_UNIQUE_CLASS_LIMIT;
SendPacket(&data);
@@ -392,7 +393,7 @@ void WorldSession::HandleCharCreateOpcode(WorldPacket & recv_data)
// speedup check for heroic class disabled case
uint32 req_level_for_heroic = sWorld->getIntConfig(CONFIG_CHARACTER_CREATING_MIN_LEVEL_FOR_HEROIC_CHARACTER);
if (GetSecurity() == SEC_PLAYER && class_ == CLASS_DEATH_KNIGHT && req_level_for_heroic > sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL))
if (AccountMgr::IsPlayerAccount(GetSecurity()) && class_ == CLASS_DEATH_KNIGHT && req_level_for_heroic > sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL))
{
data << (uint8)CHAR_CREATE_LEVEL_REQUIREMENT;
SendPacket(&data);
@@ -492,7 +493,7 @@ void WorldSession::HandleCharCreateCallback(PreparedQueryResult result, Characte
}
}
bool allowTwoSideAccounts = !sWorld->IsPvPRealm() || sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_ACCOUNTS) || GetSecurity() > SEC_PLAYER;
bool allowTwoSideAccounts = !sWorld->IsPvPRealm() || sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_ACCOUNTS) || !AccountMgr::IsPlayerAccount(GetSecurity());
uint32 skipCinematics = sWorld->getIntConfig(CONFIG_SKIP_CINEMATICS);
_charCreateCallback.FreeResult();
@@ -516,7 +517,7 @@ void WorldSession::HandleCharCreateCallback(PreparedQueryResult result, Characte
bool haveSameRace = false;
uint32 heroicReqLevel = sWorld->getIntConfig(CONFIG_CHARACTER_CREATING_MIN_LEVEL_FOR_HEROIC_CHARACTER);
bool hasHeroicReqLevel = (heroicReqLevel == 0);
bool allowTwoSideAccounts = !sWorld->IsPvPRealm() || sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_ACCOUNTS) || GetSecurity() > SEC_PLAYER;
bool allowTwoSideAccounts = !sWorld->IsPvPRealm() || sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_ACCOUNTS) || !AccountMgr::IsPlayerAccount(GetSecurity());
uint32 skipCinematics = sWorld->getIntConfig(CONFIG_SKIP_CINEMATICS);
if (result)
@@ -527,7 +528,7 @@ void WorldSession::HandleCharCreateCallback(PreparedQueryResult result, Characte
Field* field = result->Fetch();
uint8 accRace = field[1].GetUInt8();
if (GetSecurity() == SEC_PLAYER && createInfo->Class == CLASS_DEATH_KNIGHT)
if (AccountMgr::IsPlayerAccount(GetSecurity()) && createInfo->Class == CLASS_DEATH_KNIGHT)
{
uint8 accClass = field[2].GetUInt8();
if (accClass == CLASS_DEATH_KNIGHT)
@@ -588,7 +589,7 @@ void WorldSession::HandleCharCreateCallback(PreparedQueryResult result, Characte
if (!haveSameRace)
haveSameRace = createInfo->Race == accRace;
if (GetSecurity() == SEC_PLAYER && createInfo->Class == CLASS_DEATH_KNIGHT)
if (AccountMgr::IsPlayerAccount(GetSecurity()) && createInfo->Class == CLASS_DEATH_KNIGHT)
{
uint8 acc_class = field[2].GetUInt8();
if (acc_class == CLASS_DEATH_KNIGHT)
@@ -618,7 +619,7 @@ void WorldSession::HandleCharCreateCallback(PreparedQueryResult result, Characte
}
}
if (GetSecurity() == SEC_PLAYER && createInfo->Class == CLASS_DEATH_KNIGHT && !hasHeroicReqLevel)
if (AccountMgr::IsPlayerAccount(GetSecurity()) && createInfo->Class == CLASS_DEATH_KNIGHT && !hasHeroicReqLevel)
{
WorldPacket data(SMSG_CHAR_CREATE, 1);
data << uint8(CHAR_CREATE_LEVEL_REQUIREMENT);
@@ -1121,7 +1122,7 @@ void WorldSession::HandleCharRenameOpcode(WorldPacket& recv_data)
}
// check name limitations
if (GetSecurity() == SEC_PLAYER && sObjectMgr->IsReservedName(newname))
if (AccountMgr::IsPlayerAccount(GetSecurity()) && sObjectMgr->IsReservedName(newname))
{
WorldPacket data(SMSG_CHAR_RENAME, 1);
data << uint8(CHAR_NAME_RESERVED);
@@ -1383,7 +1384,7 @@ void WorldSession::HandleCharCustomize(WorldPacket& recv_data)
}
// check name limitations
if (GetSecurity() == SEC_PLAYER && sObjectMgr->IsReservedName(newname))
if (AccountMgr::IsPlayerAccount(GetSecurity()) && sObjectMgr->IsReservedName(newname))
{
WorldPacket data(SMSG_CHAR_CUSTOMIZE, 1);
data << uint8(CHAR_NAME_RESERVED);
@@ -1574,7 +1575,7 @@ void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recv_data)
return;
}
if (GetSecurity() == SEC_PLAYER)
if (AccountMgr::IsPlayerAccount(GetSecurity()))
{
uint32 raceMaskDisabled = sWorld->getIntConfig(CONFIG_CHARACTER_CREATING_DISABLED_RACEMASK);
if ((1 << (race - 1)) & raceMaskDisabled)
@@ -1605,7 +1606,7 @@ void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recv_data)
}
// check name limitations
if (GetSecurity() == SEC_PLAYER && sObjectMgr->IsReservedName(newname))
if (AccountMgr::IsPlayerAccount(GetSecurity()) && sObjectMgr->IsReservedName(newname))
{
WorldPacket data(SMSG_CHAR_FACTION_CHANGE, 1);
data << uint8(CHAR_NAME_RESERVED);
@@ -39,6 +39,7 @@
#include "SpellAuraEffects.h"
#include "Util.h"
#include "ScriptMgr.h"
#include "AccountMgr.h"
bool WorldSession::processChatmessageFurtherAfterSecurityChecks(std::string& msg, uint32 lang)
{
@@ -48,7 +49,7 @@ bool WorldSession::processChatmessageFurtherAfterSecurityChecks(std::string& msg
if (sWorld->getBoolConfig(CONFIG_CHAT_FAKE_MESSAGE_PREVENTING))
stripLineInvisibleChars(msg);
if (sWorld->getIntConfig(CONFIG_CHAT_STRICT_LINK_CHECKING_SEVERITY) && GetSecurity() < SEC_MODERATOR
if (sWorld->getIntConfig(CONFIG_CHAT_STRICT_LINK_CHECKING_SEVERITY) && AccountMgr::IsPlayerAccount(GetSecurity())
&& !ChatHandler(this).isValidChatMessage(msg.c_str()))
{
sLog->outError("Player %s (GUID: %u) sent a chatmessage with an invalid link: %s", GetPlayer()->GetName(),
@@ -269,24 +270,20 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket & recv_data)
}
Player* receiver = sObjectAccessor->FindPlayerByName(to.c_str());
uint32 senderSecurity = GetSecurity();
uint32 receiverSecurity = receiver ? receiver->GetSession()->GetSecurity() : SEC_PLAYER;
if (!receiver || (senderSecurity == SEC_PLAYER && receiverSecurity > SEC_PLAYER && !receiver->isAcceptWhispers() && !receiver->IsInWhisperWhiteList(sender->GetGUID())))
bool senderIsPlayer = AccountMgr::IsPlayerAccount(GetSecurity());
bool receiverIsPlayer = AccountMgr::IsPlayerAccount(receiver ? receiver->GetSession()->GetSecurity() : SEC_PLAYER);
if (!receiver || (senderIsPlayer && !receiverIsPlayer && !receiver->isAcceptWhispers() && !receiver->IsInWhisperWhiteList(sender->GetGUID())))
{
SendPlayerNotFoundNotice(to);
return;
}
if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHAT) && senderSecurity == SEC_PLAYER && receiverSecurity == SEC_PLAYER)
{
uint32 senderFaction = GetPlayer()->GetTeam();
uint32 receiverFaction = receiver->GetTeam();
if (senderFaction != receiverFaction)
if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHAT) && senderIsPlayer && receiverIsPlayer)
if (GetPlayer()->GetTeam() != receiver->GetTeam())
{
SendWrongFactionNotice();
return;
}
}
if (GetPlayer()->HasAura(1852) && !receiver->isGameMaster())
{
@@ -295,7 +292,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket & recv_data)
}
// If player is a Gamemaster and doesn't accept whisper, we auto-whitelist every player that the Gamemaster is talking to
if (senderSecurity > SEC_PLAYER && !sender->isAcceptWhispers() && !sender->IsInWhisperWhiteList(receiver->GetGUID()))
if (!senderIsPlayer && !sender->isAcceptWhispers() && !sender->IsInWhisperWhiteList(receiver->GetGUID()))
sender->AddWhisperWhiteList(receiver->GetGUID());
GetPlayer()->Whisper(msg, lang, receiver->GetGUID());
@@ -420,10 +417,13 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket & recv_data)
} break;
case CHAT_MSG_CHANNEL:
{
if (_player->getLevel() < sWorld->getIntConfig(CONFIG_CHAT_CHANNEL_LEVEL_REQ))
if (AccountMgr::IsPlayerAccount(GetSecurity()))
{
SendNotification(GetTrinityString(LANG_CHANNEL_REQ), sWorld->getIntConfig(CONFIG_CHAT_CHANNEL_LEVEL_REQ));
return;
if (_player->getLevel() < sWorld->getIntConfig(CONFIG_CHAT_CHANNEL_LEVEL_REQ))
{
SendNotification(GetTrinityString(LANG_CHANNEL_REQ), sWorld->getIntConfig(CONFIG_CHAT_CHANNEL_LEVEL_REQ));
return;
}
}
if (ChannelMgr* cMgr = channelMgr(_player->GetTeam()))
@@ -27,6 +27,7 @@
#include "Language.h"
#include "DBCStores.h"
#include "Item.h"
#include "AccountMgr.h"
void WorldSession::HandleSendMail(WorldPacket & recv_data)
{
@@ -160,7 +161,7 @@ void WorldSession::HandleSendMail(WorldPacket & recv_data)
}
}
if (!accountBound && !sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_MAIL) && pl->GetTeam() != rc_team && GetSecurity() == SEC_PLAYER)
if (!accountBound && !sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_MAIL) && pl->GetTeam() != rc_team && AccountMgr::IsPlayerAccount(GetSecurity()))
{
pl->SendMailResult(0, MAIL_SEND, MAIL_ERR_NOT_YOUR_TEAM);
return;
@@ -246,7 +247,7 @@ void WorldSession::HandleSendMail(WorldPacket & recv_data)
for (uint8 i = 0; i < items_count; ++i)
{
Item* item = items[i];
if (GetSecurity() > SEC_PLAYER && sWorld->getBoolConfig(CONFIG_GM_LOG_TRADE))
if (!AccountMgr::IsPlayerAccount(GetSecurity()) && sWorld->getBoolConfig(CONFIG_GM_LOG_TRADE))
{
sLog->outCommand(GetAccountId(), "GM %s (Account: %u) mail item: %s (Entry: %u Count: %u) to player: %s (Account: %u)",
GetPlayerName(), GetAccountId(), item->GetTemplate()->Name1.c_str(), item->GetEntry(), item->GetCount(), receiver.c_str(), rc_account);
@@ -266,7 +267,7 @@ void WorldSession::HandleSendMail(WorldPacket & recv_data)
needItemDelay = pl->GetSession()->GetAccountId() != rc_account;
}
if (money > 0 && GetSecurity() > SEC_PLAYER && sWorld->getBoolConfig(CONFIG_GM_LOG_TRADE))
if (money > 0 && !AccountMgr::IsPlayerAccount(GetSecurity()) && sWorld->getBoolConfig(CONFIG_GM_LOG_TRADE))
{
sLog->outCommand(GetAccountId(), "GM %s (Account: %u) mail money: %u to player: %s (Account: %u)",
GetPlayerName(), GetAccountId(), money, receiver.c_str(), rc_account);
@@ -440,7 +441,7 @@ void WorldSession::HandleMailTakeItem(WorldPacket & recv_data)
uint32 sender_accId = 0;
if (GetSecurity() > SEC_PLAYER && sWorld->getBoolConfig(CONFIG_GM_LOG_TRADE))
if (!AccountMgr::IsPlayerAccount(GetSecurity()) && sWorld->getBoolConfig(CONFIG_GM_LOG_TRADE))
{
std::string sender_name;
if (receive)
@@ -50,6 +50,7 @@
#include "InstanceScript.h"
#include "GameObjectAI.h"
#include "Group.h"
#include "AccountMgr.h"
void WorldSession::HandleRepopRequestOpcode(WorldPacket & recv_data)
{
@@ -242,7 +243,7 @@ void WorldSession::HandleWhoOpcode(WorldPacket & recv_data)
HashMapHolder<Player>::MapType& m = sObjectAccessor->GetPlayers();
for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
{
if (security == SEC_PLAYER)
if (AccountMgr::IsPlayerAccount(security))
{
// player can see member of other team only if CONFIG_ALLOW_TWO_SIDE_WHO_LIST
if (itr->second->GetTeam() != team && !allowTwoSideWhoList)
@@ -560,13 +561,13 @@ void WorldSession::HandleAddFriendOpcodeCallBack(QueryResult result, std::string
team = Player::TeamForRace((*result)[1].GetUInt8());
friendAcctid = (*result)[2].GetUInt32();
if (GetSecurity() >= SEC_MODERATOR || sWorld->getBoolConfig(CONFIG_ALLOW_GM_FRIEND) || AccountMgr::GetSecurity(friendAcctid, realmID) < SEC_MODERATOR)
if (!AccountMgr::IsPlayerAccount(GetSecurity()) || sWorld->getBoolConfig(CONFIG_ALLOW_GM_FRIEND) || AccountMgr::IsPlayerAccount(AccountMgr::GetSecurity(friendAcctid, realmID)))
{
if (friendGuid)
{
if (friendGuid == GetPlayer()->GetGUID())
friendResult = FRIEND_SELF;
else if (GetPlayer()->GetTeam() != team && !sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_ADD_FRIEND) && GetSecurity() < SEC_MODERATOR)
else if (GetPlayer()->GetTeam() != team && !sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_ADD_FRIEND) && AccountMgr::IsPlayerAccount(GetSecurity()))
friendResult = FRIEND_ENEMY;
else if (GetPlayer()->GetSocial()->HasFriend(GUID_LOPART(friendGuid)))
friendResult = FRIEND_ALREADY;
@@ -1274,7 +1275,7 @@ void WorldSession::HandleWorldTeleportOpcode(WorldPacket& recv_data)
sLog->outStaticDebug("Time %u sec, map=%u, x=%f, y=%f, z=%f, orient=%f", time/1000, mapid, PositionX, PositionY, PositionZ, Orientation);
if (GetSecurity() >= SEC_ADMINISTRATOR)
if (AccountMgr::IsAdminAccount(GetSecurity()))
GetPlayer()->TeleportTo(mapid, PositionX, PositionY, PositionZ, Orientation);
else
SendNotification(LANG_YOU_NOT_HAVE_PERMISSION);
@@ -1287,7 +1288,7 @@ void WorldSession::HandleWhoisOpcode(WorldPacket& recv_data)
std::string charname;
recv_data >> charname;
if (GetSecurity() < SEC_ADMINISTRATOR)
if (!AccountMgr::IsAdminAccount(GetSecurity()))
{
SendNotification(LANG_YOU_NOT_HAVE_PERMISSION);
return;
@@ -28,6 +28,7 @@
#include "Spell.h"
#include "SocialMgr.h"
#include "Language.h"
#include "AccountMgr.h"
void WorldSession::SendTradeStatus(TradeStatus status)
{
@@ -151,7 +152,7 @@ void WorldSession::moveItems(Item* myItems[], Item* hisItems[])
{
// logging
sLog->outDebug(LOG_FILTER_NETWORKIO, "partner storing: %u", myItems[i]->GetGUIDLow());
if (_player->GetSession()->GetSecurity() > SEC_PLAYER && sWorld->getBoolConfig(CONFIG_GM_LOG_TRADE))
if (!AccountMgr::IsPlayerAccount(_player->GetSession()->GetSecurity()) && sWorld->getBoolConfig(CONFIG_GM_LOG_TRADE))
{
sLog->outCommand(_player->GetSession()->GetAccountId(), "GM %s (Account: %u) trade: %s (Entry: %d Count: %u) to player: %s (Account: %u)",
_player->GetName(), _player->GetSession()->GetAccountId(),
@@ -169,7 +170,7 @@ void WorldSession::moveItems(Item* myItems[], Item* hisItems[])
{
// logging
sLog->outDebug(LOG_FILTER_NETWORKIO, "player storing: %u", hisItems[i]->GetGUIDLow());
if (trader->GetSession()->GetSecurity() > SEC_PLAYER && sWorld->getBoolConfig(CONFIG_GM_LOG_TRADE))
if (!AccountMgr::IsPlayerAccount(trader->GetSession()->GetSecurity()) && sWorld->getBoolConfig(CONFIG_GM_LOG_TRADE))
{
sLog->outCommand(trader->GetSession()->GetAccountId(), "GM %s (Account: %u) trade: %s (Entry: %d Count: %u) to player: %s (Account: %u)",
trader->GetName(), trader->GetSession()->GetAccountId(),
@@ -459,14 +460,14 @@ void WorldSession::HandleAcceptTradeOpcode(WorldPacket& /*recvPacket*/)
// logging money
if (sWorld->getBoolConfig(CONFIG_GM_LOG_TRADE))
{
if (_player->GetSession()->GetSecurity() > SEC_PLAYER && my_trade->GetMoney() > 0)
if (!AccountMgr::IsPlayerAccount(_player->GetSession()->GetSecurity()) && my_trade->GetMoney() > 0)
{
sLog->outCommand(_player->GetSession()->GetAccountId(), "GM %s (Account: %u) give money (Amount: %u) to player: %s (Account: %u)",
_player->GetName(), _player->GetSession()->GetAccountId(),
my_trade->GetMoney(),
trader->GetName(), trader->GetSession()->GetAccountId());
}
if (trader->GetSession()->GetSecurity() > SEC_PLAYER && his_trade->GetMoney() > 0)
if (!AccountMgr::IsPlayerAccount(trader->GetSession()->GetSecurity()) && his_trade->GetMoney() > 0)
{
sLog->outCommand(trader->GetSession()->GetAccountId(), "GM %s (Account: %u) give money (Amount: %u) to player: %s (Account: %u)",
trader->GetName(), trader->GetSession()->GetAccountId(),
+3 -2
View File
@@ -44,6 +44,7 @@
#include "Log.h"
#include "WorldLog.h"
#include "ScriptMgr.h"
#include "AccountMgr.h"
#if defined(__GNUC__)
#pragma pack(1)
@@ -935,7 +936,7 @@ int WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
// Check locked state for server
AccountTypes allowedAccountType = sWorld->GetPlayerSecurityLimit();
sLog->outDebug(LOG_FILTER_NETWORKIO, "Allowed Level: %u Player Level %u", allowedAccountType, AccountTypes(security));
if (allowedAccountType > SEC_PLAYER && AccountTypes(security) < allowedAccountType)
if (AccountTypes(security) < allowedAccountType)
{
WorldPacket Packet (SMSG_AUTH_RESPONSE, 1);
Packet << uint8 (AUTH_UNAVAILABLE);
@@ -1039,7 +1040,7 @@ int WorldSocket::HandlePing (WorldPacket& recvPacket)
{
ACE_GUARD_RETURN (LockType, Guard, m_SessionLock, -1);
if (m_Session && m_Session->GetSecurity() == SEC_PLAYER)
if (m_Session && AccountMgr::IsPlayerAccount(m_Session->GetSecurity()))
{
Player* _player = m_Session->GetPlayer();
sLog->outError("WorldSocket::HandlePing: Player (account: %u, GUID: %u, name: %s) kicked for over-speed pings (address: %s)",