mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-18 16:38:42 +01:00
Core/ScriptSystem: Refactor ScriptMgr::OnPlayerChat to no longer accept a C-style parameter of type void*.
Instead, use overloaded methods for the different types. --HG-- branch : trunk
This commit is contained in:
@@ -1117,9 +1117,29 @@ void ScriptMgr::OnPlayerReputationChange(Player *player, uint32 factionID, int32
|
||||
FOREACH_SCRIPT(PlayerScript)->OnReputationChange(player, factionID, standing, incremental);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnPlayerChat(Player* player, uint32 type, uint32 lang, std::string msg, void* param)
|
||||
void ScriptMgr::OnPlayerChat(Player* player, uint32 type, uint32 lang, std::string msg)
|
||||
{
|
||||
FOREACH_SCRIPT(PlayerScript)->OnChat(player, type, lang, msg, param);
|
||||
FOREACH_SCRIPT(PlayerScript)->OnChat(player, type, lang, msg);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnPlayerChat(Player* player, uint32 type, uint32 lang, std::string msg, Player* receiver)
|
||||
{
|
||||
FOREACH_SCRIPT(PlayerScript)->OnChat(player, type, lang, msg, receiver);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnPlayerChat(Player* player, uint32 type, uint32 lang, std::string msg, Group* group)
|
||||
{
|
||||
FOREACH_SCRIPT(PlayerScript)->OnChat(player, type, lang, msg, group);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnPlayerChat(Player* player, uint32 type, uint32 lang, std::string msg, Guild* guild)
|
||||
{
|
||||
FOREACH_SCRIPT(PlayerScript)->OnChat(player, type, lang, msg, guild);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnPlayerChat(Player* player, uint32 type, uint32 lang, std::string msg, Channel* channel)
|
||||
{
|
||||
FOREACH_SCRIPT(PlayerScript)->OnChat(player, type, lang, msg, channel);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnPlayerEmote(Player* player, uint32 emote)
|
||||
|
||||
@@ -675,15 +675,12 @@ public:
|
||||
// Called when a player's reputation changes (before it is actually changed)
|
||||
virtual void OnReputationChange(Player* /*player*/, uint32 /*factionID*/, int32& /*standing*/, bool /*incremental*/) { }
|
||||
|
||||
// Called when a player sends a chat message. param depends on the chat type:
|
||||
// CHAT_MSG_WHISPER - Player*: receiver;
|
||||
// CHAT_MSG_PARTY, CHAT_MSG_PARTY_LEADER - Group*: group of player;
|
||||
// CHAT_MSG_OFFICER, CHAT_MSG_GUILD - Guild*: guild of player;
|
||||
// CHAT_MSG_RAID, CHAT_MSG_RAID_LEADER, CHAT_MSG_RAID_WARNING - Group*: group of player;
|
||||
// CHAT_MSG_BATTLEGROUND, CHAT_MSG_BATTLEGROUND_LEADER - Group*: group of player;
|
||||
// CHAT_MSG_CHANNEL - Channel*: channel player speaks to;
|
||||
// other - NULL.
|
||||
virtual void OnChat(Player* /*player*/, uint32 /*type*/, uint32 /*lang*/, std::string /*msg*/, void* /*param*/ = NULL) { }
|
||||
// The following methods are called when a player sends a chat message
|
||||
virtual void OnChat(Player* /*player*/, uint32 /*type*/, uint32 /*lang*/, std::string /*msg*/) { }
|
||||
virtual void OnChat(Player* /*player*/, uint32 /*type*/, uint32 /*lang*/, std::string /*msg*/, Player* /*receiver*/) { }
|
||||
virtual void OnChat(Player* /*player*/, uint32 /*type*/, uint32 /*lang*/, std::string /*msg*/, Group* /*group*/) { }
|
||||
virtual void OnChat(Player* /*player*/, uint32 /*type*/, uint32 /*lang*/, std::string /*msg*/, Guild* /*guild*/) { }
|
||||
virtual void OnChat(Player* /*player*/, uint32 /*type*/, uint32 /*lang*/, std::string /*msg*/, Channel* /*channel*/) { }
|
||||
|
||||
// Both of the below are called on emote opcodes
|
||||
virtual void OnEmote(Player* /*player*/, uint32 /*emote*/) { }
|
||||
@@ -887,7 +884,11 @@ class ScriptMgr
|
||||
void OnPlayerMoneyChanged(Player *player, int32& amount);
|
||||
void OnGivePlayerXP(Player *player, uint32& amount, Unit *victim);
|
||||
void OnPlayerReputationChange(Player *player, uint32 factionID, int32& standing, bool incremental);
|
||||
void OnPlayerChat(Player* player, uint32 type, uint32 lang, std::string msg, void* param = NULL);
|
||||
void OnPlayerChat(Player* player, uint32 type, uint32 lang, std::string msg);
|
||||
void OnPlayerChat(Player* player, uint32 type, uint32 lang, std::string msg, Player* receiver);
|
||||
void OnPlayerChat(Player* player, uint32 type, uint32 lang, std::string msg, Group* group);
|
||||
void OnPlayerChat(Player* player, uint32 type, uint32 lang, std::string msg, Guild* guild);
|
||||
void OnPlayerChat(Player* player, uint32 type, uint32 lang, std::string msg, Channel* channel);
|
||||
void OnPlayerEmote(Player* player, uint32 emote);
|
||||
void OnPlayerTextEmote(Player* player, uint32 text_emote, uint32 emoteNum, uint64 guid);
|
||||
void OnPlayerSpellCast(Player *player, Spell *spell, bool skipCheck);
|
||||
|
||||
@@ -25,7 +25,7 @@ class ChatLogScript : public PlayerScript
|
||||
public:
|
||||
ChatLogScript() : PlayerScript("ChatLogScript") { }
|
||||
|
||||
void OnChat(Player* player, uint32 type, uint32 lang, std::string msg, void* param)
|
||||
void OnChat(Player* player, uint32 type, uint32 lang, std::string msg)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
@@ -52,62 +52,27 @@ public:
|
||||
sLog.outChat("[YELL] Player %s yells (language %u): %s",
|
||||
player->GetName(), lang, msg.c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void OnChat(Player *player, uint32 type, uint32 lang, std::string msg, Player *receiver)
|
||||
{
|
||||
if (sWorld.getBoolConfig(CONFIG_CHATLOG_WHISPER))
|
||||
{
|
||||
sLog.outChat("[WHISPER] Player %s tells %s: %s",
|
||||
player->GetName(), receiver ? receiver->GetName() : "<unknown>", msg.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
case CHAT_MSG_WHISPER:
|
||||
if (sWorld.getBoolConfig(CONFIG_CHATLOG_WHISPER))
|
||||
{
|
||||
Player* pReceiver = reinterpret_cast <Player*> (param);
|
||||
sLog.outChat("[WHISPER] Player %s tells %s: %s",
|
||||
player->GetName(), pReceiver ? pReceiver->GetName() : "<unknown>", msg.c_str());
|
||||
}
|
||||
break;
|
||||
|
||||
void OnChat(Player *player, uint32 type, uint32 lang, std::string msg, Group *group)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case CHAT_MSG_PARTY:
|
||||
if (sWorld.getBoolConfig(CONFIG_CHATLOG_PARTY))
|
||||
{
|
||||
Group* pGroup = reinterpret_cast <Group*> (param);
|
||||
sLog.outChat("[PARTY] Player %s tells group with leader %s: %s",
|
||||
player->GetName(), pGroup ? pGroup->GetLeaderName() : "<unknown>", msg.c_str());
|
||||
}
|
||||
break;
|
||||
|
||||
case CHAT_MSG_PARTY_LEADER:
|
||||
if (sWorld.getBoolConfig(CONFIG_CHATLOG_PARTY))
|
||||
sLog.outChat("[PARTY] Leader %s tells group: %s",
|
||||
player->GetName(), msg.c_str());
|
||||
break;
|
||||
|
||||
case CHAT_MSG_GUILD:
|
||||
{
|
||||
Guild* pGuild = reinterpret_cast <Guild*> (param);
|
||||
if (lang != LANG_ADDON && sWorld.getBoolConfig(CONFIG_CHATLOG_GUILD))
|
||||
{
|
||||
sLog.outChat("[GUILD] Player %s tells guild %s: %s",
|
||||
player->GetName(), pGuild ? pGuild->GetName().c_str() : "<unknown>", msg.c_str());
|
||||
}
|
||||
else if (lang == LANG_ADDON && sWorld.getBoolConfig(CONFIG_CHATLOG_ADDON))
|
||||
{
|
||||
sLog.outChat("[ADDON] Player %s sends to guild %s: %s",
|
||||
player->GetName(), pGuild ? pGuild->GetName().c_str() : "<unknown>", msg.c_str());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case CHAT_MSG_OFFICER:
|
||||
if (sWorld.getBoolConfig(CONFIG_CHATLOG_GUILD))
|
||||
{
|
||||
Guild* pGuild = reinterpret_cast <Guild*> (param);
|
||||
sLog.outChat("[OFFICER] Player %s tells guild %s officers: %s",
|
||||
player->GetName(), pGuild ? pGuild->GetName().c_str() : "<unknown>", msg.c_str());
|
||||
}
|
||||
break;
|
||||
|
||||
case CHAT_MSG_RAID:
|
||||
if (sWorld.getBoolConfig(CONFIG_CHATLOG_RAID))
|
||||
{
|
||||
Group* pGroup = reinterpret_cast <Group*> (param);
|
||||
sLog.outChat("[RAID] Player %s tells raid with leader %s: %s",
|
||||
player->GetName(), pGroup ? pGroup->GetLeaderName() : "<unknown>", msg.c_str());
|
||||
player->GetName(), group ? group->GetLeaderName() : "<unknown>", msg.c_str());
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -123,13 +88,10 @@ public:
|
||||
player->GetName(), msg.c_str());
|
||||
break;
|
||||
|
||||
case CHAT_MSG_BATTLEGROUND:
|
||||
if (sWorld.getBoolConfig(CONFIG_CHATLOG_BGROUND))
|
||||
{
|
||||
Group* pGroup = reinterpret_cast <Group*> (param);
|
||||
sLog.outChat("[BATTLEGROUND] Player %s tells battleground with leader %s: %s",
|
||||
player->GetName(), pGroup ? pGroup->GetLeaderName() : "<unknown>", msg.c_str());
|
||||
}
|
||||
case CHAT_MSG_PARTY_LEADER:
|
||||
if (sWorld.getBoolConfig(CONFIG_CHATLOG_PARTY))
|
||||
sLog.outChat("[PARTY] Leader %s tells group: %s",
|
||||
player->GetName(), msg.c_str());
|
||||
break;
|
||||
|
||||
case CHAT_MSG_BATTLEGROUND_LEADER:
|
||||
@@ -138,27 +100,69 @@ public:
|
||||
player->GetName(), msg.c_str());
|
||||
break;
|
||||
|
||||
case CHAT_MSG_CHANNEL:
|
||||
{
|
||||
Channel* pChannel = reinterpret_cast <Channel*> (param);
|
||||
bool isSystem = pChannel &&
|
||||
(pChannel->HasFlag(CHANNEL_FLAG_TRADE) ||
|
||||
pChannel->HasFlag(CHANNEL_FLAG_GENERAL) ||
|
||||
pChannel->HasFlag(CHANNEL_FLAG_CITY) ||
|
||||
pChannel->HasFlag(CHANNEL_FLAG_LFG));
|
||||
if (sWorld.getBoolConfig(CONFIG_CHATLOG_SYSCHAN) && isSystem)
|
||||
sLog.outChat("[SYSCHAN] Player %s tells channel %s: %s",
|
||||
player->GetName(), pChannel->GetName().c_str(), msg.c_str());
|
||||
else if (sWorld.getBoolConfig(CONFIG_CHATLOG_CHANNEL))
|
||||
sLog.outChat("[CHANNEL] Player %s tells channel %s: %s",
|
||||
player->GetName(), pChannel ? pChannel->GetName().c_str() : "<unknown>", msg.c_str());
|
||||
case CHAT_MSG_RAID:
|
||||
if (sWorld.getBoolConfig(CONFIG_CHATLOG_RAID))
|
||||
{
|
||||
sLog.outChat("[RAID] Player %s tells raid with leader %s: %s",
|
||||
player->GetName(), group ? group->GetLeaderName() : "<unknown>", msg.c_str());
|
||||
}
|
||||
break;
|
||||
|
||||
case CHAT_MSG_BATTLEGROUND:
|
||||
if (sWorld.getBoolConfig(CONFIG_CHATLOG_BGROUND))
|
||||
{
|
||||
sLog.outChat("[BATTLEGROUND] Player %s tells battleground with leader %s: %s",
|
||||
player->GetName(), group ? group->GetLeaderName() : "<unknown>", msg.c_str());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnChat(Player *player, uint32 type, uint32 lang, std::string msg, Guild *guild)
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case CHAT_MSG_GUILD:
|
||||
if (lang != LANG_ADDON && sWorld.getBoolConfig(CONFIG_CHATLOG_GUILD))
|
||||
{
|
||||
sLog.outChat("[GUILD] Player %s tells guild %s: %s",
|
||||
player->GetName(), guild ? guild->GetName().c_str() : "<unknown>", msg.c_str());
|
||||
}
|
||||
else if (lang == LANG_ADDON && sWorld.getBoolConfig(CONFIG_CHATLOG_ADDON))
|
||||
{
|
||||
sLog.outChat("[ADDON] Player %s sends to guild %s: %s",
|
||||
player->GetName(), guild ? guild->GetName().c_str() : "<unknown>", msg.c_str());
|
||||
}
|
||||
break;
|
||||
|
||||
case CHAT_MSG_OFFICER:
|
||||
if (sWorld.getBoolConfig(CONFIG_CHATLOG_GUILD))
|
||||
{
|
||||
sLog.outChat("[OFFICER] Player %s tells guild %s officers: %s",
|
||||
player->GetName(), guild ? guild->GetName().c_str() : "<unknown>", msg.c_str());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void OnChat(Player *player, uint32 type, uint32 lang, std::string msg, Channel *channel)
|
||||
{
|
||||
bool isSystem = channel &&
|
||||
(channel->HasFlag(CHANNEL_FLAG_TRADE) ||
|
||||
channel->HasFlag(CHANNEL_FLAG_GENERAL) ||
|
||||
channel->HasFlag(CHANNEL_FLAG_CITY) ||
|
||||
channel->HasFlag(CHANNEL_FLAG_LFG));
|
||||
|
||||
if (sWorld.getBoolConfig(CONFIG_CHATLOG_SYSCHAN) && isSystem)
|
||||
sLog.outChat("[SYSCHAN] Player %s tells channel %s: %s",
|
||||
player->GetName(), channel->GetName().c_str(), msg.c_str());
|
||||
else if (sWorld.getBoolConfig(CONFIG_CHATLOG_CHANNEL))
|
||||
sLog.outChat("[CHANNEL] Player %s tells channel %s: %s",
|
||||
player->GetName(), channel ? channel->GetName().c_str() : "<unknown>", msg.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
void AddSC_chat_log()
|
||||
{
|
||||
new ChatLogScript();
|
||||
new ChatLogScript;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user