Пример #1
0
/*
=============
Com_Printf

Both client and server can use this, and it will output
to the apropriate place.
=============
*/
void Com_Printf (char *fmt, ...)
{
	va_list		argptr;
	char		msg[MAXPRINTMSG];
	static qboolean printstamp = true; // jittimestamp

	va_start(argptr, fmt);
	_vsnprintf(msg, sizeof(msg), fmt, argptr); // jitsecurity -- prevent buffer overruns
	va_end(argptr);
	NULLTERMINATE(msg); // jitsecurity -- make sure string is null terminated.

	if (rd_target)
	{
		if ((strlen(msg) + strlen(rd_buffer)) > (rd_buffersize - 1))
		{
			rd_flush(rd_target, rd_buffer);
			*rd_buffer = 0;
		}

		strcat(rd_buffer, msg);
		return;
	}

	Con_Print(msg);

	// ===
	// jittimestamp
	if (printstamp && timestamp_console && timestamp_console->value)
	{	// don't tag timestamps on if it's not a new line
		time_t now;
		char timestamp[256];
		struct tm *nowtime;
		static int lastday = -1;

		time(&now);
		nowtime = localtime(&now);
		
		if (nowtime->tm_mday != lastday)
		{
			Com_sprintf(timestamp, sizeof(timestamp), "[********] Date: %04d-%02d-%02d\n",
				nowtime->tm_year + 1900, nowtime->tm_mon + 1, nowtime->tm_mday);
			Sys_ConsoleOutput(timestamp);
			ConsoleLogfile(timestamp);
			lastday = nowtime->tm_mday;
		}

		strftime(timestamp, sizeof(timestamp), "[%H:%M:%S] ", nowtime);
		Sys_ConsoleOutput(timestamp);
		ConsoleLogfile(timestamp);
	}
	
	Sys_ConsoleOutput(msg);
	printstamp = (strchr(msg, '\n') != NULL); // so we only print timestamps after a newline.
	ConsoleLogfile(msg);
	// jittimestamp
	// ===
}
Пример #2
0
/*
 * Both client and server can use this, and it will output
 * to the apropriate place.
 */
void
Com_Printf(char *fmt, ...)
{
	va_list argptr;
	char msg[MAXPRINTMSG];

	va_start(argptr, fmt);
	vsnprintf(msg, MAXPRINTMSG, fmt, argptr);
	va_end(argptr);

	if (rd_target)
	{
		if ((strlen(msg) + strlen(rd_buffer)) > (rd_buffersize - 1))
		{
			rd_flush(rd_target, rd_buffer);
			*rd_buffer = 0;
		}

		strcat(rd_buffer, msg);
		return;
	}

#ifndef DEDICATED_ONLY
	Con_Print(msg);
#endif

	/* also echo to debugging console */
	Sys_ConsoleOutput(msg);

	/* logfile */
	if (logfile_active && logfile_active->value)
	{
		char name[MAX_QPATH];

		if (!logfile)
		{
			Com_sprintf(name, sizeof(name), "%s/qconsole.log", FS_Gamedir());

			if (logfile_active->value > 2)
			{
				logfile = fopen(name, "a");
			}

			else
			{
				logfile = fopen(name, "w");
			}
		}

		if (logfile)
		{
			fprintf(logfile, "%s", msg);
		}

		if (logfile_active->value > 1)
		{
			fflush(logfile);  /* force it to save every time */
		}
	}
}
Пример #3
0
/*
================
Sys_Printf
================
*/
void Sys_Printf(const char *fmt, ...)
{
    va_list     argptr;
    char        msg[MAXPRINTMSG];

    va_start(argptr, fmt);
    Q_vsnprintf(msg, sizeof(msg), fmt, argptr);
    va_end(argptr);

    Sys_ConsoleOutput(msg);
}
Пример #4
0
void Sys_Error (const char *error, ...)
{
	va_list argptr;
	char text[1024];

	Sys_Backtrace();

#ifdef COMPILE_MAP
	Mem_Shutdown();
#endif

	va_start(argptr, error);
	Q_vsnprintf(text, sizeof(text), error, argptr);
	va_end(argptr);

	/* Echo to console */
	Sys_ConsoleOutput("\n");
	Sys_ConsoleOutput(text);
	Sys_ConsoleOutput("\n");

	/* Display the message and set a timer so we can flash the text */
	SetWindowText(sys_console.hWndMsg, text);
	SetTimer(sys_console.hWnd, 1, 1000, NULL);

	sys_console.timerActive = true;

	/* Show/hide everything we need */
	ShowWindow(sys_console.hWndMsg, SW_SHOW);
	ShowWindow(sys_console.hWndInput, SW_HIDE);

	Sys_ShowConsole(true);

	/* Wait for the user to quit */
	while (1) {
		Sys_ConsoleLoop(true);
		/* Don't hog the CPU */
		Sys_Sleep(25);
	}
}
Пример #5
0
void IN_StartupMouse (void)
{
	cvar_t		*cv;

	cv = Cvar_Get ("in_initmouse", "1", CVAR_NOSET);
	if ( !cv->value ) 
		return; 

	if (MOUSE_Init() != 0)
	{
		Sys_ConsoleOutput("Mouse not found\n");
		return;
	};

	mouseinitialized = true;
}
Пример #6
0
/**
 * @note Both client and server can use this, and it will output
 * to the appropriate place.
 */
