From 173d19bcd3b2a385f200550766c6782c0ebd4a5e Mon Sep 17 00:00:00 2001 From: Ben Carter Date: Fri, 13 Dec 2024 19:18:33 -0500 Subject: [PATCH] Fixed all Warnings and added in advancement methods + material types loader --- src/Scripts/PlayerMessageEvents.cpp | 115 ++++++++++++++++++++++++++++ src/Scripts/PlayerScript.cpp | 33 -------- src/Scripts/UnitScript.cpp | 1 - src/Scripts/WorldScript.cpp | 3 + 4 files changed, 118 insertions(+), 34 deletions(-) create mode 100644 src/Scripts/PlayerMessageEvents.cpp diff --git a/src/Scripts/PlayerMessageEvents.cpp b/src/Scripts/PlayerMessageEvents.cpp new file mode 100644 index 0000000..7249039 --- /dev/null +++ b/src/Scripts/PlayerMessageEvents.cpp @@ -0,0 +1,115 @@ +#include "MpLogger.h" +#include "MpDataStore.h" +#include "MpScheduler.h" +#include "MythicPlus.h" +#include "Player.h" +#include "Group.h" +#include "ScriptMgr.h" +#include "TaskScheduler.h" +#include "AdvancementMgr.cpp" +#include "Chat.h" +#include "Channel.h" +#include "ChannelMgr.h" + +#include +#include +#include + +/** + * This script file is a special event handler attached to the chat channel for MythicPlus to intercept + * message events from the client hidden chat channel and process them, as well as return events back to + * the client. It's a very simplified version of how Eluna / AIO manage messages from UI to C++ mods. + * + * All Messages come into a chat channel from a specific user on a hidden channel with details in the MythicPlus.h + * class for the protocol data definition. + */ + +class MythicPlus_PlayerMessageEvents : public PlayerScript +{ + + /** + * Listen to all messages from a playerand process them if + */ + void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg, Channel* channel) override + { + if(!player || !channel) { + return; + } + + // Handle chat message coming in to the data channel from the client. This allows backedend calls into the module + // from Eluna / AIO without the need to modify mod-eluna directly. + if(type == CHAT_MSG_CHANNEL && MP_DATA_CHAT_CHANNEL == channel->GetName()) { + MpLogger::info("Player {} sent a message {} to channel {}", player->GetName(), msg, channel->GetName()); + } + } + + /** + * When a player logs in add them to the data channel specifically for Mythic+ communication + * between UI and server module. + * + * Load advancement data for the player at load time used to apply buffs. + */ + void OnLogin(Player* player) override + { + if(!player) { + return; + } + + // Create a channel called MpEx if it does not exist + ChannelMgr* cmg = ChannelMgr::forTeam(TEAM_NEUTRAL); + Channel* channel = cmg->GetChannel(static_cast(MP_DATA_CHAT_CHANNEL), player); + + // If the channel does not yet, exist the first player to login to the server will ensure it is created. + if(!channel) { + channel = cmg->GetJoinChannel(static_cast(MP_DATA_CHAT_CHANNEL),0); + } + + } +}; + +// Split the string passed in by delimiters +std::vector splitString(const std::string& s, char delimiter) { + std::vector tokens; + size_t start = 0; + size_t end = s.find(delimiter); + + while (end != std::string::npos) { + if (end != start) { + tokens.emplace_back(s.substr(start, end - start)); + } + start = end + 1; + end = s.find(delimiter, start); + } + + // Add the last token if it's not empty + if (start < s.length()) { + tokens.emplace_back(s.substr(start)); + } + + return tokens; +} + +/** + * Parse the incoming message into its parts: + * - p:playerGuid:action:input1:input2:input3... + * i.e) p:5793:UpgradeAdvancement:0:10:2 + */ +void parsePlayerMessage(Player* player, std::string& msg) +{ + if(!player) { + MpLogger::error("Null player passed to parsePlayerMessage"); + return; + } + + if(msg[0] != 'p') { + MpLogger::warn("Invalid player message format received from player {} message: {}", player->GetName(), msg); + return; + } + + std::vector actionArgs; + char delimiter = '|'; + + // split the protocol into valid parts + std::vector parts = splitString(msg, delimiter); + +} diff --git a/src/Scripts/PlayerScript.cpp b/src/Scripts/PlayerScript.cpp index cc73ffa..8b58120 100644 --- a/src/Scripts/PlayerScript.cpp +++ b/src/Scripts/PlayerScript.cpp @@ -117,44 +117,11 @@ public: // } } - void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg, Channel* channel) override - { - if(!player || !channel) { - return; - } - - // Handle chat message coming in to the data channel from the client. This allows backedend calls into the module - // from Eluna / AIO without the need to modify mod-eluna directly. - if(type == CHAT_MSG_CHANNEL && MP_DATA_CHAT_CHANNEL == channel->GetName()) { - MpLogger::info("Player {} sent a message {} to channel {}", player->GetName(), msg, channel->GetName()); - } - } - - /** - * When a player logs in add them to the data channel specifically for Mythic+ communication - * between UI and server module. - * - * Load advancement data for the player at load time used to apply buffs. - */ void OnLogin(Player* player) override { - if(!player) { - return; - } - - // Create a channel called MpEx if it does not exist - ChannelMgr* cmg = ChannelMgr::forTeam(TEAM_NEUTRAL); - Channel* channel = cmg->GetChannel("MpEx", player); - - // If the channel does not yet, exist the first player to login to the server will ensure it is created. - if(!channel) { - channel = cmg->GetJoinChannel("MPEx",0); - } - // Load the player advancement data for the player when they login int32 size = sAdvancementMgr->LoadPlayerAdvancements(player); MpLogger::info("Loaded {} player advancements for player {}", size, player->GetName()); - } // When a player is bound to an instance need to make sure they are saved in the data soure to retrieve later. diff --git a/src/Scripts/UnitScript.cpp b/src/Scripts/UnitScript.cpp index c11ee59..564482c 100644 --- a/src/Scripts/UnitScript.cpp +++ b/src/Scripts/UnitScript.cpp @@ -187,7 +187,6 @@ public: * @TODO: Add more granular control over the scaling of healing spells */ if(sMythicPlus->EligibleHealTarget(target) && (eventType == MythicPlus::UNIT_EVENT_HEAL || eventType == MythicPlus::UNIT_EVENT_HOT)) { - bool isHeal = true; if(creature->IsDungeonBoss()) { if(spellInfo) { alteredDmgHeal = sMythicPlus->ScaleHealSpell(spellInfo, damageOrHeal, sMpDataStore->GetCreatureData(attacker->GetGUID()), creature, attacker->ToCreature(), instanceData->boss.spell); diff --git a/src/Scripts/WorldScript.cpp b/src/Scripts/WorldScript.cpp index f8db0e4..567d998 100644 --- a/src/Scripts/WorldScript.cpp +++ b/src/Scripts/WorldScript.cpp @@ -100,6 +100,9 @@ public: size = sAdvancementMgr->LoadAdvencementRanks(); MpLogger::info("Loaded {} advancement ranks...", size); + size = sAdvancementMgr->LoadMaterialTypes(); + MpLogger::info("Loaded {} material types...", size); + } };