Last fixes on chat + database incorrect charset

This commit is contained in:
Atidot3
2024-08-01 18:58:41 +02:00
parent 142f2ad212
commit ab4e3c2c45
6 changed files with 58 additions and 39 deletions

View File

@@ -19,6 +19,7 @@
#include "SharedDefines.h"
#include "WorldSession.h"
#include "ChannelMgr.h"
#include "BroadcastHelper.h"
#include <cstdio>
#include <cstring>
#include <istream>
@@ -523,37 +524,54 @@ void PlayerbotHolder::OnBotLogin(Player* const bot)
pkt << ""; // Pass
bot->GetSession()->HandleJoinChannel(pkt);
}
// join standard channels
AreaTableEntry const* current_zone = sAreaTableStore.LookupEntry(bot->GetAreaId());
uint8 locale = BroadcastHelper::GetLocale();
AreaTableEntry const* current_zone = GET_PLAYERBOT_AI(bot)->GetCurrentZone();
ChannelMgr* cMgr = ChannelMgr::forTeam(bot->GetTeamId());
std::string current_zone_name = current_zone ? GET_PLAYERBOT_AI(bot)->GetLocalizedAreaName(current_zone) : "";
if (current_zone && cMgr)
{
const auto current_str_zone = botAI->GetLocalizedAreaName(current_zone);
for (uint32 i = 0; i < sChatChannelsStore.GetNumRows(); ++i)
{
ChatChannelsEntry const* channel = sChatChannelsStore.LookupEntry(i);
if (!channel) continue;
bool isLfg = (channel->flags & CHANNEL_DBC_FLAG_LFG) != 0;
// skip non built-in channels or global channel without zone name in pattern
if (!isLfg && (!channel || (channel->flags & 4) == 4))
continue;
// new channel
Channel* new_channel = nullptr;
if (isLfg)
switch (channel->ChannelID)
{
std::string lfgChannelName = channel->pattern[sWorld->GetDefaultDbcLocale()];
new_channel = cMgr->GetJoinChannel("LookingForGroup", channel->ChannelID);
}
else
{
char new_channel_name_buf[100];
snprintf(new_channel_name_buf, 100, channel->pattern[sWorld->GetDefaultDbcLocale()], current_str_zone.c_str());
new_channel = cMgr->GetJoinChannel(new_channel_name_buf, channel->ChannelID);
case ChatChannelId::GENERAL:
case ChatChannelId::LOCAL_DEFENSE:
{
char new_channel_name_buf[100];
snprintf(new_channel_name_buf, 100, channel->pattern[locale], current_zone_name.c_str());
new_channel = cMgr->GetJoinChannel(new_channel_name_buf, channel->ChannelID);
break;
}
case ChatChannelId::TRADE:
case ChatChannelId::GUILD_RECRUITMENT:
{
char new_channel_name_buf[100];
//3459 is ID for a zone named "City" (only exists for the sake of using its name)
//Currently in magons TBC, if you switch zones, then you join "Trade - <zone>" and "GuildRecruitment - <zone>"
//which is a core bug, should be "Trade - City" and "GuildRecruitment - City" in both 1.12 and TBC
//but if you (actual player) logout in a city and log back in - you join "City" versions
snprintf(new_channel_name_buf, 100, channel->pattern[locale], GET_PLAYERBOT_AI(bot)->GetLocalizedAreaName(GetAreaEntryByAreaID(3459)).c_str());
new_channel = cMgr->GetJoinChannel(new_channel_name_buf, channel->ChannelID);
break;
}
case ChatChannelId::LOOKING_FOR_GROUP:
case ChatChannelId::WORLD_DEFENSE:
{
new_channel = cMgr->GetJoinChannel(channel->pattern[locale], channel->ChannelID);
break;
}
default:
break;
}
if (new_channel)
new_channel->JoinChannel(bot, "");
}
}
}