/** * @brief Sends a reliable command string to be interpreted by the client game * module: "cp", "print", "chat", etc * * A NULL client will broadcast to all clients */ void QDECL SV_SendServerCommand(client_t *cl, const char *fmt, ...) { va_list argptr; byte message[MAX_MSGLEN]; client_t *client; int j; va_start(argptr, fmt); Q_vsnprintf((char *)message, sizeof(message), fmt, argptr); va_end(argptr); // do not forward server command messages that would be too big to clients // ( q3infoboom / q3msgboom stuff ) // see http://aluigi.altervista.org/adv/q3msgboom-adv.txt if (strlen((char *)message) > 1022) { SV_WriteAttackLog("Warning: q3infoboom/q3msgboom exploit attack.\n"); // FIXME: add client slot return; } if (cl != NULL) { SV_AddServerCommand(cl, (char *)message); return; } // hack to echo broadcast prints to console if (com_dedicated->integer && !strncmp((char *)message, "print", 5)) { Com_Printf("broadcast: %s\n", SV_ExpandNewlines((char *)message)); } // send the data to all relevent clients for (j = 0, client = svs.clients; j < sv_maxclients->integer ; j++, client++) { if (client->state < CS_PRIMED) { continue; } // don't need to send messages to AI if (client->gentity && (client->gentity->r.svFlags & SVF_BOT)) { continue; } SV_AddServerCommand(client, (char *)message); } }
void dMessage (int num, const char *msg, ...) { va_list ap; char buf[2048]; va_start (ap, msg); Q_vsnprintf(buf, sizeof(buf), msg, ap); va_end(ap); if(num) { Com_PrintError("\nODE Message %d: %s\n", num, buf); }else{ Com_PrintError("\nODE Message: %s\n", buf); } }
/////////////////////////////////////////////////////////////////////// // botsafe centerprintf /////////////////////////////////////////////////////////////////////// void safe_centerprintf (edict_t *ent, char *fmt, ...) { char bigbuffer[0x10000]; va_list argptr; int len; if (!ent->inuse || ent->is_bot) return; va_start (argptr, fmt); len = Q_vsnprintf (bigbuffer, sizeof(bigbuffer), fmt, argptr); va_end (argptr); gi.centerprintf(ent, "%s", bigbuffer); //gi.centerprintf(ent, bigbuffer); }
void QDECL SV_RefPrintf( int print_level, const char *fmt, ...) { va_list argptr; char msg[MAXPRINTMSG]; va_start (argptr,fmt); Q_vsnprintf(msg, sizeof(msg), fmt, argptr); va_end (argptr); if ( print_level == PRINT_ALL ) { Com_Printf ("%s", msg); } else if ( print_level == PRINT_WARNING ) { Com_Printf (S_COLOR_YELLOW "%s", msg); // yellow } else if ( print_level == PRINT_DEVELOPER ) { Com_DPrintf (S_COLOR_RED "%s", msg); // red } }
void QDECL Com_Printf(const char *msg, ...) { va_list argptr; char text[1024]; va_start(argptr, msg); Q_vsnprintf(text, sizeof (text), msg, argptr); va_end(argptr); #ifdef CGAMEDLL CG_Printf("%s", text); #elif defined GAMEDLL G_Printf("%s", text); #else trap_Print(va("%s", text)); #endif }
void SetValue( const char *pValue, ... ) { char valueString[4096]; va_list marker; va_start( marker, pValue ); Q_vsnprintf( valueString, sizeof( valueString ), pValue, marker ); va_end( marker ); #ifdef WIN32 char str[4096]; Q_snprintf( str, sizeof( str ), "%s=%s", m_pVarName, valueString ); _putenv( str ); #else setenv( m_pVarName, valueString, 1 ); #endif }
void udtContext::LogError(UDT_PRINTF_FORMAT_ARG const char* format, ...) const { if(!_messageCallback) { return; } char msg[MAXPRINTMSG]; va_list argptr; va_start(argptr, format); Q_vsnprintf(msg, sizeof(msg) - 1, format, argptr); va_end(argptr); (*_messageCallback)(2, msg); }
/* <35f03> ../engine/host.c:646 */ void Host_ClientCommands(const char *fmt, ...) { va_list argptr; char string[1024]; va_start(argptr, fmt); if (!host_client->fakeclient) { Q_vsnprintf(string, sizeof(string), fmt, argptr); string[sizeof(string) - 1] = 0; MSG_WriteByte(&host_client->netchan.message, svc_stufftext); MSG_WriteString(&host_client->netchan.message, string); } va_end(argptr); }
void VID_Printf (int print_level, char *fmt, ...) { va_list argptr; char msg[MAXPRINTMSG]; // static qboolean inupdate; va_start (argptr, fmt); // vsprintf (msg, fmt, argptr); Q_vsnprintf (msg, sizeof(msg), fmt, argptr); va_end (argptr); if (print_level == PRINT_ALL) Com_Printf ("%s", msg); else Com_DPrintf ("%s", msg); }
void dError (int num, const char *msg, ...) { va_list ap; char buf[2048]; va_start (ap, msg); Q_vsnprintf(buf, sizeof(buf), msg, ap); va_end(ap); if(num) { Com_Error(ERR_FATAL, "\nODE Error %d: %s\n", num, buf); }else{ Com_Error(ERR_FATAL, "\nODE Error: %s\n", buf); } }
/** * @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 */ } } }
/** * @note Both client and server can use this, and it will * do the appropriate things. */ void Com_Error (int code, const char* fmt, ...) { va_list argptr; static char msg[MAXPRINTMSG]; static bool recursive = false; if (recursive) Sys_Error("recursive error after: %s", msg); recursive = true; va_start(argptr, fmt); Q_vsnprintf(msg, sizeof(msg), fmt, argptr); va_end(argptr); switch (code) { case ERR_DISCONNECT: Com_Printf("%s\n", msg); CL_Drop(); recursive = false; Com_Drop(); case ERR_DROP: Com_Printf("********************\n"); Com_Printf("ERROR: %s\n", msg); Com_Printf("********************\n"); Sys_Backtrace(); SV_Shutdown("Server crashed.", false); CL_Drop(); recursive = false; Com_Drop(); default: Com_Printf("%s\n", msg); SV_Shutdown("Server fatal crashed", false); /* send an receive net messages a last time */ NET_Wait(0); FS_CloseFile(&logfile); if (pipefile.f != nullptr) { FS_CloseFile(&pipefile); FS_RemoveFile(va("%s/%s", FS_Gamedir(), pipefile.name)); } CL_Shutdown(); Qcommon_Shutdown(); Sys_Error("Shutdown"); } }
void CBaseGameStats::StatsLog( char const *fmt, ... ) { if ( !m_bLogging && !m_bLoggingToFile ) return; char buf[ 2048 ]; va_list argptr; va_start( argptr, fmt ); Q_vsnprintf( buf, sizeof( buf ), fmt, argptr ); va_end( argptr ); // Prepend timestamp and spew it // Prepend the time. time_t aclock; time( &aclock ); struct tm *newtime = localtime( &aclock ); char timeString[ 128 ]; Q_strncpy( timeString, asctime( newtime ), sizeof( timeString ) ); // Get rid of the \n. char *pEnd = strstr( timeString, "\n" ); if ( pEnd ) { *pEnd = 0; } if ( m_bLogging ) { DevMsg( "[GS %s - %7.2f] %s", timeString, gpGlobals->realtime, buf ); } if ( m_bLoggingToFile ) { if ( FILESYSTEM_INVALID_HANDLE == g_LogFileHandle ) { g_LogFileHandle = filesystem->Open( GAMESTATS_LOG_FILE, "a", GAMESTATS_PATHID ); } if ( FILESYSTEM_INVALID_HANDLE != g_LogFileHandle ) { filesystem->FPrintf( g_LogFileHandle, "[GS %s - %7.2f] %s", timeString, gpGlobals->realtime, buf ); filesystem->Flush( g_LogFileHandle ); } } }
/* <2d4b0a> ../game_shared/shared_util.cpp:68 */ char *SharedVarArgs(char *format, ...) { va_list argptr; const int BufLen = 1024; const int NumBuffers = 4; static char string[ NumBuffers ][ BufLen ]; static int curstring = 0; curstring = (curstring + 1) % NumBuffers; va_start(argptr, format); Q_vsnprintf(string[ curstring ], BufLen, format, argptr); va_end(argptr); return string[ curstring ]; }
/* <35e4e> ../engine/host.c:594 */ void SV_ClientPrintf(const char *fmt, ...) { va_list va; char string[1024]; if (!host_client->fakeclient) { va_start(va, fmt); Q_vsnprintf(string, ARRAYSIZE(string) - 1, fmt, va); va_end(va); string[ARRAYSIZE(string) - 1] = 0; MSG_WriteByte(&host_client->netchan.message, svc_print); MSG_WriteString(&host_client->netchan.message, string); } }
void QDECL Com_DPrintf(const char *fmt, ...) { va_list argptr; char msg[MAXPRINTMSG]; int developer; developer = trap_Cvar_VariableValue("developer"); if (!developer) { return; } va_start(argptr, fmt); Q_vsnprintf(msg, sizeof(msg), fmt, argptr); va_end(argptr); Com_Printf("%s", msg); }
/** * @brief does a varargs printf into a temp buffer, so I don't need to have * varargs versions of all text functions. */ const char* va (const char* format, ...) { va_list argptr; /* in case va is called by nested functions */ static char string[16][VA_BUFSIZE]; static unsigned int index = 0; char* buf; buf = string[index & 0x0F]; index++; va_start(argptr, format); Q_vsnprintf(buf, VA_BUFSIZE, format, argptr); va_end(argptr); return buf; }
int DrawStringForTime( float flTime, vgui::HFont hCustomFont, int x, int y, int r, int g, int b, int a, const char *fmt, int messageID, ... ) { va_list argptr; char data[ MAX_MESSAGECHARSPANEL_LEN ]; int len; va_start(argptr, messageID); len = Q_vsnprintf(data, sizeof( data ), fmt, argptr); va_end(argptr); data[ MAX_MESSAGECHARSPANEL_LEN - 1 ] = 0; if ( !messageCharsPanel ) return x; return messageCharsPanel->AddText( flTime, hCustomFont, x, y, r, g, b, a, data, messageID ); }
/* ================= PC_SourceError ================= */ void PRINTF_LIKE(2) PC_SourceError( int handle, const char *format, ... ) { int line; char filename[ 128 ]; va_list argptr; static char string[ 4096 ]; va_start( argptr, format ); Q_vsnprintf( string, sizeof( string ), format, argptr ); va_end( argptr ); filename[ 0 ] = '\0'; line = 0; trap_Parse_SourceFileAndLine( handle, filename, &line ); Com_Printf( S_ERROR "%s, line %d: %s\n", filename, line, string ); }
__cdecl void QDECL NET_OutOfBandPrint( netsrc_t sock, netadr_t *adr, const char *format, ... ) { va_list argptr; char string[MAX_MSGLEN]; // set the header string[0] = -1; string[1] = -1; string[2] = -1; string[3] = -1; va_start( argptr, format ); Q_vsnprintf( string+4, sizeof(string)-4, format, argptr ); va_end( argptr ); // send the datagram NET_SendPacket( sock, strlen( string ), string, adr ); }
/* ================ Com_DPrintNoRedirect A Com_Printf that only shows up if the "developer" cvar is set This will not print to rcon ================ */ void QDECL Com_DPrintNoRedirect( const char *fmt, ... ) { va_list argptr; char msg[MAXPRINTMSG]; if ( !Com_IsDeveloper() ) { return; // don't confuse non-developers with techie stuff... } msg[0] = '^'; msg[1] = '2'; va_start (argptr,fmt); Q_vsnprintf (&msg[2], (sizeof(msg)-3), fmt, argptr); va_end (argptr); Com_PrintMessage( 0, msg, MSG_NORDPRINT); }
// NULL for everyone void QDECL PrintMsg( gentity_t *ent, const char *fmt, ... ) { char msg[1024]; va_list argptr; char *p; va_start (argptr,fmt); if (Q_vsnprintf (msg, sizeof(msg), fmt, argptr) > sizeof(msg)) { G_Error ( "PrintMsg overrun" ); } va_end (argptr); // double quotes are bad while ((p = strchr(msg, '"')) != NULL) *p = '\''; trap_SendServerCommand ( ( (ent == NULL) ? -1 : ent-g_entities ), va("print \"%s\"", msg )); }
/* ============= 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 ); // Strip out color codes because these aren't needed in the log/viewlog or in the output window --eez Q_StripColor( 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 ) { 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); } } }
// NULL for everyone void QDECL PrintMsg(gentity_t *ent, const char *fmt, ...) { char msg[1024]; va_list argptr; char *p; // NOTE: if buffer overflow, it's more likely to corrupt stack and crash than do a proper G_Error? va_start(argptr, fmt); if (Q_vsnprintf(msg, sizeof (msg), fmt, argptr) > (int)sizeof (msg)) { G_Error("PrintMsg overrun"); } va_end(argptr); // double quotes are bad while ((p = strchr(msg, '"')) != NULL) *p = '\''; trap_SendServerCommand(((ent == NULL) ? -1 : ent - g_entities), va("print \"%s\"", msg)); }
P_P_F void Plugin_BoldPrintf(int slot, const char *fmt, ... ) { char str[256]; client_t *cl; va_list vl; if(slot < 0) cl = NULL; else if( slot < sv_maxclients->integer) cl = &svs.clients[slot]; else return; va_start(vl,fmt); Q_vsnprintf(str, sizeof(str), fmt, vl); va_end(vl); SV_SendServerCommand(cl, "c \"%s\"", str); }
P_P_F void Plugin_Error(int code, const char *fmt, ...) { va_list argptr; char msg[1024]; volatile int pID = PHandler_CallerID(); if(pID<0){ Com_PrintError("Plugin Error called from unknown plugin!\n"); return; } va_start (argptr,fmt); Q_vsnprintf(msg, sizeof(msg), fmt, argptr); va_end (argptr); PHandler_Error(pID,code,msg); }
void Com_DPrintf (int level, const char* msg, ...) { va_list argptr; char text[1024]; /* don't confuse non-developers with techie stuff... */ if (!developer || developer->integer == 0) return; if (!(developer->integer & level)) return; va_start(argptr, msg); Q_vsnprintf(text, sizeof(text), msg, argptr); va_end(argptr); gi.DPrintf("%s", text); }
void G_refPrintf( gentity_t* ent, const char *fmt, ... ) { va_list argptr; char text[1024]; va_start (argptr, fmt); Q_vsnprintf (text, sizeof(text), fmt, argptr); va_end (argptr); // CHRUKER: b046 - Added the linebreak to the string. if(ent == NULL){ // yada - in server console color codes look stupid ConsolizeString(text,text); trap_Printf(va("%s\n",text)); }else{ // CHRUKER: b046 - Was using the cpm command, but this is really just for the console. CP(va("print \"%s\n\"", text)); } }
static void SendSystem( int clientNum, char *fmt, ... ) { va_list argptr; char buffer[1024]; va_start( argptr, fmt ); Q_vsnprintf( buffer, 1024, fmt, argptr ); va_end( argptr ); if ( uiFeedBack && clientNum == uiCaller ) { trap_SendServerCommand( clientNum, va( "pmr \"%s\"", Q_CleanStr( buffer ))); } else { trap_SendServerCommand( clientNum, va( "chat 100 \"^1System: ^7%s\"", buffer )); } }
void G_refPrintf(gentity_t *ent, const char *fmt, ...) { va_list argptr; char text[1024]; va_start(argptr, fmt); Q_vsnprintf(text, sizeof(text), fmt, argptr); va_end(argptr); if (ent == NULL) { trap_Printf(text); } else { CP(va("cpm \"%s\n\"", text)); } }