mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-22 05:06:24 +00:00
importing changes from callmephil repo
a special thanks to him
This commit is contained in:
@@ -594,7 +594,8 @@ void Channel::SetMode(Player const* player, std::string const& p2n, bool mod, bo
|
||||
if (!victim || !IsOn(victim) ||
|
||||
// allow make moderator from another team only if both is GMs
|
||||
// at this moment this only way to show channel post for GM from another team
|
||||
((!AccountMgr::IsGMAccount(sec) || !AccountMgr::IsGMAccount(newp->GetSession()->GetSecurity())) && player->GetTeamId() != newp->GetTeamId()))
|
||||
((!AccountMgr::IsGMAccount(sec) || !AccountMgr::IsGMAccount(newp->GetSession()->GetSecurity())) && player->GetTeamId() != newp->GetTeamId() &&
|
||||
!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHANNEL)))
|
||||
{
|
||||
WorldPacket data;
|
||||
MakePlayerNotFound(&data, p2n);
|
||||
@@ -659,7 +660,8 @@ void Channel::SetOwner(Player const* player, std::string const& newname)
|
||||
Player* newp = ObjectAccessor::FindPlayerByName(newname, false);
|
||||
uint64 victim = newp ? newp->GetGUID() : 0;
|
||||
|
||||
if (!victim || !IsOn(victim) || newp->GetTeamId() != player->GetTeamId())
|
||||
if (!victim || !IsOn(victim) || newp->GetTeamId() != player->GetTeamId() &&
|
||||
!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHANNEL))
|
||||
{
|
||||
WorldPacket data;
|
||||
MakePlayerNotFound(&data, newname);
|
||||
@@ -764,6 +766,9 @@ void Channel::Say(uint64 guid, std::string const& what, uint32 lang)
|
||||
if (what.empty())
|
||||
return;
|
||||
|
||||
if (sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHANNEL))
|
||||
lang = LANG_UNIVERSAL;
|
||||
|
||||
if (!IsOn(guid))
|
||||
{
|
||||
WorldPacket data;
|
||||
|
||||
@@ -1,201 +1,205 @@
|
||||
/*
|
||||
* Copyright (C)
|
||||
* 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 "ChannelMgr.h"
|
||||
#include "Player.h"
|
||||
#include "World.h"
|
||||
|
||||
ChannelMgr::~ChannelMgr()
|
||||
{
|
||||
for (ChannelMap::iterator itr = channels.begin(); itr != channels.end(); ++itr)
|
||||
delete itr->second;
|
||||
|
||||
channels.clear();
|
||||
}
|
||||
|
||||
ChannelMgr* ChannelMgr::forTeam(TeamId teamId)
|
||||
{
|
||||
if (teamId == TEAM_ALLIANCE)
|
||||
return ACE_Singleton<AllianceChannelMgr, ACE_Null_Mutex>::instance();
|
||||
|
||||
if (teamId == TEAM_HORDE)
|
||||
return ACE_Singleton<HordeChannelMgr, ACE_Null_Mutex>::instance();
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void ChannelMgr::LoadChannels()
|
||||
{
|
||||
uint32 oldMSTime = getMSTime();
|
||||
uint32 count = 0;
|
||||
|
||||
QueryResult result = CharacterDatabase.PQuery("SELECT channelId, name, team, announce, password FROM channels WHERE team = %u ORDER BY channelId ASC", _teamId);
|
||||
if (!result)
|
||||
{
|
||||
sLog->outString(">> Loaded 0 channels for %s", _teamId == TEAM_ALLIANCE ? "Alliance" : "Horde");
|
||||
sLog->outString();
|
||||
return;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
if (!fields)
|
||||
break;
|
||||
|
||||
uint32 channelDBId = fields[0].GetUInt32();
|
||||
std::string channelName = fields[1].GetString();
|
||||
std::string password = fields[4].GetString();
|
||||
std::wstring channelWName;
|
||||
Utf8toWStr(channelName, channelWName);
|
||||
|
||||
Channel* newChannel = new Channel(channelName, 0, channelDBId, TeamId(fields[2].GetUInt32()), fields[3].GetUInt8());
|
||||
newChannel->SetPassword(password);
|
||||
channels[channelWName] = newChannel;
|
||||
|
||||
if (QueryResult banResult = CharacterDatabase.PQuery("SELECT playerGUID, banTime FROM channels_bans WHERE channelId = %u", channelDBId))
|
||||
{
|
||||
do
|
||||
{
|
||||
Field* banFields = banResult->Fetch();
|
||||
if (!banFields)
|
||||
break;
|
||||
newChannel->AddBan(banFields[0].GetUInt32(), banFields[1].GetUInt32());
|
||||
}
|
||||
while (banResult->NextRow());
|
||||
}
|
||||
|
||||
if (channelDBId > ChannelMgr::_channelIdMax)
|
||||
ChannelMgr::_channelIdMax = channelDBId;
|
||||
++count;
|
||||
}
|
||||
while (result->NextRow());
|
||||
|
||||
sLog->outString(">> Loaded %u channels for %s in %ums", count, _teamId == TEAM_ALLIANCE ? "Alliance" : "Horde", GetMSTimeDiffToNow(oldMSTime));
|
||||
sLog->outString();
|
||||
}
|
||||
|
||||
Channel* ChannelMgr::GetJoinChannel(std::string const& name, uint32 channelId)
|
||||
{
|
||||
std::wstring wname;
|
||||
Utf8toWStr(name, wname);
|
||||
wstrToLower(wname);
|
||||
|
||||
ChannelMap::const_iterator i = channels.find(wname);
|
||||
|
||||
if (i == channels.end())
|
||||
{
|
||||
std::string chNameLower = name;
|
||||
std::transform(chNameLower.begin(), chNameLower.end(), chNameLower.begin(), ::tolower);
|
||||
Channel* nchan = new Channel(chNameLower, channelId, 0, _teamId);
|
||||
channels[wname] = nchan;
|
||||
return nchan;
|
||||
}
|
||||
|
||||
return i->second;
|
||||
}
|
||||
|
||||
Channel* ChannelMgr::GetChannel(std::string const& name, Player* player, bool pkt)
|
||||
{
|
||||
std::wstring wname;
|
||||
Utf8toWStr(name, wname);
|
||||
wstrToLower(wname);
|
||||
|
||||
ChannelMap::const_iterator i = channels.find(wname);
|
||||
|
||||
if (i == channels.end())
|
||||
{
|
||||
if (pkt)
|
||||
{
|
||||
WorldPacket data;
|
||||
MakeNotOnPacket(&data, name);
|
||||
player->GetSession()->SendPacket(&data);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return i->second;
|
||||
}
|
||||
|
||||
|
||||
uint32 ChannelMgr::_channelIdMax = 0;
|
||||
ChannelMgr::ChannelRightsMap ChannelMgr::channels_rights;
|
||||
ChannelRights ChannelMgr::channelRightsEmpty;
|
||||
|
||||
void ChannelMgr::LoadChannelRights()
|
||||
{
|
||||
uint32 oldMSTime = getMSTime();
|
||||
channels_rights.clear();
|
||||
|
||||
QueryResult result = CharacterDatabase.Query("SELECT name, flags, speakdelay, joinmessage, delaymessage, moderators FROM channels_rights");
|
||||
if (!result)
|
||||
{
|
||||
sLog->outString();
|
||||
sLog->outString(">> Loaded 0 Channel Rights!");
|
||||
return;
|
||||
}
|
||||
|
||||
uint32 count = 0;
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
std::set<uint32> moderators;
|
||||
const char* moderatorList = fields[5].GetCString();
|
||||
if (moderatorList)
|
||||
{
|
||||
Tokenizer tokens(moderatorList, ' ');
|
||||
for (Tokenizer::const_iterator i = tokens.begin(); i != tokens.end(); ++i)
|
||||
{
|
||||
uint64 moderator_acc = atol(*i);
|
||||
if (moderator_acc && ((uint32)moderator_acc) == moderator_acc)
|
||||
moderators.insert((uint32)moderator_acc);
|
||||
}
|
||||
}
|
||||
|
||||
SetChannelRightsFor(fields[0].GetString(), fields[1].GetUInt32(), fields[2].GetUInt32(), fields[3].GetString(), fields[4].GetString(), moderators);
|
||||
|
||||
++count;
|
||||
} while (result->NextRow());
|
||||
|
||||
sLog->outString(">> Loaded %d Channel Rights in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
|
||||
sLog->outString();
|
||||
}
|
||||
|
||||
const ChannelRights& ChannelMgr::GetChannelRightsFor(const std::string& name)
|
||||
{
|
||||
std::string nameStr = name;
|
||||
std::transform(nameStr.begin(), nameStr.end(), nameStr.begin(), ::tolower);
|
||||
ChannelRightsMap::const_iterator itr = channels_rights.find(nameStr);
|
||||
if (itr != channels_rights.end())
|
||||
return itr->second;
|
||||
return channelRightsEmpty;
|
||||
}
|
||||
|
||||
void ChannelMgr::SetChannelRightsFor(const std::string& name, const uint32& flags, const uint32& speakDelay, const std::string& joinmessage, const std::string& speakmessage, const std::set<uint32>& moderators)
|
||||
{
|
||||
std::string nameStr = name;
|
||||
std::transform(nameStr.begin(), nameStr.end(), nameStr.begin(), ::tolower);
|
||||
channels_rights[nameStr] = ChannelRights(flags, speakDelay, joinmessage, speakmessage, moderators);
|
||||
}
|
||||
|
||||
void ChannelMgr::MakeNotOnPacket(WorldPacket* data, std::string const& name)
|
||||
{
|
||||
data->Initialize(SMSG_CHANNEL_NOTIFY, 1 + name.size());
|
||||
(*data) << uint8(5) << name;
|
||||
/*
|
||||
* Copyright (C)
|
||||
* 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 "ChannelMgr.h"
|
||||
#include "Player.h"
|
||||
#include "World.h"
|
||||
|
||||
ChannelMgr::~ChannelMgr()
|
||||
{
|
||||
for (ChannelMap::iterator itr = channels.begin(); itr != channels.end(); ++itr)
|
||||
delete itr->second;
|
||||
|
||||
channels.clear();
|
||||
}
|
||||
|
||||
ChannelMgr* ChannelMgr::forTeam(TeamId teamId)
|
||||
{
|
||||
if (sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHANNEL))
|
||||
return ACE_Singleton<AllianceChannelMgr, ACE_Null_Mutex>::instance(); // cross-faction
|
||||
|
||||
if (teamId == TEAM_ALLIANCE)
|
||||
return ACE_Singleton<AllianceChannelMgr, ACE_Null_Mutex>::instance();
|
||||
|
||||
if (teamId == TEAM_HORDE)
|
||||
return ACE_Singleton<HordeChannelMgr, ACE_Null_Mutex>::instance();
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void ChannelMgr::LoadChannels()
|
||||
{
|
||||
uint32 oldMSTime = getMSTime();
|
||||
uint32 count = 0;
|
||||
|
||||
QueryResult result = CharacterDatabase.PQuery("SELECT channelId, name, team, announce, password FROM channels WHERE team = %u ORDER BY channelId ASC", _teamId);
|
||||
if (!result)
|
||||
{
|
||||
sLog->outString(">> Loaded 0 channels for %s", _teamId == TEAM_ALLIANCE ? "Alliance" : "Horde");
|
||||
sLog->outString();
|
||||
return;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
if (!fields)
|
||||
break;
|
||||
|
||||
uint32 channelDBId = fields[0].GetUInt32();
|
||||
std::string channelName = fields[1].GetString();
|
||||
std::string password = fields[4].GetString();
|
||||
std::wstring channelWName;
|
||||
Utf8toWStr(channelName, channelWName);
|
||||
|
||||
Channel* newChannel = new Channel(channelName, 0, channelDBId, TeamId(fields[2].GetUInt32()), fields[3].GetUInt8());
|
||||
newChannel->SetPassword(password);
|
||||
channels[channelWName] = newChannel;
|
||||
|
||||
if (QueryResult banResult = CharacterDatabase.PQuery("SELECT playerGUID, banTime FROM channels_bans WHERE channelId = %u", channelDBId))
|
||||
{
|
||||
do
|
||||
{
|
||||
Field* banFields = banResult->Fetch();
|
||||
if (!banFields)
|
||||
break;
|
||||
newChannel->AddBan(banFields[0].GetUInt32(), banFields[1].GetUInt32());
|
||||
}
|
||||
while (banResult->NextRow());
|
||||
}
|
||||
|
||||
if (channelDBId > ChannelMgr::_channelIdMax)
|
||||
ChannelMgr::_channelIdMax = channelDBId;
|
||||
++count;
|
||||
}
|
||||
while (result->NextRow());
|
||||
|
||||
sLog->outString(">> Loaded %u channels for %s in %ums", count, _teamId == TEAM_ALLIANCE ? "Alliance" : "Horde", GetMSTimeDiffToNow(oldMSTime));
|
||||
sLog->outString();
|
||||
}
|
||||
|
||||
Channel* ChannelMgr::GetJoinChannel(std::string const& name, uint32 channelId)
|
||||
{
|
||||
std::wstring wname;
|
||||
Utf8toWStr(name, wname);
|
||||
wstrToLower(wname);
|
||||
|
||||
ChannelMap::const_iterator i = channels.find(wname);
|
||||
|
||||
if (i == channels.end())
|
||||
{
|
||||
std::string chNameLower = name;
|
||||
std::transform(chNameLower.begin(), chNameLower.end(), chNameLower.begin(), ::tolower);
|
||||
Channel* nchan = new Channel(chNameLower, channelId, 0, _teamId);
|
||||
channels[wname] = nchan;
|
||||
return nchan;
|
||||
}
|
||||
|
||||
return i->second;
|
||||
}
|
||||
|
||||
Channel* ChannelMgr::GetChannel(std::string const& name, Player* player, bool pkt)
|
||||
{
|
||||
std::wstring wname;
|
||||
Utf8toWStr(name, wname);
|
||||
wstrToLower(wname);
|
||||
|
||||
ChannelMap::const_iterator i = channels.find(wname);
|
||||
|
||||
if (i == channels.end())
|
||||
{
|
||||
if (pkt)
|
||||
{
|
||||
WorldPacket data;
|
||||
MakeNotOnPacket(&data, name);
|
||||
player->GetSession()->SendPacket(&data);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return i->second;
|
||||
}
|
||||
|
||||
|
||||
uint32 ChannelMgr::_channelIdMax = 0;
|
||||
ChannelMgr::ChannelRightsMap ChannelMgr::channels_rights;
|
||||
ChannelRights ChannelMgr::channelRightsEmpty;
|
||||
|
||||
void ChannelMgr::LoadChannelRights()
|
||||
{
|
||||
uint32 oldMSTime = getMSTime();
|
||||
channels_rights.clear();
|
||||
|
||||
QueryResult result = CharacterDatabase.Query("SELECT name, flags, speakdelay, joinmessage, delaymessage, moderators FROM channels_rights");
|
||||
if (!result)
|
||||
{
|
||||
sLog->outString();
|
||||
sLog->outString(">> Loaded 0 Channel Rights!");
|
||||
return;
|
||||
}
|
||||
|
||||
uint32 count = 0;
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
std::set<uint32> moderators;
|
||||
const char* moderatorList = fields[5].GetCString();
|
||||
if (moderatorList)
|
||||
{
|
||||
Tokenizer tokens(moderatorList, ' ');
|
||||
for (Tokenizer::const_iterator i = tokens.begin(); i != tokens.end(); ++i)
|
||||
{
|
||||
uint64 moderator_acc = atol(*i);
|
||||
if (moderator_acc && ((uint32)moderator_acc) == moderator_acc)
|
||||
moderators.insert((uint32)moderator_acc);
|
||||
}
|
||||
}
|
||||
|
||||
SetChannelRightsFor(fields[0].GetString(), fields[1].GetUInt32(), fields[2].GetUInt32(), fields[3].GetString(), fields[4].GetString(), moderators);
|
||||
|
||||
++count;
|
||||
} while (result->NextRow());
|
||||
|
||||
sLog->outString(">> Loaded %d Channel Rights in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
|
||||
sLog->outString();
|
||||
}
|
||||
|
||||
const ChannelRights& ChannelMgr::GetChannelRightsFor(const std::string& name)
|
||||
{
|
||||
std::string nameStr = name;
|
||||
std::transform(nameStr.begin(), nameStr.end(), nameStr.begin(), ::tolower);
|
||||
ChannelRightsMap::const_iterator itr = channels_rights.find(nameStr);
|
||||
if (itr != channels_rights.end())
|
||||
return itr->second;
|
||||
return channelRightsEmpty;
|
||||
}
|
||||
|
||||
void ChannelMgr::SetChannelRightsFor(const std::string& name, const uint32& flags, const uint32& speakDelay, const std::string& joinmessage, const std::string& speakmessage, const std::set<uint32>& moderators)
|
||||
{
|
||||
std::string nameStr = name;
|
||||
std::transform(nameStr.begin(), nameStr.end(), nameStr.begin(), ::tolower);
|
||||
channels_rights[nameStr] = ChannelRights(flags, speakDelay, joinmessage, speakmessage, moderators);
|
||||
}
|
||||
|
||||
void ChannelMgr::MakeNotOnPacket(WorldPacket* data, std::string const& name)
|
||||
{
|
||||
data->Initialize(SMSG_CHANNEL_NOTIFY, 1 + name.size());
|
||||
(*data) << uint8(5) << name;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user