aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--charselect.cpp4
-rw-r--r--courtroom.cpp6
-rw-r--r--discord_rich_presence.cpp63
-rw-r--r--discord_rich_presence.h7
-rw-r--r--packet_distribution.cpp2
5 files changed, 73 insertions, 9 deletions
diff --git a/charselect.cpp b/charselect.cpp
index 1f76e0b2..4e4bccbf 100644
--- a/charselect.cpp
+++ b/charselect.cpp
@@ -151,8 +151,12 @@ void Courtroom::char_clicked(int n_char)
}
if (n_real_char == m_cid)
+ {
enter_courtroom(m_cid);
+ }
else
+ {
ao_app->send_server_packet(new AOPacket("CC#" + QString::number(ao_app->s_pv) + "#" + QString::number(n_real_char) + "#" + get_hdid() + "#%"));
+ }
}
diff --git a/courtroom.cpp b/courtroom.cpp
index a8b96eb5..14d3cbb3 100644
--- a/courtroom.cpp
+++ b/courtroom.cpp
@@ -660,9 +660,15 @@ void Courtroom::enter_courtroom(int p_cid)
QString f_char;
if (m_cid == -1)
+ {
+ ao_app->discord->state_spectate();
f_char = "";
+ }
else
+ {
f_char = ao_app->get_char_name(char_list.at(m_cid).name);
+ ao_app->discord->state_character(f_char.toStdString());
+ }
current_char = f_char;
diff --git a/discord_rich_presence.cpp b/discord_rich_presence.cpp
index f5f6c11c..bcc0d2af 100644
--- a/discord_rich_presence.cpp
+++ b/discord_rich_presence.cpp
@@ -1,6 +1,7 @@
#include "discord_rich_presence.h"
#include <cstring>
+#include <ctime>
#include <QDebug>
@@ -14,15 +15,13 @@ Discord::Discord()
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?";
+ qInfo() << "Initializing Discord RPC";
Discord_Initialize(APPLICATION_ID, &handlers, 1, nullptr);
}
@@ -35,24 +34,74 @@ void Discord::state_lobby()
{
DiscordRichPresence presence;
std::memset(&presence, 0, sizeof(presence));
+ presence.largeImageKey = "ao2-logo";
+ presence.largeImageText = "Objection!";
+ presence.instance = 1;
+
presence.state = "In Lobby";
presence.details = "Idle";
+ Discord_UpdatePresence(&presence);
+}
+
+void Discord::state_server(std::string name, std::string server_id)
+{
+ qDebug() << "Discord RPC: Setting server state";
+
+ DiscordRichPresence presence;
+ std::memset(&presence, 0, sizeof(presence));
presence.largeImageKey = "ao2-logo";
presence.largeImageText = "Objection!";
presence.instance = 1;
+
+ auto timestamp = static_cast<int64_t>(std::time(nullptr));
+
+ presence.state = "In a Server";
+ presence.details = name.c_str();
+ presence.matchSecret = server_id.c_str();
+ presence.startTimestamp = this->timestamp;
+
+ this->server_id = server_id;
+ this->server_name = name;
+ this->timestamp = timestamp;
Discord_UpdatePresence(&presence);
}
-void Discord::state_server(const char* name, const char* server_id)
+void Discord::state_character(std::string name)
{
+ auto name_internal = QString(name.c_str()).toLower().replace(' ', '_').toStdString();
+ auto name_friendly = QString(name.c_str()).replace('_', ' ').toStdString();
+ const std::string playing_as = "Playing as " + name_friendly;
+ qDebug() << "Discord RPC: Setting character state (" << playing_as.c_str() << ")";
+
+ DiscordRichPresence presence;
+ std::memset(&presence, 0, sizeof(presence));
+ presence.largeImageKey = "ao2-logo";
+ presence.largeImageText = "Objection!";
+ presence.instance = 1;
+ presence.details = this->server_name.c_str();
+ presence.matchSecret = this->server_id.c_str();
+ presence.startTimestamp = this->timestamp;
+
+ presence.state = playing_as.c_str();
+ presence.smallImageKey = name_internal.c_str();
+ // presence.smallImageText = name_internal.c_str();
+ Discord_UpdatePresence(&presence);
+}
+
+void Discord::state_spectate()
+{
+ qDebug() << "Discord RPC: Setting specator state";
+
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;
+ presence.details = this->server_name.c_str();
+ presence.matchSecret = this->server_id.c_str();
+ presence.startTimestamp = this->timestamp;
+
+ presence.state = "Spectating";
Discord_UpdatePresence(&presence);
}
diff --git a/discord_rich_presence.h b/discord_rich_presence.h
index 087fe8df..3c9f2bda 100644
--- a/discord_rich_presence.h
+++ b/discord_rich_presence.h
@@ -1,6 +1,7 @@
#ifndef DISCORD_RICH_PRESENCE_H
#define DISCORD_RICH_PRESENCE_H
+#include <string>
#include <discord-rpc.h>
namespace AttorneyOnline {
@@ -9,12 +10,16 @@ class Discord
{
private:
const char* APPLICATION_ID = "399779271737868288";
+ std::string server_name, server_id;
+ int64_t timestamp;
public:
Discord();
~Discord();
void state_lobby();
- void state_server(const char* name, const char* server_id);
+ void state_server(std::string name, std::string server_id);
+ void state_character(std::string name);
+ void state_spectate();
};
}
diff --git a/packet_distribution.cpp b/packet_distribution.cpp
index 6e3232a7..3908ffa1 100644
--- a/packet_distribution.cpp
+++ b/packet_distribution.cpp
@@ -264,7 +264,7 @@ void AOApplication::server_packet_received(AOPacket *p_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());
+ discord->state_server(server_name.toStdString(), hash.result().toBase64().toStdString());
}
else if (header == "CI")
{