void Com_PrintLogfile( const char *msg ) { Sys_EnterCriticalSection(5); if ( com_logfile && com_logfile->integer ) { // TTimo: only open the qconsole.log if the filesystem is in an initialized state // also, avoid recursing in the qconsole.log opening (i.e. if fs_debug is on) if ( !logfile && FS_Initialized()) { struct tm *newtime; time_t aclock; time( &aclock ); newtime = localtime( &aclock ); logfile = FS_FOpenFileWrite( "qconsole.log" ); if ( com_logfile->integer > 1 && logfile ) { // force it to not buffer so we get valid // data even if we are crashing FS_ForceFlush(logfile); } if ( logfile ) FS_Write(va("\nLogfile opened on %s\n", asctime( newtime )), strlen(va("\nLogfile opened on %s\n", asctime( newtime ))), logfile); } if ( logfile && FS_Initialized()) { FS_Write(msg, strlen(msg), logfile); } } Sys_LeaveCriticalSection(5); }
/* ============= Com_Printf Both client and server can use this, and it will output to the apropriate place. A raw string should NEVER be passed as fmt, because of "%f" type crashers. ============= */ void QDECL Com_Printf( const char *fmt, ... ) { va_list argptr; char msg[MAXPRINTMSG]; va_start (argptr,fmt); vsprintf (msg,fmt,argptr); va_end (argptr); if ( rd_buffer ) { if ((strlen (msg) + strlen(rd_buffer)) > (rd_buffersize - 1)) { rd_flush(rd_buffer); *rd_buffer = 0; } Q_strcat(rd_buffer, rd_buffersize, msg); rd_flush(rd_buffer); *rd_buffer = 0; return; } // echo to console if we're not a dedicated server if ( com_dedicated && !com_dedicated->integer ) { CL_ConsolePrint( msg ); } // echo to dedicated console and early console Sys_Print( msg ); // logfile #ifndef _XBOX if ( com_logfile && com_logfile->integer ) { if ( !logfile && FS_Initialized() ) { struct tm *newtime; time_t aclock; time( &aclock ); newtime = localtime( &aclock ); logfile = FS_FOpenFileWrite( "qconsole.log" ); Com_Printf( "logfile opened on %s\n", asctime( newtime ) ); if ( com_logfile->integer > 1 ) { // force it to not buffer so we get valid // data even if we are crashing FS_ForceFlush(logfile); } } if ( logfile && FS_Initialized()) { FS_Write(msg, strlen(msg), logfile); } } #endif #if defined(_WIN32) && defined(_DEBUG) && !defined(_XBOX) if ( *msg ) { OutputDebugString ( Q_CleanStr(msg) ); OutputDebugString ("\n"); } #endif }
/* =========== FS_FOpenDemoFileWrite =========== */ qboolean FS_FOpenDemoFileWrite( const char *filename, fileHandleData_t *fh ) { char ospath[MAX_OSPATH]; if ( !FS_Initialized() ) { Com_Error( ERR_FATAL, "Filesystem call made without initialization" ); } FS_BuildOSPathForThread( fs_homepath->string, filename, "", ospath, 0 ); ospath[strlen(ospath)-1] = '\0'; fh->zipFile = qfalse; if ( fs_debug->boolean ) { Com_Printf( "FS_SV_FOpenDemoFileWrite: %s\n", ospath ); } if( FS_CreatePath( ospath ) ) { return qfalse; } fh->handleFiles.file.o = fopen( ospath, "wb" ); Q_strncpyz( fh->name, filename, sizeof( fh->name ) ); fh->handleSync = qfalse; if (!fh->handleFiles.file.o) { return qfalse; } fh->writebuffer = Z_Malloc(FS_DEMOWRITEBUF_SIZE); fh->bufferSize = FS_DEMOWRITEBUF_SIZE; return qtrue; }
/* ================== CL_WriteClientChatLog ================== */ void CL_WriteClientChatLog( char *text ) { if ( cl_logs && cl_logs->integer ) { if ( LogFileOpened == qfalse || !LogFileHandle ) { CL_OpenClientLog(); } if ( FS_Initialized() && LogFileOpened == qtrue ) { if( cl.serverTime > 0 ) { // varibles char NoColorMsg[MAXPRINTMSG]; char Timestamp[ 60 ]; char LogText[ 60 + MAXPRINTMSG ]; if( cl_logs->integer == 1 ) { //just do 3 stars to seperate from normal logging stuff Q_strncpyz( Timestamp, "***", sizeof( Timestamp ) ); } else if ( cl_logs->integer == 2 ) { //just game time //do timestamp prep sprintf( Timestamp, "[%d:%02d]", cl.serverTime / 60000, ( cl.serverTime / 1000 ) % 60 ); //server Time } else if ( cl_logs->integer == 3 ) { //just system time //do timestamp prep //get current time/date info qtime_t now; Com_RealTime( &now ); sprintf( Timestamp, "[%d:%02d]", now.tm_hour, now.tm_min ); //server Time } else if( cl_logs->integer == 4 ) { //all the data //do timestamp prep //get current time/date info qtime_t now; Com_RealTime( &now ); sprintf( Timestamp, "[%d:%02d][%d:%02d]", now.tm_hour, now.tm_min, cl.serverTime / 60000, ( cl.serverTime / 1000 ) % 60 ); //server Time } //decolor the string Q_strncpyz( NoColorMsg, text, sizeof(NoColorMsg) ); Q_CleanStr( NoColorMsg ); //prepare text for log sprintf( LogText, "%s%s\n", Timestamp, NoColorMsg ); //thing to write to log //write to the file FS_Write( LogText, strlen( LogText ), LogFileHandle ); //flush the file so we can see the data FS_ForceFlush( LogFileHandle ); } } } }
/* ================== CL_CloseClientLog ================== */ void CL_CloseClientLog(void) { if( cl_logs && cl_logs->integer ) { if( FS_Initialized() && LogFileOpened == qtrue ) { //close the file FS_FCloseFile( LogFileHandle ); LogFileOpened = qfalse; //var to tell if files open } } }
void QDECL SV_EnterLeaveLog( const char *fmt, ... ) { Sys_EnterCriticalSection(5); va_list argptr; char msg[MAXPRINTMSG]; char inputmsg[MAXPRINTMSG]; struct tm *newtime; char* ltime; time_t realtime; // logfile if ( com_logfile && com_logfile->integer ) { // TTimo: only open the qconsole.log if the filesystem is in an initialized state // also, avoid recursing in the qconsole.log opening (i.e. if fs_debug is on) va_start (argptr,fmt); Q_vsnprintf (inputmsg, sizeof(inputmsg), fmt, argptr); va_end (argptr); Com_UpdateRealtime(); realtime = Com_GetRealtime(); newtime = localtime( &realtime ); ltime = asctime( newtime ); ltime[strlen(ltime)-1] = 0; if ( !enterleavelogfile && FS_Initialized()) { enterleavelogfile = FS_FOpenFileAppend( "enterleave.log" ); // force it to not buffer so we get valid if ( enterleavelogfile ){ FS_ForceFlush(enterleavelogfile); FS_Write(va("\nLogfile opened on %s\n\n", ltime), strlen(va("\nLogfile opened on %s\n\n", ltime)), enterleavelogfile); } } if ( enterleavelogfile && FS_Initialized()) { Com_sprintf(msg, sizeof(msg), "%s: %s\n", ltime, inputmsg); FS_Write(msg, strlen(msg), enterleavelogfile); } } Sys_LeaveCriticalSection(5); }
void QDECL Com_PrintAdministrativeLog( const char *msg ) { Sys_EnterCriticalSection(5); struct tm *newtime; char* ltime; time_t realtime; // logfile if ( com_logfile && com_logfile->integer ) { // TTimo: only open the qconsole.log if the filesystem is in an initialized state // also, avoid recursing in the qconsole.log opening (i.e. if fs_debug is on) if ( !adminlogfile && FS_Initialized()) { Com_UpdateRealtime(); realtime = Com_GetRealtime(); newtime = localtime( &realtime ); ltime = asctime( newtime ); ltime[strlen(ltime)-1] = 0; adminlogfile = FS_FOpenFileAppend( "adminactions.log" ); // force it to not buffer so we get valid if ( adminlogfile ){ FS_ForceFlush(adminlogfile); FS_Write(va("\nLogfile opened on %s\n\n", ltime), strlen(va("\nLogfile opened on %s\n\n", ltime)), adminlogfile); } } if ( adminlogfile && FS_Initialized()) { FS_Write(msg, strlen(msg), adminlogfile); } } Sys_LeaveCriticalSection(5); }
/* ================== CL_OpenClientLog ================== */ void CL_OpenClientLog(void) { if( cl_logs && cl_logs->integer ) { if( FS_Initialized() && LogFileOpened == qfalse ) { char FileLocation[ 255 ]; char *nowString; //get current time/date info qtime_t now; Com_RealTime( &now ); nowString = va( "%04d-%02d-%02d", 1900 + now.tm_year, 1 + now.tm_mon, now.tm_mday ); sprintf(FileLocation,"logs/%s.log", nowString ); LogFileHandle = FS_FOpenFileAppend( FileLocation ); //open file with filename as date LogFileOpened = qtrue; //var to tell if files open } } }
/* ================== CL_WriteClientLog ================== */ void CL_WriteClientLog( char *text ) { if( cl_logs && cl_logs->integer ) { if( LogFileOpened == qfalse || !LogFileHandle ) { CL_OpenClientLog(); } if( FS_Initialized() && LogFileOpened == qtrue ) { // varibles char NoColorMsg[MAXPRINTMSG]; //decolor the string Q_strncpyz( NoColorMsg, text, sizeof(NoColorMsg) ); Q_CleanStr( NoColorMsg ); //write to the file FS_Write( NoColorMsg, strlen( NoColorMsg ), LogFileHandle ); //flush the file so we can see the data FS_ForceFlush( LogFileHandle ); } } }
/* ============= Com_Printf Both client and server can use this, and it will output to the apropriate place. A raw string should NEVER be passed as fmt, because of "%f" type crashers. ============= */ void QDECL Com_Printf( const char *fmt, ... ) { va_list argptr; char msg[MAXPRINTMSG]; va_start (argptr,fmt); Q_vsnprintf (msg, sizeof(msg), fmt, argptr); va_end (argptr); if ( rd_buffer ) { if ((strlen (msg) + strlen(rd_buffer)) > (unsigned)(rd_buffersize - 1)) { rd_flush(rd_buffer); *rd_buffer = 0; } Q_strcat (rd_buffer, strlen(rd_buffer), msg); return; } CL_ConsolePrint( msg ); // echo to dedicated console and early console Sys_Print( msg ); #ifdef OUTPUT_TO_BUILD_WINDOW OutputDebugString(msg); #endif // logfile if ( com_logfile && com_logfile->integer ) { if ( !logfile && FS_Initialized() ) { logfile = FS_FOpenFileWrite( "qconsole.log" ); if ( com_logfile->integer > 1 ) { // force it to not buffer so we get valid // data even if we are crashing FS_ForceFlush(logfile); } } if ( logfile ) { FS_Write(msg, strlen(msg), logfile); } } }
/* ============= Com_Printf Both client and server can use this, and it will output to the apropriate place. A raw string should NEVER be passed as fmt, because of "%f" type crashers. ============= */ void QDECL Com_Printf( const char *fmt, ... ) { va_list argptr; char msg[MAXPRINTMSG]; static qboolean opening_qconsole = qfalse; va_start (argptr,fmt); Q_vsnprintf (msg, sizeof(msg), fmt, argptr); va_end (argptr); if ( rd_buffer ) { if ((strlen (msg) + strlen(rd_buffer)) > (rd_buffersize - 1)) { rd_flush(rd_buffer); *rd_buffer = 0; } Q_strcat(rd_buffer, rd_buffersize, msg); // TTimo nooo .. that would defeat the purpose //rd_flush(rd_buffer); //*rd_buffer = 0; return; } // echo to console if we're not a dedicated server if ( com_dedicated && !com_dedicated->integer ) { CL_ConsolePrint( msg ); } // echo to dedicated console and early console Sys_Print( msg ); // logfile if ( com_logfile && com_logfile->integer ) { // TTimo: only open the qconsole.log if the filesystem is in an initialized state // also, avoid recursing in the qconsole.log opening (i.e. if fs_debug is on) if ( !logfile && FS_Initialized() && !opening_qconsole ) { struct tm *newtime; time_t aclock; opening_qconsole = qtrue; time( &aclock ); newtime = localtime( &aclock ); logfile = FS_FOpenFileWrite( "qconsole.log" ); if ( logfile ) { Com_Printf( "logfile opened on %s\n", asctime( newtime ) ); if ( com_logfile->integer > 1 ) { // force it to not buffer so we get valid // data even if we are crashing FS_ForceFlush(logfile); } } else { Com_Printf( "Opening qconsole.log failed!\n" ); Cvar_SetValue( "logfile", 0 ); } } opening_qconsole = qfalse; if ( logfile && FS_Initialized()) { FS_Write(msg, strlen(msg), logfile); } } #if defined(_WIN32) && defined(_DEBUG) if ( *msg ) { OutputDebugString ( Q_CleanStr(msg) ); OutputDebugString ("\n"); } #endif }