Esempio n. 1
0
static void WriteCache( void ) {
    char buffer[MAX_OSPATH];
    qhandle_t f;
    int i;
    char *map, *pov;
    demoEntry_t *e;
    size_t len;

    if( m_demos.list.numItems == m_demos.numDirs ) {
        return;
    }

    len = Q_concat( buffer, sizeof( buffer ), m_demos.browse, "/" COM_DEMOCACHE_NAME, NULL );
    if( len >= sizeof( buffer ) ) {
        return;
    }
    FS_FOpenFile( buffer, &f, FS_MODE_WRITE );
    if( !f ) {
        return;
    }

    for( i = 0; i < 16; i++ ) {
        FS_FPrintf( f, "%02x", m_demos.hash[i] );
    }
    FS_FPrintf( f, "\\" );

    for( i = m_demos.numDirs; i < m_demos.list.numItems; i++ ) {
        e = m_demos.list.items[i];
        map = UI_GetColumn( e->name, COL_MAP );
        pov = UI_GetColumn( e->name, COL_POV );
        FS_FPrintf( f, "%s\\%s\\", map, pov );
    }
    FS_FCloseFile( f );
}
Esempio n. 2
0
/*
static qboolean SV_RunGameFrame( int msec )
{
int extraTime = 0;
static unsigned int accTime = 0;

accTime += msec;

// move autonomous things around if enough time has passed
if( svs.gametime < sv.nextSnapTime )
{
if( svs.gametime + svc.snapFrameTime < sv.nextSnapTime )
{
if( sv_showclamp->integer )
Com_Printf( "sv lowclamp\n" );
sv.nextSnapTime = svs.gametime + svc.snapFrameTime;
return qfalse;
}

// see if it's time to advance the world
if( accTime >= WORLDFRAMETIME )
{
if( host_speeds->integer )
time_before_game = Sys_Milliseconds();

ge->RunFrame( WORLDFRAMETIME, svs.gametime );

if( host_speeds->integer )
time_after_game = Sys_Milliseconds();

accTime = accTime - WORLDFRAMETIME;
}

if( !SV_SendClientsFragments() )
{
// FIXME: gametime might slower/faster than real time
if( dedicated->integer )
{
socket_t *sockets[] = { &svs.socket_udp, NULL };
NET_Sleep( min( WORLDFRAMETIME - accTime, sv.nextSnapTime - svs.gametime ), sockets );
}
}

return qfalse;
}

if( sv.nextSnapTime <= svs.gametime )
{
extraTime = (int)( svs.gametime - sv.nextSnapTime );
}
if( extraTime >= msec )
extraTime = msec - 1;

sv.nextSnapTime = ( svs.gametime + svc.snapFrameTime ) - extraTime;

// Execute all clients pending move commands
if( accTime )
{
ge->RunFrame( accTime, svs.gametime );
accTime = 0;
}

// update ping based on the last known frame from all clients
SV_CalcPings();

sv.framenum++;
ge->SnapFrame();

return qtrue;
}
*/
static void SV_CheckDefaultMap( void )
{
	if( svc.autostarted )
		return;

	svc.autostarted = qtrue;
	if( dedicated->integer )
	{
		if( sv.state == ss_dead && !strlen( sv.mapname ) )
        {
            int filehandle;
            if( sv_write_defaultmap && sv_write_defaultmap->integer && FS_FOpenFile( "defaultmap", &filehandle, FS_READ ) != -1 )
            {
                static char buffer[MAX_QPATH];
                buffer[0] = '\0';
                FS_Read( buffer, MAX_QPATH - 1, filehandle );
                FS_FCloseFile( filehandle );
                if( buffer[0] )
                {
                    Cbuf_ExecuteText( EXEC_APPEND, va( "map %s\n", buffer ) );
                    return;
                }
            }
            if( sv_defaultmap && strlen( sv_defaultmap->string ) )
                Cbuf_ExecuteText( EXEC_APPEND, va( "map %s\n", sv_defaultmap->string ) );
        }
	}
}
Esempio n. 3
0
// returns static string of md5 contents
const char *MM_PasswordRead( const char *user )
{
	static char buffer[MAX_STRING_CHARS];
	const char *filename;
	int filenum;
	size_t bytes;

	Com_DPrintf( "MM_PasswordRead %s\n", user );

	filename = mm_passwordFilename( user );
	if( FS_FOpenFile( filename, &filenum, FS_READ ) == -1 )
	{
		Com_Printf( "MM_PasswordRead: Couldnt open file %s\n", filename);
		return NULL;
	}

	bytes = FS_Read(buffer, sizeof( buffer ) - 1,  filenum );
	FS_FCloseFile( filenum );

	if( bytes == 0 || bytes >= sizeof(buffer) - 1 )
		return NULL;

	buffer[bytes] = '\0';

	return buffer;
}
Esempio n. 4
0
/*
* CL_CheckOrDownloadFile
* 
* Returns true if the file exists or couldn't send download request
* Files with .pk3 or .pak extension have to have gamedir attached
* Other files must not have gamedir
*/
qboolean CL_CheckOrDownloadFile( const char *filename )
{
	const char *ext;

	if( !cl_downloads->integer )
		return qtrue;

	if( !COM_ValidateRelativeFilename( filename ) )
		return qtrue;

	ext = COM_FileExtension( filename );
	if( !ext || !*ext )
		return qtrue;

	if( FS_CheckPakExtension( filename ) )
	{
		if( FS_FOpenBaseFile( filename, NULL, FS_READ ) != -1 )
			return qtrue;
	}
	else
	{
		if( FS_FOpenFile( filename, NULL, FS_READ ) != -1 )
			return qtrue;
	}

	if( !CL_DownloadRequest( filename, qtrue ) )
		return qtrue;

	cls.download.requestnext = qtrue; // call CL_RequestNextDownload when done

	return qfalse;
}
Esempio n. 5
0
static size_t wswcurl_write(void *ptr, size_t size, size_t nmemb, void *stream)
{
    wswcurl_req *req = (wswcurl_req*)stream;
    if (!req->filename) {
        // Reallocate buffer
        req->rxdata = WREALLOC(req->rxdata, req->rxsize + (size * nmemb) + 1);
        // Set remaining data to 0
        memset(&(req->rxdata[req->rxsize]), 0, (size * nmemb));
        // Copy received data
        memcpy(&(req->rxdata[req->rxsize]), ptr, size*nmemb);
        // Recalculate size
        req->rxsize += size*nmemb;
        // Add trailing NULL byte at the end to prevent string overflow
        req->rxdata[req->rxsize] = '\0';
    } else {
        // Receive to the filename.
        // TODO: FILE RESUMING??
#ifndef WSWCURL_TEST_MAIN
        if ( (req->filenum < 0) && ( FS_FOpenFile( req->filename, &(req->filenum), FS_WRITE ) < 0 ) ) {
            return 0; // RETURN ERROR
        }
        FS_Write(ptr, size * nmemb, req->filenum);
#else
        // TODO: IMPLEMENT TEST
#endif
    }
    // Mark connection as having had activity.
    req->activity = 1;
    if (req->callback_progress) {
        // Execute progress callback
        // ??? What to return when expected size is unknown? - currently, return 0.0
        req->callback_progress(req, ( req->rx_expsize < 0 ) ? 0.0 : (req->rxsize / req->rx_expsize) * 100.0);
    }
    return size*nmemb;
}
Esempio n. 6
0
/*
 * Filename are reletive to the quake search path. A null buffer will just
 * return the file length without loading.
 */
