2020-08-17 01:31:03 +00:00
|
|
|
// SONIC ROBO BLAST 2 KART
|
2018-10-22 04:34:45 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2020-08-17 01:31:03 +00:00
|
|
|
// Copyright (C) 2018-2020 by Sally "TehRealSalt" Cochenour.
|
|
|
|
// Copyright (C) 2018-2020 by Kart Krew.
|
2018-10-22 04:34:45 +00:00
|
|
|
//
|
|
|
|
// This program is free software distributed under the
|
|
|
|
// terms of the GNU General Public License, version 2.
|
|
|
|
// See the 'LICENSE' file for more details.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/// \file discord.h
|
|
|
|
/// \brief Discord Rich Presence handling
|
|
|
|
|
|
|
|
#ifdef HAVE_DISCORDRPC
|
|
|
|
|
2020-09-30 10:55:16 +00:00
|
|
|
#include <time.h>
|
2020-08-17 04:29:52 +00:00
|
|
|
|
2018-10-22 04:34:45 +00:00
|
|
|
#include "i_system.h"
|
|
|
|
#include "d_clisrv.h"
|
|
|
|
#include "d_netcmd.h"
|
|
|
|
#include "i_net.h"
|
|
|
|
#include "g_game.h"
|
|
|
|
#include "p_tick.h"
|
|
|
|
#include "m_menu.h" // gametype_cons_t
|
|
|
|
#include "r_things.h" // skins
|
2020-09-11 12:56:40 +00:00
|
|
|
#include "mserv.h" // cv_advertise
|
2020-08-21 08:14:33 +00:00
|
|
|
#include "z_zone.h"
|
2020-08-22 05:53:27 +00:00
|
|
|
#include "byteptr.h"
|
2020-09-30 10:55:16 +00:00
|
|
|
#include "stun.h"
|
|
|
|
#include "i_tcp.h" // current_port
|
2018-10-22 04:34:45 +00:00
|
|
|
|
|
|
|
#include "discord.h"
|
|
|
|
#include "doomdef.h"
|
|
|
|
|
2020-08-17 06:25:05 +00:00
|
|
|
// Feel free to provide your own, if you care enough to create another Discord app for this :P
|
|
|
|
#define DISCORD_APPID "503531144395096085"
|
|
|
|
|
2020-08-21 08:14:33 +00:00
|
|
|
// length of IP strings
|
2020-08-31 03:41:27 +00:00
|
|
|
#define IP_SIZE 21
|
2020-08-21 08:14:33 +00:00
|
|
|
|
2020-08-17 06:25:05 +00:00
|
|
|
consvar_t cv_discordrp = {"discordrp", "On", CV_SAVE|CV_CALL, CV_OnOff, DRPC_UpdatePresence, 0, NULL, NULL, 0, 0, NULL};
|
2020-08-22 05:53:27 +00:00
|
|
|
consvar_t cv_discordstreamer = {"discordstreamer", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL};
|
|
|
|
consvar_t cv_discordasks = {"discordasks", "Yes", CV_SAVE|CV_CALL, CV_YesNo, DRPC_UpdatePresence, 0, NULL, NULL, 0, 0, NULL};
|
|
|
|
|
|
|
|
struct discordInfo_s discordInfo;
|
2018-10-30 09:44:29 +00:00
|
|
|
|
2020-08-21 08:14:33 +00:00
|
|
|
discordRequest_t *discordRequestList = NULL;
|
2020-08-21 05:16:11 +00:00
|
|
|
|
2020-08-17 10:13:32 +00:00
|
|
|
static char self_ip[IP_SIZE];
|
|
|
|
|
2020-08-21 05:16:11 +00:00
|
|
|
/*--------------------------------------------------
|
|
|
|
static char *DRPC_XORIPString(const char *input)
|
|
|
|
|
|
|
|
Simple XOR encryption/decryption. Not complex or
|
|
|
|
very secretive because we aren't sending anything
|
2020-08-22 04:11:33 +00:00
|
|
|
that isn't easily accessible via our Master Server anyway.
|
2020-08-21 05:16:11 +00:00
|
|
|
--------------------------------------------------*/
|
|
|
|
static char *DRPC_XORIPString(const char *input)
|
|
|
|
{
|
2020-08-31 04:25:28 +00:00
|
|
|
const UINT8 xor[IP_SIZE] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21};
|
2020-08-22 13:46:25 +00:00
|
|
|
char *output = malloc(sizeof(char) * (IP_SIZE+1));
|
2020-08-21 05:16:11 +00:00
|
|
|
UINT8 i;
|
|
|
|
|
|
|
|
for (i = 0; i < IP_SIZE; i++)
|
|
|
|
{
|
2020-08-22 13:46:25 +00:00
|
|
|
char xorinput;
|
|
|
|
|
|
|
|
if (!input[i])
|
|
|
|
break;
|
|
|
|
|
|
|
|
xorinput = input[i] ^ xor[i];
|
|
|
|
|
|
|
|
if (xorinput < 32 || xorinput > 126)
|
|
|
|
{
|
|
|
|
xorinput = input[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
output[i] = xorinput;
|
2020-08-21 05:16:11 +00:00
|
|
|
}
|
|
|
|
|
2020-08-22 13:46:25 +00:00
|
|
|
output[i] = '\0';
|
|
|
|
|
2020-08-21 05:16:11 +00:00
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2020-08-17 10:13:32 +00:00
|
|
|
/*--------------------------------------------------
|
|
|
|
static void DRPC_HandleReady(const DiscordUser *user)
|
|
|
|
|
2020-08-21 05:16:11 +00:00
|
|
|
Callback function, ran when the game connects to Discord.
|
2020-08-17 10:13:32 +00:00
|
|
|
|
|
|
|
Input Arguments:-
|
|
|
|
user - Struct containing Discord user info.
|
|
|
|
|
|
|
|
Return:-
|
|
|
|
None
|
|
|
|
--------------------------------------------------*/
|
|
|
|
static void DRPC_HandleReady(const DiscordUser *user)
|
2018-10-22 04:34:45 +00:00
|
|
|
{
|
2020-08-22 05:53:27 +00:00
|
|
|
if (cv_discordstreamer.value)
|
|
|
|
{
|
|
|
|
CONS_Printf("Discord: connected to %s\n", user->username);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CONS_Printf("Discord: connected to %s#%s (%s)\n", user->username, user->discriminator, user->userId);
|
|
|
|
}
|
2018-10-22 04:34:45 +00:00
|
|
|
}
|
|
|
|
|
2020-08-17 10:13:32 +00:00
|
|
|
/*--------------------------------------------------
|
|
|
|
static void DRPC_HandleDisconnect(int err, const char *msg)
|
|
|
|
|
2020-08-21 05:16:11 +00:00
|
|
|
Callback function, ran when disconnecting from Discord.
|
2020-08-17 10:13:32 +00:00
|
|
|
|
|
|
|
Input Arguments:-
|
|
|
|
err - Error type
|
|
|
|
msg - Error message
|
|
|
|
|
|
|
|
Return:-
|
|
|
|
None
|
|
|
|
--------------------------------------------------*/
|
|
|
|
static void DRPC_HandleDisconnect(int err, const char *msg)
|
2018-10-22 04:34:45 +00:00
|
|
|
{
|
|
|
|
CONS_Printf("Discord: disconnected (%d: %s)\n", err, msg);
|
|
|
|
}
|
|
|
|
|
2020-08-17 10:13:32 +00:00
|
|
|
/*--------------------------------------------------
|
|
|
|
static void DRPC_HandleError(int err, const char *msg)
|
|
|
|
|
2020-08-21 05:16:11 +00:00
|
|
|
Callback function, ran when Discord outputs an error.
|
2020-08-17 10:13:32 +00:00
|
|
|
|
|
|
|
Input Arguments:-
|
|
|
|
err - Error type
|
|
|
|
msg - Error message
|
|
|
|
|
|
|
|
Return:-
|
|
|
|
None
|
|
|
|
--------------------------------------------------*/
|
|
|
|
static void DRPC_HandleError(int err, const char *msg)
|
2018-10-22 04:34:45 +00:00
|
|
|
{
|
2020-08-17 10:13:32 +00:00
|
|
|
CONS_Alert(CONS_WARNING, "Discord error (%d: %s)\n", err, msg);
|
2018-10-22 04:34:45 +00:00
|
|
|
}
|
|
|
|
|
2020-08-17 10:13:32 +00:00
|
|
|
/*--------------------------------------------------
|
|
|
|
static void DRPC_HandleJoin(const char *secret)
|
|
|
|
|
2020-08-21 05:16:11 +00:00
|
|
|
Callback function, ran when Discord wants to
|
2020-08-17 10:13:32 +00:00
|
|
|
connect a player to the game via a channel invite
|
|
|
|
or a join request.
|
|
|
|
|
|
|
|
Input Arguments:-
|
|
|
|
secret - Value that links you to the server.
|
|
|
|
|
|
|
|
Return:-
|
|
|
|
None
|
|
|
|
--------------------------------------------------*/
|
|
|
|
static void DRPC_HandleJoin(const char *secret)
|
2018-10-22 04:34:45 +00:00
|
|
|
{
|
2020-08-21 05:16:11 +00:00
|
|
|
char *ip = DRPC_XORIPString(secret);
|
|
|
|
CONS_Printf("Connecting to %s via Discord\n", ip);
|
2021-09-11 00:25:13 +00:00
|
|
|
M_ClearMenus(true); //Don't have menus open during connection screen
|
|
|
|
if (demo.playback && demo.title)
|
|
|
|
G_CheckDemoStatus(); //Stop the title demo, so that the connect command doesn't error if a demo is playing
|
2020-08-21 05:16:11 +00:00
|
|
|
COM_BufAddText(va("connect \"%s\"\n", ip));
|
|
|
|
free(ip);
|
2018-10-22 04:34:45 +00:00
|
|
|
}
|
|
|
|
|
2020-08-22 05:53:27 +00:00
|
|
|
/*--------------------------------------------------
|
|
|
|
static boolean DRPC_InvitesAreAllowed(void)
|
|
|
|
|
|
|
|
Determines whenever or not invites or
|
|
|
|
ask to join requests are allowed.
|
|
|
|
|
|
|
|
Input Arguments:-
|
|
|
|
None
|
|
|
|
|
|
|
|
Return:-
|
|
|
|
true if invites are allowed, false otherwise.
|
|
|
|
--------------------------------------------------*/
|
|
|
|
static boolean DRPC_InvitesAreAllowed(void)
|
|
|
|
{
|
|
|
|
if (!Playing())
|
|
|
|
{
|
|
|
|
// We're not playing, so we should not be getting invites.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cv_discordasks.value == 0)
|
|
|
|
{
|
|
|
|
// Client has the CVar set to off, so never allow invites from this client.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (discordInfo.joinsAllowed == true)
|
|
|
|
{
|
|
|
|
if (discordInfo.everyoneCanInvite == true)
|
|
|
|
{
|
|
|
|
// Everyone's allowed!
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (consoleplayer == serverplayer || IsPlayerAdmin(consoleplayer))
|
|
|
|
{
|
|
|
|
// Only admins are allowed!
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Did not pass any of the checks
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-08-21 08:14:33 +00:00
|
|
|
/*--------------------------------------------------
|
|
|
|
static void DRPC_HandleJoinRequest(const DiscordUser *requestUser)
|
|
|
|
|
|
|
|
Callback function, ran when Discord wants to
|
|
|
|
ask the player if another Discord user can join
|
|
|
|
or not.
|
|
|
|
|
|
|
|
Input Arguments:-
|
|
|
|
requestUser - DiscordUser struct for the user trying to connect.
|
|
|
|
|
|
|
|
Return:-
|
|
|
|
None
|
|
|
|
--------------------------------------------------*/
|
|
|
|
static void DRPC_HandleJoinRequest(const DiscordUser *requestUser)
|
|
|
|
{
|
|
|
|
discordRequest_t *append = discordRequestList;
|
2020-08-22 05:53:27 +00:00
|
|
|
discordRequest_t *newRequest;
|
2020-08-21 08:14:33 +00:00
|
|
|
|
2020-08-22 05:53:27 +00:00
|
|
|
if (DRPC_InvitesAreAllowed() == false)
|
|
|
|
{
|
|
|
|
// Something weird happened if this occurred...
|
|
|
|
Discord_Respond(requestUser->userId, DISCORD_REPLY_IGNORE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
newRequest = Z_Calloc(sizeof(discordRequest_t), PU_STATIC, NULL);
|
|
|
|
|
|
|
|
newRequest->username = Z_Calloc(344, PU_STATIC, NULL);
|
|
|
|
snprintf(newRequest->username, 344, "%s", requestUser->username);
|
|
|
|
|
|
|
|
newRequest->discriminator = Z_Calloc(8, PU_STATIC, NULL);
|
|
|
|
snprintf(newRequest->discriminator, 8, "%s", requestUser->discriminator);
|
2020-08-21 08:14:33 +00:00
|
|
|
|
|
|
|
newRequest->userID = Z_Calloc(32, PU_STATIC, NULL);
|
|
|
|
snprintf(newRequest->userID, 32, "%s", requestUser->userId);
|
|
|
|
|
|
|
|
if (append != NULL)
|
|
|
|
{
|
|
|
|
discordRequest_t *prev = NULL;
|
|
|
|
|
|
|
|
while (append != NULL)
|
|
|
|
{
|
2020-08-22 04:01:56 +00:00
|
|
|
// CHECK FOR DUPES!! Ignore any that already exist from the same user.
|
|
|
|
if (!strcmp(newRequest->userID, append->userID))
|
|
|
|
{
|
|
|
|
Discord_Respond(newRequest->userID, DISCORD_REPLY_IGNORE);
|
|
|
|
DRPC_RemoveRequest(newRequest);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-21 08:14:33 +00:00
|
|
|
prev = append;
|
|
|
|
append = append->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
newRequest->prev = prev;
|
|
|
|
prev->next = newRequest;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
discordRequestList = newRequest;
|
2020-08-23 00:16:49 +00:00
|
|
|
M_RefreshPauseMenu();
|
2020-08-21 08:14:33 +00:00
|
|
|
}
|
2020-08-22 08:54:08 +00:00
|
|
|
|
|
|
|
// Made it to the end, request was valid, so play the request sound :)
|
|
|
|
S_StartSound(NULL, sfx_requst);
|
2020-08-21 08:14:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*--------------------------------------------------
|
|
|
|
void DRPC_RemoveRequest(discordRequest_t *removeRequest)
|
|
|
|
|
|
|
|
See header file for description.
|
|
|
|
--------------------------------------------------*/
|
|
|
|
void DRPC_RemoveRequest(discordRequest_t *removeRequest)
|
|
|
|
{
|
|
|
|
if (removeRequest->prev != NULL)
|
|
|
|
{
|
|
|
|
removeRequest->prev->next = removeRequest->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (removeRequest->next != NULL)
|
|
|
|
{
|
|
|
|
removeRequest->next->prev = removeRequest->prev;
|
|
|
|
|
|
|
|
if (removeRequest == discordRequestList)
|
|
|
|
{
|
|
|
|
discordRequestList = removeRequest->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (removeRequest == discordRequestList)
|
|
|
|
{
|
|
|
|
discordRequestList = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Z_Free(removeRequest->username);
|
|
|
|
Z_Free(removeRequest->userID);
|
|
|
|
Z_Free(removeRequest);
|
|
|
|
}
|
|
|
|
|
2020-08-17 10:13:32 +00:00
|
|
|
/*--------------------------------------------------
|
|
|
|
void DRPC_Init(void)
|
|
|
|
|
|
|
|
See header file for description.
|
|
|
|
--------------------------------------------------*/
|
2018-10-22 04:34:45 +00:00
|
|
|
void DRPC_Init(void)
|
|
|
|
{
|
|
|
|
DiscordEventHandlers handlers;
|
|
|
|
memset(&handlers, 0, sizeof(handlers));
|
|
|
|
|
|
|
|
handlers.ready = DRPC_HandleReady;
|
|
|
|
handlers.disconnected = DRPC_HandleDisconnect;
|
|
|
|
handlers.errored = DRPC_HandleError;
|
|
|
|
handlers.joinGame = DRPC_HandleJoin;
|
2020-08-21 08:14:33 +00:00
|
|
|
handlers.joinRequest = DRPC_HandleJoinRequest;
|
2018-10-22 04:34:45 +00:00
|
|
|
|
2018-10-30 09:44:29 +00:00
|
|
|
Discord_Initialize(DISCORD_APPID, &handlers, 1, NULL);
|
2018-10-22 04:34:45 +00:00
|
|
|
I_AddExitFunc(Discord_Shutdown);
|
|
|
|
DRPC_UpdatePresence();
|
|
|
|
}
|
|
|
|
|
2020-08-17 10:13:32 +00:00
|
|
|
/*--------------------------------------------------
|
2020-09-30 10:55:16 +00:00
|
|
|
static void DRPC_GotServerIP(UINT32 address)
|
2020-08-17 04:29:52 +00:00
|
|
|
|
2020-09-30 10:55:16 +00:00
|
|
|
Callback triggered by successful STUN response.
|
2020-08-17 10:13:32 +00:00
|
|
|
|
|
|
|
Input Arguments:-
|
2020-09-30 10:55:16 +00:00
|
|
|
address - IPv4 address of this machine, in network byte order.
|
2020-08-17 04:29:52 +00:00
|
|
|
|
2020-08-17 10:13:32 +00:00
|
|
|
Return:-
|
2020-09-30 10:55:16 +00:00
|
|
|
None
|
2020-08-17 10:13:32 +00:00
|
|
|
--------------------------------------------------*/
|
2020-09-30 10:55:16 +00:00
|
|
|
static void DRPC_GotServerIP(UINT32 address)
|
2020-08-17 04:29:52 +00:00
|
|
|
{
|
2020-09-30 10:55:16 +00:00
|
|
|
const unsigned char * p = (const unsigned char *)&address;
|
|
|
|
sprintf(self_ip, "%u.%u.%u.%u:%u", p[0], p[1], p[2], p[3], current_port);
|
2020-08-17 04:29:52 +00:00
|
|
|
}
|
|
|
|
|
2020-08-17 10:13:32 +00:00
|
|
|
/*--------------------------------------------------
|
|
|
|
static const char *DRPC_GetServerIP(void)
|
|
|
|
|
|
|
|
Retrieves the IP address of the server that you're
|
2021-02-27 05:37:15 +00:00
|
|
|
connected to. Will attempt to use STUN for getting your
|
|
|
|
own IP address.
|
2020-08-17 10:13:32 +00:00
|
|
|
--------------------------------------------------*/
|
2020-08-17 04:29:52 +00:00
|
|
|
static const char *DRPC_GetServerIP(void)
|
|
|
|
{
|
|
|
|
const char *address;
|
|
|
|
|
|
|
|
// If you're connected
|
|
|
|
if (I_GetNodeAddress && (address = I_GetNodeAddress(servernode)) != NULL)
|
|
|
|
{
|
|
|
|
if (strcmp(address, "self"))
|
2020-08-17 10:13:32 +00:00
|
|
|
{
|
|
|
|
// We're not the server, so we could successfully get the IP!
|
|
|
|
// No need to do anything else :)
|
2021-04-13 04:56:14 +00:00
|
|
|
return address;
|
2020-08-17 10:13:32 +00:00
|
|
|
}
|
2020-08-17 04:29:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (self_ip[0])
|
2020-09-30 10:55:16 +00:00
|
|
|
{
|
2020-08-17 04:29:52 +00:00
|
|
|
return self_ip;
|
2020-09-30 10:55:16 +00:00
|
|
|
}
|
2020-08-17 04:29:52 +00:00
|
|
|
else
|
2020-09-30 10:55:16 +00:00
|
|
|
{
|
|
|
|
// There happens to be a good way to get it after all! :D
|
|
|
|
STUN_bind(DRPC_GotServerIP);
|
|
|
|
return NULL;
|
|
|
|
}
|
2020-08-17 04:29:52 +00:00
|
|
|
}
|
|
|
|
|
2020-08-23 11:15:33 +00:00
|
|
|
/*--------------------------------------------------
|
|
|
|
void DRPC_EmptyRequests(void)
|
|
|
|
|
|
|
|
Empties the request list. Any existing requests
|
|
|
|
will get an ignore reply.
|
|
|
|
--------------------------------------------------*/
|
|
|
|
static void DRPC_EmptyRequests(void)
|
|
|
|
{
|
|
|
|
while (discordRequestList != NULL)
|
|
|
|
{
|
|
|
|
Discord_Respond(discordRequestList->userID, DISCORD_REPLY_IGNORE);
|
|
|
|
DRPC_RemoveRequest(discordRequestList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-17 10:13:32 +00:00
|
|
|
/*--------------------------------------------------
|
|
|
|
void DRPC_UpdatePresence(void)
|
|
|
|
|
|
|
|
See header file for description.
|
|
|
|
--------------------------------------------------*/
|
2018-10-22 04:34:45 +00:00
|
|
|
void DRPC_UpdatePresence(void)
|
|
|
|
{
|
2020-08-17 13:08:05 +00:00
|
|
|
char detailstr[48+1];
|
|
|
|
|
2020-08-17 08:42:22 +00:00
|
|
|
char mapimg[8+1];
|
|
|
|
char mapname[5+21+21+2+1];
|
|
|
|
|
|
|
|
char charimg[4+SKINNAMESIZE+1];
|
|
|
|
char charname[11+SKINNAMESIZE+1];
|
2020-08-17 04:29:52 +00:00
|
|
|
|
2020-08-22 08:54:08 +00:00
|
|
|
boolean joinSecretSet = false;
|
|
|
|
|
2018-10-22 04:34:45 +00:00
|
|
|
DiscordRichPresence discordPresence;
|
|
|
|
memset(&discordPresence, 0, sizeof(discordPresence));
|
|
|
|
|
2020-09-16 02:56:08 +00:00
|
|
|
if (dedicated)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-17 06:25:05 +00:00
|
|
|
if (!cv_discordrp.value)
|
|
|
|
{
|
|
|
|
// User doesn't want to show their game information, so update with empty presence.
|
|
|
|
// This just shows that they're playing SRB2Kart. (If that's too much, then they should disable game activity :V)
|
2020-08-23 11:15:33 +00:00
|
|
|
DRPC_EmptyRequests();
|
2020-08-17 06:25:05 +00:00
|
|
|
Discord_UpdatePresence(&discordPresence);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-17 13:08:05 +00:00
|
|
|
#ifdef DEVELOP
|
|
|
|
// This way, we can use the invite feature in-dev, but not have snoopers seeing any potential secrets! :P
|
|
|
|
discordPresence.largeImageKey = "miscdevelop";
|
2020-08-21 05:16:11 +00:00
|
|
|
discordPresence.largeImageText = "No peeking!";
|
|
|
|
discordPresence.state = "Testing the game";
|
2020-08-17 13:08:05 +00:00
|
|
|
|
2020-08-23 11:15:33 +00:00
|
|
|
DRPC_EmptyRequests();
|
2020-08-17 13:08:05 +00:00
|
|
|
Discord_UpdatePresence(&discordPresence);
|
|
|
|
return;
|
|
|
|
#endif // DEVELOP
|
|
|
|
|
2018-10-30 09:44:29 +00:00
|
|
|
// Server info
|
|
|
|
if (netgame)
|
2018-10-22 04:34:45 +00:00
|
|
|
{
|
2021-02-27 05:37:15 +00:00
|
|
|
if (cv_advertise.value)
|
|
|
|
{
|
|
|
|
discordPresence.state = "Public";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
discordPresence.state = "Private";
|
|
|
|
}
|
|
|
|
|
|
|
|
discordPresence.partyId = server_context; // Thanks, whoever gave us Mumble support, for implementing the EXACT thing Discord wanted for this field!
|
|
|
|
discordPresence.partySize = D_NumPlayers(); // Players in server
|
|
|
|
discordPresence.partyMax = discordInfo.maxPlayers; // Max players
|
|
|
|
|
2020-08-22 05:53:27 +00:00
|
|
|
if (DRPC_InvitesAreAllowed() == true)
|
2020-08-21 05:16:11 +00:00
|
|
|
{
|
2020-08-22 05:53:27 +00:00
|
|
|
const char *join;
|
|
|
|
|
|
|
|
// Grab the host's IP for joining.
|
|
|
|
if ((join = DRPC_GetServerIP()) != NULL)
|
|
|
|
{
|
2021-04-12 22:33:06 +00:00
|
|
|
discordPresence.joinSecret = DRPC_XORIPString(join);
|
2020-08-22 08:54:08 +00:00
|
|
|
joinSecretSet = true;
|
2020-08-22 05:53:27 +00:00
|
|
|
}
|
2020-09-30 10:55:16 +00:00
|
|
|
}
|
2018-10-30 09:44:29 +00:00
|
|
|
}
|
|
|
|
else
|
2020-08-17 06:05:16 +00:00
|
|
|
{
|
2020-08-22 09:03:08 +00:00
|
|
|
// Reset discord info if you're not in a place that uses it!
|
|
|
|
// Important for if you join a server that compiled without HAVE_DISCORDRPC,
|
|
|
|
// so that you don't ever end up using bad information from another server.
|
|
|
|
memset(&discordInfo, 0, sizeof(discordInfo));
|
|
|
|
|
2020-08-17 06:05:16 +00:00
|
|
|
// Offline info
|
|
|
|
if (Playing())
|
|
|
|
discordPresence.state = "Offline";
|
|
|
|
else if (demo.playback && !demo.title)
|
|
|
|
discordPresence.state = "Watching Replay";
|
|
|
|
else
|
|
|
|
discordPresence.state = "Menu";
|
|
|
|
}
|
2018-10-30 09:44:29 +00:00
|
|
|
|
|
|
|
// Gametype info
|
2020-08-21 08:14:33 +00:00
|
|
|
if ((gamestate == GS_LEVEL || gamestate == GS_INTERMISSION || gamestate == GS_VOTING) && Playing())
|
2018-10-30 09:44:29 +00:00
|
|
|
{
|
|
|
|
if (modeattacking)
|
2020-08-17 06:25:05 +00:00
|
|
|
discordPresence.details = "Time Attack";
|
2018-10-30 09:44:29 +00:00
|
|
|
else
|
2020-08-17 13:08:05 +00:00
|
|
|
{
|
|
|
|
snprintf(detailstr, 48, "%s%s%s",
|
|
|
|
gametype_cons_t[gametype].strvalue,
|
|
|
|
(gametype == GT_RACE) ? va(" | %s", kartspeed_cons_t[gamespeed].strvalue) : "",
|
|
|
|
(encoremode == true) ? " | Encore" : ""
|
|
|
|
);
|
|
|
|
discordPresence.details = detailstr;
|
|
|
|
}
|
2018-10-30 09:44:29 +00:00
|
|
|
}
|
|
|
|
|
2020-08-21 05:18:40 +00:00
|
|
|
if ((gamestate == GS_LEVEL || gamestate == GS_INTERMISSION) // Map info
|
|
|
|
&& !(demo.playback && demo.title))
|
2018-10-30 09:44:29 +00:00
|
|
|
{
|
2020-08-17 04:29:52 +00:00
|
|
|
if ((gamemap >= 1 && gamemap <= 60) // supported race maps
|
|
|
|
|| (gamemap >= 136 && gamemap <= 164)) // supported battle maps
|
2018-10-22 04:34:45 +00:00
|
|
|
{
|
|
|
|
snprintf(mapimg, 8, "%s", G_BuildMapName(gamemap));
|
|
|
|
strlwr(mapimg);
|
|
|
|
discordPresence.largeImageKey = mapimg; // Map image
|
|
|
|
}
|
2020-08-17 08:42:22 +00:00
|
|
|
else if (mapheaderinfo[gamemap-1]->menuflags & LF2_HIDEINMENU)
|
|
|
|
{
|
|
|
|
// Hell map, use the method that got you here :P
|
2020-08-17 13:08:05 +00:00
|
|
|
discordPresence.largeImageKey = "miscdice";
|
2020-08-17 08:42:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// This is probably a custom map!
|
|
|
|
discordPresence.largeImageKey = "mapcustom";
|
|
|
|
}
|
2018-10-30 09:44:29 +00:00
|
|
|
|
2020-08-17 08:42:22 +00:00
|
|
|
if (mapheaderinfo[gamemap-1]->menuflags & LF2_HIDEINMENU)
|
|
|
|
{
|
|
|
|
// Hell map, hide the name
|
2018-10-30 09:44:29 +00:00
|
|
|
discordPresence.largeImageText = "Map: ???";
|
2020-08-17 08:42:22 +00:00
|
|
|
}
|
2018-10-30 09:44:29 +00:00
|
|
|
else
|
2018-10-22 04:34:45 +00:00
|
|
|
{
|
2020-08-17 13:08:05 +00:00
|
|
|
// Map name on tool tip
|
2022-12-15 19:23:06 +00:00
|
|
|
char *title = G_BuildMapTitle(gamemap);
|
|
|
|
snprintf(mapname, 48, "Map: %s", title);
|
2020-08-17 13:08:05 +00:00
|
|
|
discordPresence.largeImageText = mapname;
|
2022-12-15 19:23:06 +00:00
|
|
|
Z_Free(title);
|
2018-10-22 04:34:45 +00:00
|
|
|
}
|
|
|
|
|
2020-08-21 08:14:33 +00:00
|
|
|
if (gamestate == GS_LEVEL && Playing())
|
2020-08-17 06:05:16 +00:00
|
|
|
{
|
|
|
|
const time_t currentTime = time(NULL);
|
2020-08-17 10:13:32 +00:00
|
|
|
const time_t mapTimeStart = currentTime - ((leveltime + (modeattacking ? starttime : 0)) / TICRATE);
|
2020-08-17 06:05:16 +00:00
|
|
|
|
|
|
|
discordPresence.startTimestamp = mapTimeStart;
|
|
|
|
|
|
|
|
if (timelimitintics > 0)
|
|
|
|
{
|
|
|
|
const time_t mapTimeEnd = mapTimeStart + ((timelimitintics + starttime + 1) / TICRATE);
|
|
|
|
discordPresence.endTimestamp = mapTimeEnd;
|
|
|
|
}
|
|
|
|
}
|
2018-10-30 09:44:29 +00:00
|
|
|
}
|
|
|
|
else if (gamestate == GS_VOTING)
|
|
|
|
{
|
|
|
|
discordPresence.largeImageKey = (G_BattleGametype() ? "miscredplanet" : "miscblueplanet");
|
|
|
|
discordPresence.largeImageText = "Voting";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
discordPresence.largeImageKey = "misctitle";
|
|
|
|
discordPresence.largeImageText = "Title Screen";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Character info
|
|
|
|
if (Playing() && playeringame[consoleplayer] && !players[consoleplayer].spectator)
|
|
|
|
{
|
2020-08-17 08:42:05 +00:00
|
|
|
// Supported skin names
|
|
|
|
static const char *supportedSkins[] = {
|
|
|
|
// base game
|
|
|
|
"sonic",
|
|
|
|
"tails",
|
|
|
|
"knuckles",
|
|
|
|
"eggman",
|
|
|
|
"metalsonic",
|
|
|
|
// bonus chars
|
|
|
|
"flicky",
|
|
|
|
"motobug",
|
|
|
|
"amy",
|
|
|
|
"mighty",
|
|
|
|
"ray",
|
|
|
|
"espio",
|
|
|
|
"vector",
|
|
|
|
"chao",
|
|
|
|
"gamma",
|
|
|
|
"chaos",
|
|
|
|
"shadow",
|
|
|
|
"rouge",
|
|
|
|
"herochao",
|
|
|
|
"darkchao",
|
|
|
|
"cream",
|
|
|
|
"omega",
|
|
|
|
"blaze",
|
|
|
|
"silver",
|
|
|
|
"wonderboy",
|
|
|
|
"arle",
|
|
|
|
"nights",
|
|
|
|
"sakura",
|
|
|
|
"ulala",
|
|
|
|
"beat",
|
|
|
|
"vyse",
|
|
|
|
"aiai",
|
|
|
|
"kiryu",
|
|
|
|
"aigis",
|
|
|
|
"miku",
|
|
|
|
"doom",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
boolean customChar = true;
|
|
|
|
UINT8 checkSkin = 0;
|
|
|
|
|
|
|
|
// Character image
|
|
|
|
while (supportedSkins[checkSkin] != NULL)
|
2018-10-22 04:34:45 +00:00
|
|
|
{
|
2020-08-17 08:42:05 +00:00
|
|
|
if (!strcmp(skins[players[consoleplayer].skin].name, supportedSkins[checkSkin]))
|
|
|
|
{
|
|
|
|
snprintf(charimg, 21, "char%s", supportedSkins[checkSkin]);
|
|
|
|
discordPresence.smallImageKey = charimg;
|
|
|
|
customChar = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
checkSkin++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (customChar == true)
|
|
|
|
{
|
|
|
|
// Use the custom character icon!
|
|
|
|
discordPresence.smallImageKey = "charcustom";
|
2018-10-22 04:34:45 +00:00
|
|
|
}
|
2018-10-30 09:44:29 +00:00
|
|
|
|
|
|
|
snprintf(charname, 28, "Character: %s", skins[players[consoleplayer].skin].realname);
|
|
|
|
discordPresence.smallImageText = charname; // Character name
|
2018-10-22 04:34:45 +00:00
|
|
|
}
|
|
|
|
|
2020-08-22 08:54:08 +00:00
|
|
|
if (joinSecretSet == false)
|
|
|
|
{
|
|
|
|
// Not able to join? Flush the request list, if it exists.
|
2020-08-23 11:15:33 +00:00
|
|
|
DRPC_EmptyRequests();
|
2020-08-22 08:54:08 +00:00
|
|
|
}
|
|
|
|
|
2018-10-22 04:34:45 +00:00
|
|
|
Discord_UpdatePresence(&discordPresence);
|
|
|
|
}
|
|
|
|
|
2020-08-17 13:08:05 +00:00
|
|
|
#endif // HAVE_DISCORDRPC
|