Skip to content

Commit

Permalink
[c12795] Chat system refactoring All chat function now call same method
Browse files Browse the repository at this point in the history
I also reworked the packet structure to be more near of original.
Due to havy of code changed this commit need to be applyed carrefully.

Any feedback is welcome here or on cmangos.net

(based on commit [12587] - 1af082e)

Signed-off-by: Xfurry <xfurry@scriptdev2.com>
  • Loading branch information
Cyberium authored and xfurry committed Jan 21, 2014
1 parent 2edd930 commit cd8e266
Show file tree
Hide file tree
Showing 19 changed files with 209 additions and 338 deletions.
13 changes: 4 additions & 9 deletions src/game/AchievementMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@
#include "Map.h"
#include "InstanceData.h"
#include "DBCStructure.h"
#include "Chat.h"

#include "Policies/Singleton.h"


INSTANTIATE_SINGLETON_1(AchievementGlobalMgr);

namespace MaNGOS
Expand All @@ -57,15 +59,8 @@ namespace MaNGOS
{
char const* text = sObjectMgr.GetMangosString(i_textId, loc_idx);

data << uint8(i_msgtype);
data << uint32(LANG_UNIVERSAL);
data << i_player.GetObjectGuid();
data << uint32(5);
data << i_player.GetObjectGuid();
data << uint32(strlen(text) + 1);
data << text;
data << uint8(0);
data << uint32(i_achievementId);
ChatHandler::BuildChatPacket(data, i_msgtype, text, LANG_UNIVERSAL, i_player.GetObjectGuid(), NULL, i_player.GetObjectGuid(), NULL, NULL,
i_achievementId, false, i_player.GetChatTag());
}

private:
Expand Down
76 changes: 18 additions & 58 deletions src/game/BattleGround/BattleGround.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "Util.h"
#include "Formulas.h"
#include "GridNotifiersImpl.h"
#include "Chat.h"

namespace MaNGOS
{
Expand All @@ -56,26 +57,12 @@ namespace MaNGOS
vsnprintf(str, 2048, text, ap);
va_end(ap);

do_helper(data, &str[0]);
ChatHandler::BuildChatPacket(data, i_msgtype, &str[0], LANG_UNIVERSAL, i_source ? i_source ->GetObjectGuid() : ObjectGuid(), i_source ? i_source ->GetName() : "");
}
else
do_helper(data, text);
ChatHandler::BuildChatPacket(data, i_msgtype, text, LANG_UNIVERSAL, i_source ? i_source ->GetObjectGuid() : ObjectGuid(), i_source ? i_source ->GetName() : "");
}
private:
void do_helper(WorldPacket& data, char const* text)
{
ObjectGuid targetGuid = i_source ? i_source ->GetObjectGuid() : ObjectGuid();

data << uint8(i_msgtype);
data << uint32(LANG_UNIVERSAL);
data << ObjectGuid(targetGuid); // there 0 for BG messages
data << uint32(0); // can be chat msg group or something
data << ObjectGuid(targetGuid);
data << uint32(strlen(text) + 1);
data << text;
data << uint8(i_source ? i_source->GetChatTag() : uint8(CHAT_TAG_NONE));
}

ChatMsg i_msgtype;
int32 i_textId;
Player const* i_source;
Expand All @@ -85,7 +72,7 @@ namespace MaNGOS
class BattleGroundYellBuilder
{
public:
BattleGroundYellBuilder(uint32 language, int32 textId, Creature const* source, va_list* args = NULL)
BattleGroundYellBuilder(Language language, int32 textId, Creature const* source, va_list* args = NULL)
: i_language(language), i_textId(textId), i_source(source), i_args(args) {}
void operator()(WorldPacket& data, int32 loc_idx)
{
Expand All @@ -101,28 +88,13 @@ namespace MaNGOS
vsnprintf(str, 2048, text, ap);
va_end(ap);

do_helper(data, &str[0]);
ChatHandler::BuildChatPacket(data, CHAT_MSG_MONSTER_YELL, &str[0], i_language, i_source->GetObjectGuid(), i_source->GetName());
}
else
do_helper(data, text);
ChatHandler::BuildChatPacket(data, CHAT_MSG_MONSTER_YELL, text, i_language, i_source->GetObjectGuid(), i_source->GetName());
}
private:
void do_helper(WorldPacket& data, char const* text)
{
// copyied from BuildMonsterChat
data << uint8(CHAT_MSG_MONSTER_YELL);
data << uint32(i_language);
data << ObjectGuid(i_source->GetObjectGuid());
data << uint32(0); // 2.1.0
data << uint32(strlen(i_source->GetName()) + 1);
data << i_source->GetName();
data << ObjectGuid(); // Unit Target - isn't important for bgs
data << uint32(strlen(text) + 1);
data << text;
data << uint8(0); // ChatTag - for bgs allways 0?
}

