aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Entities
diff options
context:
space:
mode:
authorariel- <ariel-@users.noreply.github.com>2016-07-15 17:33:49 -0300
committerjackpoz <giacomopoz@gmail.com>2016-07-15 22:33:49 +0200
commitfbbb03212e93591a77a1169a30fb01867cd3c0e9 (patch)
treeb149e12bdead2d300215142e6e4bc1a8a33ec86e /src/server/game/Entities
parent11558b3bdc10ad429e8dbb9ab4489e39eb2d6fcc (diff)
Core/Chat: general cleanup and revamping: (#17576)
- Remove duplicate ObjectGuid in Channel (both as key and value member) - Add const-ness to Channel methods - NULL->nullptr - const type* -> type const* - Removed all instances of std::map::operator[] except where it is actually INTENDED to insert an element - Use Trinity::StringFormat instead of snprintf
Diffstat (limited to 'src/server/game/Entities')
-rw-r--r--src/server/game/Entities/Player/Player.cpp92
1 files changed, 44 insertions, 48 deletions
diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp
index 0345e679ac3..ad20ba07773 100644
--- a/src/server/game/Entities/Player/Player.cpp
+++ b/src/server/game/Entities/Player/Player.cpp
@@ -5176,71 +5176,67 @@ void Player::UpdateLocalChannels(uint32 newZone)
return;
std::string current_zone_name = current_zone->area_name[GetSession()->GetSessionDbcLocale()];
-
for (uint32 i = 0; i < sChatChannelsStore.GetNumRows(); ++i)
{
- if (ChatChannelsEntry const* channel = sChatChannelsStore.LookupEntry(i))
- {
- Channel* usedChannel = nullptr;
+ ChatChannelsEntry const* channelEntry = sChatChannelsStore.LookupEntry(i);
+ if (!channelEntry)
+ continue;
- for (JoinedChannelsList::iterator itr = m_channels.begin(); itr != m_channels.end(); ++itr)
+ Channel* usedChannel = nullptr;
+ for (Channel* channel : m_channels)
+ {
+ if (channel->GetChannelId() == i)
{
- if ((*itr)->GetChannelId() == i)
- {
- usedChannel = *itr;
- break;
- }
+ usedChannel = channel;
+ break;
}
+ }
- Channel* removeChannel = nullptr;
- Channel* joinChannel = nullptr;
- bool sendRemove = true;
+ Channel* removeChannel = nullptr;
+ Channel* joinChannel = nullptr;
+ bool sendRemove = true;
- if (CanJoinConstantChannelInZone(channel, current_zone))
+ if (CanJoinConstantChannelInZone(channelEntry, current_zone))
+ {
+ if (!(channelEntry->flags & CHANNEL_DBC_FLAG_GLOBAL))
{
- if (!(channel->flags & CHANNEL_DBC_FLAG_GLOBAL))
- {
- if (channel->flags & CHANNEL_DBC_FLAG_CITY_ONLY && usedChannel)
- continue; // Already on the channel, as city channel names are not changing
-
- char new_channel_name_buf[100];
- char const* currentNameExt;
-
- if (channel->flags & CHANNEL_DBC_FLAG_CITY_ONLY)
- currentNameExt = sObjectMgr->GetTrinityStringForDBCLocale(LANG_CHANNEL_CITY);
- else
- currentNameExt = current_zone_name.c_str();
+ if (channelEntry->flags & CHANNEL_DBC_FLAG_CITY_ONLY && usedChannel)
+ continue; // Already on the channel, as city channel names are not changing
- snprintf(new_channel_name_buf, 100, channel->pattern[m_session->GetSessionDbcLocale()], currentNameExt);
+ std::string currentNameExt;
+ if (channelEntry->flags & CHANNEL_DBC_FLAG_CITY_ONLY)
+ currentNameExt = sObjectMgr->GetTrinityStringForDBCLocale(LANG_CHANNEL_CITY);
+ else
+ currentNameExt = current_zone_name;
- joinChannel = cMgr->GetJoinChannel(new_channel_name_buf, channel->ChannelID);
- if (usedChannel)
+ std::string newChannelName = Trinity::StringFormat(channelEntry->pattern[m_session->GetSessionDbcLocale()], currentNameExt.c_str());
+ joinChannel = cMgr->GetJoinChannel(newChannelName, channelEntry->ChannelID);
+ if (usedChannel)
+ {
+ if (joinChannel != usedChannel)
{
- if (joinChannel != usedChannel)
- {
- removeChannel = usedChannel;
- sendRemove = false; // Do not send leave channel, it already replaced at client
- }
- else
- joinChannel = nullptr;
+ removeChannel = usedChannel;
+ sendRemove = false; // Do not send leave channel, it already replaced at client
}
+ else
+ joinChannel = nullptr;
}
- else
- joinChannel = cMgr->GetJoinChannel(channel->pattern[m_session->GetSessionDbcLocale()], channel->ChannelID);
}
else
- removeChannel = usedChannel;
+ joinChannel = cMgr->GetJoinChannel(channelEntry->pattern[m_session->GetSessionDbcLocale()], channelEntry->ChannelID);
+ }
+ else
+ removeChannel = usedChannel;
- if (joinChannel)
- joinChannel->JoinChannel(this, ""); // Changed Channel: ... or Joined Channel: ...
+ if (joinChannel)
+ joinChannel->JoinChannel(this, ""); // Changed Channel: ... or Joined Channel: ...
- if (removeChannel)
- {
- removeChannel->LeaveChannel(this, sendRemove); // Leave old channel
- std::string name = removeChannel->GetName(); // Store name, (*i)erase in LeftChannel
- LeftChannel(removeChannel); // Remove from player's channel list
- cMgr->LeftChannel(name); // Delete if empty
- }
+ if (removeChannel)
+ {
+ removeChannel->LeaveChannel(this, sendRemove); // Leave old channel
+ std::string name = removeChannel->GetName(); // Store name, (*i)erase in LeftChannel
+ LeftChannel(removeChannel); // Remove from player's channel list
+ cMgr->LeftChannel(name); // Delete if empty
}
}
}