mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2024-12-26 20:31:30 +00:00
Invite menu started
Functions! Is not pretty yet!
This commit is contained in:
parent
7b1e14d017
commit
339be6f90e
3 changed files with 226 additions and 6 deletions
|
@ -25,6 +25,7 @@
|
|||
#include "m_menu.h" // gametype_cons_t
|
||||
#include "r_things.h" // skins
|
||||
#include "mserv.h" // ms_RoomId
|
||||
#include "z_zone.h"
|
||||
|
||||
#include "discord.h"
|
||||
#include "doomdef.h"
|
||||
|
@ -32,9 +33,12 @@
|
|||
// Feel free to provide your own, if you care enough to create another Discord app for this :P
|
||||
#define DISCORD_APPID "503531144395096085"
|
||||
|
||||
// length of IP strings
|
||||
#define IP_SIZE 16
|
||||
|
||||
consvar_t cv_discordrp = {"discordrp", "On", CV_SAVE|CV_CALL, CV_OnOff, DRPC_UpdatePresence, 0, NULL, NULL, 0, 0, NULL};
|
||||
|
||||
#define IP_SIZE 16 // length of IP strings
|
||||
discordRequest_t *discordRequestList = NULL;
|
||||
|
||||
#ifdef HAVE_CURL
|
||||
struct SelfIPbuffer
|
||||
|
@ -81,7 +85,7 @@ static char *DRPC_XORIPString(const char *input)
|
|||
--------------------------------------------------*/
|
||||
static void DRPC_HandleReady(const DiscordUser *user)
|
||||
{
|
||||
CONS_Printf("Discord: connected to %s#%s - %s\n", user->username, user->discriminator, user->userId);
|
||||
CONS_Printf("Discord: connected to %s#%s (%s)\n", user->username, user->discriminator, user->userId);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------
|
||||
|
@ -139,6 +143,89 @@ static void DRPC_HandleJoin(const char *secret)
|
|||
free(ip);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------
|
||||
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;
|
||||
discordRequest_t *newRequest = Z_Calloc(sizeof (discordRequest_t), PU_STATIC, NULL);
|
||||
|
||||
// Discord requests exprie after 30 seconds, give 1 second of lee-way for connection discrepancies
|
||||
newRequest->timer = 29*TICRATE;
|
||||
|
||||
newRequest->username = Z_Calloc(344+1+8, PU_STATIC, NULL);
|
||||
snprintf(newRequest->username, 344+1+8, "%s#%s",
|
||||
requestUser->username,
|
||||
requestUser->discriminator
|
||||
);
|
||||
|
||||
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)
|
||||
{
|
||||
prev = append;
|
||||
append = append->next;
|
||||
}
|
||||
|
||||
newRequest->prev = prev;
|
||||
prev->next = newRequest;
|
||||
}
|
||||
else
|
||||
{
|
||||
discordRequestList = newRequest;
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------
|
||||
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);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------
|
||||
void DRPC_Init(void)
|
||||
|
||||
|
@ -153,7 +240,7 @@ void DRPC_Init(void)
|
|||
handlers.disconnected = DRPC_HandleDisconnect;
|
||||
handlers.errored = DRPC_HandleError;
|
||||
handlers.joinGame = DRPC_HandleJoin;
|
||||
//handlers.joinRequest = DRPC_HandleJoinRequest;
|
||||
handlers.joinRequest = DRPC_HandleJoinRequest;
|
||||
|
||||
Discord_Initialize(DISCORD_APPID, &handlers, 1, NULL);
|
||||
I_AddExitFunc(Discord_Shutdown);
|
||||
|
@ -347,8 +434,7 @@ void DRPC_UpdatePresence(void)
|
|||
}
|
||||
|
||||
// Gametype info
|
||||
if ((gamestate == GS_LEVEL || gamestate == GS_INTERMISSION || gamestate == GS_VOTING)
|
||||
&& !demo.playback)
|
||||
if ((gamestate == GS_LEVEL || gamestate == GS_INTERMISSION || gamestate == GS_VOTING) && Playing())
|
||||
{
|
||||
if (modeattacking)
|
||||
discordPresence.details = "Time Attack";
|
||||
|
@ -396,7 +482,7 @@ void DRPC_UpdatePresence(void)
|
|||
discordPresence.largeImageText = mapname;
|
||||
}
|
||||
|
||||
if (Playing())
|
||||
if (gamestate == GS_LEVEL && Playing())
|
||||
{
|
||||
const time_t currentTime = time(NULL);
|
||||
const time_t mapTimeStart = currentTime - ((leveltime + (modeattacking ? starttime : 0)) / TICRATE);
|
||||
|
|
|
@ -19,6 +19,32 @@
|
|||
|
||||
extern consvar_t cv_discordrp;
|
||||
|
||||
typedef struct discordRequest_s {
|
||||
tic_t timer; // Tics left on the request before it expires.
|
||||
char *username; // Discord user name + their discriminator.
|
||||
char *userID; // The ID of the Discord user, gets used with Discord_Respond()
|
||||
|
||||
// HAHAHA, no.
|
||||
// *Maybe* if it was only PNG I would boot up curl just to get AND convert this to Doom GFX,
|
||||
// but it can be a JEPG, WebP, or GIF too :)
|
||||
//patch_t *avatar;
|
||||
|
||||
struct discordRequest_s *next; // Next request in the list.
|
||||
struct discordRequest_s *prev; // Previous request in the list. Not used normally, but just in case something funky happens, this should repair the list.
|
||||
} discordRequest_t;
|
||||
|
||||
extern discordRequest_t *discordRequestList;
|
||||
|
||||
|
||||
/*--------------------------------------------------
|
||||
void DRPC_RemoveRequest(void);
|
||||
|
||||
Removes an invite from the list.
|
||||
--------------------------------------------------*/
|
||||
|
||||
void DRPC_RemoveRequest(discordRequest_t *removeRequest);
|
||||
|
||||
|
||||
/*--------------------------------------------------
|
||||
void DRPC_Init(void);
|
||||
|
||||
|
|
108
src/m_menu.c
108
src/m_menu.c
|
@ -82,6 +82,7 @@ int snprintf(char *str, size_t n, const char *fmt, ...);
|
|||
#endif
|
||||
|
||||
#ifdef HAVE_DISCORDRPC
|
||||
//#include "discord_rpc.h"
|
||||
#include "discord.h"
|
||||
#endif
|
||||
|
||||
|
@ -192,6 +193,12 @@ static void M_RoomMenu(INT32 choice);
|
|||
// the haxor message menu
|
||||
menu_t MessageDef;
|
||||
|
||||
#ifdef HAVE_DISCORDRPC
|
||||
menu_t DiscordRequestsDef;
|
||||
static void M_HandleDiscordRequests(INT32 choice);
|
||||
static void M_DrawDiscordRequests(void);
|
||||
#endif
|
||||
|
||||
menu_t SPauseDef;
|
||||
|
||||
#define lsheadingheight 16
|
||||
|
@ -662,6 +669,13 @@ typedef enum
|
|||
spause_quit
|
||||
} spause_e;
|
||||
|
||||
#ifdef HAVE_DISCORDRPC
|
||||
static menuitem_t DiscordRequestsMenu[] =
|
||||
{
|
||||
{IT_KEYHANDLER|IT_NOTHING, NULL, "", M_HandleDiscordRequests, 0},
|
||||
};
|
||||
#endif
|
||||
|
||||
// -----------------
|
||||
// Misc menu options
|
||||
// -----------------
|
||||
|
@ -1663,6 +1677,21 @@ menu_t MAPauseDef = PAUSEMENUSTYLE(MAPauseMenu, 40, 72);
|
|||
menu_t SPauseDef = PAUSEMENUSTYLE(SPauseMenu, 40, 72);
|
||||
menu_t MPauseDef = PAUSEMENUSTYLE(MPauseMenu, 40, 72);
|
||||
|
||||
#ifdef HAVE_DISCORDRPC
|
||||
static void M_HandleDiscordRequests(INT32 choice);
|
||||
static void M_DrawDiscordRequests(void);
|
||||
menu_t DiscordRequestsDef = {
|
||||
NULL,
|
||||
sizeof (DiscordRequestsMenu)/sizeof (menuitem_t),
|
||||
NULL,
|
||||
DiscordRequestsMenu,
|
||||
M_DrawDiscordRequests,
|
||||
0, 0,
|
||||
0,
|
||||
NULL
|
||||
};
|
||||
#endif
|
||||
|
||||
// Misc Main Menu
|
||||
menu_t MISC_ScrambleTeamDef = DEFAULTMENUSTYLE(NULL, MISC_ScrambleTeamMenu, &MPauseDef, 27, 40);
|
||||
menu_t MISC_ChangeTeamDef = DEFAULTMENUSTYLE(NULL, MISC_ChangeTeamMenu, &MPauseDef, 27, 40);
|
||||
|
@ -3289,6 +3318,17 @@ void M_StartControlPanel(void)
|
|||
itemOn = mpause_continue;
|
||||
}
|
||||
|
||||
#ifdef HAVE_DISCORDRPC
|
||||
// Kind of hi-jacking this...
|
||||
if (discordRequestList != NULL)
|
||||
{
|
||||
// Gotta take care of these requests first
|
||||
DiscordRequestsDef.prevMenu = currentMenu;
|
||||
currentMenu = &DiscordRequestsDef;
|
||||
itemOn = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
CON_ToggleOff(); // move away console
|
||||
}
|
||||
|
||||
|
@ -11268,3 +11308,71 @@ static void M_OGL_DrawColorMenu(void)
|
|||
highlightflags, "Gamma correction");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_DISCORDRPC
|
||||
static void M_HandleDiscordRequests(INT32 choice)
|
||||
{
|
||||
discordRequest_t *curRequest = discordRequestList;
|
||||
|
||||
if (curRequest == NULL)
|
||||
{
|
||||
if (currentMenu->prevMenu)
|
||||
M_SetupNextMenu(currentMenu->prevMenu);
|
||||
else
|
||||
M_ClearMenus(true);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
switch (choice)
|
||||
{
|
||||
case KEY_ESCAPE:
|
||||
Discord_Respond(curRequest->userID, DISCORD_REPLY_NO);
|
||||
DRPC_RemoveRequest(curRequest);
|
||||
break;
|
||||
|
||||
case KEY_ENTER:
|
||||
Discord_Respond(curRequest->userID, DISCORD_REPLY_YES);
|
||||
DRPC_RemoveRequest(curRequest);
|
||||
break;
|
||||
}
|
||||
|
||||
if (curRequest == NULL)
|
||||
{
|
||||
// was removed, we can exit menu
|
||||
if (currentMenu->prevMenu)
|
||||
M_SetupNextMenu(currentMenu->prevMenu);
|
||||
else
|
||||
M_ClearMenus(true);
|
||||
}
|
||||
}
|
||||
|
||||
static void M_DrawDiscordRequests(void)
|
||||
{
|
||||
discordRequest_t *curRequest = discordRequestList;
|
||||
|
||||
INT32 x = 64;
|
||||
INT32 y = 135;
|
||||
|
||||
if (curRequest == NULL)
|
||||
{
|
||||
// Uh oh! Shouldn't happen!
|
||||
if (currentMenu->prevMenu)
|
||||
M_SetupNextMenu(currentMenu->prevMenu);
|
||||
else
|
||||
M_ClearMenus(true);
|
||||
return;
|
||||
}
|
||||
|
||||
V_DrawThinString(x, y, V_ALLOWLOWERCASE|V_6WIDTHSPACE, curRequest->username);
|
||||
V_DrawThinString(x, y + 24, V_ALLOWLOWERCASE|V_6WIDTHSPACE, "A - Accept B - Decline");
|
||||
y -= 16;
|
||||
|
||||
while (curRequest->next != NULL)
|
||||
{
|
||||
curRequest = curRequest->next;
|
||||
V_DrawThinString(x, y, V_ALLOWLOWERCASE|V_6WIDTHSPACE, curRequest->username);
|
||||
y -= 8;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue