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 ); }
/* <35df2> ../engine/host.c:516 */ void Host_WriteCustomConfig(void) { #ifndef SWDS FILE *f; kbutton_t *ml; kbutton_t *jl; #endif char configname[261]; Q_snprintf(configname, 257, "%s", Cmd_Args()); if (Q_strstr(configname, "..") || !Q_stricmp(configname, "config") || !Q_stricmp(configname, "autoexec") || !Q_stricmp(configname, "listenserver") || !Q_stricmp(configname, "server") || !Q_stricmp(configname, "userconfig")) { Con_Printf("skipping writecfg output, invalid filename given\n"); } #ifndef SWDS else { if (host_initialized && g_pcls.state != ca_dedicated) { if (Key_CountBindings() < 2) Con_Printf("skipping config.cfg output, no keys bound\n"); else { Q_strcat(configname, ".cfg"); f = FS_OpenPathID(configname, "w", "GAMECONFIG"); if (!f) { Con_Printf("Couldn't write %s.\n", configname); return; } FS_FPrintf(f, "unbindall\n"); Key_WriteBindings(f); Cvar_WriteVariables(f); Info_WriteVars(f); ml = ClientDLL_FindKey("in_mlook"); jl = ClientDLL_FindKey("in_jlook"); if (ml && ml->state & 1) FS_FPrintf(f, "+mlook\n"); if (jl && jl->state & 1) FS_FPrintf(f, "+jlook\n"); FS_Close(f); Con_Printf("%s successfully created!\n", configname); } } } #endif // SWDS }
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); }
/* <9a0ba> ../engine/sv_log.c:37 */ void Log_Printf(const char *fmt, ...) { va_list argptr; char string[1024]; time_t ltime; tm *today; LOGLIST_T *list; if (!g_psvs.log.net_log_ && !firstLog && !g_psvs.log.active) return; time(<ime); today = localtime(<ime); va_start(argptr, fmt); Q_snprintf(string,sizeof(string), "L %02i/%02i/%04i - %02i:%02i:%02i: ", today->tm_mon + 1, today->tm_mday, today->tm_year + 1900, today->tm_hour, today->tm_min, today->tm_sec); Q_vsnprintf(&string[Q_strlen(string)], sizeof(string) - Q_strlen(string), fmt, argptr); va_end(argptr); #ifdef REHLDS_FLIGHT_REC FR_Log("REHLDS_LOG", string); #endif if (g_psvs.log.net_log_ || firstLog != NULL) { if (g_psvs.log.net_log_) Netchan_OutOfBandPrint(NS_SERVER, g_psvs.log.net_address_, "log %s", string); for (list = firstLog; list != NULL; list = list->next) { if (sv_logsecret.value == 0.0f) Netchan_OutOfBandPrint(NS_SERVER, list->log.net_address_, "log %s", string); else Netchan_OutOfBandPrint(NS_SERVER, list->log.net_address_, "%c%s%s", S2A_LOGKEY, sv_logsecret.string, string); } } if (g_psvs.log.active && (g_psvs.maxclients > 1 || sv_log_singleplayer.value != 0.0f)) { if (mp_logecho.value != 0.0f) Con_Printf("%s", string); if (g_psvs.log.file) { if (mp_logfile.value != 0.0f) FS_FPrintf((FileHandle_t)g_psvs.log.file, "%s", string); } } }
/* ============ Key_WriteBindings Writes lines containing "bind key value" ============ */ void Key_WriteBindings(qhandle_t f) { int i; for (i = 0; i < 256; i++) { if (keybindings[i] && keybindings[i][0]) { FS_FPrintf(f, "bind %s \"%s\"\n", Key_KeynumToString(i), keybindings[i]); } } }
/* <18ca4> ../engine/cvar.c:601 */ NOXREF void Cvar_WriteVariables(FileHandle_t f) { NOXREFCHECK; cvar_t *var; for (var = cvar_vars; var; var = var->next) { if (var->flags & FCVAR_ARCHIVE) { FS_FPrintf(f, "%s \"%s\"\n", var->name, var->string); } } }
/* <35d28> ../engine/host.c:349 */ NOXREF void Info_WriteVars(FileHandle_t fp) { cvar_t *pcvar; char *s; char pkey[512]; static char value[4][512]; static int valueindex; char *o; valueindex = (valueindex + 1) % 4; s = &g_pcls.userinfo[0]; if (*s == '\\') s++; while (1) { o = pkey; while (*s != '\\') { if (!*s) return; *o++ = *s++; } *o = 0; s++; o = value[valueindex]; while (*s != '\\' && *s) { if (!*s) return; *o++ = *s++; } *o = 0; pcvar = Cvar_FindVar(pkey); if (!pcvar && pkey[0] != '*') FS_FPrintf(fp, "setinfo \"%s\" \"%s\"\n", pkey, value[valueindex]); if (!*s) return; s++; } }
/* <18cdc> ../engine/cvar.c:627 */ void Cmd_CvarListPrintCvar(cvar_t *var, FileHandle_t f) { char szOutstr[256]; #ifdef REHLDS_FIXES // Do correct output of string valued cvars Q_snprintf(szOutstr, ARRAYSIZE(szOutstr) - 1, "%-28s : %16s", var->name, var->string); #else // REHLDS_FIXES if (var->value == (float)(int)var->value) { Q_snprintf(szOutstr, ARRAYSIZE(szOutstr) - 1, "%-15s : %8i", var->name, (int)var->value); } else { Q_snprintf(szOutstr, ARRAYSIZE(szOutstr) - 1, "%-15s : %8.3f", var->name, var->value); } #endif // REHLDS_FIXES szOutstr[ARRAYSIZE(szOutstr) - 1] = 0; if (var->flags & FCVAR_ARCHIVE) { Q_strcat(szOutstr, ", a"); } if (var->flags & FCVAR_SERVER) { Q_strcat(szOutstr, ", sv"); } if (var->flags & FCVAR_USERINFO) { Q_strcat(szOutstr, ", i"); } Q_strcat(szOutstr, "\n"); Con_Printf("%s", szOutstr); if (f) { FS_FPrintf(f, "%s", szOutstr); } }
/* <4b17> ../engine/cmd.c:1301 */ void Cmd_CmdList_f(void) { cmd_function_t *cmd; int iCmds; int iArgs; const char *partial, *arg1; int ipLen; char szTemp[MAX_PATH]; FileHandle_t f; FileHandle_t fp; qboolean bLogging; iCmds = 0; partial = NULL; f = NULL; fp = NULL; bLogging = FALSE; iArgs = Cmd_Argc(); if (iArgs > 1) { arg1 = Cmd_Argv(1); if (!Q_stricmp(arg1, "?")) { Con_Printf("CmdList : List all commands\nCmdList [Partial] : List commands starting with 'Partial'\nCmdList log [Partial] : Logs commands to file \"cmdlist.txt\" in the gamedir.\n"); return; } if (!Q_stricmp(arg1, "log")) { // Open log int i; for (i = 0; i < 100; i++) { Q_snprintf(szTemp, ARRAYSIZE(szTemp) - 1, "cmdlist%02d.txt", i); szTemp[ARRAYSIZE(szTemp) - 1] = 0; fp = FS_Open(szTemp, "r"); if (!fp) { break; } FS_Close(fp); } if (i >= 100) { Con_Printf("Can't cmdlist! Too many existing cmdlist output files in the gamedir!\n"); return; } f = FS_Open(szTemp, "wt"); if (!f) { Con_Printf("Couldn't open \"%s\" for writing!\n", szTemp); return; } bLogging = TRUE; // Get next argument into partial, if present if (iArgs >= 2) { partial = Cmd_Argv(2); ipLen = Q_strlen(partial); } } else { partial = arg1; ipLen = Q_strlen(partial); } } // Print commands Con_Printf("Command List\n--------------\n"); for (cmd = cmd_functions; cmd; cmd = cmd->next) { if (partial && Q_strnicmp(cmd->name, partial, ipLen)) { continue; } Con_Printf("%s\n", cmd->name); if (bLogging) { FS_FPrintf(f, "%s\n", cmd->name); } iCmds++; } if (partial && *partial) { Con_Printf("--------------\n%3i Commands for [%s]\nCmdList ? for syntax\n", iCmds, partial); } else { Con_Printf("--------------\n%3i Total Commands\nCmdList ? for syntax\n", iCmds); } // Close log if (bLogging) { FS_Close(f); Con_Printf("cmdlist logged to %s\n", szTemp); } }
/* ============= Com_Error Both client and server can use this, and it will do the apropriate things. ============= */ void Com_Error(error_type_t code, const char *fmt, ...) { char msg[MAXERRORMSG]; va_list argptr; size_t len; // may not be entered recursively if (com_errorEntered) { #ifdef _DEBUG if (com_debug_break && com_debug_break->integer) { Sys_DebugBreak(); } #endif Sys_Error("recursive error after: %s", com_errorMsg); } com_errorEntered = qtrue; va_start(argptr, fmt); len = Q_vscnprintf(msg, sizeof(msg), fmt, argptr); va_end(argptr); // save error msg // can't print into it directly since it may // overlap with one of the arguments! memcpy(com_errorMsg, msg, len + 1); // fix up drity message buffers MSG_Init(); // abort any console redirects Com_AbortRedirect(); // reset Com_Printf recursion level com_printEntered = 0; X86_POP_FPCW; if (code == ERR_DISCONNECT || code == ERR_RECONNECT) { Com_WPrintf("%s\n", com_errorMsg); SV_Shutdown(va("Server was killed: %s\n", com_errorMsg), code); CL_Disconnect(code); goto abort; } #ifdef _DEBUG if (com_debug_break && com_debug_break->integer) { Sys_DebugBreak(); } #endif // make otherwise non-fatal errors fatal if (com_fatal_error && com_fatal_error->integer) { code = ERR_FATAL; } if (code == ERR_DROP) { Com_EPrintf("********************\n" "ERROR: %s\n" "********************\n", com_errorMsg); SV_Shutdown(va("Server crashed: %s\n", com_errorMsg), ERR_DROP); CL_Disconnect(ERR_DROP); goto abort; } if (com_logFile) { FS_FPrintf(com_logFile, "FATAL: %s\n", com_errorMsg); } SV_Shutdown(va("Server fatal crashed: %s\n", com_errorMsg), ERR_FATAL); CL_Shutdown(); NET_Shutdown(); logfile_close(); FS_Shutdown(); Sys_Error("%s", com_errorMsg); // doesn't get there abort: if (com_logFile) { FS_Flush(com_logFile); } com_errorEntered = qfalse; longjmp(abortframe, -1); }
/* <35dc8> ../engine/host.c:409 */ void Host_WriteConfiguration(void) { #ifndef SWDS FILE *f; kbutton_t *ml; kbutton_t *jl; qboolean bSetFileToReadOnly; char nameBuf[4096]; if (!host_initialized || g_pcls.state == ca_dedicated) return; #ifdef _WIN32 Sys_GetRegKeyValue("Software\\Valve\\Steam", "rate", rate_.string); if (cl_name.string && Q_stricmp(cl_name.string, "unnamed") && Q_stricmp(cl_name.string, "player") && Q_strlen(cl_name.string)) Sys_GetRegKeyValue("Software\\Valve\\Steam", "LastGameNameUsed", cl_name.string); #else SetRateRegistrySetting(rate_.string); #endif // _WIN32 if (Key_CountBindings() <= 1) { Con_Printf("skipping config.cfg output, no keys bound\n"); return; } bSetFileToReadOnly = FALSE; f = FS_OpenPathID("config.cfg", "w", "GAMECONFIG"); if (!f) { if (!developer.value || !FS_FileExists("../goldsrc/dev_build_all.bat")) { if (FS_GetLocalPath("config.cfg", nameBuf, sizeof(nameBuf))) { bSetFileToReadOnly = TRUE; chmod(nameBuf, S_IREAD|S_IWRITE); } f = FS_OpenPathID("config.cfg", "w", "GAMECONFIG"); if (!f) { Con_Printf("Couldn't write config.cfg.\n"); return; } } } FS_FPrintf(f, "// This file is overwritten whenever you change your user settings in the game.\n"); FS_FPrintf(f, "// Add custom configurations to the file \"userconfig.cfg\".\n\n"); FS_FPrintf(f, "unbindall\n"); Key_WriteBindings(f); Cvar_WriteVariables(f); Info_WriteVars(f); ml = ClientDLL_FindKey("in_mlook"); jl = ClientDLL_FindKey("in_jlook"); if (ml && (ml->state & 1)) FS_FPrintf(f, "+mlook\n"); if (jl && (jl->state & 1)) FS_FPrintf(f, "+jlook\n"); FS_FPrintf(f, "exec userconfig.cfg\n"); FS_Close(f); if (bSetFileToReadOnly) { FS_GetLocalPath("config.cfg", nameBuf, sizeof(nameBuf)); chmod(nameBuf, S_IREAD); } #endif // SWDS }