mirror of
https://github.com/araxiaonline/mod-mythic-plus.git
synced 2026-06-13 03:02:24 -04:00
Updated logger, and fixed up event handlers
This commit is contained in:
@@ -261,7 +261,8 @@ bool AdvancementMgr::UpgradeAdvancement(Player* player, MpAdvancements advanceme
|
||||
|
||||
if(playerRank->rank == MP_MAX_ADVANCEMENT_RANK) {
|
||||
MpLogger::error("Player {} has reached the maximum rank for advancement {}", player->GetName(), advancement);
|
||||
return false;
|
||||
|
||||
throw std::runtime_error("Player has reached the maximum rank for advancement");
|
||||
}
|
||||
|
||||
uint32 newRank = playerRank->rank + 1;
|
||||
@@ -274,7 +275,8 @@ bool AdvancementMgr::UpgradeAdvancement(Player* player, MpAdvancements advanceme
|
||||
// If the player has the items needed to upgrade this advancement, then remove the items from the player inventory and apply the upgrade
|
||||
if(!_PlayerHasItems(player, advancementRank, diceCostLevel, itemEntry1, itemEntry2, itemEntry3)) {
|
||||
MpLogger::info("Player {} does not have the required items to upgrade advancement {}", player->GetName(), advancement);
|
||||
return false;
|
||||
|
||||
throw std::runtime_error("Player does not have the required items to upgrade advancement");
|
||||
}
|
||||
|
||||
// Charge the player the cost of the upgrade
|
||||
@@ -298,7 +300,7 @@ bool AdvancementMgr::ResetPlayerAdvancements(Player* /*player*/)
|
||||
return true;
|
||||
}
|
||||
|
||||
void AdvancementMgr::_ResetPlayerAdvancement(Player* player, MpAdvancements advancement)
|
||||
void AdvancementMgr::_ResetPlayerAdvancement(Player* /*player*/, MpAdvancements /*advancement*/)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_playerAdvancementMutex);
|
||||
return;
|
||||
@@ -308,6 +310,7 @@ void AdvancementMgr::_ResetPlayerAdvancement(Player* player, MpAdvancements adva
|
||||
float AdvancementMgr::_RollAdvancement(MpAdvancementRank* advancementRank, uint32 diceCostLevel)
|
||||
{
|
||||
uint32 min, max;
|
||||
min = max = 0;
|
||||
|
||||
switch (diceCostLevel)
|
||||
{
|
||||
|
||||
@@ -11,16 +11,18 @@
|
||||
|
||||
enum MpAdvancements
|
||||
{
|
||||
MP_ADV_STRENGTH = 0,
|
||||
MP_ADV_AGILITY = 1,
|
||||
MP_ADV_STAMINA = 2,
|
||||
MP_ADV_INTELLECT = 3,
|
||||
MP_ADV_SPIRIT = 4,
|
||||
MP_ADV_RESIST_FIRE = 5,
|
||||
MP_ADV_RESIST_NATURE = 6,
|
||||
MP_ADV_RESIST_FROST = 7,
|
||||
MP_ADV_RESIST_SHADOW = 8,
|
||||
MP_ADV_RESIST_ARCANE = 9,
|
||||
MP_ADV_INTELLECT = 0,
|
||||
MP_ADV_SPIRIT = 1,
|
||||
MP_ADV_STRENGTH = 3,
|
||||
MP_ADV_AGILITY = 4,
|
||||
MP_ADV_STAMINA = 5,
|
||||
|
||||
MP_ADV_RESIST_ARCANE = 5,
|
||||
MP_ADV_RESIST_FIRE = 6,
|
||||
MP_ADV_RESIST_NATURE = 7,
|
||||
MP_ADV_RESIST_FROST = 8,
|
||||
MP_ADV_RESIST_SHADOW = 9,
|
||||
|
||||
MP_ADV_MAX = 10
|
||||
};
|
||||
|
||||
|
||||
@@ -21,7 +21,8 @@ bool MpClientDispatcher::Dispatch(MpClientEvent event, Player* player, std::vect
|
||||
|
||||
// Build the message string in same format to send to the client.
|
||||
std::string_view eventName = MpClientEventNames.at(event);
|
||||
std::string message = std::to_string(player->GetGUID().GetCounter()) + "|" + eventName.data();
|
||||
uint32 playerGuid = player->GetGUID().GetCounter();
|
||||
std::string message = "s|" + std::to_string(playerGuid) + "|" + std::string(eventName);
|
||||
for(auto& arg : args) {
|
||||
message += "|" + arg;
|
||||
}
|
||||
@@ -29,17 +30,19 @@ bool MpClientDispatcher::Dispatch(MpClientEvent event, Player* player, std::vect
|
||||
std::string prefix = std::string(MP_DATA_CHAT_CHANNEL);
|
||||
std::string fullmsg = prefix + "\t" + message;
|
||||
|
||||
MpLogger::debug("Dispatching client event: {} length {} for event {}", fullmsg, fullmsg.length(), std::string(eventName));
|
||||
|
||||
WorldPacket data(SMSG_MESSAGECHAT, 100);
|
||||
data << uint8(CHAT_MSG_ADDON);
|
||||
data << uint8(ChatMsg::CHAT_MSG_WHISPER);
|
||||
data << int32(LANG_ADDON);
|
||||
data << player->GetGUID().GetCounter();
|
||||
data << player->GetGUID();
|
||||
data << uint32(0);
|
||||
data << player->GetGUID().GetCounter();
|
||||
data << player->GetGUID();
|
||||
data << uint32(fullmsg.length() + 1);
|
||||
data << fullmsg;
|
||||
data << uint8(0);
|
||||
|
||||
player->GetSession()->SendPacket(&data);
|
||||
return 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -20,18 +20,23 @@
|
||||
enum class MP_EVENT_CODE
|
||||
{
|
||||
SUCCESS = 0,
|
||||
|
||||
// API Errors
|
||||
INVALID_EVENT = 100,
|
||||
INVALID_ARGUMENT_SIZE = 201,
|
||||
INVALID_ARGUMENT = 202,
|
||||
INVALID_ARGUMENT_TYPE = 203,
|
||||
|
||||
// Game Response Codes
|
||||
FAILED_UPGRADE_ADV = 300,
|
||||
|
||||
};
|
||||
|
||||
// Send an error event to the client
|
||||
bool SendEventError(Player* player, const std::string& method, MP_EVENT_CODE code, std::string message)
|
||||
{
|
||||
std::vector<std::string> clientError = { std::to_string(static_cast<int>(code)), message };
|
||||
MpLogger::error("Event Processor) Sending client error: {} {}", code, message);
|
||||
MpLogger::error("(Event Processor) Sending client error: {} {}", code, message);
|
||||
sMpClientDispatcher->Dispatch(MpClientEvent::Error, player, clientError);
|
||||
return false;
|
||||
}
|
||||
@@ -49,7 +54,8 @@ class UpdateAdvancements : public MpEventInterface
|
||||
// Store the event data to send back to the client for parsing
|
||||
std::vector<std::string> eventData;
|
||||
|
||||
MpLogger::info("(EventProcessor) Executing {}}", EventName());
|
||||
std::string eventName = EventName();
|
||||
MpLogger::info("(EventProcessor) Executing {}", eventName.c_str());
|
||||
for(auto& arg : args) {
|
||||
MpLogger::info("{} Arg: {}", EventName(), arg);
|
||||
}
|
||||
@@ -78,9 +84,14 @@ class UpdateAdvancements : public MpEventInterface
|
||||
uint32 itemEntry3 = std::stoi(args[4]);
|
||||
|
||||
// Upgrade the advancement for the player!
|
||||
if(! sAdvancementMgr->UpgradeAdvancement(player, static_cast<MpAdvancements>(advancementId), diceLevel, itemEntry1, itemEntry2, itemEntry3)) {
|
||||
return SendEventError(player, EventName(),MP_EVENT_CODE::INVALID_ARGUMENT, "Failed to upgrade advancement for player " + player->GetName());
|
||||
try {
|
||||
if(! sAdvancementMgr->UpgradeAdvancement(player, static_cast<MpAdvancements>(advancementId), diceLevel, itemEntry1, itemEntry2, itemEntry3)) {
|
||||
return SendEventError(player, EventName(),MP_EVENT_CODE::INVALID_ARGUMENT, "Failed to upgrade advancement invalid request see error logs for player " + player->GetName());
|
||||
}
|
||||
} catch(const std::exception& e) {
|
||||
return SendEventError(player, EventName(),MP_EVENT_CODE::FAILED_UPGRADE_ADV, "Failed to upgrade: " + std::string(e.what()) + " for player " + player->GetName());
|
||||
}
|
||||
|
||||
eventData = {"0", "success"};
|
||||
|
||||
// Send response back to the client
|
||||
|
||||
@@ -2,35 +2,74 @@
|
||||
#define MP_LOGGER_H
|
||||
|
||||
#include "Log.h"
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <boost/stacktrace.hpp>
|
||||
|
||||
class MpLogger
|
||||
{
|
||||
|
||||
public:
|
||||
template<typename... Args>
|
||||
static void debug(const char* fmt, Args&&... args) {
|
||||
LOG_DEBUG("module.MythicPlus", "[MythicPlus] DEBUG " + std::string(fmt), std::forward<Args>(args)...);
|
||||
try {
|
||||
LOG_DEBUG("module.MythicPlus", "[MythicPlus] DEBUG " + std::string(fmt), std::forward<Args>(args)...);
|
||||
} catch (const std::exception& e) {
|
||||
LOG_ERROR("module.MythicPlus", "[MythicPlus] DEBUG EXCEPTION: " + std::string(e.what()) +
|
||||
"\nStack trace: " + boost::stacktrace::to_string(boost::stacktrace::stacktrace()));
|
||||
} catch (...) {
|
||||
LOG_ERROR("module.MythicPlus", "[MythicPlus] DEBUG NON-STANDARD EXCEPTION");
|
||||
}
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
static void error(const char* fmt, Args&&... args) {
|
||||
LOG_ERROR("module.MythicPlus", "[MythicPlus] ERROR " + std::string(fmt), std::forward<Args>(args)...);
|
||||
try {
|
||||
LOG_ERROR("module.MythicPlus", "[MythicPlus] ERROR " + std::string(fmt), std::forward<Args>(args)...);
|
||||
} catch (const std::exception& e) {
|
||||
|
||||
LOG_ERROR("module.MythicPlus", "[MythicPlus] ERROR EXCEPTION: " + std::string(e.what()) +
|
||||
"\nStack trace: " + boost::stacktrace::to_string(boost::stacktrace::stacktrace()));
|
||||
} catch (...) {
|
||||
LOG_ERROR("module.MythicPlus", "[MythicPlus] ERROR NON-STANDARD EXCEPTION");
|
||||
}
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
static void info(const char* fmt, Args&&... args) {
|
||||
LOG_INFO("module.MythicPlus", "[MythicPlus] INFO " + std::string(fmt), std::forward<Args>(args)...);
|
||||
try {
|
||||
LOG_INFO("module.MythicPlus", "[MythicPlus] INFO " + std::string(fmt), std::forward<Args>(args)...);
|
||||
} catch (const std::exception& e) {
|
||||
LOG_ERROR("module.MythicPlus", "[MythicPlus] INFO EXCEPTION: " + std::string(e.what()) +
|
||||
"\nStack trace: " + boost::stacktrace::to_string(boost::stacktrace::stacktrace()));
|
||||
} catch (...) {
|
||||
LOG_ERROR("module.MythicPlus", "[MythicPlus] INFO NON-STANDARD EXCEPTION");
|
||||
}
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
static void warn(const char* fmt, Args&&... args) {
|
||||
LOG_WARN("module.MythicPlus", "[MythicPlus] WARN " + std::string(fmt), std::forward<Args>(args)...);
|
||||
try {
|
||||
LOG_WARN("module.MythicPlus", "[MythicPlus] WARN " + std::string(fmt), std::forward<Args>(args)...);
|
||||
} catch (const std::exception& e) {
|
||||
LOG_ERROR("module.MythicPlus", "[MythicPlus] WARN EXCEPTION: " + std::string(e.what()) +
|
||||
"\nStack trace: " + boost::stacktrace::to_string(boost::stacktrace::stacktrace()));
|
||||
} catch (...) {
|
||||
LOG_ERROR("module.MythicPlus", "[MythicPlus] WARN NON-STANDARD EXCEPTION");
|
||||
}
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
static void trace(const char* fmt, Args&&... args) {
|
||||
LOG_TRACE("module.MythicPlus", "[MythicPlus] TRACE " + std::string(fmt), std::forward<Args>(args)...);
|
||||
try {
|
||||
LOG_TRACE("module.MythicPlus", "[MythicPlus] TRACE " + std::string(fmt), std::forward<Args>(args)...);
|
||||
} catch (const std::exception& e) {
|
||||
LOG_ERROR("module.MythicPlus", "[MythicPlus] TRACE EXCEPTION: " + std::string(e.what()) +
|
||||
"\nStack trace: " + boost::stacktrace::to_string(boost::stacktrace::stacktrace()));
|
||||
} catch (...) {
|
||||
LOG_ERROR("module.MythicPlus", "[MythicPlus] TRACE NON-STANDARD EXCEPTION");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // MP_LOGGER_H
|
||||
|
||||
@@ -39,13 +39,13 @@ public:
|
||||
|
||||
MpGroupData *data = sMpDataStore->GetGroupData(player->GetGroup());
|
||||
if (!data) {
|
||||
MpLogger::warn("Missin group data for player {}", player->GetName());
|
||||
MpLogger::warn("Missing group data for player {}", player->GetName());
|
||||
return;
|
||||
}
|
||||
|
||||
MpPlayerData *playerData = sMpDataStore->GetPlayerData(player->GetGUID());
|
||||
if (!playerData) {
|
||||
MpLogger::warn("Missin player data for player {}", player->GetName());
|
||||
MpLogger::warn("Missing player data for player {}", player->GetName());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user