From 4537a7f8f0b577dbb48ead678f4dfdf1a7e11dc8 Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Sun, 13 Apr 2014 17:09:29 +0300 Subject: [PATCH] Eluna --- HookMgr.cpp | 33 +++++++++++++++------------------ HookMgr.h | 4 ++-- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/HookMgr.cpp b/HookMgr.cpp index f860d29..db926b6 100644 --- a/HookMgr.cpp +++ b/HookMgr.cpp @@ -215,21 +215,17 @@ bool HookMgr::OnPacketReceive(WorldSession* session, WorldPacket& packet) return result; } // AddOns -void HookMgr::OnAddonMessage(Player* sender, uint32 type, std::string& msg, Player* receiver, Guild* guild, Group* group, Channel* channel) +bool HookMgr::OnAddonMessage(Player* sender, uint32 type, std::string& msg, Player* receiver, Guild* guild, Group* group, Channel* channel) { if (!sEluna->ServerEventBindings.HasEvents(ADDON_EVENT_ON_MESSAGE)) - return; + return false; ELUNA_GUARD(); sEluna->ServerEventBindings.BeginCall(ADDON_EVENT_ON_MESSAGE); sEluna->Push(sEluna->L, sender); sEluna->Push(sEluna->L, type); const char* c_msg = msg.c_str(); - char* arg = strtok((char*)c_msg, "\t"); - while (arg) - { - sEluna->Push(sEluna->L, arg); - arg = strtok(NULL, "\t"); - } + sEluna->Push(sEluna->L, strtok((char*)c_msg, "\t")); // prefix + sEluna->Push(sEluna->L, strtok(NULL, "")); // msg if (receiver) sEluna->Push(sEluna->L, receiver); else if (guild) @@ -242,6 +238,7 @@ void HookMgr::OnAddonMessage(Player* sender, uint32 type, std::string& msg, Play sEluna->Push(sEluna->L); sEluna->ServerEventBindings.ExecuteCall(); sEluna->ServerEventBindings.EndCall(); + return true; } #ifndef MANGOS @@ -982,8 +979,8 @@ void HookMgr::OnMapChanged(Player* player) bool HookMgr::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg) { - if (lang == LANG_ADDON) - OnAddonMessage(pPlayer, type, msg, NULL, NULL, NULL, NULL); + if (lang == LANG_ADDON && OnAddonMessage(pPlayer, type, msg, NULL, NULL, NULL, NULL)) + return true; bool result = true; if (sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_CHAT)) { @@ -1013,8 +1010,8 @@ bool HookMgr::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg bool HookMgr::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Group* pGroup) { - if (lang == LANG_ADDON) - OnAddonMessage(pPlayer, type, msg, NULL, NULL, pGroup, NULL); + if (lang == LANG_ADDON && OnAddonMessage(pPlayer, type, msg, NULL, NULL, pGroup, NULL)) + return true; bool result = true; if (sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_GROUP_CHAT)) { @@ -1045,8 +1042,8 @@ bool HookMgr::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg bool HookMgr::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Guild* pGuild) { - if (lang == LANG_ADDON) - OnAddonMessage(pPlayer, type, msg, NULL, pGuild, NULL, NULL); + if (lang == LANG_ADDON && OnAddonMessage(pPlayer, type, msg, NULL, pGuild, NULL, NULL)) + return true; bool result = true; if (sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_GUILD_CHAT)) { @@ -1077,8 +1074,8 @@ bool HookMgr::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg bool HookMgr::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Channel* pChannel) { - if (lang == LANG_ADDON) - OnAddonMessage(pPlayer, type, msg, NULL, NULL, NULL, pChannel); + if (lang == LANG_ADDON && OnAddonMessage(pPlayer, type, msg, NULL, NULL, NULL, pChannel)) + return true; bool result = true; if (sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_CHANNEL_CHAT)) { @@ -1109,8 +1106,8 @@ bool HookMgr::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg bool HookMgr::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Player* pReceiver) { - if (lang == LANG_ADDON) - OnAddonMessage(pPlayer, type, msg, pReceiver, NULL, NULL, NULL); + if (lang == LANG_ADDON && OnAddonMessage(pPlayer, type, msg, pReceiver, NULL, NULL, NULL)) + return true; bool result = true; if (sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_WHISPER)) { diff --git a/HookMgr.h b/HookMgr.h index 2a772c3..7bd8b3b 100644 --- a/HookMgr.h +++ b/HookMgr.h @@ -125,7 +125,7 @@ enum ServerEvents AUCTION_EVENT_ON_EXPIRE = 29, // (event, AHObject) // NOT SUPPORTED YET // AddOns - ADDON_EVENT_ON_MESSAGE = 30, // (event, sender, type, msg_split_by_\t, nil/whisper_target/guid/group/channel) + ADDON_EVENT_ON_MESSAGE = 30, // (event, sender, type, prefix, msg, target) - target can be nil/whisper_target/guid/group/channel SERVER_EVENT_COUNT }; @@ -332,7 +332,7 @@ public: void OnGmTicketDelete(Player* pPlayer); // Not on TC InventoryResult OnCanUseItem(const Player* pPlayer, uint32 itemEntry); void OnEngineRestart(); - void OnAddonMessage(Player* sender, uint32 type, std::string& msg, Player* receiver, Guild* guild, Group* group, Channel* channel); + bool OnAddonMessage(Player* sender, uint32 type, std::string& msg, Player* receiver, Guild* guild, Group* group, Channel* channel); /* Item */ bool OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, Item* pTarget);