mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-15 08:21:28 +00:00
[Discord] Add Discord webhook callback processing to world (#3322)
This commit is contained in:
parent
95b306599f
commit
ecf2a369cc
@ -17,6 +17,7 @@ public:
|
|||||||
void Disconnect() { if(connection && connection->Handle()) connection->Handle()->Disconnect(); }
|
void Disconnect() { if(connection && connection->Handle()) connection->Handle()->Disconnect(); }
|
||||||
void SendMessage(const char *From, const char *Message);
|
void SendMessage(const char *From, const char *Message);
|
||||||
const std::shared_ptr<EQ::Net::ServertalkServerConnection> &GetConnection() const;
|
const std::shared_ptr<EQ::Net::ServertalkServerConnection> &GetConnection() const;
|
||||||
|
inline bool IsConnected() const { return connection->Handle() ? connection->Handle()->IsConnected() : false; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline std::string GetIP() const { return (connection && connection->Handle()) ? connection->Handle()->RemoteIP() : 0; }
|
inline std::string GetIP() const { return (connection && connection->Handle()) ? connection->Handle()->RemoteIP() : 0; }
|
||||||
|
|||||||
@ -300,6 +300,8 @@ bool WorldBoot::DatabaseLoadRoutines(int argc, char **argv)
|
|||||||
->SetLogPath(path.GetLogPath())
|
->SetLogPath(path.GetLogPath())
|
||||||
->LoadLogDatabaseSettings();
|
->LoadLogDatabaseSettings();
|
||||||
|
|
||||||
|
LogSys.SetDiscordHandler(&WorldBoot::DiscordWebhookMessageHandler);
|
||||||
|
|
||||||
if (!ignore_db) {
|
if (!ignore_db) {
|
||||||
LogInfo("Checking Database Conversions");
|
LogInfo("Checking Database Conversions");
|
||||||
database.CheckDatabaseConversions();
|
database.CheckDatabaseConversions();
|
||||||
@ -662,3 +664,18 @@ void WorldBoot::Shutdown()
|
|||||||
safe_delete(mutex);
|
safe_delete(mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WorldBoot::SendDiscordMessage(int webhook_id, const std::string &message)
|
||||||
|
{
|
||||||
|
if (UCSLink.IsConnected()) {
|
||||||
|
auto pack = new ServerPacket(ServerOP_DiscordWebhookMessage, sizeof(DiscordWebhookMessage_Struct) + 1);
|
||||||
|
auto *q = (DiscordWebhookMessage_Struct *) pack->pBuffer;
|
||||||
|
|
||||||
|
strn0cpy(q->message, message.c_str(), 2000);
|
||||||
|
q->webhook_id = webhook_id;
|
||||||
|
|
||||||
|
UCSLink.SendPacket(pack);
|
||||||
|
|
||||||
|
safe_delete(pack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,9 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "../common/types.h"
|
#include "../common/types.h"
|
||||||
|
#include "../common/discord/discord.h"
|
||||||
|
|
||||||
|
extern UCSConnection UCSLink;
|
||||||
|
|
||||||
class WorldBoot {
|
class WorldBoot {
|
||||||
public:
|
public:
|
||||||
@ -16,6 +19,16 @@ public:
|
|||||||
static bool DatabaseLoadRoutines(int argc, char **argv);
|
static bool DatabaseLoadRoutines(int argc, char **argv);
|
||||||
static void CheckForPossibleConfigurationIssues();
|
static void CheckForPossibleConfigurationIssues();
|
||||||
static void Shutdown();
|
static void Shutdown();
|
||||||
|
static void SendDiscordMessage(int webhook_id, const std::string& message);
|
||||||
|
static void DiscordWebhookMessageHandler(uint16 log_category, int webhook_id, const std::string &message)
|
||||||
|
{
|
||||||
|
std::string message_prefix = fmt::format(
|
||||||
|
"[**{}**] **World** ",
|
||||||
|
Logs::LogCategoryName[log_category]
|
||||||
|
);
|
||||||
|
|
||||||
|
SendDiscordMessage(webhook_id, message_prefix + Discord::FormatDiscordMessage(log_category, message));
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user