void Com_vPrintf (const char* fmt, va_list ap)
{
	char msg[MAXPRINTMSG];

	Q_vsnprintf(msg, sizeof(msg), fmt, ap);

	/* redirect the output? */
	if (rd_buffer) {
		if ((strlen(msg) + strlen(rd_buffer)) > (rd_buffersize - 1)) {
			NET_OOB_Printf(rd_stream, SV_CMD_PRINT "\n%s", rd_buffer);
			rd_buffer[0] = '\0';
		}
		Q_strcat(rd_buffer, sizeof(char) * rd_buffersize, "%s", msg);
		return;
	}

	Con_Print(msg);

	/* also echo to debugging console */
	Sys_ConsoleOutput(msg);

	/* logfile */
	if (logfile_active && logfile_active->integer) {
		if (!logfile.f) {
			if (logfile_active->integer > 2)
				FS_OpenFile(consoleLogName, &logfile, FILE_APPEND);
			else
				FS_OpenFile(consoleLogName, &logfile, FILE_WRITE);
		}
		if (logfile.f) {
			/* strip color codes */
			const char* output = msg;

			if (output[strlen(output) - 1] == '\n') {
				char timestamp[40];
				Com_MakeTimestamp(timestamp, sizeof(timestamp));
				FS_Write(timestamp, strlen(timestamp), &logfile);
				FS_Write(" ", 1, &logfile);
			}

			FS_Write(output, strlen(output), &logfile);

			if (logfile_active->integer > 1)
				fflush(logfile.f);	/* force it to save every time */
		}
	}
}
Пример #7
0
/*
* Com_Printf
* 
* Both client and server can use this, and it will output
* to the apropriate place.
*/
void Com_Printf( const char *format, ... )
{
	va_list	argptr;
	char msg[MAX_PRINTMSG];

	time_t timestamp;
	char timestamp_str[MAX_PRINTMSG];
	struct tm *timestampptr;
	timestamp = time( NULL );
	timestampptr = gmtime( &timestamp );
	strftime( timestamp_str, MAX_PRINTMSG, "%Y-%m-%dT%H:%M:%SZ ", timestampptr );

	va_start( argptr, format );
	Q_vsnprintfz( msg, sizeof( msg ), format, argptr );
	va_end( argptr );

	if( rd_target )
	{
		if( (int)( strlen( msg ) + strlen( rd_buffer ) ) > ( rd_buffersize - 1 ) )
		{
			rd_flush( rd_target, rd_buffer, rd_extra );
			*rd_buffer = 0;
		}
		strcat( rd_buffer, msg );
		return;
	}

	QMutex_Lock( com_print_mutex );

	Con_Print( msg );

	// also echo to debugging console
	Sys_ConsoleOutput( msg );

	// logconsole
	if( logconsole && logconsole->modified )
	{
		logconsole->modified = qfalse;

		if( log_file )
		{
			FS_FCloseFile( log_file );
			log_file = 0;
		}

		if( logconsole->string && logconsole->string[0] )
		{
			size_t name_size;
			char *name;

			name_size = strlen( logconsole->string ) + strlen( ".log" ) + 1;
			name = ( char* )Mem_TempMalloc( name_size );
			Q_strncpyz( name, logconsole->string, name_size );
			COM_DefaultExtension( name, ".log", name_size );

			if( FS_FOpenFile( name, &log_file, ( logconsole_append && logconsole_append->integer ? FS_APPEND : FS_WRITE ) ) == -1 )
			{
				log_file = 0;
				Com_Printf( "Couldn't open: %s\n", name );
			}

			Mem_TempFree( name );
		}
	}

	if( log_file )
	{
		if( logconsole_timestamp && logconsole_timestamp->integer )
			FS_Printf( log_file, "%s", timestamp_str );
		FS_Printf( log_file, "%s", msg );
		if( logconsole_flush && logconsole_flush->integer )
			FS_Flush( log_file ); // force it to save every time
	}

	QMutex_Unlock( com_print_mutex );
}
Пример #8
0
/*
=============
Com_Printf

Both client and server can use this, and it will output
to the apropriate place.
=============
*/
void Com_LPrintf(print_type_t type, const char *fmt, ...)
{
    va_list     argptr;
    char        msg[MAXPRINTMSG];
    size_t      len;

    // may be entered recursively only once
    if (com_printEntered >= 2) {
        return;
    }

    com_printEntered++;

    va_start(argptr, fmt);
    len = Q_vscnprintf(msg, sizeof(msg), fmt, argptr);
    va_end(argptr);

    if (type == PRINT_ERROR && !com_errorEntered && len) {
        size_t errlen = len;

        if (errlen >= sizeof(com_errorMsg)) {
            errlen = sizeof(com_errorMsg) - 1;
        }

        // save error msg
        memcpy(com_errorMsg, msg, errlen);
        com_errorMsg[errlen] = 0;

        // strip trailing '\n'
        if (com_errorMsg[errlen - 1] == '\n') {
            com_errorMsg[errlen - 1] = 0;
        }
    }

    if (rd_target) {
        Com_Redirect(msg, len);
    } else {
        switch (type) {
        case PRINT_TALK:
            Com_SetColor(COLOR_ALT);
            break;
        case PRINT_DEVELOPER:
            Com_SetColor(COLOR_BLUE);
            break;
        case PRINT_WARNING:
            Com_SetColor(COLOR_YELLOW);
            break;
        case PRINT_ERROR:
            Com_SetColor(COLOR_RED);
            break;
        case PRINT_NOTICE:
            Com_SetColor(COLOR_CYAN);
            break;
        default:
            break;
        }

        // graphical console
        Con_Print(msg);

        // debugging console
        Sys_ConsoleOutput(msg);

        // remote console
        //SV_ConsoleOutput(msg);

        // logfile
        if (com_logFile) {
            logfile_write(type, msg);
        }

        if (type) {
            Com_SetColor(COLOR_NONE);
        }
    }

    com_printEntered--;
}
Пример #9
0
/*
 * Both client and server can use this, and it will output
 * to the apropriate place.
 */
