Add spectate state; add "playing as character" state

This commit is contained in:
oldmud0 2018-01-08 13:33:39 -06:00
parent dee8de29da
commit 8a91dea6ce
5 changed files with 76 additions and 12 deletions

View File

@ -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() + "#%"));
}
}

View File

@ -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;

View File

@ -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";
presence.largeImageKey = "ao2-logo";
presence.largeImageText = "Objection!";
presence.instance = 1;
Discord_UpdatePresence(&presence);
}
void Discord::state_server(const char* name, const char* server_id)
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.state = "In a Server";
presence.details = name;
presence.largeImageKey = "ao2-logo";
presence.largeImageText = "Objection!";
presence.instance = 1;
presence.matchSecret = server_id;
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_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.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 = "Spectating";
Discord_UpdatePresence(&presence);
}

View File

@ -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();
};
}

View File

@ -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")
{