Browse Source

engine: server: simplified strings operations.

pull/2/head
Andrey Akhmichin 4 years ago committed by Alibek Omarov
parent
commit
1332381e2d
  1. 16
      engine/server/sv_client.c
  2. 6
      engine/server/sv_cmds.c
  3. 2
      engine/server/sv_custom.c
  4. 12
      engine/server/sv_game.c
  5. 4
      engine/server/sv_init.c
  6. 11
      engine/server/sv_log.c
  7. 50
      engine/server/sv_save.c

16
engine/server/sv_client.c

@ -935,7 +935,7 @@ Rcon_Validate @@ -935,7 +935,7 @@ Rcon_Validate
*/
qboolean Rcon_Validate( void )
{
if( !Q_strlen( rcon_password.string ))
if( !COM_CheckString( rcon_password.string ))
return false;
if( Q_strcmp( Cmd_Argv( 1 ), rcon_password.string ))
return false;
@ -1289,7 +1289,7 @@ void SV_PutClientInServer( sv_client_t *cl ) @@ -1289,7 +1289,7 @@ void SV_PutClientInServer( sv_client_t *cl )
svgame.dllFuncs.pfnParmsChangeLevel();
MSG_BeginServerCmd( &msg, svc_restore );
Q_snprintf( name, sizeof( name ), "%s%s.HL2", DEFAULT_SAVE_DIRECTORY, sv.name );
Q_snprintf( name, sizeof( name ), DEFAULT_SAVE_DIRECTORY "%s.HL2", sv.name );
COM_FixSlashes( name );
MSG_WriteString( &msg, name );
MSG_WriteByte( &msg, levelData.connectionCount );
@ -1560,9 +1560,9 @@ static qboolean SV_New_f( sv_client_t *cl ) @@ -1560,9 +1560,9 @@ static qboolean SV_New_f( sv_client_t *cl )
if(( cl->state == cs_spawned ) && cl->edict )
svgame.dllFuncs.pfnClientDisconnect( cl->edict );
Q_snprintf( szName, sizeof( szName ), "%s", cl->name );
Q_snprintf( szAddress, sizeof( szAddress ), "%s", NET_AdrToString( cl->netchan.remote_address ));
Q_snprintf( szRejectReason, sizeof( szRejectReason ), "Connection rejected by game\n");
Q_strncpy( szName, cl->name, sizeof( szName ) );
Q_strncpy( szAddress, NET_AdrToString( cl->netchan.remote_address ), sizeof( szAddress ) );
Q_strncpy( szRejectReason, "Connection rejected by game\n", sizeof( szRejectReason ) );
// Allow the game dll to reject this client.
if( !svgame.dllFuncs.pfnClientConnect( cl->edict, szName, szAddress, szRejectReason ))
@ -1686,7 +1686,7 @@ void SV_UserinfoChanged( sv_client_t *cl ) @@ -1686,7 +1686,7 @@ void SV_UserinfoChanged( sv_client_t *cl )
val = Info_ValueForKey( cl->userinfo, "name" );
}
if( !Q_strlen( name1 ))
if( !COM_CheckStringEmpty( name1 ) )
{
Info_SetValueForKey( cl->userinfo, "name", "unnamed", MAX_INFO_STRING );
val = Info_ValueForKey( cl->userinfo, "name" );
@ -1724,7 +1724,7 @@ void SV_UserinfoChanged( sv_client_t *cl ) @@ -1724,7 +1724,7 @@ void SV_UserinfoChanged( sv_client_t *cl )
// rate command
val = Info_ValueForKey( cl->userinfo, "rate" );
if( Q_strlen( val ))
if( COM_CheckString( val ) )
cl->netchan.rate = bound( MIN_RATE, Q_atoi( val ), MAX_RATE );
else cl->netchan.rate = DEFAULT_RATE;
@ -1745,7 +1745,7 @@ void SV_UserinfoChanged( sv_client_t *cl ) @@ -1745,7 +1745,7 @@ void SV_UserinfoChanged( sv_client_t *cl )
val = Info_ValueForKey( cl->userinfo, "cl_updaterate" );
if( Q_strlen( val ))
if( COM_CheckString( val ) )
{
if( Q_atoi( val ) != 0 )
{

6
engine/server/sv_cmds.c

@ -379,7 +379,7 @@ void SV_Load_f( void ) @@ -379,7 +379,7 @@ void SV_Load_f( void )
return;
}
Q_snprintf( path, sizeof( path ), "%s%s.sav", DEFAULT_SAVE_DIRECTORY, Cmd_Argv( 1 ));
Q_snprintf( path, sizeof( path ), DEFAULT_SAVE_DIRECTORY "%s.sav", Cmd_Argv( 1 ));
SV_LoadGame( path );
}
@ -442,8 +442,8 @@ void SV_DeleteSave_f( void ) @@ -442,8 +442,8 @@ void SV_DeleteSave_f( void )
}
// delete save and saveshot
FS_Delete( va( "%s%s.sav", DEFAULT_SAVE_DIRECTORY, Cmd_Argv( 1 )));
FS_Delete( va( "%s%s.bmp", DEFAULT_SAVE_DIRECTORY, Cmd_Argv( 1 )));
FS_Delete( va( DEFAULT_SAVE_DIRECTORY "%s.sav", Cmd_Argv( 1 )));
FS_Delete( va( DEFAULT_SAVE_DIRECTORY "%s.bmp", Cmd_Argv( 1 )));
}
/*

2
engine/server/sv_custom.c

@ -212,7 +212,7 @@ void SV_TransferConsistencyInfo( void ) @@ -212,7 +212,7 @@ void SV_TransferConsistencyInfo( void )
SetBits( pResource->ucFlags, RES_CHECKFILE );
if( pResource->type == t_sound )
Q_snprintf( filepath, sizeof( filepath ), "%s%s", DEFAULT_SOUNDPATH, pResource->szFileName );
Q_snprintf( filepath, sizeof( filepath ), DEFAULT_SOUNDPATH "%s", pResource->szFileName );
else Q_strncpy( filepath, pResource->szFileName, sizeof( filepath ));
MD5_HashFile( pResource->rgucMD5_hash, filepath, NULL );

12
engine/server/sv_game.c

@ -772,7 +772,8 @@ void SV_WriteEntityPatch( const char *filename ) @@ -772,7 +772,8 @@ void SV_WriteEntityPatch( const char *filename )
dheader_t *header;
file_t *f;
Q_strncpy( bspfilename, va( "maps/%s.bsp", filename ), sizeof( bspfilename ));
Q_snprintf( bspfilename, sizeof( bspfilename ), "maps/%s.bsp", filename );
f = FS_Open( bspfilename, "rb", false );
if( !f ) return;
@ -824,7 +825,8 @@ static char *SV_ReadEntityScript( const char *filename, int *flags ) @@ -824,7 +825,8 @@ static char *SV_ReadEntityScript( const char *filename, int *flags )
*flags = 0;
Q_strncpy( bspfilename, va( "maps/%s.bsp", filename ), sizeof( bspfilename ));
Q_snprintf( bspfilename, sizeof( bspfilename ), "maps/%s.bsp", filename );
f = FS_Open( bspfilename, "rb", false );
if( !f ) return NULL;
@ -846,7 +848,7 @@ static char *SV_ReadEntityScript( const char *filename, int *flags ) @@ -846,7 +848,7 @@ static char *SV_ReadEntityScript( const char *filename, int *flags )
lumplen = header->lumps[LUMP_ENTITIES].filelen;
// check for entfile too
Q_strncpy( entfilename, va( "maps/%s.ent", filename ), sizeof( entfilename ));
Q_snprintf( entfilename, sizeof( entfilename ), "maps/%s.ent", filename );
// make sure what entity patch is newer than bsp
ft1 = FS_FileTime( bspfilename, false );
@ -888,10 +890,12 @@ int SV_MapIsValid( const char *filename, const char *spawn_entity, const char *l @@ -888,10 +890,12 @@ int SV_MapIsValid( const char *filename, const char *spawn_entity, const char *l
if( ents )
{
qboolean need_landmark = Q_strlen( landmark_name ) > 0 ? true : false;
qboolean need_landmark;
char token[MAX_TOKEN];
string check_name;
need_landmark = COM_CheckString( landmark_name );
// g-cont. in-dev mode we can entering on map even without "info_player_start"
if( !need_landmark && host_developer.value )
{

4
engine/server/sv_init.c

@ -67,7 +67,7 @@ void SV_SendSingleResource( const char *name, resourcetype_t type, int index, by @@ -67,7 +67,7 @@ void SV_SendSingleResource( const char *name, resourcetype_t type, int index, by
nSize = ( name[0] != '*' ) ? FS_FileSize( name, false ) : 0;
break;
case t_sound:
nSize = FS_FileSize( va( "%s%s", DEFAULT_SOUNDPATH, name ), false );
nSize = FS_FileSize( va( DEFAULT_SOUNDPATH "%s", name ), false );
break;
default:
nSize = FS_FileSize( name, false );
@ -358,7 +358,7 @@ void SV_CreateResourceList( void ) @@ -358,7 +358,7 @@ void SV_CreateResourceList( void )
}
else
{
nSize = FS_FileSize( va( "%s%s", DEFAULT_SOUNDPATH, s ), false );
nSize = FS_FileSize( va( DEFAULT_SOUNDPATH "%s", s ), false );
SV_AddResource( t_sound, s, nSize, 0, i );
}
}

11
engine/server/sv_log.c

@ -42,7 +42,7 @@ void Log_Open( void ) @@ -42,7 +42,7 @@ void Log_Open( void )
today = localtime( &ltime );
temp = Cvar_VariableString( "logsdir" );
if( temp && Q_strlen( temp ) > 0 && !Q_strstr( temp, ":" ) && !Q_strstr( temp, ".." ))
if( COM_CheckString( temp ) && !Q_strchr( temp, ':' ) && !Q_strstr( temp, ".." ))
Q_snprintf( szFileBase, sizeof( szFileBase ), "%s/L%02i%02i", temp, today->tm_mon + 1, today->tm_mday );
else Q_snprintf( szFileBase, sizeof( szFileBase ), "logs/L%02i%02i", today->tm_mon + 1, today->tm_mday );
@ -100,7 +100,8 @@ void Log_Printf( const char *fmt, ... ) @@ -100,7 +100,8 @@ void Log_Printf( const char *fmt, ... )
static char string[1024];
char *p;
time_t ltime;
struct tm *today;
struct tm *today;
int len;
if( !svs.log.active )
return;
@ -108,13 +109,13 @@ void Log_Printf( const char *fmt, ... ) @@ -108,13 +109,13 @@ void Log_Printf( const char *fmt, ... )
time( &ltime );
today = localtime( &ltime );
Q_snprintf( string, sizeof( string ), "%02i/%02i/%04i - %02i:%02i:%02i: ",
len = Q_snprintf( string, sizeof( string ), "%02i/%02i/%04i - %02i:%02i:%02i: ",
today->tm_mon+1, today->tm_mday, 1900 + today->tm_year, today->tm_hour, today->tm_min, today->tm_sec );
p = string + Q_strlen( string );
p = string + len;
va_start( argptr, fmt );
Q_vsnprintf( p, sizeof( string ) - Q_strlen( string ), fmt, argptr );
Q_vsnprintf( p, sizeof( string ) - len, fmt, argptr );
va_end( argptr );
if( svs.log.net_log )

50
engine/server/sv_save.c

@ -398,7 +398,7 @@ static void ClearSaveDir( void ) @@ -398,7 +398,7 @@ static void ClearSaveDir( void )
int i;
// just delete all HL? files
t = FS_Search( va( "%s*.HL?", DEFAULT_SAVE_DIRECTORY ), true, true );
t = FS_Search( DEFAULT_SAVE_DIRECTORY "*.HL?", true, true );
if( !t ) return; // already empty
for( i = 0; i < t->numfilenames; i++ )
@ -491,8 +491,8 @@ static void AgeSaveList( const char *pName, int count ) @@ -491,8 +491,8 @@ static void AgeSaveList( const char *pName, int count )
char newShot[MAX_OSPATH], oldShot[MAX_OSPATH];
// delete last quick/autosave (e.g. quick05.sav)
Q_snprintf( newName, sizeof( newName ), "%s%s%02d.sav", DEFAULT_SAVE_DIRECTORY, pName, count );
Q_snprintf( newShot, sizeof( newShot ), "%s%s%02d.bmp", DEFAULT_SAVE_DIRECTORY, pName, count );
Q_snprintf( newName, sizeof( newName ), DEFAULT_SAVE_DIRECTORY "%s%02d.sav", pName, count );
Q_snprintf( newShot, sizeof( newShot ), DEFAULT_SAVE_DIRECTORY "%s%02d.bmp", pName, count );
// only delete from game directory, basedir is read-only
FS_Delete( newName );
@ -508,18 +508,18 @@ static void AgeSaveList( const char *pName, int count ) @@ -508,18 +508,18 @@ static void AgeSaveList( const char *pName, int count )
if( count == 1 )
{
// quick.sav
Q_snprintf( oldName, sizeof( oldName ), "%s%s.sav", DEFAULT_SAVE_DIRECTORY, pName );
Q_snprintf( oldShot, sizeof( oldShot ), "%s%s.bmp", DEFAULT_SAVE_DIRECTORY, pName );
Q_snprintf( oldName, sizeof( oldName ), DEFAULT_SAVE_DIRECTORY "%s.sav", pName );
Q_snprintf( oldShot, sizeof( oldShot ), DEFAULT_SAVE_DIRECTORY "%s.bmp", pName );
}
else
{
// quick04.sav, etc.
Q_snprintf( oldName, sizeof( oldName ), "%s%s%02d.sav", DEFAULT_SAVE_DIRECTORY, pName, count - 1 );
Q_snprintf( oldShot, sizeof( oldShot ), "%s%s%02d.bmp", DEFAULT_SAVE_DIRECTORY, pName, count - 1 );
Q_snprintf( oldName, sizeof( oldName ), DEFAULT_SAVE_DIRECTORY "%s%02d.sav", pName, count - 1 );
Q_snprintf( oldShot, sizeof( oldShot ), DEFAULT_SAVE_DIRECTORY "%s%02d.bmp", pName, count - 1 );
}
Q_snprintf( newName, sizeof( newName ), "%s%s%02d.sav", DEFAULT_SAVE_DIRECTORY, pName, count );
Q_snprintf( newShot, sizeof( newShot ), "%s%s%02d.bmp", DEFAULT_SAVE_DIRECTORY, pName, count );
Q_snprintf( newName, sizeof( newName ), DEFAULT_SAVE_DIRECTORY "%s%02d.sav", pName, count );
Q_snprintf( newShot, sizeof( newShot ), DEFAULT_SAVE_DIRECTORY "%s%02d.bmp", pName, count );
#if !XASH_DEDICATED
// unloading the oldshot footprint too
@ -584,7 +584,7 @@ static void DirectoryExtract( file_t *pFile, int fileCount ) @@ -584,7 +584,7 @@ static void DirectoryExtract( file_t *pFile, int fileCount )
// filename can only be as long as a map name + extension
FS_Read( pFile, szName, MAX_OSPATH );
FS_Read( pFile, &fileSize, sizeof( int ));
Q_snprintf( fileName, sizeof( fileName ), "%s%s", DEFAULT_SAVE_DIRECTORY, szName );
Q_snprintf( fileName, sizeof( fileName ), DEFAULT_SAVE_DIRECTORY "%s", szName );
COM_FixSlashes( fileName );
pCopy = FS_Open( fileName, "wb", true );
@ -773,7 +773,7 @@ static int GetClientDataSize( const char *level ) @@ -773,7 +773,7 @@ static int GetClientDataSize( const char *level )
char name[MAX_QPATH];
file_t *pFile;
Q_snprintf( name, sizeof( name ), "%s%s.HL2", DEFAULT_SAVE_DIRECTORY, level );
Q_snprintf( name, sizeof( name ), DEFAULT_SAVE_DIRECTORY "%s.HL2", level );
if(( pFile = FS_Open( name, "rb", true )) == NULL )
return 0;
@ -819,7 +819,7 @@ static SAVERESTOREDATA *LoadSaveData( const char *level ) @@ -819,7 +819,7 @@ static SAVERESTOREDATA *LoadSaveData( const char *level )
int totalSize;
file_t *pFile;
Q_snprintf( name, sizeof( name ), "%s%s.HL1", DEFAULT_SAVE_DIRECTORY, level );
Q_snprintf( name, sizeof( name ), DEFAULT_SAVE_DIRECTORY "%s.HL1", level );
Con_Printf( "Loading game from %s...\n", name );
if(( pFile = FS_Open( name, "rb", true )) == NULL )
@ -929,7 +929,7 @@ static void EntityPatchWrite( SAVERESTOREDATA *pSaveData, const char *level ) @@ -929,7 +929,7 @@ static void EntityPatchWrite( SAVERESTOREDATA *pSaveData, const char *level )
int i, size = 0;
file_t *pFile;
Q_snprintf( name, sizeof( name ), "%s%s.HL3", DEFAULT_SAVE_DIRECTORY, level );
Q_snprintf( name, sizeof( name ), DEFAULT_SAVE_DIRECTORY "%s.HL3", level );
if(( pFile = FS_Open( name, "wb", true )) == NULL )
return;
@ -966,7 +966,7 @@ static void EntityPatchRead( SAVERESTOREDATA *pSaveData, const char *level ) @@ -966,7 +966,7 @@ static void EntityPatchRead( SAVERESTOREDATA *pSaveData, const char *level )
int i, size, entityId;
file_t *pFile;
Q_snprintf( name, sizeof( name ), "%s%s.HL3", DEFAULT_SAVE_DIRECTORY, level );
Q_snprintf( name, sizeof( name ), DEFAULT_SAVE_DIRECTORY "%s.HL3", level );
if(( pFile = FS_Open( name, "rb", true )) == NULL )
return;
@ -1166,7 +1166,7 @@ static void SaveClientState( SAVERESTOREDATA *pSaveData, const char *level, int @@ -1166,7 +1166,7 @@ static void SaveClientState( SAVERESTOREDATA *pSaveData, const char *level, int
// Write entity string token table
pTokenData = StoreHashTable( pSaveData );
Q_snprintf( name, sizeof( name ), "%s%s.HL2", DEFAULT_SAVE_DIRECTORY, level );
Q_snprintf( name, sizeof( name ), DEFAULT_SAVE_DIRECTORY "%s.HL2", level );
// output to disk
if(( pFile = FS_Open( name, "wb", true )) == NULL )
@ -1205,7 +1205,7 @@ static void LoadClientState( SAVERESTOREDATA *pSaveData, const char *level, qboo @@ -1205,7 +1205,7 @@ static void LoadClientState( SAVERESTOREDATA *pSaveData, const char *level, qboo
SAVE_CLIENT header;
file_t *pFile;
Q_snprintf( name, sizeof( name ), "%s%s.HL2", DEFAULT_SAVE_DIRECTORY, level );
Q_snprintf( name, sizeof( name ), DEFAULT_SAVE_DIRECTORY "%s.HL2", level );
if(( pFile = FS_Open( name, "rb", true )) == NULL )
return; // something bad is happens
@ -1288,7 +1288,7 @@ static void LoadClientState( SAVERESTOREDATA *pSaveData, const char *level, qboo @@ -1288,7 +1288,7 @@ static void LoadClientState( SAVERESTOREDATA *pSaveData, const char *level, qboo
// restore camera view here
edict_t *pent = pSaveData->pTable[bound( 0, (word)header.viewentity, pSaveData->tableCount )].pent;
if( Q_strlen( header.introTrack ))
if( COM_CheckStringEmpty( header.introTrack ) )
{
// NOTE: music is automatically goes across transition, never restore it on changelevel
MSG_BeginServerCmd( &sv.signon, svc_stufftext );
@ -1390,7 +1390,7 @@ static SAVERESTOREDATA *SaveGameState( int changelevel ) @@ -1390,7 +1390,7 @@ static SAVERESTOREDATA *SaveGameState( int changelevel )
pSaveData = SaveInit( SAVE_HEAPSIZE, SAVE_HASHSTRINGS );
Q_snprintf( name, sizeof( name ), "%s%s.HL1", DEFAULT_SAVE_DIRECTORY, sv.name );
Q_snprintf( name, sizeof( name ), DEFAULT_SAVE_DIRECTORY "%s.HL1", sv.name );
COM_FixSlashes( name );
// initialize entity table to count moved entities
@ -1612,7 +1612,7 @@ static int SaveGameSlot( const char *pSaveName, const char *pSaveComment ) @@ -1612,7 +1612,7 @@ static int SaveGameSlot( const char *pSaveName, const char *pSaveComment )
SaveFinish( pSaveData );
pSaveData = SaveInit( SAVE_HEAPSIZE, SAVE_HASHSTRINGS ); // re-init the buffer
Q_snprintf( hlPath, sizeof( hlPath ), "%s*.HL?", DEFAULT_SAVE_DIRECTORY );
Q_strncpy( hlPath, DEFAULT_SAVE_DIRECTORY "*.HL?", sizeof( hlPath ) );
Q_strncpy( gameHeader.mapName, sv.name, sizeof( gameHeader.mapName )); // get the name of level where a player
Q_strncpy( gameHeader.comment, pSaveComment, sizeof( gameHeader.comment ));
gameHeader.mapCount = DirectoryCount( hlPath ); // counting all the adjacency maps
@ -1626,7 +1626,7 @@ static int SaveGameSlot( const char *pSaveName, const char *pSaveComment ) @@ -1626,7 +1626,7 @@ static int SaveGameSlot( const char *pSaveName, const char *pSaveComment )
// Write entity string token table
pTokenData = StoreHashTable( pSaveData );
Q_snprintf( name, sizeof( name ), "%s%s.sav", DEFAULT_SAVE_DIRECTORY, pSaveName );
Q_snprintf( name, sizeof( name ), DEFAULT_SAVE_DIRECTORY "%s.sav", pSaveName );
COM_FixSlashes( name );
// output to disk
@ -2092,7 +2092,7 @@ void SV_SaveGame( const char *pName ) @@ -2092,7 +2092,7 @@ void SV_SaveGame( const char *pName )
{
Q_snprintf( savename, sizeof( savename ), "save%03d", n );
if( !FS_FileExists( va( "%s%s.sav", DEFAULT_SAVE_DIRECTORY, savename ), true ))
if( !FS_FileExists( va( DEFAULT_SAVE_DIRECTORY "%s.sav", savename ), true ))
break;
}
@ -2106,7 +2106,7 @@ void SV_SaveGame( const char *pName ) @@ -2106,7 +2106,7 @@ void SV_SaveGame( const char *pName )
#if !XASH_DEDICATED
// unload previous image from memory (it's will be overwritten)
GL_FreeImage( va( "%s%s.bmp", DEFAULT_SAVE_DIRECTORY, savename ));
GL_FreeImage( va( DEFAULT_SAVE_DIRECTORY "%s.bmp", savename ) );
#endif // XASH_DEDICATED
SaveBuildComment( comment, sizeof( comment ));
@ -2132,7 +2132,7 @@ const char *SV_GetLatestSave( void ) @@ -2132,7 +2132,7 @@ const char *SV_GetLatestSave( void )
int i, found = 0;
search_t *t;
if(( t = FS_Search( va( "%s*.sav", DEFAULT_SAVE_DIRECTORY ), true, true )) == NULL )
if(( t = FS_Search( DEFAULT_SAVE_DIRECTORY "*.sav" , true, true )) == NULL )
return NULL;
for( i = 0; i < t->numfilenames; i++ )
@ -2176,7 +2176,7 @@ int GAME_EXPORT SV_GetSaveComment( const char *savename, char *comment ) @@ -2176,7 +2176,7 @@ int GAME_EXPORT SV_GetSaveComment( const char *savename, char *comment )
if(( f = FS_Open( savename, "rb", true )) == NULL )
{
// just not exist - clear comment
Q_strncpy( comment, "", MAX_STRING );
comment[0] = '\0';
return 0;
}
@ -2305,7 +2305,7 @@ int GAME_EXPORT SV_GetSaveComment( const char *savename, char *comment ) @@ -2305,7 +2305,7 @@ int GAME_EXPORT SV_GetSaveComment( const char *savename, char *comment )
FS_Close( f );
// at least mapname should be filled
if( Q_strlen( mapName ) > 0 )
if( COM_CheckStringEmpty( mapName ) )
{
time_t fileTime;
const struct tm *file_tm;

Loading…
Cancel
Save