mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2025-01-28 04:00:41 +00:00
Fix ZONE being all caps, standardize the function comments
This commit is contained in:
parent
da5bda72ee
commit
83192827dc
8 changed files with 139 additions and 41 deletions
|
@ -1382,7 +1382,7 @@ static void SV_SendServerInfo(INT32 node, tic_t servertime)
|
||||||
mapheaderinfo[gamemap-1]->lvlttl, mapheaderinfo[gamemap-1]->zonttl, mapheaderinfo[gamemap-1]->actnum) < 0)
|
mapheaderinfo[gamemap-1]->lvlttl, mapheaderinfo[gamemap-1]->zonttl, mapheaderinfo[gamemap-1]->actnum) < 0)
|
||||||
{
|
{
|
||||||
// If there's an encoding error, send UNKNOWN, we accept that the above may be truncated
|
// If there's an encoding error, send UNKNOWN, we accept that the above may be truncated
|
||||||
strncpy(netbuffer->u.serverinfo.maptitle, "UNKNOWN", 33);
|
strncpy(netbuffer->u.serverinfo.maptitle, "Unknown", 33);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1393,13 +1393,13 @@ static void SV_SendServerInfo(INT32 node, tic_t servertime)
|
||||||
mapheaderinfo[gamemap-1]->lvlttl, mapheaderinfo[gamemap-1]->zonttl) < 0)
|
mapheaderinfo[gamemap-1]->lvlttl, mapheaderinfo[gamemap-1]->zonttl) < 0)
|
||||||
{
|
{
|
||||||
// If there's an encoding error, send UNKNOWN, we accept that the above may be truncated
|
// If there's an encoding error, send UNKNOWN, we accept that the above may be truncated
|
||||||
strncpy(netbuffer->u.serverinfo.maptitle, "UNKNOWN", 33);
|
strncpy(netbuffer->u.serverinfo.maptitle, "Unknown", 33);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
strncpy(netbuffer->u.serverinfo.maptitle, "UNKNOWN", 33);
|
strncpy(netbuffer->u.serverinfo.maptitle, "Unknown", 33);
|
||||||
|
|
||||||
netbuffer->u.serverinfo.maptitle[32] = '\0';
|
netbuffer->u.serverinfo.maptitle[32] = '\0';
|
||||||
|
|
||||||
|
@ -1725,7 +1725,7 @@ static void CL_LoadReceivedSavegame(void)
|
||||||
if (strlen(mapheaderinfo[gamemap-1]->zonttl) > 0)
|
if (strlen(mapheaderinfo[gamemap-1]->zonttl) > 0)
|
||||||
CON_LogMessage(va(" %s", mapheaderinfo[gamemap-1]->zonttl));
|
CON_LogMessage(va(" %s", mapheaderinfo[gamemap-1]->zonttl));
|
||||||
else if (!(mapheaderinfo[gamemap-1]->levelflags & LF_NOZONE))
|
else if (!(mapheaderinfo[gamemap-1]->levelflags & LF_NOZONE))
|
||||||
CON_LogMessage(M_GetText(" ZONE"));
|
CON_LogMessage(M_GetText(" Zone"));
|
||||||
if (strlen(mapheaderinfo[gamemap-1]->actnum) > 0)
|
if (strlen(mapheaderinfo[gamemap-1]->actnum) > 0)
|
||||||
CON_LogMessage(va(" %s", mapheaderinfo[gamemap-1]->actnum));
|
CON_LogMessage(va(" %s", mapheaderinfo[gamemap-1]->actnum));
|
||||||
}
|
}
|
||||||
|
|
142
src/discord.c
142
src/discord.c
|
@ -34,33 +34,96 @@
|
||||||
|
|
||||||
consvar_t cv_discordrp = {"discordrp", "On", CV_SAVE|CV_CALL, CV_OnOff, DRPC_UpdatePresence, 0, NULL, NULL, 0, 0, NULL};
|
consvar_t cv_discordrp = {"discordrp", "On", CV_SAVE|CV_CALL, CV_OnOff, DRPC_UpdatePresence, 0, NULL, NULL, 0, 0, NULL};
|
||||||
|
|
||||||
//
|
#ifdef HAVE_CURL
|
||||||
// DRPC_Handle's
|
struct SelfIPbuffer
|
||||||
//
|
{
|
||||||
static inline void DRPC_HandleReady(const DiscordUser *user)
|
CURL *curl;
|
||||||
|
char *pointer;
|
||||||
|
size_t length;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define IP_SIZE 16
|
||||||
|
static char self_ip[IP_SIZE];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*--------------------------------------------------
|
||||||
|
static void DRPC_HandleReady(const DiscordUser *user)
|
||||||
|
|
||||||
|
Handler function, ran when the game connects to Discord.
|
||||||
|
|
||||||
|
Input Arguments:-
|
||||||
|
user - Struct containing Discord user info.
|
||||||
|
|
||||||
|
Return:-
|
||||||
|
None
|
||||||
|
--------------------------------------------------*/
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void DRPC_HandleDisconnect(int err, const char *msg)
|
/*--------------------------------------------------
|
||||||
|
static void DRPC_HandleDisconnect(int err, const char *msg)
|
||||||
|
|
||||||
|
Handler function, ran when disconnecting from Discord.
|
||||||
|
|
||||||
|
Input Arguments:-
|
||||||
|
err - Error type
|
||||||
|
msg - Error message
|
||||||
|
|
||||||
|
Return:-
|
||||||
|
None
|
||||||
|
--------------------------------------------------*/
|
||||||
|
static void DRPC_HandleDisconnect(int err, const char *msg)
|
||||||
{
|
{
|
||||||
CONS_Printf("Discord: disconnected (%d: %s)\n", err, msg);
|
CONS_Printf("Discord: disconnected (%d: %s)\n", err, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void DRPC_HandleError(int err, const char *msg)
|
/*--------------------------------------------------
|
||||||
|
static void DRPC_HandleError(int err, const char *msg)
|
||||||
|
|
||||||
|
Handler function, ran when Discord outputs an error.
|
||||||
|
|
||||||
|
Input Arguments:-
|
||||||
|
err - Error type
|
||||||
|
msg - Error message
|
||||||
|
|
||||||
|
Return:-
|
||||||
|
None
|
||||||
|
--------------------------------------------------*/
|
||||||
|
static void DRPC_HandleError(int err, const char *msg)
|
||||||
{
|
{
|
||||||
CONS_Alert(CONS_WARNING, "Discord: error (%d, %s)\n", err, msg);
|
CONS_Alert(CONS_WARNING, "Discord error (%d: %s)\n", err, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void DRPC_HandleJoin(const char *secret)
|
/*--------------------------------------------------
|
||||||
|
static void DRPC_HandleJoin(const char *secret)
|
||||||
|
|
||||||
|
Handler function, ran when Discord wants to
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
CONS_Printf("Discord: connecting to %s\n", secret);
|
// Yes, this is called a "secret", but we send & use it
|
||||||
|
// directly, because if you're hosting SRB2, then you've
|
||||||
|
// already made your IP address totally public.
|
||||||
|
|
||||||
|
CONS_Printf("Connecting to %s via Discord\n", secret);
|
||||||
COM_BufAddText(va("connect \"%s\"\n", secret));
|
COM_BufAddText(va("connect \"%s\"\n", secret));
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
/*--------------------------------------------------
|
||||||
// DRPC_Init: starting up the handles, call Discord_initalize
|
void DRPC_Init(void)
|
||||||
//
|
|
||||||
|
See header file for description.
|
||||||
|
--------------------------------------------------*/
|
||||||
void DRPC_Init(void)
|
void DRPC_Init(void)
|
||||||
{
|
{
|
||||||
DiscordEventHandlers handlers;
|
DiscordEventHandlers handlers;
|
||||||
|
@ -77,17 +140,21 @@ void DRPC_Init(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_CURL
|
#ifdef HAVE_CURL
|
||||||
#define IP_SIZE 16
|
/*--------------------------------------------------
|
||||||
static char self_ip[IP_SIZE];
|
static size_t DRPC_WriteServerIP(char *s, size_t size, size_t n, void *userdata)
|
||||||
|
|
||||||
struct SelfIPbuffer
|
Writing function for use with curl. Only intended to be used with simple text.
|
||||||
{
|
|
||||||
CURL *curl;
|
|
||||||
char *pointer;
|
|
||||||
size_t length;
|
|
||||||
};
|
|
||||||
|
|
||||||
static size_t DRPC_WriteServerIP(char *s, size_t size, size_t n, void *userdata )
|
Input Arguments:-
|
||||||
|
s - Data to write
|
||||||
|
size - Always 1.
|
||||||
|
n - Length of data
|
||||||
|
userdata - Passed in from CURLOPT_WRITEDATA, intended to be SelfIPbuffer
|
||||||
|
|
||||||
|
Return:-
|
||||||
|
Number of bytes wrote in this pass.
|
||||||
|
--------------------------------------------------*/
|
||||||
|
static size_t DRPC_WriteServerIP(char *s, size_t size, size_t n, void *userdata)
|
||||||
{
|
{
|
||||||
struct SelfIPbuffer *buffer;
|
struct SelfIPbuffer *buffer;
|
||||||
size_t newlength;
|
size_t newlength;
|
||||||
|
@ -106,9 +173,13 @@ static size_t DRPC_WriteServerIP(char *s, size_t size, size_t n, void *userdata
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//
|
/*--------------------------------------------------
|
||||||
// DRPC_GetServerIP: Gets the server's IP address, used to
|
static const char *DRPC_GetServerIP(void)
|
||||||
//
|
|
||||||
|
Retrieves the IP address of the server that you're
|
||||||
|
connected to. Will attempt to use curl for getting your
|
||||||
|
own IP address, if it's not yours.
|
||||||
|
--------------------------------------------------*/
|
||||||
static const char *DRPC_GetServerIP(void)
|
static const char *DRPC_GetServerIP(void)
|
||||||
{
|
{
|
||||||
const char *address;
|
const char *address;
|
||||||
|
@ -117,7 +188,11 @@ static const char *DRPC_GetServerIP(void)
|
||||||
if (I_GetNodeAddress && (address = I_GetNodeAddress(servernode)) != NULL)
|
if (I_GetNodeAddress && (address = I_GetNodeAddress(servernode)) != NULL)
|
||||||
{
|
{
|
||||||
if (strcmp(address, "self"))
|
if (strcmp(address, "self"))
|
||||||
return address; // We're not the server, so we could successfully get the IP! No problem here :)
|
{
|
||||||
|
// We're not the server, so we could successfully get the IP!
|
||||||
|
// No need to do anything else :)
|
||||||
|
return address;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_CURL
|
#ifdef HAVE_CURL
|
||||||
|
@ -133,7 +208,10 @@ static const char *DRPC_GetServerIP(void)
|
||||||
|
|
||||||
if (curl)
|
if (curl)
|
||||||
{
|
{
|
||||||
const char *api = "http://ip4only.me/api/"; // API to get your public IP address from
|
// The API to get your public IP address from.
|
||||||
|
// Picked because it's stupid simple and it's been up for a long time.
|
||||||
|
const char *api = "http://ip4only.me/api/";
|
||||||
|
|
||||||
struct SelfIPbuffer buffer;
|
struct SelfIPbuffer buffer;
|
||||||
CURLcode success;
|
CURLcode success;
|
||||||
|
|
||||||
|
@ -171,9 +249,11 @@ static const char *DRPC_GetServerIP(void)
|
||||||
return NULL; // Could not get your IP for whatever reason, so we cannot do Discord invites
|
return NULL; // Could not get your IP for whatever reason, so we cannot do Discord invites
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
/*--------------------------------------------------
|
||||||
// DRPC_UpdatePresence: Called whenever anything changes about server info
|
void DRPC_UpdatePresence(void)
|
||||||
//
|
|
||||||
|
See header file for description.
|
||||||
|
--------------------------------------------------*/
|
||||||
void DRPC_UpdatePresence(void)
|
void DRPC_UpdatePresence(void)
|
||||||
{
|
{
|
||||||
char mapimg[8+1];
|
char mapimg[8+1];
|
||||||
|
@ -271,10 +351,10 @@ void DRPC_UpdatePresence(void)
|
||||||
discordPresence.largeImageText = mapname; // Map name
|
discordPresence.largeImageText = mapname; // Map name
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gamestate == GS_LEVEL)
|
if (Playing())
|
||||||
{
|
{
|
||||||
const time_t currentTime = time(NULL);
|
const time_t currentTime = time(NULL);
|
||||||
const time_t mapTimeStart = currentTime - (leveltime / TICRATE);
|
const time_t mapTimeStart = currentTime - ((leveltime + (modeattacking ? starttime : 0)) / TICRATE);
|
||||||
|
|
||||||
discordPresence.startTimestamp = mapTimeStart;
|
discordPresence.startTimestamp = mapTimeStart;
|
||||||
|
|
||||||
|
|
|
@ -19,9 +19,27 @@
|
||||||
|
|
||||||
extern consvar_t cv_discordrp;
|
extern consvar_t cv_discordrp;
|
||||||
|
|
||||||
|
/*--------------------------------------------------
|
||||||
|
void DRPC_Init(void);
|
||||||
|
|
||||||
|
Initalizes Discord Rich Presence by linking the Application ID
|
||||||
|
and setting the handler functions.
|
||||||
|
--------------------------------------------------*/
|
||||||
|
|
||||||
void DRPC_Init(void);
|
void DRPC_Init(void);
|
||||||
|
|
||||||
|
|
||||||
|
/*--------------------------------------------------
|
||||||
|
void DRPC_UpdatePresence(void);
|
||||||
|
|
||||||
|
Updates what is displayed by Rich Presence on the user's profile.
|
||||||
|
Should be called whenever something that is displayed is
|
||||||
|
changed in-game.
|
||||||
|
--------------------------------------------------*/
|
||||||
|
|
||||||
void DRPC_UpdatePresence(void);
|
void DRPC_UpdatePresence(void);
|
||||||
|
|
||||||
|
|
||||||
#endif // HAVE_DISCORDRPC
|
#endif // HAVE_DISCORDRPC
|
||||||
|
|
||||||
#endif // __DISCORD__
|
#endif // __DISCORD__
|
||||||
|
|
|
@ -4725,7 +4725,7 @@ char *G_BuildMapTitle(INT32 mapnum)
|
||||||
}
|
}
|
||||||
else if (!(mapheaderinfo[mapnum-1]->levelflags & LF_NOZONE))
|
else if (!(mapheaderinfo[mapnum-1]->levelflags & LF_NOZONE))
|
||||||
{
|
{
|
||||||
zonetext = M_GetText("ZONE");
|
zonetext = M_GetText("Zone");
|
||||||
len += strlen(zonetext) + 1; // ' ' + zonetext
|
len += strlen(zonetext) + 1; // ' ' + zonetext
|
||||||
}
|
}
|
||||||
if (strlen(mapheaderinfo[mapnum-1]->actnum) > 0)
|
if (strlen(mapheaderinfo[mapnum-1]->actnum) > 0)
|
||||||
|
|
|
@ -7474,7 +7474,7 @@ static void M_DrawStatsMaps(int location)
|
||||||
else
|
else
|
||||||
V_DrawString(20, y, 0, va("%s %s %s",
|
V_DrawString(20, y, 0, va("%s %s %s",
|
||||||
mapheaderinfo[mnum]->lvlttl,
|
mapheaderinfo[mnum]->lvlttl,
|
||||||
(mapheaderinfo[mnum]->zonttl[0] ? mapheaderinfo[mnum]->zonttl : "ZONE"),
|
(mapheaderinfo[mnum]->zonttl[0] ? mapheaderinfo[mnum]->zonttl : "Zone"),
|
||||||
mapheaderinfo[mnum]->actnum));
|
mapheaderinfo[mnum]->actnum));
|
||||||
|
|
||||||
y += 8;
|
y += 8;
|
||||||
|
|
|
@ -2974,7 +2974,7 @@ boolean P_SetupLevel(boolean skipprecip)
|
||||||
snprintf(tx, 63, "%s%s%s",
|
snprintf(tx, 63, "%s%s%s",
|
||||||
mapheaderinfo[gamemap-1]->lvlttl,
|
mapheaderinfo[gamemap-1]->lvlttl,
|
||||||
(strlen(mapheaderinfo[gamemap-1]->zonttl) > 0) ? va(" %s",mapheaderinfo[gamemap-1]->zonttl) : // SRB2kart
|
(strlen(mapheaderinfo[gamemap-1]->zonttl) > 0) ? va(" %s",mapheaderinfo[gamemap-1]->zonttl) : // SRB2kart
|
||||||
((mapheaderinfo[gamemap-1]->levelflags & LF_NOZONE) ? "" : " ZONE"),
|
((mapheaderinfo[gamemap-1]->levelflags & LF_NOZONE) ? "" : " Zone"),
|
||||||
(strlen(mapheaderinfo[gamemap-1]->actnum) > 0) ? va(", Act %s",mapheaderinfo[gamemap-1]->actnum) : "");
|
(strlen(mapheaderinfo[gamemap-1]->actnum) > 0) ? va(", Act %s",mapheaderinfo[gamemap-1]->actnum) : "");
|
||||||
V_DrawSmallString(1, 195, V_ALLOWLOWERCASE, tx);
|
V_DrawSmallString(1, 195, V_ALLOWLOWERCASE, tx);
|
||||||
I_UpdateNoVsync();
|
I_UpdateNoVsync();
|
||||||
|
|
|
@ -776,7 +776,7 @@ static void ST_drawLevelTitle(void)
|
||||||
if (zonttl[0])
|
if (zonttl[0])
|
||||||
zonexpos -= V_LevelNameWidth(zonttl); // SRB2kart
|
zonexpos -= V_LevelNameWidth(zonttl); // SRB2kart
|
||||||
else
|
else
|
||||||
zonexpos -= V_LevelNameWidth(M_GetText("ZONE"));
|
zonexpos -= V_LevelNameWidth(M_GetText("Zone"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lvlttlxpos < 0)
|
if (lvlttlxpos < 0)
|
||||||
|
@ -813,7 +813,7 @@ static void ST_drawLevelTitle(void)
|
||||||
if (strlen(zonttl) > 0)
|
if (strlen(zonttl) > 0)
|
||||||
V_DrawLevelTitle(zonexpos, bary+6, 0, zonttl);
|
V_DrawLevelTitle(zonexpos, bary+6, 0, zonttl);
|
||||||
else if (!(mapheaderinfo[gamemap-1]->levelflags & LF_NOZONE))
|
else if (!(mapheaderinfo[gamemap-1]->levelflags & LF_NOZONE))
|
||||||
V_DrawLevelTitle(zonexpos, bary+6, 0, M_GetText("ZONE"));
|
V_DrawLevelTitle(zonexpos, bary+6, 0, M_GetText("Zone"));
|
||||||
|
|
||||||
if (actnum[0])
|
if (actnum[0])
|
||||||
V_DrawLevelTitle(ttlnumxpos+12, bary+6, 0, actnum);
|
V_DrawLevelTitle(ttlnumxpos+12, bary+6, 0, actnum);
|
||||||
|
|
|
@ -233,7 +233,7 @@ static void Y_CalculateMatchData(UINT8 rankingsmode, void (*comparison)(INT32))
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const char *zonttl = (mapheaderinfo[prevmap]->zonttl[0] ? mapheaderinfo[prevmap]->zonttl : "ZONE");
|
const char *zonttl = (mapheaderinfo[prevmap]->zonttl[0] ? mapheaderinfo[prevmap]->zonttl : "Zone");
|
||||||
if (mapheaderinfo[prevmap]->actnum[0])
|
if (mapheaderinfo[prevmap]->actnum[0])
|
||||||
snprintf(data.match.levelstring,
|
snprintf(data.match.levelstring,
|
||||||
sizeof data.match.levelstring,
|
sizeof data.match.levelstring,
|
||||||
|
|
Loading…
Reference in a new issue