void
Com_VPrintf(int print_level, const char *fmt, va_list argptr)
{
	if((print_level == PRINT_DEVELOPER) && (!developer || !developer->value))
	{
		return; /* don't confuse non-developers with techie stuff... */
	}
	else
	{
		int i;
		char msg[MAXPRINTMSG];
		int msgLen = vsnprintf(msg, MAXPRINTMSG, fmt, argptr);
		if(msgLen >= MAXPRINTMSG)  msgLen = MAXPRINTMSG-1;
		if (rd_target)
		{
			if ((msgLen + strlen(rd_buffer)) > (rd_buffersize - 1))
			{
				rd_flush(rd_target, rd_buffer);
				*rd_buffer = 0;
			}

			strcat(rd_buffer, msg);
			return;
		}

	#ifndef DEDICATED_ONLY
		Con_Print(msg);
	#endif

		// remove unprintable characters
		for(i=0; i<msgLen; ++i)
		{
			char c = msg[i];
			if(c < ' ' && (c < '\t' || c > '\r'))
			{
				switch(c)
				{
					// no idea if the following two are ever sent here, but in conchars.pcx they look like this
					// so do the replacements.. won't hurt I guess..
					case 0x10:
						msg[i] = '[';
						break;
					case 0x11:
						msg[i] = ']';
						break;
					// horizontal line chars
					case 0x1D:
					case 0x1F:
						msg[i] = '-';
						break;
					case 0x1E:
						msg[i] = '=';
						break;
					default: // just replace all other unprintable chars with space, should be good enough
						msg[i] = ' ';
				}
			}
		}

		/* also echo to debugging console */
		Sys_ConsoleOutput(msg);

		/* logfile */
		if (logfile_active && logfile_active->value)
		{
			char name[MAX_OSPATH];

			if (!logfile)
			{
				Com_sprintf(name, sizeof(name), "%s/qconsole.log", FS_Gamedir());

				if (logfile_active->value > 2)
				{
					logfile = fopen(name, "a");
				}

				else
				{
					logfile = fopen(name, "w");
				}
			}

			if (logfile)
			{
				fprintf(logfile, "%s", msg);
			}

			if (logfile_active->value > 1)
			{
				fflush(logfile);  /* force it to save every time */
			}
		}
	}
}
Пример #10
0
/*
=============
Com_Printf

Both client and server can use this, and it will output
to the apropriate place.
=============
*/
void Com_Printf (const char *fmt, ...)
{
	va_list		argptr;
	char		msg[MAXPRINTMSG], *s, *text;

	va_start (argptr,fmt);
	vsnprintf(msg, MAXPRINTMSG, fmt, argptr);
	va_end (argptr);

	if (rd_target)
	{
		if ((strlen (msg) + strlen(rd_buffer)) > (rd_buffersize - 1)) {
			rd_flush(rd_target, rd_buffer);
			*rd_buffer = 0;
		}
		strcat (rd_buffer, msg);
		return;
	}

	Con_Print (msg);

	text = msg;
	//Remove color triggers
	switch (msg[0]) {
	case 1:
	case 2:
		text++;
	default:
		for (s = text; *s; s++)
			*s &= 127;
		break;
	case COLOR_ONE:
		text++;
		if (Q_IsColorString(text))
			text += 2;

		for (s = text; *s; s++)
			*s &= 127;
		break;
	case COLOR_ENABLE:
		text++;
		for (s = text; *s;) {
			if(Q_IsColorString(s)) {
				memmove( s, s + 2, MAXPRINTMSG - 2 - (s - msg));
				continue;
			}
			*s++ &= 127;
		}
		break;
	}

	// also echo to debugging console
	Sys_ConsoleOutput (text);

	// logfile
	if (logfile_active->integer) {
		if (!logfile) {
			logfile = fopen(va("%s/qconsole.log", FS_Gamedir()), (logfile_active->integer > 2) ? "a" : "w");
		}
		if (logfile) {
			fprintf(logfile, "%s", text);
			if (logfile_active->integer > 1)
				fflush(logfile);		// force it to save every time
		}
	}
}