2016-07-12 00:40:13 +00:00
# include "../plugin.h"
2019-09-04 07:59:40 +00:00
static plugsubconsolefuncs_t * confuncs ;
static plugfsfuncs_t * filefuncs ;
static plugclientfuncs_t * clientfuncs ;
2016-07-12 00:40:13 +00:00
# include "../jabber/xml.h"
# define DATABASEURL "https: //www.quaddicted.com/reviews/quaddicted_database.xml"
# define FILEIMAGEURL "https: //www.quaddicted.com/reviews/screenshots/%s_injector.jpg"
# define FILEDOWNLOADURL "https: //www.quaddicted.com/filebase/%s.zip"
# define WINDOWTITLE "Quaddicted Map+Mod Archive"
# define WINDOWNAME "QI"
/*
< file id = " downloadname " type = " 1=map. 2=mod " rating = " 5-star-rating " >
< author > meh < / author >
< title > some readable name < / title >
< md5sum > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx < / md5sum >
< size > size - in - kb < / size >
< date > dd . mm . yy < / date >
< description > HTML - encoded text . just to be awkward < / description >
< techinfo >
< zipbasedir > additional path needed to make it relative to the quake directory < / zipbasedir >
< requirements >
< file id = " quoth " / >
< / requirements >
< / techinfo >
< / file >
*/
2019-06-21 03:59:46 +00:00
static xmltree_t * thedatabase ;
static qhandle_t dlcontext = - 1 ;
2016-07-12 00:40:13 +00:00
2019-06-21 03:59:46 +00:00
static struct
2016-07-12 00:40:13 +00:00
{
char namefilter [ 256 ] ;
int minrating ;
int maxrating ;
int type ;
} filters ;
2019-09-04 07:59:40 +00:00
static struct
{
int width ;
int height ;
} pvid ;
static void QDECL QI_UpdateVideo ( int width , int height )
{
pvid . width = width ;
pvid . height = height ;
}
void Con_SubPrintf ( const char * subname , char * format , . . . )
2016-07-12 00:40:13 +00:00
{
va_list argptr ;
static char string [ 8192 ] ;
va_start ( argptr , format ) ;
Q_vsnprintf ( string , sizeof ( string ) , format , argptr ) ;
va_end ( argptr ) ;
2019-09-04 07:59:40 +00:00
confuncs - > SubPrint ( subname , string ) ;
2016-07-12 00:40:13 +00:00
}
2019-09-04 07:59:40 +00:00
static void QI_Shutdown ( void )
2016-07-12 00:40:13 +00:00
{
if ( dlcontext ! = - 1 )
{ //we're still downloading something? :o
2019-09-04 07:59:40 +00:00
filefuncs - > Close ( dlcontext ) ;
2016-07-12 00:40:13 +00:00
dlcontext = - 1 ;
}
if ( thedatabase )
XML_Destroy ( thedatabase ) ;
thedatabase = NULL ;
}
2018-10-11 10:31:23 +00:00
static qboolean QI_SetupWindow ( const char * console , qboolean force )
2016-07-12 00:40:13 +00:00
{
2019-09-04 07:59:40 +00:00
if ( ! confuncs )
2016-07-12 00:40:13 +00:00
return false ;
//only redraw the window if it actually exists. if they closed it, then don't mess things up.
2019-09-04 07:59:40 +00:00
if ( ! force & & confuncs - > GetConsoleFloat ( console , " iswindow " ) < = 0 )
2016-07-12 00:40:13 +00:00
return false ;
2019-09-04 07:59:40 +00:00
if ( confuncs - > GetConsoleFloat ( console , " iswindow " ) ! = true )
2016-07-12 00:40:13 +00:00
{
2019-09-04 07:59:40 +00:00
confuncs - > SetConsoleString ( console , " title " , WINDOWTITLE ) ;
confuncs - > SetConsoleFloat ( console , " iswindow " , true ) ;
confuncs - > SetConsoleFloat ( console , " forceutf8 " , true ) ;
confuncs - > SetConsoleFloat ( console , " linebuffered " , false ) ;
confuncs - > SetConsoleFloat ( console , " maxlines " , 16384 ) ; //the line limit is more a sanity thing than anything else. so long as we explicitly clear before spamming more, then its not an issue...
confuncs - > SetConsoleFloat ( console , " wnd_x " , 8 ) ;
confuncs - > SetConsoleFloat ( console , " wnd_y " , 8 ) ;
confuncs - > SetConsoleFloat ( console , " wnd_w " , pvid . width - 16 ) ;
confuncs - > SetConsoleFloat ( console , " wnd_h " , pvid . height - 16 ) ;
confuncs - > SetConsoleString ( console , " footer " , " " ) ;
2016-07-12 00:40:13 +00:00
}
2019-09-04 07:59:40 +00:00
confuncs - > SetConsoleFloat ( console , " linecount " , 0 ) ; //clear it
2016-07-12 00:40:13 +00:00
if ( force )
2019-09-04 07:59:40 +00:00
confuncs - > SetActive ( console ) ;
2016-07-12 00:40:13 +00:00
return true ;
}
2018-10-11 10:31:23 +00:00
static void QI_DeHTML ( const char * in , char * out , size_t outsize )
2016-07-12 00:40:13 +00:00
{
outsize - - ;
while ( * in & & outsize > 0 )
{
if ( * in = = ' \r ' | | * in = = ' \n ' )
in + + ;
else if ( * in = = ' < ' )
{
char tag [ 256 ] ;
int i ;
qboolean open = false ;
qboolean close = false ;
in + + ;
if ( * in = = ' / ' )
{
in + + ;
close = true ;
}
else
open = true ;
while ( * in = = ' ' | | * in = = ' \n ' | | * in = = ' \t ' | | * in = = ' \r ' )
in + + ;
for ( i = 0 ; i < countof ( tag ) - 1 ; )
{
if ( * in = = ' > ' )
break ;
if ( ! * in | | * in = = ' ' | | * in = = ' \n ' | | * in = = ' \t ' | | * in = = ' \r ' | | ( in [ 0 ] = = ' / ' & & in [ 1 ] = = ' > ' ) )
break ;
tag [ i + + ] = * in + + ;
}
tag [ i ] = 0 ;
while ( * in & & * in )
{
if ( * in = = ' / ' & & in [ 1 ] = = ' > ' )
{
in + = 2 ;
close = true ;
break ;
}
if ( * in + + = = ' > ' )
break ;
}
if ( ! strcmp ( tag , " br " ) & & open & & outsize > 0 )
{ //new lines!
* out + + = ' \n ' ;
outsize - - ;
}
else if ( ! strcmp ( tag , " b " ) & & open ! = close & & outsize > 1 )
{ //bold
* out + + = ' ^ ' ;
outsize - - ;
* out + + = ' a ' ;
outsize - - ;
}
else if ( ! strcmp ( tag , " i " ) & & open ! = close & & outsize > 1 )
{ //italics
* out + + = ' ^ ' ;
outsize - - ;
2018-06-02 08:55:57 +00:00
* out + + = close ? ' 7 ' : ' 3 ' ;
2016-07-12 00:40:13 +00:00
outsize - - ;
}
}
else if ( * in = = ' ^ ' )
{
if ( outsize > 1 )
{
* out + + = * in ;
outsize - - ;
* out + + = * in + + ;
outsize - - ;
}
}
else
{
* out + + = * in + + ;
outsize - - ;
}
}
* out = 0 ;
}
static char * QI_strcasestr ( const char * haystack , const char * needle )
{
int c1 , c2 , c2f ;
int i ;
c2f = * needle ;
if ( c2f > = ' a ' & & c2f < = ' z ' )
c2f - = ( ' a ' - ' A ' ) ;
if ( ! c2f )
return ( char * ) haystack ;
while ( 1 )
{
c1 = * haystack ;
if ( ! c1 )
return NULL ;
if ( c1 > = ' a ' & & c1 < = ' z ' )
c1 - = ( ' a ' - ' A ' ) ;
if ( c1 = = c2f )
{
for ( i = 1 ; ; i + + )
{
c1 = haystack [ i ] ;
c2 = needle [ i ] ;
if ( c1 > = ' a ' & & c1 < = ' z ' )
c1 - = ( ' a ' - ' A ' ) ;
if ( c2 > = ' a ' & & c2 < = ' z ' )
c2 - = ( ' a ' - ' A ' ) ;
if ( ! c2 )
return ( char * ) haystack ; //end of needle means we found a complete match
if ( ! c1 ) //end of haystack means we can't possibly find needle in it any more
return NULL ;
if ( c1 ! = c2 ) //mismatch means no match starting at haystack[0]
break ;
}
}
haystack + + ;
}
return NULL ; //didn't find it
}
2018-10-11 10:31:23 +00:00
static void QI_RefreshMapList ( qboolean forcedisplay )
2016-07-12 00:40:13 +00:00
{
xmltree_t * file ;
const char * console = WINDOWNAME ;
char descbuf [ 1024 ] ;
2019-06-21 03:59:46 +00:00
float donestats [ 4 ] ;
2016-07-12 00:40:13 +00:00
if ( ! QI_SetupWindow ( console , forcedisplay ) )
return ;
if ( ! thedatabase )
{
if ( dlcontext ! = - 1 )
Con_SubPrintf ( console , " Downloading database... \n " ) ;
else
Con_SubPrintf ( console , " Unable to download HTTP database \n " ) ;
return ;
}
if ( ! thedatabase - > child )
{
Con_SubPrintf ( console , " No maps in database... SPIRIT! YOU BROKE IT! \n " ) ;
return ;
}
for ( file = thedatabase - > child ; file ; file = file - > sibling )
{
2017-10-12 12:02:25 +00:00
const char * id = XML_GetParameter ( file , " id " , " unnamed " ) ;
const char * rating = XML_GetParameter ( file , " rating " , " " ) ;
2016-07-12 00:40:13 +00:00
int ratingnum = atoi ( rating ) ;
2017-10-12 12:02:25 +00:00
const char * author = XML_GetChildBody ( file , " author " , " unknown " ) ;
const char * desc = XML_GetChildBody ( file , " description " , " <NO DESCRIPTION> " ) ;
const char * type ;
const char * date ;
2016-07-12 00:40:13 +00:00
int year , month , day ;
int startmapnum , i ;
char ratingtext [ 65 ] ;
xmltree_t * tech ;
xmltree_t * startmap ;
if ( strcmp ( file - > name , " file " ) )
continue ; //erk?
if ( atoi ( XML_GetParameter ( file , " hide " , " " ) ) | | atoi ( XML_GetParameter ( file , " fte_hide " , " " ) ) )
continue ;
type = XML_GetParameter ( file , " type " , " " ) ;
if ( filters . type & & atoi ( type ) ! = filters . type )
continue ;
switch ( atoi ( type ) )
{
case 1 :
2019-06-21 03:59:46 +00:00
type = " map " ; //'single map file(s)'
2016-07-12 00:40:13 +00:00
break ;
case 2 :
2019-06-21 03:59:46 +00:00
type = " mod " ; //'Partial conversion'
break ;
case 4 :
type = " spd " ; //'speedmapping'
2016-07-12 00:40:13 +00:00
break ;
case 5 :
2019-06-21 03:59:46 +00:00
type = " otr " ; //'misc files'
2016-07-12 00:40:13 +00:00
break ;
default :
2019-06-21 03:59:46 +00:00
type = " ??? " ; //no idea
2016-07-12 00:40:13 +00:00
break ;
}
if ( filters . maxrating > = 0 & & ratingnum > filters . maxrating )
continue ;
if ( filters . minrating > = 0 & & ratingnum < filters . minrating )
continue ;
tech = XML_ChildOfTree ( file , " techinfo " , 0 ) ;
//if the filter isn't contained in the id/desc then don't display it.
2018-08-04 19:00:19 +00:00
if ( * filters . namefilter )
2016-07-12 00:40:13 +00:00
{
if ( ! QI_strcasestr ( id , filters . namefilter ) & & ! QI_strcasestr ( desc , filters . namefilter ) & & ! QI_strcasestr ( author , filters . namefilter ) )
{
//check map list too
for ( startmapnum = 0 ; ; startmapnum + + )
{
startmap = XML_ChildOfTree ( tech , " startmap " , startmapnum ) ;
if ( ! startmap )
break ;
if ( QI_strcasestr ( startmap - > body , filters . namefilter ) )
break ;
}
if ( ! startmap )
continue ;
}
}
if ( ratingnum > ( sizeof ( ratingtext ) - 5 ) / 6 )
ratingnum = ( sizeof ( ratingtext ) - 5 ) / 6 ;
if ( ratingnum )
{
Q_snprintf ( ratingtext , sizeof ( ratingtext ) , " ^a " ) ;
for ( i = 0 ; i < ratingnum ; i + + )
Q_snprintf ( ratingtext + i + 2 , sizeof ( ratingtext ) - i * 2 + 2 , " * " ) ;
Q_snprintf ( ratingtext + i + 2 , sizeof ( ratingtext ) - i * 2 + 2 , " ^a " ) ;
}
else if ( * rating )
Q_snprintf ( ratingtext , sizeof ( ratingtext ) , " %s " , rating ) ;
else
Q_snprintf ( ratingtext , sizeof ( ratingtext ) , " %s " , " unrated " ) ;
date = XML_GetChildBody ( file , " date " , " 1.1.1990 " ) ;
day = atoi ( date ? date : " 1 " ) ;
date = date ? strchr ( date , ' . ' ) : NULL ;
month = atoi ( date ? date + 1 : " 1 " ) ;
date = date ? strchr ( date , ' . ' ) : NULL ;
year = atoi ( date ? date + 1 : " 1990 " ) ;
if ( year < 90 )
year + = 2000 ;
else if ( year < 1900 )
year + = 1900 ;
2019-06-21 03:59:46 +00:00
Q_snprintf ( descbuf , sizeof ( descbuf ) , " ^aId:^a %s \n ^aAuthor(s):^a %s \n ^aDate:^a %04u-%02u-%02u \n ^aRating:^a %s \n \n " , id , author , year , month , day , ratingtext ) ;
2016-07-12 00:40:13 +00:00
QI_DeHTML ( desc , descbuf + strlen ( descbuf ) , sizeof ( descbuf ) - strlen ( descbuf ) ) ;
desc = descbuf ;
2019-06-21 03:59:46 +00:00
Con_SubPrintf ( console , " %s %s ^[^4%s: ^1%s \\ tip \\ %s \\ tipimg \\ " FILEIMAGEURL " \\ id \\ %s^] " , type , ratingtext , id , XML_GetChildBody ( file , " title " , " <NO TITLE> " ) , desc , id , id ) ;
2016-07-12 00:40:13 +00:00
for ( startmapnum = 0 ; ; startmapnum + + )
{
2019-06-21 03:59:46 +00:00
char bspfile [ MAX_QPATH ] ;
2016-07-12 00:40:13 +00:00
startmap = XML_ChildOfTree ( tech , " startmap " , startmapnum ) ;
if ( ! startmap )
break ;
2019-06-21 03:59:46 +00:00
Q_snprintf ( bspfile , sizeof ( bspfile ) , " maps/%s.bsp " , startmap - > body ) ;
2019-09-04 07:59:40 +00:00
if ( clientfuncs & & clientfuncs - > MapLog_Query ( va ( FILEDOWNLOADURL , id ) , bspfile , donestats ) )
Con_SubPrintf ( console , " ^[^2[%s, complete %.1f] \\ tip \\ ^7^aBest Time:^a ^2%.9f^7 \n ^aCompletion Time:^a %.9f \n ^aKills:^a %.9f \n ^aSecrets:^a %.9f \n \n \n %s " /*"\\tipimg\\"FILEIMAGEURL*/ " \\ id \\ %s \\ startmap \\ %s^] " , startmap - > body , donestats [ 0 ] , donestats [ 0 ] , donestats [ 1 ] , donestats [ 2 ] , donestats [ 3 ] , desc , /*id,*/ id , startmap - > body ) ;
2019-06-21 03:59:46 +00:00
else
2019-09-04 07:59:40 +00:00
Con_SubPrintf ( console , " ^[^4[%s] \\ tip \\ %s " /*"\\tipimg\\"FILEIMAGEURL*/ " \\ id \\ %s \\ startmap \\ %s^] " , startmap - > body , desc , /*id,*/ id , startmap - > body ) ;
2016-07-12 00:40:13 +00:00
}
2019-06-21 03:59:46 +00:00
Con_SubPrintf ( console , " \n " ) ;
2016-07-12 00:40:13 +00:00
}
Con_SubPrintf ( console , " \n Filter: \n " ) ;
if ( * filters . namefilter )
Con_SubPrintf ( console , " Contains: %s " , filters . namefilter ) ;
Con_SubPrintf ( console , " ^[Change Filter^] \n " ) ;
Con_SubPrintf ( console , " ^[Maps^] %s \n " , ( filters . type ! = 2 ) ? " shown " : " hidden " ) ;
Con_SubPrintf ( console , " ^[Mods^] %s \n " , ( filters . type ! = 1 ) ? " shown " : " hidden " ) ;
if ( filters . minrating = = filters . maxrating )
{
char * gah [ ] = { " Any Rating " , " Unrated " , " 1 " , " 2 " , " 3 " , " 4 " , " 5 " } ;
int i ;
Con_SubPrintf ( console , " Rating " ) ;
for ( i = 0 ; i < countof ( gah ) ; i + + )
{
if ( i = = filters . minrating + 1 )
Con_SubPrintf ( console , " %s " , gah [ i ] ) ;
else
Con_SubPrintf ( console , " ^[%s^] " , gah [ i ] ) ;
}
Con_SubPrintf ( console , " \n " ) ;
}
else
{
if ( filters . minrating )
Con_SubPrintf ( console , " Min Rating: %i stars \n " , filters . minrating ) ;
if ( filters . maxrating )
Con_SubPrintf ( console , " Max Rating: %i stars \n " , filters . maxrating ) ;
}
}
static void QI_UpdateFilter ( char * filtertext )
{
if ( ! strcmp ( filtertext , " all " ) )
{
filters . type = 0 ;
filters . minrating = filters . maxrating = - 1 ;
Q_strlcpy ( filters . namefilter , " " , sizeof ( filters . namefilter ) ) ;
}
else if ( * filtertext = = ' > ' )
filters . minrating = atoi ( filtertext + 1 ) ;
else if ( * filtertext = = ' < ' )
filters . maxrating = atoi ( filtertext + 1 ) ;
else if ( * filtertext = = ' = ' )
filters . minrating = filters . maxrating = atoi ( filtertext + 1 ) ;
else if ( ! strcmp ( filtertext , " any " ) )
{
filters . type = 0 ;
filters . minrating = filters . maxrating = - 1 ;
}
else if ( ! strcmp ( filtertext , " maps " ) )
filters . type = 1 ;
else if ( ! strcmp ( filtertext , " mods " ) )
filters . type = 2 ;
else
Q_strlcpy ( filters . namefilter , filtertext , sizeof ( filters . namefilter ) ) ;
}
static xmltree_t * QI_FindArchive ( const char * name )
{
xmltree_t * file ;
for ( file = thedatabase - > child ; file ; file = file - > sibling )
{
2017-10-12 12:02:25 +00:00
const char * id = XML_GetParameter ( file , " id " , " unnamed " ) ;
2016-07-12 00:40:13 +00:00
if ( strcmp ( file - > name , " file " ) )
continue ; //erk?
if ( ! strcmp ( id , name ) )
return file ;
}
return NULL ;
}
static void QI_AddPackages ( xmltree_t * qifile )
{
2017-10-12 12:02:25 +00:00
const char * id ;
2016-07-12 00:40:13 +00:00
char extra [ 1024 ] ;
char clean [ 512 ] ;
2021-04-14 05:21:04 +00:00
const char * hash ;
2016-07-12 00:40:13 +00:00
unsigned int i ;
xmltree_t * tech ;
const char * basedir ;
xmltree_t * requires ;
xmltree_t * req ;
//quaddicted's database contains various zips that are meant to be extracted to various places.
//this can either be the quake root (no path), a mod directory (typically the name of the mod), or the maps directory (id1/maps or some such)
//unfortunately, quake files are relative to the subdir, so we need to strip the first subdir. anyone that tries to put dlls in there is evil. and if there isn't one, we need to get the engine to compensate.
//we also need to clean up the paths so they're not badly formed
tech = XML_ChildOfTree ( qifile , " techinfo " , 0 ) ;
basedir = XML_GetChildBody ( tech , " zipbasedir " , " " ) ;
//skip any dodgy leading slashes
while ( * basedir = = ' / ' | | * basedir = = ' \\ ' )
basedir + + ;
if ( ! * basedir )
strcpy ( clean , " .. " ) ; //err, there wasn't a directory... we still need to 'strip' it though.
else
{
//skip the gamedir
while ( * basedir & & * basedir ! = ' / ' & & * basedir ! = ' \\ ' )
basedir + + ;
//skip any trailing
while ( * basedir = = ' / ' | | * basedir = = ' \\ ' )
basedir + + ;
for ( i = 0 ; * basedir ; i + + )
{
if ( i > = sizeof ( clean ) - 1 )
break ;
if ( * basedir = = ' \\ ' ) //sigh
clean [ i ] = ' / ' ;
else
clean [ i ] = * basedir ;
basedir + + ;
}
while ( i > 0 & & clean [ i - 1 ] = = ' / ' )
i - - ;
clean [ i ] = 0 ;
}
requires = XML_ChildOfTree ( tech , " requirements " , 0 ) ;
if ( requires )
{
for ( i = 0 ; ; i + + )
{
req = XML_ChildOfTree ( requires , " file " , i ) ;
if ( ! req )
break ;
id = XML_GetParameter ( req , " id " , " unknown " ) ;
QI_AddPackages ( QI_FindArchive ( id ) ) ;
}
}
2021-04-14 05:21:04 +00:00
hash = XML_GetChildBody ( qifile , " md5hash " , " " ) ;
if ( strchr ( hash , ' \\ ' ) | | strchr ( hash , ' \" ' ) ) //if it has a dodgy escape-breaking char then drop it.
hash = " " ;
2016-07-12 00:40:13 +00:00
id = XML_GetParameter ( qifile , " id " , " unknown " ) ;
if ( strchr ( clean , ' \\ ' ) | | strchr ( clean , ' \" ' ) | | strchr ( clean , ' \n ' ) | | strchr ( clean , ' ; ' ) )
return ;
if ( strchr ( id , ' \\ ' ) | | strchr ( id , ' \" ' ) | | strchr ( id , ' \n ' ) | | strchr ( id , ' ; ' ) )
return ;
2021-04-14 05:21:04 +00:00
Q_snprintf ( extra , sizeof ( extra ) , " package \" " FILEDOWNLOADURL " \" prefix \" %s \" hash \" md5:%s \" " , id , clean , hash ) ;
2019-09-04 07:59:40 +00:00
cmdfuncs - > AddText ( extra , false ) ;
2016-07-12 00:40:13 +00:00
}
static void QI_RunMap ( xmltree_t * qifile , const char * map )
{
if ( ! qifile )
{
return ;
}
//type 1 (maps) often don't list any map names
if ( ! * map ) // && atoi(XML_GetParameter(qifile, "type", "0")) == 1)
map = XML_GetParameter ( qifile , " id " , " unknown " ) ;
if ( ! * map | | strchr ( map , ' \\ ' ) | | strchr ( map , ' \" ' ) | | strchr ( map , ' \n ' ) | | strchr ( map , ' ; ' ) )
map = " " ;
2019-09-04 07:59:40 +00:00
cmdfuncs - > AddText ( " fs_changemod spmap \" " , false ) ;
cmdfuncs - > AddText ( map , false ) ;
cmdfuncs - > AddText ( " \" " , false ) ;
2016-07-12 00:40:13 +00:00
QI_AddPackages ( qifile ) ;
// Con_Printf("Command: %s\n", cmd);
2019-09-04 07:59:40 +00:00
cmdfuncs - > AddText ( " \n " , false ) ;
2016-07-12 00:40:13 +00:00
}
2019-09-04 07:59:40 +00:00
static qboolean QDECL QI_ConsoleLink ( void )
2016-07-12 00:40:13 +00:00
{
xmltree_t * file ;
char * map ;
char * id ;
char * e ;
char text [ 2048 ] ;
char link [ 8192 ] ;
2019-09-04 07:59:40 +00:00
cmdfuncs - > Argv ( 0 , text , sizeof ( text ) ) ;
cmdfuncs - > Argv ( 1 , link , sizeof ( link ) ) ;
2016-07-12 00:40:13 +00:00
if ( ! strcmp ( text , " Change Filter " ) & & ! * link )
{
const char * console = WINDOWNAME ;
2019-09-04 07:59:40 +00:00
confuncs - > SetConsoleFloat ( console , " linebuffered " , true ) ;
confuncs - > SetConsoleString ( console , " footer " , " Please enter filter: " ) ;
2016-07-12 00:40:13 +00:00
return true ;
}
if ( ! strcmp ( text , " Maps " ) & & ! * link )
{
filters . type = ( filters . type = = 2 ) ? 0 : 2 ;
QI_RefreshMapList ( true ) ;
return true ;
}
if ( ! strcmp ( text , " Mods " ) & & ! * link )
{
filters . type = ( filters . type = = 1 ) ? 0 : 1 ;
QI_RefreshMapList ( true ) ;
return true ;
}
if ( ! strcmp ( text , " Any Rating " ) & & ! * link )
{
filters . minrating = filters . maxrating = - 1 ;
QI_RefreshMapList ( true ) ;
return true ;
}
if ( ( atoi ( text ) | | ! strcmp ( text , " Unrated " ) ) & & ! * link )
{
filters . minrating = filters . maxrating = atoi ( text ) ;
QI_RefreshMapList ( true ) ;
return true ;
}
id = strstr ( link , " \\ id \\ " ) ;
map = strstr ( link , " \\ startmap \\ " ) ;
if ( id )
{
id + = 4 ;
e = strchr ( id , ' \\ ' ) ;
if ( e )
* e = 0 ;
if ( map )
{
map + = 10 ;
e = strchr ( map , ' \\ ' ) ;
if ( e )
* e = 0 ;
}
else
map = " " ;
file = QI_FindArchive ( id ) ;
if ( ! file )
{
Con_Printf ( " Unknown file \" %s \" \n " , id ) ;
return true ;
}
QI_RunMap ( file , map ) ;
return true ;
}
return false ;
}
2019-09-04 07:59:40 +00:00
static void QDECL QI_Tick ( double realtime , double gametime )
2016-07-12 00:40:13 +00:00
{
if ( dlcontext ! = - 1 )
{
2019-09-04 07:59:40 +00:00
qofs_t flen ;
if ( filefuncs - > GetLen ( dlcontext , & flen ) )
2016-07-12 00:40:13 +00:00
{
int ofs = 0 ;
char * file ;
qboolean archive = true ;
if ( flen = = 0 )
{
2019-09-04 07:59:40 +00:00
filefuncs - > Close ( dlcontext ) ;
flen = filefuncs - > Open ( " **plugconfig " , & dlcontext , 1 ) ;
2016-07-12 00:40:13 +00:00
if ( dlcontext = = - 1 )
{
QI_RefreshMapList ( false ) ;
2019-09-04 07:59:40 +00:00
return ;
2016-07-12 00:40:13 +00:00
}
archive = false ;
}
file = malloc ( flen + 1 ) ;
file [ flen ] = 0 ;
2019-09-04 07:59:40 +00:00
filefuncs - > Read ( dlcontext , file , flen ) ;
filefuncs - > Close ( dlcontext ) ;
2016-07-12 00:40:13 +00:00
if ( archive )
{
2019-09-04 07:59:40 +00:00
filefuncs - > Open ( " **plugconfig " , & dlcontext , 2 ) ;
2016-07-12 00:40:13 +00:00
if ( dlcontext ! = - 1 )
{
2019-09-04 07:59:40 +00:00
filefuncs - > Write ( dlcontext , file , flen ) ;
filefuncs - > Close ( dlcontext ) ;
2016-07-12 00:40:13 +00:00
}
}
dlcontext = - 1 ;
do
{
if ( thedatabase )
XML_Destroy ( thedatabase ) ;
thedatabase = XML_Parse ( file , & ofs , flen , false , " " ) ;
} while ( thedatabase & & ! thedatabase - > child ) ;
free ( file ) ;
QI_RefreshMapList ( false ) ;
// XML_ConPrintTree(thedatabase, "quadicted_xml", 0);
}
}
}
2019-09-04 07:59:40 +00:00
static int QDECL QI_ConExecuteCommand ( qboolean isinsecure )
2016-07-12 00:40:13 +00:00
{
char console [ 256 ] ;
char filter [ 256 ] ;
2019-09-04 07:59:40 +00:00
if ( isinsecure )
return false ;
cmdfuncs - > Argv ( 0 , console , sizeof ( console ) ) ;
cmdfuncs - > Args ( filter , sizeof ( filter ) ) ;
2016-07-12 00:40:13 +00:00
QI_UpdateFilter ( filter ) ;
QI_RefreshMapList ( true ) ;
2019-09-04 07:59:40 +00:00
confuncs - > SetConsoleFloat ( console , " linebuffered " , false ) ;
confuncs - > SetConsoleString ( console , " footer " , " " ) ;
2016-07-12 00:40:13 +00:00
return true ;
}
2019-09-04 07:59:40 +00:00
static qboolean QI_ExecuteCommand ( qboolean isinsecure )
2016-07-12 00:40:13 +00:00
{
char cmd [ 256 ] ;
2019-09-04 07:59:40 +00:00
cmdfuncs - > Argv ( 0 , cmd , sizeof ( cmd ) ) ;
2016-07-12 00:40:13 +00:00
if ( ! strcmp ( cmd , " qi " ) | | ! strcmp ( cmd , " quaddicted " ) )
{
2019-09-04 07:59:40 +00:00
if ( cmdfuncs - > Argc ( ) > 1 )
2016-07-12 00:40:13 +00:00
{
2019-09-04 07:59:40 +00:00
cmdfuncs - > Args ( cmd , sizeof ( cmd ) ) ;
2016-07-12 00:40:13 +00:00
QI_UpdateFilter ( cmd ) ;
}
else if ( QI_SetupWindow ( WINDOWNAME , false ) )
{
2019-09-04 07:59:40 +00:00
confuncs - > SetActive ( WINDOWNAME ) ;
2016-07-12 00:40:13 +00:00
return true ;
}
if ( ! thedatabase & & dlcontext = = - 1 )
2019-09-04 07:59:40 +00:00
filefuncs - > Open ( DATABASEURL , & dlcontext , 1 ) ;
2016-07-12 00:40:13 +00:00
QI_RefreshMapList ( true ) ;
return true ;
}
return false ;
}
2019-09-04 07:59:40 +00:00
qboolean Plug_Init ( void )
2016-07-12 00:40:13 +00:00
{
2019-09-04 07:59:40 +00:00
confuncs = plugfuncs - > GetEngineInterface ( plugsubconsolefuncs_name , sizeof ( * confuncs ) ) ;
filefuncs = plugfuncs - > GetEngineInterface ( plugfsfuncs_name , sizeof ( * filefuncs ) ) ;
clientfuncs = plugfuncs - > GetEngineInterface ( plugclientfuncs_name , sizeof ( * clientfuncs ) ) ;
if ( confuncs & & filefuncs & & clientfuncs )
2016-07-12 00:40:13 +00:00
{
2019-09-04 07:59:40 +00:00
filters . minrating = filters . maxrating = - 1 ;
plugfuncs - > ExportFunction ( " UpdateVideo " , QI_UpdateVideo ) ;
if ( plugfuncs - > ExportFunction ( " Tick " , QI_Tick ) & &
plugfuncs - > ExportFunction ( " Shutdown " , QI_Shutdown ) & &
plugfuncs - > ExportFunction ( " ExecuteCommand " , QI_ExecuteCommand ) & &
plugfuncs - > ExportFunction ( " ConExecuteCommand " , QI_ConExecuteCommand ) & &
plugfuncs - > ExportFunction ( " ConsoleLink " , QI_ConsoleLink ) )
{
cmdfuncs - > AddCommand ( " qi " ) ;
cmdfuncs - > AddCommand ( " quaddicted " ) ;
return true ;
}
2016-07-12 00:40:13 +00:00
}
2019-09-04 07:59:40 +00:00
//else not available in dedicated servers
2016-07-12 00:40:13 +00:00
return false ;
}