uint32 i_language;
Language i_language;
int32 i_textId;
Creature const* i_source;
va_list* i_args;
Expand All @@ -142,19 +114,16 @@ namespace MaNGOS
char str [2048];
snprintf(str, 2048, text, arg1str, arg2str);

ObjectGuid targetGuid = i_source ? i_source ->GetObjectGuid() : ObjectGuid();

data << uint8(i_msgtype);
data << uint32(LANG_UNIVERSAL);
data << ObjectGuid(targetGuid); // there 0 for BG messages
data << uint32(0); // can be chat msg group or something
data << ObjectGuid(targetGuid);
data << uint32(strlen(str) + 1);
data << str;
data << uint8(i_source ? i_source->GetChatTag() : uint8(CHAT_TAG_NONE));
ObjectGuid guid;
char const* pName = NULL;
if (i_source)
{
guid = i_source->GetObjectGuid();
pName = i_source->GetName();
}
ChatHandler::BuildChatPacket(data, i_msgtype, str, LANG_UNIVERSAL, ObjectGuid(), NULL, guid, pName);
}
private:

ChatMsg i_msgtype;
int32 i_textId;
Player const* i_source;
Expand All @@ -175,17 +144,8 @@ namespace MaNGOS

char str [2048];
snprintf(str, 2048, text, arg1str, arg2str);
// copyied from BuildMonsterChat
data << uint8(CHAT_MSG_MONSTER_YELL);
data << uint32(i_language);
data << ObjectGuid(i_source->GetObjectGuid());
data << uint32(0); // 2.1.0
data << uint32(strlen(i_source->GetName()) + 1);
data << i_source->GetName();
data << ObjectGuid(); // Unit Target - isn't important for bgs
data << uint32(strlen(str) + 1);
data << str;
data << uint8(0); // ChatTag - for bgs allways 0?

ChatHandler::BuildChatPacket(data, CHAT_MSG_MONSTER_YELL, str, LANG_UNIVERSAL, i_source ? i_source ->GetObjectGuid() : ObjectGuid(), i_source ? i_source ->GetName() : "");
}
private:

Expand Down Expand Up @@ -1549,7 +1509,7 @@ void BattleGround::SendYellToAll(int32 entry, uint32 language, ObjectGuid guid)
Creature* source = GetBgMap()->GetCreature(guid);
if (!source)
return;
MaNGOS::BattleGroundYellBuilder bg_builder(language, entry, source);
MaNGOS::BattleGroundYellBuilder bg_builder(Language(language), entry, source);
MaNGOS::LocalizedPacketDo<MaNGOS::BattleGroundYellBuilder> bg_do(bg_builder);
BroadcastWorker(bg_do);
}
Expand Down
17 changes: 3 additions & 14 deletions src/game/Channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "ObjectMgr.h"
#include "World.h"
#include "SocialMgr.h"
#include "chat.h"

Channel::Channel(const std::string& name, uint32 channel_id)
: m_announce(true), m_moderate(false), m_name(name), m_flags(0), m_channelId(channel_id)
Expand Down Expand Up @@ -583,20 +584,8 @@ void Channel::Say(Player* player, const char* text, uint32 lang)
// send channel message
if (sWorld.getConfig(CONFIG_BOOL_ALLOW_TWO_SIDE_INTERACTION_CHANNEL))
lang = LANG_UNIVERSAL;

uint32 messageLength = strlen(text) + 1;

WorldPacket data(SMSG_MESSAGECHAT, 1 + 4 + 8 + 4 + m_name.size() + 1 + 8 + 4 + messageLength + 1);
data << uint8(CHAT_MSG_CHANNEL);
data << uint32(lang);
data << ObjectGuid(guid); // 2.1.0
data << uint32(0); // 2.1.0
data << m_name;
data << ObjectGuid(guid);
data << uint32(messageLength);
data << text;
data << uint8(player ? player->GetChatTag() : uint8(CHAT_TAG_NONE));

WorldPacket data;
ChatHandler::BuildChatPacket(data, CHAT_MSG_CHANNEL, text, Language(lang), guid, "", ObjectGuid(), "", m_name.c_str(), 0, player->isGMChat(), player->GetChatTag());
SendToAll(&data, !m_players[guid].IsModerator() ? guid : ObjectGuid());
}

Expand Down

0 comments on commit cd8e266

Please sign in to comment.