diff --git a/Attorney_Online_remake.pro b/Attorney_Online_remake.pro index 1f4df76..40355c5 100644 --- a/Attorney_Online_remake.pro +++ b/Attorney_Online_remake.pro @@ -47,7 +47,8 @@ SOURCES += main.cpp\ aotextarea.cpp \ aolineedit.cpp \ aotextedit.cpp \ - aoevidencedisplay.cpp + aoevidencedisplay.cpp \ + discord_rich_presence.cpp HEADERS += lobby.h \ aoimage.h \ @@ -76,9 +77,16 @@ HEADERS += lobby.h \ aotextarea.h \ aolineedit.h \ aotextedit.h \ - aoevidencedisplay.h + aoevidencedisplay.h \ + discord_rich_presence.h -unix:LIBS += -L$$PWD -lbass +# 1. You need to get BASS and put the x86 bass DLL/headers in the project root folder +# AND the compilation output folder. If you want a static link, you'll probably +# need the .lib file too. MinGW-GCC is really finicky finding BASS, it seems. +# 2. You need to compile the Discord Rich Presence SDK separately and add the lib/headers +# in the same way as BASS. Discord RPC uses CMake, which does not play nicely with +# QMake, so this step must be manual. +unix:LIBS += -L$$PWD -lbass -ldiscord-rpc win32:LIBS += "$$PWD/bass.dll" android:LIBS += -L$$PWD\android\libs\armeabi-v7a\ -lbass diff --git a/aoapplication.cpp b/aoapplication.cpp index 4362902..e170c99 100644 --- a/aoapplication.cpp +++ b/aoapplication.cpp @@ -12,6 +12,7 @@ AOApplication::AOApplication(int &argc, char **argv) : QApplication(argc, argv) { net_manager = new NetworkManager(this); + discord = new AttorneyOnline::Discord(); QObject::connect(net_manager, SIGNAL(ms_connect_finished(bool, bool)), SLOT(ms_connect_finished(bool, bool))); } @@ -20,6 +21,7 @@ AOApplication::~AOApplication() { destruct_lobby(); destruct_courtroom(); + delete discord; } void AOApplication::construct_lobby() @@ -38,6 +40,8 @@ void AOApplication::construct_lobby() int y = (screenGeometry.height()-w_lobby->height()) / 2; w_lobby->move(x, y); + discord->state_lobby(); + w_lobby->show(); } diff --git a/aoapplication.h b/aoapplication.h index 30b16b5..146850d 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -3,6 +3,7 @@ #include "aopacket.h" #include "datatypes.h" +#include "discord_rich_presence.h" #include #include @@ -23,6 +24,7 @@ public: NetworkManager *net_manager; Lobby *w_lobby; Courtroom *w_courtroom; + AttorneyOnline::Discord *discord; bool lobby_constructed = false; bool courtroom_constructed = false; diff --git a/discord_rich_presence.cpp b/discord_rich_presence.cpp new file mode 100644 index 0000000..5d64c10 --- /dev/null +++ b/discord_rich_presence.cpp @@ -0,0 +1,58 @@ +#include "discord_rich_presence.h" + +#include + +#include + +namespace AttorneyOnline { + +Discord::Discord() +{ + DiscordEventHandlers handlers; + std::memset(&handlers, 0, sizeof(handlers)); + handlers = {}; + handlers.ready = [] { + qInfo() << "Discord RPC ready"; + }; + /* + handlers.disconnected = [](int errorCode, const char* message) { + qInfo() << "Discord RPC disconnected! " << message; + }; + handlers.errored = [](int errorCode, const char* message) { + qWarning() << "Discord RPC errored out! " << message; + }; + */ + qInfo() << "Are things working out all right?"; + Discord_Initialize(APPLICATION_ID, &handlers, 1, nullptr); +} + +Discord::~Discord() +{ + Discord_Shutdown(); +} + +void Discord::state_lobby() +{ + DiscordRichPresence presence; + std::memset(&presence, 0, sizeof(presence)); + presence.state = "In Lobby"; + presence.details = "Idle"; + presence.largeImageKey = "ao2-logo"; + presence.largeImageText = "Objection!"; + presence.instance = 1; + Discord_UpdatePresence(&presence); +} + +void Discord::state_server(const char* name, const char* server_id) +{ + DiscordRichPresence presence; + std::memset(&presence, 0, sizeof(presence)); + presence.state = "In a Server"; + presence.details = name; + presence.largeImageKey = "ao2-logo"; + presence.largeImageText = "Objection!"; + presence.instance = 1; + presence.matchSecret = server_id; +} + +} diff --git a/discord_rich_presence.h b/discord_rich_presence.h new file mode 100644 index 0000000..087fe8d --- /dev/null +++ b/discord_rich_presence.h @@ -0,0 +1,21 @@ +#ifndef DISCORD_RICH_PRESENCE_H +#define DISCORD_RICH_PRESENCE_H + +#include + +namespace AttorneyOnline { + +class Discord +{ +private: + const char* APPLICATION_ID = "399779271737868288"; +public: + Discord(); + ~Discord(); + + void state_lobby(); + void state_server(const char* name, const char* server_id); +}; + +} +#endif // DISCORD_RICH_PRESENCE_H diff --git a/packet_distribution.cpp b/packet_distribution.cpp index 4d74654..6e3232a 100644 --- a/packet_distribution.cpp +++ b/packet_distribution.cpp @@ -8,6 +8,7 @@ #include "debug_functions.h" #include +#include void AOApplication::ms_packet_received(AOPacket *p_packet) { @@ -226,15 +227,24 @@ void AOApplication::server_packet_received(AOPacket *p_packet) QString window_title = "Attorney Online 2"; int selected_server = w_lobby->get_selected_server(); + QString server_address = "", server_name = ""; if (w_lobby->public_servers_selected) { - if (selected_server >= 0 && selected_server < server_list.size()) - window_title += ": " + server_list.at(selected_server).name; + if (selected_server >= 0 && selected_server < server_list.size()) { + auto info = server_list.at(selected_server); + server_name = info.name; + server_address = info.ip + info.port; + window_title += ": " + server_name; + } } else { - if (selected_server >= 0 && selected_server < favorite_list.size()) - window_title += ": " + favorite_list.at(selected_server).name; + if (selected_server >= 0 && selected_server < favorite_list.size()) { + auto info = favorite_list.at(selected_server); + server_name = info.name; + server_address = info.ip + info.port; + window_title += ": " + server_name; + } } w_courtroom->set_window_title(window_title); @@ -251,6 +261,10 @@ void AOApplication::server_packet_received(AOPacket *p_packet) f_packet = new AOPacket("askchar2#%"); send_server_packet(f_packet); + + QCryptographicHash hash(QCryptographicHash::Algorithm::Sha256); + hash.addData(server_address.toUtf8()); + discord->state_server((const char*) server_name.toLocal8Bit().data(), (const char*) hash.result().toBase64()); } else if (header == "CI") {