Skip to content

Commit 7beb194

Browse files
committed
Use global \sv_referencedPakNames cvar to check for download files
\sv_referencedPakNames is set only once at server startup and never changes while further FS_ReferencedPakNames() may return different (longer) output during server run so either \sv_referencedPakNames must be updated after each FS_ReferencedPakNames() call or we must use initial cvar all the time - what we will do for now Code cleanup
1 parent f0fd1a8 commit 7beb194

File tree

5 files changed

+25
-15
lines changed

5 files changed

+25
-15
lines changed

src/qcommon/files.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,7 +1765,7 @@ long FS_ReadFileDir(const char *qpath, void *searchPath, bool unpure, void **buf
17651765
fs_loadStack++;
17661766

17671767
// guarantee that it will have a trailing 0 for string operations
1768-
buf[len] = 0;
1768+
buf[len] = '\0';
17691769

17701770
return len;
17711771
}
@@ -1825,7 +1825,7 @@ long FS_ReadFileDir(const char *qpath, void *searchPath, bool unpure, void **buf
18251825
FS_Read(buf, len, h);
18261826

18271827
// guarantee that it will have a trailing 0 for string operations
1828-
buf[len] = 0;
1828+
buf[len] = '\0';
18291829
FS_FCloseFile(h);
18301830

18311831
// if we are journalling and it is a config file, write it to the journal file
@@ -2087,7 +2087,7 @@ static int FS_ReturnPath(const char *zname, char *zpath, int *depth)
20872087
int newdep = 0;
20882088
int len = 0;
20892089
int at = 0;
2090-
zpath[0] = 0;
2090+
zpath[0] = '\0';
20912091

20922092
while (zname[at] != 0)
20932093
{
@@ -2099,7 +2099,7 @@ static int FS_ReturnPath(const char *zname, char *zpath, int *depth)
20992099
at++;
21002100
}
21012101
strcpy(zpath, zname);
2102-
zpath[len] = 0;
2102+
zpath[len] = '\0';
21032103
*depth = newdep;
21042104

21052105
return len;
@@ -3488,7 +3488,7 @@ Servers with sv_pure set will get this string and pass it to clients.
34883488
const char *FS_LoadedPakChecksums(bool alternate)
34893489
{
34903490
static char info[BIG_INFO_STRING];
3491-
info[0] = 0;
3491+
info[0] = '\0';
34923492

34933493
for (auto search = fs_searchpaths; search; search = search->next)
34943494
{
@@ -3513,7 +3513,7 @@ Servers with sv_pure set will get this string and pass it to clients.
35133513
const char *FS_LoadedPakNames(bool alternate)
35143514
{
35153515
static char info[BIG_INFO_STRING];
3516-
info[0] = 0;
3516+
info[0] = '\0';
35173517

35183518
for (auto search = fs_searchpaths; search; search = search->next)
35193519
{
@@ -3540,7 +3540,7 @@ back to the server.
35403540
const char *FS_LoadedPakPureChecksums(bool alternate)
35413541
{
35423542
static char info[BIG_INFO_STRING];
3543-
info[0] = 0;
3543+
info[0] = '\0';
35443544

35453545
for (auto search = fs_searchpaths; search; search = search->next)
35463546
{
@@ -3565,7 +3565,7 @@ The server will send this to the clients so they can check which files should be
35653565
const char *FS_ReferencedPakChecksums(bool alternate)
35663566
{
35673567
static char info[BIG_INFO_STRING];
3568-
info[0] = 0;
3568+
info[0] = '\0';
35693569

35703570
for (auto search = fs_searchpaths; search; search = search->next)
35713571
{
@@ -3602,7 +3602,7 @@ The string has a specific order, "cgame ui @ ref1 ref2 ref3 ..."
36023602
const char *FS_ReferencedPakPureChecksums(void)
36033603
{
36043604
static char info[BIG_INFO_STRING];
3605-
info[0] = 0;
3605+
info[0] = '\0';
36063606

36073607
int checksum = fs_checksumFeed;
36083608
int numPaks = 0;
@@ -3648,7 +3648,7 @@ The server will send this to the clients so they can check which files should be
36483648
const char *FS_ReferencedPakNames(bool alternate)
36493649
{
36503650
static char info[BIG_INFO_STRING];
3651-
info[0] = 0;
3651+
info[0] = '\0';
36523652

36533653
// we want to return ALL pk3's from the fs_game path
36543654
// and referenced one's from base

src/server/server.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ extern cvar_t *sv_padPackets;
341341
extern cvar_t *sv_killserver;
342342
extern cvar_t *sv_mapname;
343343
extern cvar_t *sv_mapChecksum;
344+
extern cvar_t *sv_referencedPakNames;
345+
extern cvar_t *sv_referencedAlternatePakNames;
344346
extern cvar_t *sv_serverid;
345347
extern cvar_t *sv_minRate;
346348
extern cvar_t *sv_maxRate;

src/server/sv_client.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -857,11 +857,17 @@ int SV_WriteDownloadToClient(client_t *cl, msg_t *msg)
857857
// Check for pk3 filename extension
858858
if(!Q_stricmp(pakptr + 1, "pk3"))
859859
{
860-
const char *referencedPaks = FS_ReferencedPakNames( cl->netchan.alternateProtocol == 2 );
861-
862860
// Check whether the file appears in the list of referenced
863861
// paks to prevent downloading of arbitrary files.
864-
Cmd_TokenizeStringIgnoreQuotes(referencedPaks);
862+
if (cl->netchan.alternateProtocol == 2)
863+
{
864+
Cmd_TokenizeStringIgnoreQuotes(sv_referencedAlternatePakNames->string);
865+
}
866+
else
867+
{
868+
Cmd_TokenizeStringIgnoreQuotes(sv_referencedPakNames->string);
869+
}
870+
865871
numRefPaks = Cmd_Argc();
866872

867873
for(curindex = 0; curindex < numRefPaks; curindex++)

src/server/sv_init.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -892,11 +892,11 @@ void SV_Init(void)
892892
Cvar_Get("sv_paks", "", CVAR_SYSTEMINFO | CVAR_ROM);
893893
Cvar_Get("sv_pakNames", "", CVAR_SYSTEMINFO | CVAR_ROM);
894894
Cvar_Get("sv_referencedPaks", "", CVAR_SYSTEMINFO | CVAR_ROM);
895-
Cvar_Get("sv_referencedPakNames", "", CVAR_SYSTEMINFO | CVAR_ROM);
895+
sv_referencedPakNames = Cvar_Get("sv_referencedPakNames", "", CVAR_SYSTEMINFO | CVAR_ROM);
896896
Cvar_Get("sv_alternatePaks", "", CVAR_ALTERNATE_SYSTEMINFO | CVAR_ROM);
897897
Cvar_Get("sv_alternatePakNames", "", CVAR_ALTERNATE_SYSTEMINFO | CVAR_ROM);
898898
Cvar_Get("sv_referencedAlternatePaks", "", CVAR_ALTERNATE_SYSTEMINFO | CVAR_ROM);
899-
Cvar_Get("sv_referencedAlternatePakNames", "", CVAR_ALTERNATE_SYSTEMINFO | CVAR_ROM);
899+
sv_referencedAlternatePakNames = Cvar_Get("sv_referencedAlternatePakNames", "", CVAR_ALTERNATE_SYSTEMINFO | CVAR_ROM);
900900

901901
// server vars
902902
sv_rconPassword = Cvar_Get("rconPassword", "", CVAR_TEMP);

src/server/sv_main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ cvar_t *sv_padPackets; // add nop bytes to messages
5252
cvar_t *sv_killserver; // menu system can set to 1 to shut server down
5353
cvar_t *sv_mapname;
5454
cvar_t *sv_mapChecksum;
55+
cvar_t *sv_referencedPakNames;
56+
cvar_t *sv_referencedAlternatePakNames;
5557
cvar_t *sv_serverid;
5658
cvar_t *sv_minRate;
5759
cvar_t *sv_maxRate;

0 commit comments

Comments
 (0)