void G_SaveBanIP( void ) {//save out all the banned IPs int i; char *str; fileHandle_t fh; byte b[4]; trap_FS_FOpenFile("banip.txt", &fh, FS_WRITE); if ( !fh ) { G_Printf ( "G_SaveBanIP - ERROR: can't open banip.txt\n" ); return; } str = va("%d \n", numIPFilters); trap_FS_Write(str, strlen(str), fh); for ( i = 0 ; i < numIPFilters ; i++ ) { if (ipFilters[i].compare == 0xffffffff) { str = "unused \n"; trap_FS_Write(str, strlen(str), fh); } else { *(unsigned *)b = ipFilters[i].compare; str = va("%i.%i.%i.%i \n", b[0], b[1], b[2], b[3]); trap_FS_Write(str, strlen(str), fh); } } trap_FS_FCloseFile(fh); }
static void CG_SaveFileAiNode_f(void) { int i; fileHandle_t file; char *filename; const char *info; const char *map; char header[] = "AI-NODES"; if(!cg_cheats) return; // get mapname info = CG_ConfigString( CS_SERVERINFO ); map = Info_ValueForKey( info, "mapname" ); filename = va("maps/%s.ai", map); if ( trap_FS_FOpenFile( filename, &file, FS_WRITE ) < 0 ) { CG_Printf( "Could not write AI-node file: %s\n", filename ); trap_FS_FCloseFile( file ); return; } // write the ai-node-date // first write ai-node header for verification trap_FS_Write(header, sizeof(header), file); // loop through the nodes for(i=0; i<ai_nodepointer; i++) { trap_FS_Write(ai_nodes[i], sizeof(vec3_t), file); } trap_FS_FCloseFile(file); CG_Printf("AI-Node_File: %s succesfully written.\n", filename); }
static void UpdateIDBans (void) { fileHandle_t f; int i; char buffer[1024]; idFilter_t *id; //TiM: Create and/reset the ban file trap_FS_FOpenFile( "RPG-X_Banned_Players.txt", &f, FS_WRITE ); if ( !f ) { G_Printf( "ERROR: Couldn't update the ban file.\n" ); return; } //file header memset( buffer, 0, sizeof( buffer ) ); Q_strcat( buffer, sizeof(buffer), "//***************************************************\n" ); Q_strcat( buffer, sizeof(buffer), "//RPG-X Banned Users ID List\n" ); Q_strcat( buffer, sizeof(buffer), "//\n" ); Q_strcat( buffer, sizeof(buffer), "//The formatting for each entry goes as such:\n" ); Q_strcat( buffer, sizeof(buffer), "//{\n" ); Q_strcat( buffer, sizeof(buffer), "//\t-ID : Unique Player ID\n" ); Q_strcat( buffer, sizeof(buffer), "//\t-Name : User name of the banned player\n" ); Q_strcat( buffer, sizeof(buffer), "//\t-Ban Reason : Reason for being banned.\n" ); Q_strcat( buffer, sizeof(buffer), "//}\n" ); Q_strcat( buffer, sizeof(buffer), "//\n" ); Q_strcat( buffer, sizeof(buffer), "//***************************************************\n" ); Q_strcat( buffer, sizeof(buffer), "\n" ); //write the header to the file trap_FS_Write( buffer, strlen(buffer), f ); //write out the data for each banned player for ( i = 0; i < numIDFilters; i++ ) { id = &idFilters[i]; if ( !id || id->playerID == 0 ) continue; memset( buffer, 0, sizeof( buffer ) ); //will produce this output: //i //{ // <ID> // <Name> // <Reason> //} //When parsed back in, the line breaks will be used to divide it up Com_sprintf( buffer, sizeof( buffer ), "%i\n{\n\t%lu\n\t\"%s\"\n\t\"%s\"\n}\n\n", i, id->playerID, id->playerName, id->banReason ); trap_FS_Write( buffer, strlen(buffer), f ); } trap_FS_FCloseFile( f ); }
/* * SV_WriteIPList */ void SV_WriteIPList( void ) { int file; char name[MAX_QPATH]; char string[MAX_STRING_CHARS]; qbyte b[4]; int i; Q_strncpyz( name, "listip.cfg", sizeof( name ) ); //G_Printf( "Writing %s.\n", name ); if( trap_FS_FOpenFile( name, &file, FS_WRITE ) == -1 ) { G_Printf( "Couldn't open %s\n", name ); return; } Q_snprintfz( string, sizeof( string ), "set filterban %d\r\n", filterban->integer ); trap_FS_Write( string, strlen( string ), file ); for( i = 0; i < numipfilters; i++ ) { if (ipfilters[i].timeout && ipfilters[i].timeout <= game.serverTime) continue; *(unsigned *)b = ipfilters[i].compare; if( ipfilters[i].timeout ) Q_snprintfz( string, sizeof( string ), "addip %i.%i.%i.%i %.2f\r\n", b[0], b[1], b[2], b[3], (ipfilters[i].timeout - game.serverTime)/(1000.0f*60.0f) ); else Q_snprintfz( string, sizeof( string ), "addip %i.%i.%i.%i\r\n", b[0], b[1], b[2], b[3] ); trap_FS_Write( string, strlen( string ), file ); } trap_FS_FCloseFile( file ); }
/* =============== UI_ClearScores =============== */ void UI_ClearScores() { char gameList[4096]; char *gameFile; int i, len, count, size; fileHandle_t f; postGameInfo_t newInfo; count = trap_FS_GetFileList( "games", "game", gameList, sizeof(gameList) ); size = sizeof(postGameInfo_t); memset(&newInfo, 0, size); if (count > 0) { gameFile = gameList; for ( i = 0; i < count; i++ ) { len = strlen(gameFile); if (trap_FS_FOpenFile(va("games/%s",gameFile), &f, FS_WRITE) >= 0) { trap_FS_Write(&size, sizeof(int), f); trap_FS_Write(&newInfo, size, f); trap_FS_FCloseFile(f); } gameFile += len + 1; } } UI_SetBestScores(&newInfo, qfalse); }
/* ================ writeFile_int This writes an integer to the file. Since there is no logic as to where it writes, it must be called "just-in-time." ================ */ void writeFile_int( int v, fileHandle_t f ) { char buf[ 32 ]; Com_sprintf( buf, sizeof( buf ), "%d", v ); trap_FS_Write( buf, strlen( buf ), f ); trap_FS_Write( "\n", 1, f ); }
//=========================================================================== // Routine : AOTCTC_Holocron_Savepositions // Description : Saves holocron positions to a .hpf file on disk void AOTCTC_Holocron_Savepositions( void ) { fileHandle_t f; char *fileString; //[DynamicMemoryTweaks] char savePath[MAX_QPATH]; //[/DynamicMemoryTweaks] //[RawMapName] //vmCvar_t mapname; //[/RawMapName] char lineout[MAX_INFO_STRING]; int loop = 0; number_of_holocronpositions--; G_Printf("^7Saving holocron position table.\n"); fileString = NULL; //[RawMapName] //savePath = (char *)B_TempAlloc(1024*4); //trap_Cvar_Register( &mapname, "mapname", "", CVAR_SERVERINFO | CVAR_ROM ); //Com_sprintf(savePath, 1024*4, "holocron_positions/%s.hpf\0", mapname.string); Com_sprintf(savePath, sizeof(savePath), "holocron_positions/%s.hpf", level.rawmapname); //[/RawMapName] trap_FS_FOpenFile(savePath, &f, FS_WRITE); if ( !f ) { return; } Com_sprintf( lineout, sizeof(lineout), "%i ", number_of_holocronpositions); trap_FS_Write( lineout, strlen(lineout), f); while (loop < number_of_holocronpositions) { char lineout[MAX_INFO_STRING]; Com_sprintf( lineout, sizeof(lineout), "%f %f %f ", holocrons[loop].origin[0], holocrons[loop].origin[1], holocrons[loop].origin[2] ); trap_FS_Write( lineout, strlen(lineout), f); loop++; } G_Printf("^7Holocron Position table saved %i holocron positions to file %s.\n", number_of_holocronpositions, savePath); trap_FS_FCloseFile( f ); }
/* ================ writeFile_string This writes a string to the file. Since there is no logic as to where it writes, it must be called "just-in-time." ================ */ void writeFile_string( char *s, fileHandle_t f ) { char buf[ MAX_STRING_CHARS ]; buf[ 0 ] = '\0'; if( s[ 0 ] ) { //Q_strcat(buf, sizeof(buf), s); Q_strncpyz( buf, s, sizeof( buf ) ); trap_FS_Write( buf, strlen( buf ), f ); } trap_FS_Write( "\n", 1, f ); }
static void WriteWeaponCacheFile ( weaponData_t *weaponDataTable, int *numLoadedWeapons ) { fileHandle_t f; char *buffer; char *p; weaponDataCacheHeader_t *header = NULL; int bufferSize; trap_FS_FOpenFile ("ext_data/weapons/weapcache.bin", &f, FS_WRITE); if ( !f ) { return; } bufferSize = sizeof (weaponDataCacheHeader_t) + sizeof (weaponData_t) * *numLoadedWeapons; buffer = (char *)malloc (bufferSize); p = buffer; header = (weaponDataCacheHeader_t *)p; header->version = WEAPON_DATA_CACHE_VERSION; header->numWeapons = *numLoadedWeapons; p += sizeof (weaponDataCacheHeader_t); memcpy (p, weaponDataTable, sizeof (weaponData_t) * *numLoadedWeapons); trap_FS_Write ((void *)buffer, bufferSize, f); trap_FS_FCloseFile (f); free (buffer); }
/* ================= G_LogPrintf Print to the logfile with a time stamp if it is open ================= */ void QDECL G_LogPrintf( const char *fmt, ... ) { va_list argptr; char string[1024]; int min, tens, sec; sec = ( level.time - level.startTime ) / 1000; min = sec / 60; sec -= min * 60; tens = sec / 10; sec -= tens * 10; Com_sprintf( string, sizeof(string), "%3i:%i%i ", min, tens, sec ); va_start( argptr, fmt ); Q_vsnprintf(string + 7, sizeof(string) - 7, fmt, argptr); va_end( argptr ); if ( g_dedicated.integer ) { G_Printf( "%s", string + 7 ); } if ( !level.logFile ) { return; } trap_FS_Write( string, strlen( string ), level.logFile ); }
qboolean Script_WriteProfile(char *profile_path) { fileHandle_t f; char com_pid[256]; if (FileExists(profile_path)) { trap_FS_Delete(profile_path); } if (trap_FS_FOpenFile(profile_path, &f, FS_WRITE) < 0) { Com_Printf("Script_WriteProfile: Can't write %s.\n", profile_path); return qfalse; } if (f < 0) { Com_Printf("Script_WriteProfile: Can't write %s.\n", profile_path); return qfalse; } DC->getCVarString("com_pid", com_pid, sizeof(com_pid)); trap_FS_Write(com_pid, strlen(com_pid), f); trap_FS_FCloseFile(f); return qtrue; }
void QDECL LUA_LOG(const char *fmt, ...) { va_list argptr; char buff[1024], string[1024]; int min, tens, sec; va_start(argptr, fmt); Com_sprintf(buff, sizeof(buff), fmt, argptr); va_end(argptr); if(g_dedicated.integer) { trap_Printf(buff); } if(level.logFile) { sec = level.time / 1000; min = sec / 60; sec -= min * 60; tens = sec / 10; sec -= tens * 10; Com_sprintf(string, sizeof(string), "%i:%i%i %s", min, tens, sec, buff); trap_FS_Write(string, strlen(string), level.logFile); } }
void G_DebugAddSkillLevel(gentity_t *ent, skillType_t skill) { qtime_t ct; if (!g_debugSkills.integer) { return; } trap_SendServerCommand(ent - g_entities, va("sdbg \"^%c(SK: %2i XP: %6.2f) %s: You raised your skill level to %i.\"\n", COLOR_RED + skill, ent->client->sess.skill[skill], ent->client->sess.skillpoints[skill], skillNames[skill], ent->client->sess.skill[skill])); trap_RealTime(&ct); if (g_debugSkills.integer >= 2 && skillDebugLog != -1) { char *s = va("%02d:%02d:%02d : ^%c(SK: %2i XP: %6.2f) %s: %s raised in skill level to %i.\n", ct.tm_hour, ct.tm_min, ct.tm_sec, COLOR_RED + skill, ent->client->sess.skill[skill], ent->client->sess.skillpoints[skill], skillNames[skill], ent->client->pers.netname, ent->client->sess.skill[skill]); trap_FS_Write(s, strlen(s), skillDebugLog); } }
void G_DebugOpenSkillLog(void) { vmCvar_t mapname; qtime_t ct; char *s; if (g_debugSkills.integer < 2) { return; } trap_Cvar_Register(&mapname, "mapname", "", CVAR_SERVERINFO | CVAR_ROM); trap_RealTime(&ct); if (trap_FS_FOpenFile(va("skills-%d-%02d-%02d-%02d%02d%02d-%s.log", 1900 + ct.tm_year, ct.tm_mon + 1, ct.tm_mday, ct.tm_hour, ct.tm_min, ct.tm_sec, mapname.string), &skillDebugLog, FS_APPEND_SYNC) < 0) { return; } s = va("%02d:%02d:%02d : Logfile opened.\n", ct.tm_hour, ct.tm_min, ct.tm_sec); trap_FS_Write(s, strlen(s), skillDebugLog); }
void G_DebugAddSkillPoints(gentity_t *ent, skillType_t skill, float points, const char *reason) { qtime_t ct; if (!g_debugSkills.integer) { return; } trap_SendServerCommand(ent - g_entities, va("sdbg \"^%c(SK: %2i XP: %6.2f) %s: You gained %.2fXP, reason: %s.\"\n", COLOR_RED + skill, ent->client->sess.skill[skill], ent->client->sess.skillpoints[skill], skillNames[skill], points, reason)); trap_RealTime(&ct); if (g_debugSkills.integer >= 2 && skillDebugLog != -1) { char *s = va("%02d:%02d:%02d : ^%c(SK: %2i XP: %6.2f) %s: %s gained %.2fXP, reason: %s.\n", ct.tm_hour, ct.tm_min, ct.tm_sec, COLOR_RED + skill, ent->client->sess.skill[skill], ent->client->sess.skillpoints[skill], skillNames[skill], ent->client->pers.netname, points, reason); trap_FS_Write(s, strlen(s), skillDebugLog); } }
void G_DebugWrite(const char *path, const char *text) { fileHandle_t f; trap_FS_FOpenFile( path, &f, FS_APPEND ); trap_FS_Write(text, strlen(text), f); trap_FS_FCloseFile(f); }
/* ================= Bot_ScriptLog_Entry ================= */ void Bot_ScriptLog_Entry( bot_state_t *bs, qboolean showDetails, char *preText, char *fmt, ... ) { va_list ap; char text[1024], *pStr, *token; fileHandle_t f; int i; // if (!(f = bs->script.logFile)) return; // // timestamp // get the time/date Q_strncpyz( text, va("(%i) ", level.time), sizeof(text) ); trap_FS_Write( text, strlen(text), f ); // i = 40; // padding for indentation // pretext if (preText) { trap_FS_Write( preText, strlen(preText), f ); i -= strlen(preText); if (i < 0) i = 0; } // indentation while (i--) trap_FS_Write( " ", 1, f ); // if (showDetails && (Bot_Script_GetCurrentLine( bs ) > -1)) { // show the current script line and text Q_strncpyz( text, va("(line %i:", Bot_Script_GetCurrentLine( bs )), sizeof(text) ); trap_FS_Write( text, strlen(text), f ); // text pStr = bs->script.status.currentItem->text; while ((token = COM_ParseExt( &pStr, qfalse )) && token[0]) { trap_FS_Write( " ", 1, f ); trap_FS_Write( token, strlen(token), f ); } trap_FS_Write( ") ", 2, f ); } // if (fmt) { va_start(ap, fmt); Q_vsnprintf( text, sizeof(text), fmt, ap ); if (strlen(text) >= sizeof(text)) { //G_Error( "Bot_ScriptLog_Entry: text exceeded buffer size" ); // just cut it short text[sizeof(text)-1] = '\0'; } va_end(ap); // trap_FS_Write( text, strlen(text), f ); } trap_FS_Write( "\r\n", 2, f ); }
static int GLua_File_Write(lua_State *L) { fileHandle_t f; int len; const void *buff = lua_tolstring(L, 2, (size_t *)&len); trap_FS_FOpenFile(va("glua/data/%s", luaL_checkstring(L,1)), &f, FS_WRITE); trap_FS_Write(buff, len, f); trap_FS_FCloseFile(f); return 0; }
/* * AI_SavePLKFile * save nodes and plinks to file. * Only navigation nodes are saved. Item nodes aren't */ static qboolean AI_SavePLKFile( char *mapname ) { char filename[MAX_QPATH]; int version = NAV_FILE_VERSION; int filenum; int length; int i; int numNodes; Q_snprintfz( filename, sizeof( filename ), "%s/%s.%s", NAV_FILE_FOLDER, mapname, NAV_FILE_EXTENSION ); length = trap_FS_FOpenFile( filename, &filenum, FS_WRITE ); if( length == -1 ) return qfalse; if( nav.serverNodesStart && nav.serverNodesStart < nav.num_nodes ) numNodes = nav.serverNodesStart; else numNodes = nav.num_nodes; trap_FS_Write( &version, sizeof( int ), filenum ); trap_FS_Write( &numNodes, sizeof( int ), filenum ); // write out nodes for( i = 0; i < numNodes; i++ ) { trap_FS_Write( &nodes[i], sizeof( nav_node_t ), filenum ); } // write out plinks array for( i = 0; i < numNodes; i++ ) { trap_FS_Write( &pLinks[i], sizeof( nav_plink_t ), filenum ); } trap_FS_FCloseFile( filenum ); return qtrue; }
/* =================== CG_DumpLocation_f Dump a target_location definition to a file =================== */ static void CG_DumpLocation_f( void ) { char locfilename[MAX_QPATH]; char locname[MAX_STRING_CHARS]; char *extptr, *buffptr; fileHandle_t f; // Check for argument if ( trap_Argc() < 2 ) { CG_Printf( "Usage: dumploc <locationname>\n" ); return; } trap_Args( locname, sizeof( locname ) ); // Open locations file Q_strncpyz( locfilename, cgs.mapname, sizeof( locfilename ) ); extptr = locfilename + strlen( locfilename ) - 4; if ( extptr < locfilename || Q_stricmp( extptr, ".bsp" ) ) { CG_Printf( "Unable to dump, unknown map name?\n" ); return; } Q_strncpyz( extptr, ".loc", 5 ); trap_FS_FOpenFile( locfilename, &f, FS_APPEND_SYNC ); if ( !f ) { CG_Printf( "Failed to open '%s' for writing.\n", locfilename ); return; } // Strip bad characters out for ( buffptr = locname; *buffptr; buffptr++ ) { if ( *buffptr == '\n' ) { *buffptr = ' '; } else if ( *buffptr == '"' ) { *buffptr = '\''; } } // Kill any trailing space as well if ( *( buffptr - 1 ) == ' ' ) { *( buffptr - 1 ) = 0; } // Build the entity definition buffptr = va( "{\n\"classname\" \"target_location\"\n\"origin\" \"%i %i %i\"\n\"message\" \"%s\"\n}\n\n", (int) cg.snap->ps.origin[0], (int) cg.snap->ps.origin[1], (int) cg.snap->ps.origin[2], locname ); // And write out/acknowledge trap_FS_Write( buffptr, strlen( buffptr ), f ); trap_FS_FCloseFile( f ); CG_Printf( "Entity dumped to '%s' (%i %i %i).\n", locfilename, (int) cg.snap->ps.origin[0], (int) cg.snap->ps.origin[1], (int) cg.snap->ps.origin[2] ); }
void demoAddViewPos( const char *baseName, const vec3_t origin, const vec3_t angles, float fov ) { char dataLine[256]; char fileName[MAX_OSPATH]; fileHandle_t fileHandle; Com_sprintf( fileName, sizeof( fileName ), "%s.cam", baseName ); trap_FS_FOpenFile( fileName, &fileHandle, FS_APPEND ); if (!fileHandle) return; Com_sprintf( dataLine, sizeof( dataLine ), "%.3f %.3f %.3f %.3f %.3f %.3f %.3f\n", origin[0], origin[1], origin[2], angles[0], angles[1], angles[2], fov ); trap_FS_Write( &dataLine, strlen( dataLine ), fileHandle ); trap_FS_FCloseFile( fileHandle ); }
/* ================ CG_SaveConsoleHistory Save the console history into the cvar cl_consoleHistory so that it persists across invocations of q3 ================ */ void CG_SaveConsoleHistory( void ) { int i; int lineLength, saveBufferLength, additionalLength; fileHandle_t f; consoleSaveBuffer[ 0 ] = '\0'; i = ( nextHistoryLine - 1 ) % COMMAND_HISTORY; do { if( historyEditLines[ i ].buffer[ 0 ] ) { lineLength = strlen( historyEditLines[ i ].buffer ); saveBufferLength = strlen( consoleSaveBuffer ); //ICK additionalLength = lineLength + strlen( "999 999 999 " ); if( saveBufferLength + additionalLength < MAX_CONSOLE_SAVE_BUFFER ) { Q_strcat( consoleSaveBuffer, MAX_CONSOLE_SAVE_BUFFER, va( "%d %d %d %s ", historyEditLines[ i ].cursor, historyEditLines[ i ].scroll, lineLength, historyEditLines[ i ].buffer ) ); } else break; } i = ( i - 1 + COMMAND_HISTORY ) % COMMAND_HISTORY; } while( i != ( nextHistoryLine - 1 ) % COMMAND_HISTORY ); consoleSaveBufferSize = strlen( consoleSaveBuffer ); trap_FS_FOpenFile( CONSOLE_HISTORY_FILE, &f, FS_WRITE ); if( !f ) { Com_Printf( "Couldn't write %s.\n", CONSOLE_HISTORY_FILE ); return; } if( trap_FS_Write( consoleSaveBuffer, consoleSaveBufferSize, f ) < consoleSaveBufferSize ) Com_Printf( "Couldn't write %s.\n", CONSOLE_HISTORY_FILE ); trap_FS_FCloseFile( f ); }
void MV_DumpAnimationMappingTable( void ) { fileHandle_t dumpFile; char line[512]; int i, j; trap_FS_FOpenFile("animMappingTableDump.txt", &dumpFile, FS_WRITE); if ( !dumpFile ) { trap_FS_FCloseFile(dumpFile); return; } Q_strncpyz( line, "animNumber_1_02_t animMappingTable_1_04_to_1_02[MAX_TOTALANIMATIONS] = \n" "{\n", sizeof(line) ); trap_FS_Write( line, strlen(line), dumpFile ); for ( i = 0; i < MAX_TOTALANIMATIONS; i++ ) { for ( j = 0; j < sizeof(animTable_1_02); j++ ) { if ( animTable_1_02[j].id == animMappingTable_1_04_to_1_02[i] ) { Q_strncpyz( line, va(" %s, // %s\n", animTable_1_02[j].name, animTable[i].name), sizeof(line) ); // It's only an assumption that animTable[i].name is the right 1.04 name. :/ trap_FS_Write( line, strlen(line), dumpFile ); break; } } } Q_strncpyz( line, "};\n\n", sizeof(line) ); trap_FS_Write( line, strlen(line), dumpFile ); Q_strncpyz( line, "animNumber_t animMappingTable_1_02_to_1_04[MAX_TOTALANIMATIONS_1_02] = \n" "{\n", sizeof(line) ); trap_FS_Write( line, strlen(line), dumpFile ); for ( i = 0; i < MAX_TOTALANIMATIONS_1_02; i++ ) { for ( j = 0; j < sizeof(animTable); j++ ) { if ( animTable[j].id == animMappingTable_1_02_to_1_04[i] ) { Q_strncpyz( line, va(" %s, // %s\n", animTable[j].name, animTable_1_02[i].name), sizeof(line) ); // It's only an assumption that animTable_1_02[i].name is the right 1.02 name. :/ trap_FS_Write( line, strlen(line), dumpFile ); break; } } } Q_strncpyz( line, "};\n\n", sizeof(line) ); trap_FS_Write( line, strlen(line), dumpFile ); trap_FS_FCloseFile( dumpFile ); return; }
// Save to disk file // // Since my compression routines are one thing I did not want to // release, I took out the compressed format option. Most levels will // save out to a node file around 50-200k, so compression is not really // a big deal. void ACEND_SaveNodes() { fileHandle_t file; char filename[MAX_QPATH]; int i, j; int version = 1; char mapname[MAX_QPATH]; ACEND_ResolveAllPaths(); trap_Cvar_VariableStringBuffer("mapname", mapname, sizeof(mapname)); Com_sprintf(filename, sizeof(filename), "nav/%s.nod", mapname); trap_FS_FOpenFile(filename, &file, FS_WRITE); if(!file) { G_Printf("WARNING: Couldn't write node table: %s\n", filename); return; } else G_Printf("ACE: Saving node table '%s'...", filename); trap_FS_Write(&version, sizeof(int), file); trap_FS_Write(&numNodes, sizeof(int), file); trap_FS_Write(nodes, sizeof(node_t) * numNodes, file); for(i = 0; i < numNodes; i++) for(j = 0; j < numNodes; j++) trap_FS_Write(&path_table[i][j], sizeof(short int), file); // write count trap_FS_FCloseFile(file); G_Printf("done.\n"); G_Printf("%i nodes saved\n", numNodes); }
qboolean BG_DumpWeaponList ( const char *filename ) { char buffer[8192] = { 0 }; char *classnames[MAX_WEAPON_TABLE_SIZE] = { NULL }; int i; fileHandle_t f; Com_sprintf (buffer, sizeof (buffer), "%-64s | %s\n", "Display Name", "Class Name"); Q_strcat (buffer, sizeof (buffer), "-----------------------------------------------------------------+----------------------------------\n"); for ( i = 0; i < numLoadedWeapons; i++ ) { weaponData_t *w = &weaponDataTable[i]; Q_strcat (buffer, sizeof (buffer), va ("%-64s | %s\n", w->displayName, w->classname)); classnames[i] = w->classname; } Q_strcat (buffer, sizeof (buffer), "\n"); //qsort (classnames, numLoadedWeapons, sizeof (char *), strcmp); i = 0; while ( i < numLoadedWeapons ) { int duplicates = 0; int j = i + 1; while ( j < numLoadedWeapons && strcmp (classnames[i], classnames[j]) == 0 ) { duplicates++; j++; } if ( duplicates > 0 ) { Q_strcat (buffer, sizeof (buffer), va ("%s has %d duplicates.\n", classnames[i], duplicates)); } i = j; } trap_FS_FOpenFile (filename, &f, FS_WRITE); if ( f ) { trap_FS_Write (buffer, strlen (buffer), f); trap_FS_FCloseFile (f); return qtrue; } return qfalse; }
void MM_WriteData(const char *fileName, void(*processData)(char *fileData, int *fileSize)) { fileHandle_t f; int fileSize = MAX_DATA_SIZE; char *fileData = (char*)calloc(1, fileSize); char fullFileName[512] = { 0 }; // Seems reasonable for a path sprintf_s(fullFileName, sizeof(fullFileName), "data\\%s", fileName); trap_FS_FOpenFile(fullFileName, &f, FS_WRITE); processData(fileData, &fileSize); trap_FS_Write(fileData, fileSize > MAX_DATA_SIZE ? MAX_DATA_SIZE : fileSize, f); trap_FS_FCloseFile(f); free(fileData); }
void G_DebugCloseSkillLog( void ) { qtime_t ct; char *s; if( skillDebugLog == -1 ) return; trap_RealTime( &ct ); s = va( "%02d:%02d:%02d : Logfile closed.\n", ct.tm_hour, ct.tm_min, ct.tm_sec ); trap_FS_Write( s, strlen( s ), skillDebugLog ); trap_FS_FCloseFile( skillDebugLog ); }
/* =============== CG_WritePTRCode Write a PTR code to disk =============== */ void CG_WritePTRCode(int code) { char text[16]; fileHandle_t f; Com_sprintf(text, 16, "%d", code); // open file if(trap_FS_FOpenFile(PTRC_FILE, &f, FS_WRITE) < 0) return; // write the code trap_FS_Write(text, strlen(text), f); trap_FS_FCloseFile(f); }
qboolean BG_StoreCampaignSave(const char *filename, cpsFile_t * file, const char *profile) { fileHandle_t f; long hash; char *ch; int i, j; // open the file if(trap_FS_FOpenFile(filename, &f, FS_WRITE) < 0) { return (qfalse); } // write the header file->header.ident = CPS_IDENT; file->header.version = CPS_VERSION; trap_FS_Write(&file->header.ident, sizeof(int), f); trap_FS_Write(&file->header.version, 1, f); trap_FS_Write(&file->header.numCampaigns, sizeof(int), f); // generate hash for profile for(hash = 0, ch = (char *)profile; *ch != '\0'; ch++) { hash += (long)(tolower(*ch)) * ((ch - profile) + 119); } file->header.profileHash = (int)hash; trap_FS_Write(&file->header.profileHash, sizeof(int), f); // write the campaigns and maps for(i = 0; i < file->header.numCampaigns; i++) { trap_FS_Write(&file->campaigns[i].shortnameHash, sizeof(int), f); trap_FS_Write(&file->campaigns[i].progress, sizeof(int), f); // all completed maps for(j = 0; j < file->campaigns[i].progress; j++) { trap_FS_Write(&file->campaigns[i].maps[j].mapnameHash, sizeof(int), f); } } // done trap_FS_FCloseFile(f); return (qtrue); }
/* ================== G_WriteSessionData ================== */ void G_WriteSessionData( void ) { int i; fileHandle_t tmpfile; trap_Cvar_Set( "session", va("%i", g_gametype.integer) ); for ( i = 0 ; i < level.maxclients ; i++ ) { if ( level.clients[i].pers.connected == CON_CONNECTED ) { G_WriteClientSessionData( &level.clients[i] ); } } //save2file //PLS2DO!!!! trap_FS_FOpenFile( "sess.dat", &tmpfile, FS_WRITE ); trap_FS_Write( g_sess, g_maxclients.integer * sizeof( clientSession_t ), tmpfile ); trap_FS_FCloseFile( tmpfile ); //plskthx //free( g_sess ); }