mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-01-30 13:10:55 +00:00
Add support for srb2:// URL handler (server links)
This commit is contained in:
parent
04131d3268
commit
feb18208cb
4 changed files with 52 additions and 5 deletions
27
src/d_main.c
27
src/d_main.c
|
@ -889,6 +889,29 @@ static void IdentifyVersion(void)
|
||||||
char *srb2wad;
|
char *srb2wad;
|
||||||
const char *srb2waddir = NULL;
|
const char *srb2waddir = NULL;
|
||||||
|
|
||||||
|
// URL handlers are opened by web browsers (at least Firefox) from the browser's working directory, not the game's stored directory,
|
||||||
|
// so chdir to that directory unless overridden.
|
||||||
|
if (M_GetUrlProtocolArg() != NULL && !M_CheckParm("-nochdir"))
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
CONS_Printf("srb2:// connect links load game files from the SRB2 application's stored directory. Switching to ");
|
||||||
|
strlcpy(srb2path, myargv[0], sizeof(srb2path));
|
||||||
|
|
||||||
|
// Get just the directory, minus the EXE name
|
||||||
|
for (i = strlen(srb2path)-1; i > 0; i--)
|
||||||
|
{
|
||||||
|
if (srb2path[i] == '/' || srb2path[i] == '\\')
|
||||||
|
{
|
||||||
|
srb2path[i] = '\0';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CONS_Printf("%s\n", srb2path);
|
||||||
|
chdir(srb2path);
|
||||||
|
}
|
||||||
|
|
||||||
#if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) || defined (HAVE_SDL)
|
#if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) || defined (HAVE_SDL)
|
||||||
// change to the directory where 'srb2.pk3' is found
|
// change to the directory where 'srb2.pk3' is found
|
||||||
srb2waddir = I_LocateWad();
|
srb2waddir = I_LocateWad();
|
||||||
|
@ -1152,7 +1175,7 @@ void D_SRB2Main(void)
|
||||||
|
|
||||||
// add any files specified on the command line with -file wadfile
|
// add any files specified on the command line with -file wadfile
|
||||||
// to the wad list
|
// to the wad list
|
||||||
if (!(M_CheckParm("-connect") && !M_CheckParm("-server")))
|
if (!((M_GetUrlProtocolArg() || M_CheckParm("-connect")) && !M_CheckParm("-server")))
|
||||||
{
|
{
|
||||||
if (M_CheckParm("-file"))
|
if (M_CheckParm("-file"))
|
||||||
{
|
{
|
||||||
|
@ -1187,7 +1210,7 @@ void D_SRB2Main(void)
|
||||||
M_InitMenuPresTables();
|
M_InitMenuPresTables();
|
||||||
|
|
||||||
// init title screen display params
|
// init title screen display params
|
||||||
if (M_CheckParm("-connect"))
|
if (M_GetUrlProtocolArg() || M_CheckParm("-connect"))
|
||||||
F_InitMenuPresValues();
|
F_InitMenuPresValues();
|
||||||
|
|
||||||
//---------------------------------------------------- READY TIME
|
//---------------------------------------------------- READY TIME
|
||||||
|
|
|
@ -1423,6 +1423,7 @@ static void SOCK_ClearBans(void)
|
||||||
boolean I_InitTcpNetwork(void)
|
boolean I_InitTcpNetwork(void)
|
||||||
{
|
{
|
||||||
char serverhostname[255];
|
char serverhostname[255];
|
||||||
|
const char *urlparam = NULL;
|
||||||
boolean ret = false;
|
boolean ret = false;
|
||||||
// initilize the OS's TCP/IP stack
|
// initilize the OS's TCP/IP stack
|
||||||
if (!I_InitTcpDriver())
|
if (!I_InitTcpDriver())
|
||||||
|
@ -1476,10 +1477,12 @@ boolean I_InitTcpNetwork(void)
|
||||||
|
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
else if (M_CheckParm("-connect"))
|
else if ((urlparam = M_GetUrlProtocolArg()) != NULL || M_CheckParm("-connect"))
|
||||||
{
|
{
|
||||||
if (M_IsNextParm())
|
if (urlparam != NULL)
|
||||||
strcpy(serverhostname, M_GetNextParm());
|
strlcpy(serverhostname, urlparam, sizeof(serverhostname));
|
||||||
|
else if (M_IsNextParm())
|
||||||
|
strlcpy(serverhostname, M_GetNextParm(), sizeof(serverhostname));
|
||||||
else
|
else
|
||||||
serverhostname[0] = 0; // assuming server in the LAN, use broadcast to detect it
|
serverhostname[0] = 0; // assuming server in the LAN, use broadcast to detect it
|
||||||
|
|
||||||
|
|
18
src/m_argv.c
18
src/m_argv.c
|
@ -34,6 +34,24 @@ boolean myargmalloc = false;
|
||||||
*/
|
*/
|
||||||
static INT32 found;
|
static INT32 found;
|
||||||
|
|
||||||
|
/** \brief Parses a server URL (such as srb2://127.0.0.1) as may be passed to the game via a web browser, etc.
|
||||||
|
|
||||||
|
\return the contents of the URL after the protocol (a server to join), or NULL if not found
|
||||||
|
*/
|
||||||
|
const char *M_GetUrlProtocolArg(void)
|
||||||
|
{
|
||||||
|
INT32 i;
|
||||||
|
|
||||||
|
for (i = 1; i < myargc; i++)
|
||||||
|
{
|
||||||
|
if (!strnicmp(myargv[i], "srb2://", 7))
|
||||||
|
{
|
||||||
|
return &myargv[i][7];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/** \brief The M_CheckParm function
|
/** \brief The M_CheckParm function
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,9 @@ extern INT32 myargc;
|
||||||
extern char **myargv;
|
extern char **myargv;
|
||||||
extern boolean myargmalloc;
|
extern boolean myargmalloc;
|
||||||
|
|
||||||
|
// Looks for an srb2:// (or similar) URL passed in as an argument and returns the IP to connect to if found.
|
||||||
|
const char *M_GetUrlProtocolArg(void);
|
||||||
|
|
||||||
// Returns the position of the given parameter in the arg list (0 if not found).
|
// Returns the position of the given parameter in the arg list (0 if not found).
|
||||||
INT32 M_CheckParm(const char *check);
|
INT32 M_CheckParm(const char *check);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue