/* ================ Con_Dump_f Save the console contents out to a file ================ */ void Con_Dump_f( void ) { int l; fileHandle_t f; char name[ MAX_STRING_CHARS ]; l = Cmd_Argc(); if ( l > 2 ) { Cmd_PrintUsage(_("[<filename>]"), NULL); return; } if ( l == 1 ) { time_t now = time( NULL ); strftime( name, sizeof( name ), "condump/%Y%m%d-%H%M%S%z.txt", localtime( &now ) ); } else { Q_snprintf( name, sizeof( name ), "condump/%s", Cmd_Argv( 1 ) ); } f = FS_FOpenFileWrite( name ); if ( !f ) { Com_Log(LOG_ERROR, _( "couldn't open." )); return; } Com_Printf(_( "Dumped console text to %s.\n"), name ); // skip empty lines for ( l = consoleState.currentLine - consoleState.maxScrollbackLengthInLines + 1; l <= consoleState.currentLine; l++ ) { if ( consoleState.text[ CON_LINE( l ) ].ch ) { break; } } // write the remaining lines for ( ; l <= consoleState.currentLine; l++ ) { const char *buffer = Con_LineToString( l, qtrue ); FS_Write( buffer, strlen( buffer ), f ); } FS_FCloseFile( f ); }
/* =================== CL_GetServerCommand Set up argc/argv for the given command =================== */ qboolean CL_GetServerCommand( int serverCommandNumber ) { const char *s; char *cmd; static char bigConfigString[ BIG_INFO_STRING ]; int argc; // if we have irretrievably lost a reliable command, drop the connection if ( serverCommandNumber <= clc.serverCommandSequence - MAX_RELIABLE_COMMANDS ) { // when a demo record was started after the client got a whole bunch of // reliable commands then the client never got those first reliable commands if ( clc.demoplaying ) { return qfalse; } Com_Error( ERR_DROP, "CL_GetServerCommand: a reliable command was cycled out" ); } if ( serverCommandNumber > clc.serverCommandSequence ) { Com_Error( ERR_DROP, "CL_GetServerCommand: requested a command not received" ); } s = clc.serverCommands[ serverCommandNumber & ( MAX_RELIABLE_COMMANDS - 1 ) ]; clc.lastExecutedServerCommand = serverCommandNumber; if ( cl_showServerCommands->integer ) { // NERVE - SMF Com_Printf( "serverCommand: %i : %s\n", serverCommandNumber, s ); } rescan: Cmd_TokenizeString( s ); cmd = Cmd_Argv( 0 ); argc = Cmd_Argc(); if ( !strcmp( cmd, "disconnect" ) ) { // NERVE - SMF - allow server to indicate why they were disconnected if ( argc >= 2 ) { Com_Error( ERR_SERVERDISCONNECT, "Server disconnected: %s", Cmd_Argv( 1 ) ); } else { Com_Error( ERR_SERVERDISCONNECT, "Server disconnected" ); } } if ( !strcmp( cmd, "bcs0" ) ) { Com_sprintf( bigConfigString, BIG_INFO_STRING, "cs %s %s", Cmd_Argv( 1 ), Cmd_QuoteString( Cmd_Argv( 2 ) ) ); return qfalse; } if ( !strcmp( cmd, "bcs1" ) ) { s = Cmd_QuoteString( Cmd_Argv( 2 ) ); if ( strlen( bigConfigString ) + strlen( s ) >= BIG_INFO_STRING ) { Com_Error( ERR_DROP, "bcs exceeded BIG_INFO_STRING" ); } strcat( bigConfigString, s ); return qfalse; } if ( !strcmp( cmd, "bcs2" ) ) { s = Cmd_QuoteString( Cmd_Argv( 2 ) ); if ( strlen( bigConfigString ) + strlen( s ) + 1 >= BIG_INFO_STRING ) { Com_Error( ERR_DROP, "bcs exceeded BIG_INFO_STRING" ); } strcat( bigConfigString, s ); strcat( bigConfigString, "\"" ); s = bigConfigString; goto rescan; } if ( !strcmp( cmd, "cs" ) ) { CL_ConfigstringModified(); // reparse the string, because CL_ConfigstringModified may have done another Cmd_TokenizeString() Cmd_TokenizeString( s ); return qtrue; } if ( !strcmp( cmd, "map_restart" ) ) { // clear outgoing commands before passing // the restart to the cgame memset( cl.cmds, 0, sizeof( cl.cmds ) ); return qtrue; } if ( !strcmp( cmd, "popup" ) ) { // direct server to client popup request, bypassing cgame // trap_UI_Popup(Cmd_Argv(1)); // if ( cls.state == CA_ACTIVE && !clc.demoplaying ) { // VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_CLIPBOARD); // Menus_OpenByName(Cmd_Argv(1)); // } return qfalse; } if ( !strcmp( cmd, "pubkey_decrypt" ) ) { char buffer[ MAX_STRING_CHARS ] = "pubkey_identify "; unsigned int msg_len = MAX_STRING_CHARS - 16; mpz_t message; if ( argc == 1 ) { Com_Log(LOG_ERROR, _( "Server sent a pubkey_decrypt command, but sent nothing to decrypt!" )); return qfalse; } mpz_init_set_str( message, Cmd_Argv( 1 ), 16 ); if ( rsa_decrypt( &private_key, &msg_len, ( unsigned char * ) buffer + 16, message ) ) { nettle_mpz_set_str_256_u( message, msg_len, ( unsigned char * ) buffer + 16 ); mpz_get_str( buffer + 16, 16, message ); CL_AddReliableCommand( buffer ); } mpz_clear( message ); return qfalse; } // we may want to put a "connect to other server" command here // cgame can now act on the command return qtrue; }