summaryrefslogtreecommitdiff
path: root/source/sv_mvd.c
diff options
context:
space:
mode:
authorAndrey Nazarov <skuller@skuller.net>2010-07-03 16:01:48 +0000
committerAndrey Nazarov <skuller@skuller.net>2010-07-03 16:01:48 +0000
commit7a914ef872a436adcdb36d21ceddba6bb24eb993 (patch)
treedafc86024742e7bbced8ef897754beff5160f1ae /source/sv_mvd.c
parent1acd69e9a128e4f3abf06b5ae97c968c87663864 (diff)
Yet another huge commit.
Implemented new error reporting framework based on errno and custom error codes. Converted filesystem code, image and model managers, BSP loader to use the new framework and report errors more accurately. Replaced fileHandle_t with qhandle_t. Removed INVALID_LENGTH definition. Killed USE_LOADBUF code. Defined FS_FileExists(Ex) macro, implemented FS_EasyOpenFile and FS_WriteFile helper functions. When testing for free screenshot slots, open the file with O_EXCL flag to avoid race conditions (works only on glibc yet). Don't allow quake paths with high bits set. Don't tolerate any fatal errors encountered when searching for files and pass errors back to the caller. FS_Seek() now fails on files from packs instead of returning an invalid position. Fixed ‘mvdskip’ command not working properly. Avoid inefficient usage of MakeColor macro in image loading functions. Prevent memory leak in JPEG and PNG image functions after calling longjmp() by marking some local variables volatile. Added support for loading monochrome JPEG images. Fixed signed integer overflow in GetWavinfo(). Fixed missing return statement in BSP_LoadSurfEdges() causing out of range edge indices to be left uncaught. Fixed possible access to uninitialized memory in BSP_LoadLeafs() for maps with no leafs. Properly NUL terminate the buffer in SCR_ScoreDump_f(), also check for being in a level. Always free latched_string when cvar is set back to current value. Fixed a crash in ‘mvdplay’ command possible when demo file is invalid.
Diffstat (limited to 'source/sv_mvd.c')
-rw-r--r--source/sv_mvd.c53
1 files changed, 17 insertions, 36 deletions
diff --git a/source/sv_mvd.c b/source/sv_mvd.c
index 16d959e..a425938 100644
--- a/source/sv_mvd.c
+++ b/source/sv_mvd.c
@@ -73,7 +73,7 @@ typedef struct {
entity_state_t *entities; // [MAX_EDICTS]
// local recorder
- fileHandle_t recording;
+ qhandle_t recording;
int numlevels; // stop after that many levels
int numframes; // stop after that many frames
@@ -119,7 +119,7 @@ static void flush_stream( gtv_client_t *client, int flush );
static void rec_stop( void );
static qboolean rec_allowed( void );
-static void rec_start( fileHandle_t demofile );
+static void rec_start( qhandle_t demofile );
static void rec_write( void );
@@ -163,8 +163,7 @@ static void dummy_forward_f( void ) {
static void dummy_record_f( void ) {
char buffer[MAX_OSPATH];
- fileHandle_t demofile;
- size_t len;
+ qhandle_t f;
if( !sv_mvd_autorecord->integer ) {
return;
@@ -179,24 +178,18 @@ static void dummy_record_f( void ) {
return;
}
- len = Q_concat( buffer, sizeof( buffer ), "demos/", Cmd_Argv( 1 ), ".mvd2", NULL );
- if( len >= sizeof( buffer ) ) {
- Com_EPrintf( "Oversize filename specified.\n" );
- return;
- }
-
- FS_FOpenFile( buffer, &demofile, FS_MODE_WRITE );
- if( !demofile ) {
- Com_EPrintf( "Couldn't open %s for writing\n", buffer );
+ f = FS_EasyOpenFile( buffer, sizeof( buffer ), FS_MODE_WRITE,
+ "demos/", Cmd_Argv( 1 ), ".mvd2" );
+ if( !f ) {
return;
}
if( !mvd_enable() ) {
- FS_FCloseFile( demofile );
+ FS_FCloseFile( f );
return;
}
- rec_start( demofile );
+ rec_start( f );
Com_Printf( "Auto-recording local MVD to %s\n", buffer );
}
@@ -2023,7 +2016,7 @@ static qboolean rec_allowed( void ) {
return qtrue;
}
-static void rec_start( fileHandle_t demofile ) {
+static void rec_start( qhandle_t demofile ) {
uint32_t magic;
mvd.recording = demofile;
@@ -2061,10 +2054,9 @@ Every entity, every playerinfo and every message will be recorded.
*/
static void SV_MvdRecord_f( void ) {
char buffer[MAX_OSPATH];
- fileHandle_t demofile;
- qboolean gzip = qfalse;
+ qhandle_t f;
+ unsigned mode = FS_MODE_WRITE;
int c;
- size_t len;
if( sv.state != ss_game ) {
#if USE_MVD_CLIENT
@@ -2086,7 +2078,7 @@ static void SV_MvdRecord_f( void ) {
Cmd_PrintHelp( o_record );
return;
case 'z':
- gzip = qtrue;
+ mode |= FS_FLAG_GZIP;
break;
default:
return;
@@ -2106,29 +2098,18 @@ static void SV_MvdRecord_f( void ) {
//
// open the demo file
//
- len = Q_concat( buffer, sizeof( buffer ), "demos/", cmd_optarg,
- gzip ? ".mvd2.gz" : ".mvd2", NULL );
- if( len >= sizeof( buffer ) ) {
- Com_EPrintf( "Oversize filename specified.\n" );
- return;
- }
-
- FS_FOpenFile( buffer, &demofile, FS_MODE_WRITE );
- if( !demofile ) {
- Com_EPrintf( "Couldn't open %s for writing\n", buffer );
+ f = FS_EasyOpenFile( buffer, sizeof( buffer ), mode,
+ "demos/", cmd_optarg, ".mvd2" );
+ if( !f ) {
return;
}
if( !mvd_enable() ) {
- FS_FCloseFile( demofile );
+ FS_FCloseFile( f );
return;
}
- if( gzip ) {
- FS_FilterFile( demofile );
- }
-
- rec_start( demofile );
+ rec_start( f );
Com_Printf( "Recording local MVD to %s\n", buffer );
}