int
FS_LoadFile(char *path, void **buffer)
{
	byte *buf; /* Buffer. */
	int size; /* File size. */
	fileHandle_t f; /* File handle. */

	buf = NULL;
	size = FS_FOpenFile(path, &f, FS_READ);

	if (size <= 0)
	{
		if (buffer)
		{
			*buffer = NULL;
		}

		return size;
	}

	if (buffer == NULL)
	{
		FS_FCloseFile(f);
		return size;
	}

	buf = Z_Malloc(size);
	*buffer = buf;

	FS_Read(buf, size, f);
	FS_FCloseFile(f);

	return size;
}
Esempio n. 7
0
void
SV_ReadLevelFile(void)
{
	char name[MAX_OSPATH];
	fileHandle_t f;

	Com_DPrintf("SV_ReadLevelFile()\n");

	Com_sprintf(name, sizeof(name), "save/current/%s.sv2", sv.name);
	FS_FOpenFile(name, &f, FS_READ);

	if (!f)
	{
		Com_Printf("Failed to open %s\n", name);
		return;
	}

	FS_Read(sv.configstrings, sizeof(sv.configstrings), f);
	CM_ReadPortalState(f);
	FS_FCloseFile(f);

	Com_sprintf(name, sizeof(name), "%s/save/current/%s.sav",
				FS_Gamedir(), sv.name);
	ge->ReadLevel(name);
}
Esempio n. 8
0
File: files.c Progetto: qbism/qbq2
/*
============
FS_LoadFile

Filename are reletive to the quake search path
a null buffer will just return the file length without loading
============
*/
int FS_LoadFile(char *path, void **buffer)
{
	FILE	*h;
	byte	*buf;
	int		len;

	buf = NULL;	// quiet compiler warning

	// look for it in the filesystem or pack files
	len = FS_FOpenFile(path, &h);
	if (!h)
	{
		if (buffer)
			*buffer = NULL;
		return -1;
	}

	if (!buffer)
	{
		fclose(h);
		return len;
	}

	buf = Z_Malloc(len);
	*buffer = buf;

	FS_Read(buf, len, h);

	fclose(h);

	return len;
}
Esempio n. 9
0
void Prompt_LoadHistory( commandPrompt_t *prompt, const char *filename ) {
    char buffer[MAX_FIELD_TEXT];
    qhandle_t f;
    int i;
    ssize_t len;

    FS_FOpenFile( filename, &f, FS_MODE_READ|FS_TYPE_REAL|FS_PATH_BASE );
    if( !f ) {
        return;
    }

    for( i = 0; i < HISTORY_SIZE; i++ ) {
        if( ( len = FS_ReadLine( f, buffer, sizeof( buffer ) ) ) < 1 ) {
            break;
        }
        if( prompt->history[i] ) {
            Z_Free( prompt->history[i] );
        }
        prompt->history[i] = memcpy( Z_Malloc( len + 1 ), buffer, len + 1 );
    }

    FS_FCloseFile( f );

    prompt->historyLineNum = i;
    prompt->inputLineNum = i;
}
Esempio n. 10
0
void Prompt_SaveHistory( commandPrompt_t *prompt, const char *filename, int lines ) {
    qhandle_t f;
    char *s;
    int i;

    FS_FOpenFile( filename, &f, FS_MODE_WRITE|FS_PATH_BASE );
    if( !f ) {
        return;
    }

    if( lines > HISTORY_SIZE ) {
        lines = HISTORY_SIZE;
    }

    i = prompt->inputLineNum - lines;
    if( i < 0 ) {
        i = 0;
    }
    for( ; i < prompt->inputLineNum; i++ ) {
        s = prompt->history[i & HISTORY_MASK];
        if( s ) {
            FS_FPrintf( f, "%s\n", s );
        }
    }

    FS_FCloseFile( f );
}
Esempio n. 11
0
File: save.c Progetto: jdolan/q2pro
static int read_binary_file(const char *name)
{
    qhandle_t f;
    size_t len;

    len = FS_FOpenFile(name, &f, FS_MODE_READ | FS_TYPE_REAL | FS_PATH_GAME);
    if (!f)
        return -1;

    if (len > MAX_MSGLEN)
        goto fail;

    if (FS_Read(msg_read_buffer, len, f) != len)
        goto fail;

    SZ_Init(&msg_read, msg_read_buffer, len);
    msg_read.cursize = len;

    FS_FCloseFile(f);
    return 0;

fail:
    FS_FCloseFile(f);
    return -1;
}
Esempio n. 12
0
/*
* SNAP_WriteDemoMetaData
*/
void SNAP_WriteDemoMetaData( const char *filename, const char *meta_data, size_t meta_data_realsize )
{
	unsigned i;
	unsigned v;
	char tmpn[256];
	int filenum, filelen;
	msg_t msg;
	uint8_t msg_buffer[MAX_MSGLEN];
	void *compressed_msg;

	MSG_Init( &msg, msg_buffer, sizeof( msg_buffer ) );

	// write to a temp file
	v = 0;
	for( i = 0; filename[i]; i++ ) {
		v = ( v + i ) * 37 + tolower( filename[i] ); // case insensitivity
	}
	Q_snprintfz( tmpn, sizeof( tmpn ), "%u.tmp", v );

	if( FS_FOpenFile( tmpn, &filenum, FS_WRITE|SNAP_DEMO_GZ ) == -1 ) {
		return;
	}

	SNAP_DemoMetaDataMessage( &msg, meta_data, meta_data_realsize );
	SNAP_RecordDemoMetaDataMessage( filenum, &msg );

	// now open the original file in update mode and overwrite metadata

	// important note: we need to the load the temp file before closing it
	// because in the case of gz compression, closing the file may actually
	// write some data we don't want to copy
	filelen = FS_LoadFile( tmpn, &compressed_msg, NULL, 0 );

	if( compressed_msg ) {
		int origfile;

		if( FS_FOpenFile( filename, &origfile, FS_READ|FS_UPDATE ) != -1 ) {
			FS_Write( compressed_msg, filelen, origfile );
			FS_FCloseFile( origfile );
		}
		FS_FreeFile( compressed_msg );
	}

	FS_FCloseFile( filenum );

	FS_RemoveFile( tmpn );
}
Esempio n. 13
0
/*
* CL_ReadServerCache
*/
void CL_ReadServerCache( void )
{
	int filelen, filehandle;
	qbyte *buf = NULL;
	char *ptr, *token;
	netadr_t adr;
	char adrString[64];
	qboolean favorite = qfalse;

	filelen = FS_FOpenFile( SERVERSFILE, &filehandle, FS_READ );
	if( !filehandle || filelen < 1 )
	{
		FS_FCloseFile( filehandle );
	}
	else
	{
		buf = Mem_TempMalloc( filelen + 1 );
		filelen = FS_Read( buf, filelen, filehandle );
		FS_FCloseFile( filehandle );
	}

	if( !buf )
		return;

	ptr = ( char * )buf;
	while( ptr )
	{
		token = COM_ParseExt( &ptr, qtrue );
		if( !token[0] )
			break;

		if( !Q_stricmp( token, "master" ) )
		{
			favorite = qfalse;
			continue;
		}

		if( !Q_stricmp( token, "favorites" ) )
		{
			favorite = qtrue;
			continue;
		}

		if( NET_StringToAddress( token, &adr ) )
		{
			Q_strncpyz( adrString, token, sizeof( adrString ) );
			token = COM_ParseExt( &ptr, qfalse );
			if( !token[0] )
				continue;

			if( favorite )
				CL_AddServerToList( &favoritesList, adrString, (unsigned int)atoi( token ) );
			else
				CL_AddServerToList( &masterList, adrString, (unsigned int)atoi( token ) );
		}
	}

	Mem_TempFree( buf );
}
Esempio n. 14
0
/*
=================
S_OpenBackgroundTrack
=================
*/
static qboolean S_OpenBackgroundTrack (char *name, bgTrack_t *track)
{
	OggVorbis_File	*vorbisFile;
	vorbis_info		*vorbisInfo;
	ov_callbacks	vorbisCallbacks = {ovc_read, ovc_seek, ovc_close, ovc_tell};
#ifdef OGG_DIRECT_FILE
	char	filename[1024];
	char	*path = NULL;
#endif

//	Com_Printf("Opening background track: %s\n", name);

#ifdef OGG_DIRECT_FILE
	do {
		path = FS_NextPath( path );
		Com_sprintf( filename, sizeof(filename), "%s/%s", path, name );
		if ( (track->file = fopen(filename, "rb")) != 0)
			break;
	} while ( path );
#else
	FS_FOpenFile(name, &track->file);
#endif
	if (!track->file)
	{
		Com_Printf("S_OpenBackgroundTrack: couldn't find %s\n", name);
		return false;
	}

	track->vorbisFile = vorbisFile = Z_Malloc(sizeof(OggVorbis_File));

//	Com_Printf("Opening callbacks for background track\n");

	// bombs out here- ovc_read, FS_Read 0 bytes error
	if (ov_open_callbacks(track, vorbisFile, NULL, 0, vorbisCallbacks) < 0)
	{
		Com_Printf("S_OpenBackgroundTrack: couldn't open OGG stream (%s)\n", name);
		return false;
	}

//	Com_Printf("Getting info for background track\n");

	vorbisInfo = ov_info(vorbisFile, -1);
	if (vorbisInfo->channels != 1 && vorbisInfo->channels != 2)
	{
		Com_Printf("S_OpenBackgroundTrack: only mono and stereo OGG files supported (%s)\n", name);
		return false;
	}

	track->start = ov_raw_tell(vorbisFile);
	track->rate = vorbisInfo->rate;
	track->width = 2;
	track->channels = vorbisInfo->channels; // Knightmare added
	track->format = (vorbisInfo->channels == 2) ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16;

//	Com_Printf("Vorbis info: frequency: %i channels: %i bitrate: %i\n",
//		vorbisInfo->rate, vorbisInfo->channels, vorbisInfo->bitrate_nominal);

	return true;
}
Esempio n. 15
0
/*
==================
SV_BeginDemoServer
==================
*/
void SV_BeginDemoserver(void){
	char	name[MAX_OSPATH];

	Com_sprintf(name, sizeof(name), "demos/%s", sv.name);
	FS_FOpenFile(name, &sv.demofile);
	if(!sv.demofile)
		Com_Error(ERR_DROP, "Couldn't open %s\n", name);
}
Esempio n. 16
0
/*
* Con_Dump_f
*
* Save the console contents out to a file
*/
static void Con_Dump_f( void )
{
    int file;
    size_t buffer_size;
    char *buffer;
    size_t name_size;
    char *name;
    const char *newline = "\r\n";

    if( !con_initialized )
        return;

    if( Cmd_Argc() != 2 )
    {
        Com_Printf( "usage: condump <filename>\n" );
        return;
    }

    name_size = sizeof( char ) * ( strlen( Cmd_Argv( 1 ) ) + strlen( ".txt" ) + 1 );
    name = Mem_TempMalloc( name_size );

    Q_strncpyz( name, Cmd_Argv( 1 ), name_size );
    COM_DefaultExtension( name, ".txt", name_size );
    COM_SanitizeFilePath( name );

    if( !COM_ValidateRelativeFilename( name ) )
    {
        Com_Printf( "Invalid filename.\n" );
        Mem_TempFree( name );
        return;
    }

    if( FS_FOpenFile( name, &file, FS_WRITE ) == -1 )
    {
        Com_Printf( "Couldn't open: %s\n", name );
        Mem_TempFree( name );
        return;
    }

    buffer_size = Con_BufferText( NULL, newline ) + 1;
    buffer = Mem_TempMalloc( buffer_size );

    Con_BufferText( buffer, newline );

    FS_Write( buffer, buffer_size - 1, file );

    FS_FCloseFile( file );

    Mem_TempFree( buffer );

    Com_Printf( "Dumped console text: %s\n", name );
    Mem_TempFree( name );
}
Esempio n. 17
0
struct sfx_s *S_RegisterSexedSound (entity_state_t *ent, char *base)
{
	int				n;
	char			*p;
	struct sfx_s	*sfx;
	FILE			*f;
	char			model[MAX_QPATH];
	char			sexedFilename[MAX_QPATH];
	char			maleFilename[MAX_QPATH];

