void HPAK_CheckSize( const char *filename ) { string pakname; int maxsize; maxsize = hpk_maxsize->integer; if( maxsize <= 0 ) return; if( !filename || !filename[0] ) return; Q_strncpy( pakname, filename, sizeof( pakname )); FS_StripExtension( pakname ); FS_DefaultExtension( pakname, ".hpk" ); if( FS_FileSize( pakname, false ) > ( maxsize * 1000000 )) MsgDev( D_ERROR, "HPAK_CheckSize: %s is too large.\n", filename ); }
int Netchan_CreateFileFragments(qboolean server, netchan_t *chan, const char *filename) #ifdef REHLDS_FIXES { if (!server) return Netchan_CreateFileFragments_(server, chan, filename); if (!FS_FileExists(filename)) return FALSE; if (FS_FileSize(filename) > sv_filetransfermaxsize.value) return FALSE; auto wait = (fragbufwaiting_t *)Mem_ZeroMalloc(sizeof(fragbufwaiting_t)); auto buf = Netchan_AllocFragbuf(); buf->bufferid = 1; buf->isbuffer = false; buf->isfile = true; Q_strncpy(buf->filename, filename, sizeof(buf->filename)); buf->filename[sizeof(buf->filename) - 1] = '\0'; Netchan_AddFragbufToTail(wait, buf); if (!chan->waitlist[FRAG_FILE_STREAM]) { chan->waitlist[FRAG_FILE_STREAM] = wait; } else { auto p = chan->waitlist[FRAG_FILE_STREAM]; while (p->next) p = p->next; p->next = wait; } return TRUE; }
qboolean Cmd_CheckMapsList_R( qboolean fRefresh, qboolean onlyingamedir ) { byte buf[MAX_SYSPATH]; char *buffer; string result; int i, size; search_t *t; file_t *f; if( FS_FileSize( "maps.lst", onlyingamedir ) > 0 && !fRefresh ) { MsgDev( D_NOTE, "maps.lst is exist: %s\n", onlyingamedir ? "basedir" : "gamedir" ); return true; // exist } t = FS_Search( "maps/*.bsp", false, onlyingamedir ); if( !t ) { if( onlyingamedir ) { // mod doesn't contain any maps (probably this is a bot) return Cmd_CheckMapsList_R( fRefresh, false ); } return false; } buffer = Mem_Alloc( host.mempool, t->numfilenames * 2 * sizeof( result )); for( i = 0; i < t->numfilenames; i++ ) { char *ents = NULL, *pfile; int ver = -1, lumpofs = 0, lumplen = 0; string mapname, message, entfilename; const char *ext = FS_FileExtension( t->filenames[i] ); if( Q_stricmp( ext, "bsp" )) continue; f = FS_Open( t->filenames[i], "rb", onlyingamedir ); FS_FileBase( t->filenames[i], mapname ); if( f ) { int num_spawnpoints = 0; dheader_t *header; Q_memset( buf, 0, MAX_SYSPATH ); FS_Read( f, buf, MAX_SYSPATH ); ver = *(uint *)buf; switch( ver ) { case Q1BSP_VERSION: case HLBSP_VERSION: case XTBSP_VERSION: header = (dheader_t *)buf; if( header->lumps[LUMP_ENTITIES].fileofs <= 1024 ) { lumpofs = header->lumps[LUMP_PLANES].fileofs; lumplen = header->lumps[LUMP_PLANES].filelen; } else { lumpofs = header->lumps[LUMP_ENTITIES].fileofs; lumplen = header->lumps[LUMP_ENTITIES].filelen; } break; } Q_strncpy( entfilename, t->filenames[i], sizeof( entfilename )); FS_StripExtension( entfilename ); FS_DefaultExtension( entfilename, ".ent" ); ents = FS_LoadFile( entfilename, NULL, true ); if( !ents && lumplen >= 10 ) { FS_Seek( f, lumpofs, SEEK_SET ); ents = (char *)Mem_Alloc( host.mempool, lumplen + 1 ); FS_Read( f, ents, lumplen ); } if( ents ) { // if there are entities to parse, a missing message key just // means there is no title, so clear the message string now char token[2048]; qboolean worldspawn = true; Q_strncpy( message, "No Title", MAX_STRING ); pfile = ents; while(( pfile = COM_ParseFile( pfile, token )) != NULL ) { if( token[0] == '}' && worldspawn ) worldspawn = false; else if( !Q_strcmp( token, "message" ) && worldspawn ) { // get the message contents pfile = COM_ParseFile( pfile, message ); } else if( !Q_strcmp( token, "classname" )) { pfile = COM_ParseFile( pfile, token ); if( !Q_strcmp( token, GI->mp_entity )) num_spawnpoints++; } if( num_spawnpoints ) break; // valid map } Mem_Free( ents ); } if( f ) FS_Close( f ); if( num_spawnpoints ) { // format: mapname "maptitle"\n Q_sprintf( result, "%s \"%s\"\n", mapname, message ); Q_strcat( buffer, result ); // add new string } } } if( t ) Mem_Free( t ); // free search result size = Q_strlen( buffer ); if( !size ) { if( buffer ) Mem_Free( buffer ); if( onlyingamedir ) return Cmd_CheckMapsList_R( fRefresh, false ); return false; } // write generated maps.lst if( FS_WriteFile( "maps.lst", buffer, Q_strlen( buffer ))) { if( buffer ) Mem_Free( buffer ); return true; } return false; }
/* DESCRIPTION: COM_FileSize // LOCATION: who cares // PATH: here and there // // Gets a file's size. Hey! There's an FS function that does that. */ HLDS_DLLEXPORT int COM_FileSize(char *filename) { return(FS_FileSize(filename)); }
/* ============= COM_FileSize ============= */ int COM_FileSize( const char *filename ) { return FS_FileSize( filename, false ); }
/* ============================== Netchan_CreateFileFragments ============================== */ int Netchan_CreateFileFragments( qboolean server, netchan_t *chan, const char *filename ) { int chunksize; int send, pos; int remaining; int bufferid = 1; int filesize = 0; qboolean firstfragment = true; fragbufwaiting_t *wait, *p; fragbuf_t *buf; chunksize = bound( 16, net_blocksize->integer, 512 ); filesize = FS_FileSize( filename, false ); if( filesize <= 0 ) { MsgDev( D_WARN, "Unable to open %s for transfer\n", filename ); return 0; } wait = (fragbufwaiting_t *)Mem_Alloc( net_mempool, sizeof( fragbufwaiting_t )); remaining = filesize; pos = 0; while( remaining > 0 ) { send = min( remaining, chunksize ); buf = Netchan_AllocFragbuf(); buf->bufferid = bufferid++; // copy in data BF_Clear( &buf->frag_message ); if( firstfragment ) { firstfragment = false; // Write filename BF_WriteString( &buf->frag_message, filename ); // Send a bit less on first package send -= BF_GetNumBytesWritten( &buf->frag_message ); } buf->isfile = true; buf->size = send; buf->foffset = pos; Q_strncpy( buf->filename, filename, sizeof( buf->filename )); pos += send; remaining -= send; Netchan_AddFragbufToTail( wait, buf ); } // now add waiting list item to end of buffer queue if( !chan->waitlist[FRAG_FILE_STREAM] ) { chan->waitlist[FRAG_FILE_STREAM] = wait; } else { p = chan->waitlist[FRAG_FILE_STREAM]; while( p->next ) { p = p->next; } p->next = wait; } return 1; }