	// determine what model the client is using
	model[0] = 0;
	n = CS_PLAYERSKINS + ent->number - 1;
	if (cl.configstrings[n][0])
	{
		p = strchr(cl.configstrings[n], '\\');
		if (p)
		{
			p += 1;
			strcpy(model, p);
			p = strchr(model, '/');
			if (p)
				*p = 0;
		}
	}
	// if we can't figure it out, they're male
	if (!model[0])
		strcpy(model, "male");

	// see if we already know of the model specific sound
	Com_sprintf (sexedFilename, sizeof(sexedFilename), "#players/%s/%s", model, base+1);
	sfx = S_FindName (sexedFilename, false);

	if (!sfx)
	{
		// no, so see if it exists
		FS_FOpenFile (&sexedFilename[1], &f);
		if (f)
		{
			// yes, close the file and register it
			FS_FCloseFile (f);
			sfx = S_RegisterSound (sexedFilename);
		}
		else
		{
			// no, revert to the male sound in the pak0.pak
			Com_sprintf (maleFilename, sizeof(maleFilename), "player/%s/%s", "male", base+1);
			sfx = S_AliasName (sexedFilename, maleFilename);
		}
	}

	return sfx;
}
Esempio n. 18
0
/*
* ML_Restart
* Restart map list stuff
*/
void ML_Restart( bool forcemaps )
{
	ML_Shutdown();
	if( forcemaps )
	{
		int filenum;
		if( FS_FOpenFile( MLIST_CACHE, &filenum, FS_WRITE|FS_CACHE ) != -1 )
			FS_FCloseFile( filenum );
	}
	FS_Rescan();
	ML_Init();
}
Esempio n. 19
0
/*
* CL_DownloadRequest
* 
* Request file download
* return qfalse if couldn't request it for some reason
* Files with .pk3 or .pak extension have to have gamedir attached
* Other files must not have gamedir
*/
qboolean CL_DownloadRequest( const char *filename, qboolean requestpak )
{
	if( cls.download.requestname )
	{
		Com_Printf( "Can't download: %s. Download already in progress.\n", filename );
		return qfalse;
	}

	if( !COM_ValidateRelativeFilename( filename ) )
	{
		Com_Printf( "Can't download: %s. Invalid filename.\n", filename );
		return qfalse;
	}

	if( FS_CheckPakExtension( filename ) )
	{
		if( FS_FOpenBaseFile( filename, NULL, FS_READ ) != -1 )
		{
			Com_Printf( "Can't download: %s. File already exists.\n", filename );
			return qfalse;
		}

		if( !Q_strnicmp( COM_FileBase( filename ), "modules", strlen( "modules" ) ) )
		{
			if( !CL_CanDownloadModules() )
				return qfalse;
		}
	}
	else
	{
		if( FS_FOpenFile( filename, NULL, FS_READ ) != -1 )
		{
			Com_Printf( "Can't download: %s. File already exists.\n", filename );
			return qfalse;
		}
	}

	if( cls.socket->type == SOCKET_LOOPBACK )
	{
		Com_DPrintf( "Can't download: %s. Loopback server.\n", filename );
		return qfalse;
	}

	Com_Printf( "Asking to download: %s\n", filename );

	cls.download.requestpak = requestpak;
	cls.download.requestname = Mem_ZoneMalloc( sizeof( char ) * ( strlen( filename ) + 1 ) );
	Q_strncpyz( cls.download.requestname, filename, sizeof( char ) * ( strlen( filename ) + 1 ) );
	cls.download.timeout = Sys_Milliseconds() + 5000;
	CL_AddReliableCommand( va( "download %i \"%s\"", requestpak, filename ) );

	return qtrue;
}
Esempio n. 20
0
void
SV_ReadServerFile(void)
{
	fileHandle_t f;
	char name[MAX_OSPATH], string[128];
	char comment[32];
	char mapcmd[MAX_TOKEN_CHARS];

	Com_DPrintf("SV_ReadServerFile()\n");

	Com_sprintf(name, sizeof(name), "save/current/server.ssv");
	FS_FOpenFile(name, &f, FS_READ);

	if (!f)
	{
		Com_Printf("Couldn't read %s\n", name);
		return;
	}

	/* read the comment field */
	FS_Read(comment, sizeof(comment), f);

	/* read the mapcmd */
	FS_Read(mapcmd, sizeof(mapcmd), f);

	/* read all CVAR_LATCH cvars
	   these will be things like 
	   coop, skill, deathmatch, etc */
	while (1)
	{
		char cvarname[LATCH_CVAR_SAVELENGTH] = {0};
		if (!FS_FRead(cvarname, 1, sizeof(cvarname), f))
		{
			break;
		}

		FS_Read(string, sizeof(string), f);
		Com_DPrintf("Set %s = %s\n", cvarname, string);
		Cvar_ForceSet(cvarname, string);
	}

	FS_FCloseFile(f);

	/* start a new game fresh with new cvars */
	SV_InitGame();

	strcpy(svs.mapcmd, mapcmd);

	/* read game state */
	Com_sprintf(name, sizeof(name), "%s/save/current/game.ssv", FS_Gamedir());
	ge->ReadGame(name);
}
Esempio n. 21
0
/*
* CL_WriteServerCache
*/
void CL_WriteServerCache( void )
{
	serverlist_t *server;
	int filehandle;
	char str[256];
	netadr_t adr;

	if( FS_FOpenFile( SERVERSFILE, &filehandle, FS_WRITE ) == -1 )
	{
		Com_Printf( "CL_WriteServerList: Couldn't create the cache file\n" );
		return;
	}

	Q_snprintfz( str, sizeof( str ), "// servers cache file generated by %s. Do not modify\n", APPLICATION );
	FS_Print( filehandle, str );

	FS_Print( filehandle, "master\n" );
	server = masterList;
	while( server )
	{
		if( server->lastValidPing + 7 > Com_DaysSince1900() )
		{
			if( NET_StringToAddress( server->address, &adr ) )
			{
				Q_snprintfz( str, sizeof( str ), "%s %i\n", server->address, (int)server->lastValidPing );
				FS_Print( filehandle, str );
			}
		}

		server = server->pnext;
	}

	FS_Print( filehandle, "favorites\n" );
	server = favoritesList;
	while( server )
	{
		if( server->lastValidPing + 7 > Com_DaysSince1900() )
		{
			if( NET_StringToAddress( server->address, &adr ) )
			{
				Q_snprintfz( str, sizeof( str ), "%s %i\n", server->address, (int)server->lastValidPing );
				FS_Print( filehandle, str );
			}
		}

		server = server->pnext;
	}

	FS_FCloseFile( filehandle );
}
Esempio n. 22
0
qboolean
FS_FileExists(char *path)
{
	fileHandle_t f;

	FS_FOpenFile(path, &f, FS_READ);

	if (f != 0)
	{
		FS_FCloseFile(f);
		return true;
	}

	return false;
}
Esempio n. 23
0
static qboolean SV_FilenameForDownloadRequest( const char *requestname, qboolean requestpak,
	const char **uploadname, const char **errormsg )
{
	if( FS_CheckPakExtension( requestname ) )
	{
		if( !requestpak )
		{
			*errormsg = "Pak file requested as a non pak file";
			return qfalse;
		}
		if( FS_FOpenBaseFile( requestname, NULL, FS_READ ) == -1 )
		{
			*errormsg = "File not found";
			return qfalse;
		}

		*uploadname = requestname;
	}
	else
	{
		if( FS_FOpenFile( requestname, NULL, FS_READ ) == -1 )
		{
			*errormsg = "File not found";
			return qfalse;
		}

		// check if file is inside a PAK
		if( requestpak )
		{
			*uploadname = FS_PakNameForFile( requestname );
			if( !*uploadname )
			{
				*errormsg = "File not available in pack";
				return qfalse;
			}
		}
		else
		{
			*uploadname = FS_BaseNameForFile( requestname );
			if( !*uploadname )
			{
				*errormsg = "File only available in pack";
				return qfalse;
			}
		}
	}
	return qtrue;
}
Esempio n. 24
0
/*
* SCR_PlayCinematic
*/
static void SCR_PlayCinematic( char *arg )
{
	int len;
	size_t name_size;
	static cinematics_t clientCin;
	cinematics_t *cin = cl.cin = &clientCin;
	roq_chunk_t *chunk = &cin->chunk;

	name_size = strlen( "video/" ) + strlen( arg ) + strlen( ".roq" ) + 1;
	cin->name = Mem_ZoneMalloc( name_size );
	Q_snprintfz( cin->name, name_size, "video/%s", arg );
	COM_DefaultExtension( cin->name, ".roq", name_size );

	// nasty hack
	cin->s_rate = 22050;
	cin->s_width = 2;
	cin->width = cin->height = 0;

	cin->frame = 0;
	len = FS_FOpenFile( cin->name, &cin->file, FS_READ );
	if( !cin->file || len < 1 )
	{
		Com_Printf( "Couldn't find %s\n", cin->name );
		SCR_StopCinematic();
		return;
	}

	// read header
	RoQ_ReadChunk( cin );

	if( chunk->id != RoQ_HEADER1 || chunk->size != RoQ_HEADER2 || chunk->argument != RoQ_HEADER3 )
	{
		Com_Printf( "Invalid video file %s\n", cin->name );
		SCR_StopCinematic();
		return;
	}

	SCR_EndLoadingPlaque();

	cin->headerlen = FS_Tell( cin->file );
	cin->frame = 0;
	cin->pic = cin->pic_pending = SCR_ReadNextCinematicFrame();
	cin->time = cls.realtime + 1; // add 1 msec so SCR_GetCinematicTime is also valid for early commands

	CL_SetClientState( CA_ACTIVE );

	CL_SoundModule_StopAllSounds();
}
Esempio n. 25
0
/*
==============
SV_ReadServerFile

==============
*/
void SV_ReadServerFile (void)
{
	fileHandle_t	f;
	char	fileName[MAX_OSPATH], varName[128], string[128];
	char	comment[32];
	char	mapcmd[MAX_TOKEN_CHARS];

	Com_DPrintf("SV_ReadServerFile()\n");

	Com_sprintf (fileName, sizeof(fileName), "save/current/server.ssv");
	FS_FOpenFile (fileName, &f, FS_READ);
	if (!f)
	{
		Com_Printf ("Couldn't read %s\n", fileName);
		return;
	}
	// read the comment field
	FS_Read (comment, sizeof(comment), f);

	// read the mapcmd
	FS_Read (mapcmd, sizeof(mapcmd), f);

	// read all CVAR_LATCH cvars
	// these will be things like coop, skill, deathmatch, etc
	while (1)
	{
		if (!FS_FRead (varName, 1, sizeof(varName), f))
			break;
		FS_Read (string, sizeof(string), f);
		Com_DPrintf ("Set %s = %s\n", varName, string);
		Cvar_ForceSet (varName, string);
	}

	FS_FCloseFile(f);

	// start a new game fresh with new cvars
	SV_InitGame ();

//	strncpy (svs.mapcmd, mapcmd);
	Q_strncpyz (svs.mapcmd, mapcmd, sizeof(svs.mapcmd));

	// read game state
	Com_sprintf (fileName, sizeof(fileName), "%s/save/current/game.ssv", FS_Gamedir());
	ge->ReadGame (fileName);
}
Esempio n. 26
0
//handle a map <mapname> command from the console or progs.
void SV_Map_f (void) {
	char level[MAX_QPATH], expanded[MAX_QPATH];
#ifndef WITH_FTE_VFS
	FILE *f;
#else
	vfsfile_t *f;
#endif
	qbool devmap;

	if (Cmd_Argc() != 2) {
		Com_Printf ("%s <levelname> : continue game on a new level\n", Cmd_Argv(0));
		return;
	}
	devmap = !strcasecmp (Cmd_Argv(0), "devmap");
	strlcpy (level, Cmd_Argv(1), sizeof(level));

	// check to make sure the level exists
	snprintf (expanded, sizeof(expanded), "maps/%s.bsp", level);
#ifndef WITH_FTE_VFS
	if (FS_FOpenFile (expanded, &f) == -1) {
		Com_Printf ("Can't find %s\n", expanded);
		return;
	}
	fclose (f);
#else
	if (!(f = FS_OpenVFS(expanded, "rb", FS_ANY))) {
		Com_Printf ("Can't find %s\n", expanded);
		return;
	}
	VFS_CLOSE(f);
#endif // WITH_FTE_VFS

#ifndef SERVERONLY
	if (!dedicated)
		CL_BeginLocalConnection ();
#endif

	SV_BroadcastCommand ("changing\n");
	SV_SendMessagesToAll ();

	SV_SpawnServer (level, devmap);

	SV_BroadcastCommand ("reconnect\n");
}
Esempio n. 27
0
void Create_Savestrings(void)
{
    int          i;
    fileHandle_t f;
    char         name[MAX_OSPATH];
    char         mapname[MAX_TOKEN_CHARS];
    char         *ch;

    for (i = 0; i < MAX_SAVEGAMES; i++)
    {
        Com_sprintf(name, sizeof(name), "save/kmq2save%i/server.ssv", i);
        FS_FOpenFile(name, &f, FS_READ);
        if (!f)
        {
            //Com_Printf("Save file %s not found.\n", name);
            strcpy(m_savestrings[i], "<EMPTY>");
            m_savevalid[i] = false;
        }
        else
        {
            FS_Read(m_savestrings[i], sizeof(m_savestrings[i]), f);

            if (i == 0)             // grab mapname
            {
                FS_Read(mapname, sizeof(mapname), f);
                if (mapname[0] == '*')                 // skip * marker
                {
                    Com_sprintf(m_mapname, sizeof(m_mapname), mapname + 1);
                }
                else
                {
                    Com_sprintf(m_mapname, sizeof(m_mapname), mapname);
                }
                ch = strchr(m_mapname, '$');
                if (ch)
                {
                    *ch = 0;                     // terminate string at $ marker
                }
            }
            FS_FCloseFile(f);
            m_savevalid[i] = true;
        }
    }
}
Esempio n. 28
0
void ReadTextureSurfaceAssignments()
{
	char	filename[MAX_OSPATH];
	FILE	*f;
	char	line[80];

	num_texsurfs = 0;

	Com_sprintf (filename, sizeof(filename), "texsurfs.txt");
	FS_FOpenFile (filename, &f);
	if (!f) return;
	while (fgets(line, sizeof(line), f) && num_texsurfs < MAX_TEX_SURF)
	{
		sscanf(line,"%d %s",&tex_surf[num_texsurfs].step_id,tex_surf[num_texsurfs].tex);
		//Com_Printf("%d %s\n",tex_surf[num_texsurfs].step_id,tex_surf[num_texsurfs].tex);
		num_texsurfs++;
	}
	fclose(f);
}
Esempio n. 29
0
File: files.c Progetto: Slipyx/r1q2
/*
============
FS_LoadFile

Filename are reletive to the quake search path
a null buffer will just return the file length without loading
============
*/
int EXPORT FS_LoadFile (const char *path, void /*@out@*/ /*@null@*/**buffer)
{
	FILE		*h;
	byte		*buf;
	int			len;
	qboolean	closeHandle;
	// look for it in the filesystem or pack files
	//START_PERFORMANCE_TIMER;
	//Com_Printf ("%s... ", path);
	len = FS_FOpenFile (path, &h, buffer ? HANDLE_OPEN : HANDLE_NONE, &closeHandle);
	//STOP_PERFORMANCE_TIMER;

	//Com_Printf ("TOTAL SO FAR: %.5f\n", totalTime);

	if (len == -1)
	{
		if (buffer)
			*buffer = NULL;
		return -1;
	}
	
	if (!buffer)
		return len;

	if (!len)
	{
		fclose (h);
		Com_Printf ("WARNING: 0 byte file: %s\n", LOG_GENERAL|LOG_WARNING, path);
		*buffer = CopyString ("", TAGMALLOC_FSLOADFILE);
		return 0;
	}

	buf = Z_TagMalloc(len, TAGMALLOC_FSLOADFILE);
	*buffer = buf;
	current_filename = path;
	FS_Read (buf, len, h);
	current_filename = "unknown";

	if (closeHandle)
		fclose (h);

	return len;
}
Esempio n. 30
0
//FIXME: this is bad, loads entire file for just 8 bytes!
qboolean GetWalInfo (const char *name, int *width, int *height)
{
		miptex_t	mt;
		qboolean	closeFile;
		FILE		*h;

		FS_FOpenFile (name, &h, HANDLE_OPEN, &closeFile);
		if (!h)
			return false;

		/*if (fread (&mt, sizeof(mt), 1, h) != 1)
		{
			ri.FS_FCloseFile (h);
			return false;
		}*/
		FS_Read (&mt, sizeof(mt), h);

		if (closeFile)
			FS_FCloseFile (h);
		
		*width = LittleLong(mt.width);
		*height = LittleLong(mt.height);

#if defined(_DEBUG) && !defined(EMSCRIPTEN)
		int		i;
		char	grey = 8;

		FS_CreatePath (va("wals/%s", name));
		h = fopen (va("wals/%s", name), "wb");
		fwrite (&mt, 1, sizeof(mt), h);
		for (i = 0; i < mt.width * mt.height; i++)
			fwrite (&grey, 1, 1, h);
		for (i = 0; i < (mt.width * mt.height) / 2; i++)
			fwrite (&grey, 1, 1, h);
		for (i = 0; i < (mt.width * mt.height) / 4; i++)
			fwrite (&grey, 1, 1, h);
		for (i = 0; i < (mt.width * mt.height) / 8; i++)
			fwrite (&grey, 1, 1, h);
		fclose (h);
#endif

		return true;
}