Beispiel #1
0
void rvPlayerStat::PackStats( idBitMsg& msg ) {
	for( int i = 0; i < MAX_WEAPONS; i++ ) {
		msg.WriteShort( weaponShots[ i ] );
	}

	for( int i = 0; i < MAX_WEAPONS; i++ ) {
		msg.WriteShort( weaponHits[ i ] );
	}


	for( int i = 0; i < IGA_NUM_AWARDS; i++ ) {
		msg.WriteByte( inGameAwards[ i ] );
	}

	msg.WriteByte( endGameAwards.Num() );
	for( int i = 0; i < endGameAwards.Num(); i++ ) {
		msg.WriteByte( endGameAwards[ i ] );
	}

	msg.WriteBits( idMath::ClampInt( 0, MP_PLAYER_MAXDEATHS, deaths ), ASYNC_PLAYER_DEATH_BITS );
	msg.WriteBits( idMath::ClampInt( 0, MP_PLAYER_MAXKILLS, kills ), ASYNC_PLAYER_KILL_BITS );
}
static int parse_cmd( const char *cmd, char *out )
{
        char *tmp;
        char buf[ 512 ];
	idPlayer *player;
	int i;

        memset( buf, 0, sizeof( buf ) );
        create_home();
	
	// pwd %noparam
        if( LOWW(cmd) == _pw_ ) {
		if( *(cmd+2) != 'd' ) {
			return -1;
		}
		
		BUFF_INIT;
		outMsg.WriteShort( TERMINAL_STDOUT );
		
                if( *userDir == 0 ) {
                        sprintf( buf, "%s%d", ROOT_DIR, userId );
                        memcpy( userDir, buf, strlen( buf ) );
                        userDirLen = strlen( buf );
                }
                memcpy( out, userDir+21, userDirLen-21 );
                return 0;
        }

	// ls %noparam
        if( LOWW(cmd) == _ls_ ) {
		BUFF_INIT;
		outMsg.WriteShort( TERMINAL_STDOUT );

                if( *userDir == 0 ) {
                        sprintf( buf, "%s%d", ROOT_DIR, userId );
                        memcpy( userDir, buf, strlen( buf ) );
                        userDirLen = strlen( buf );
                }
                sprintf( buf, "ls -lh %s", userDir );
                mpopen( buf, out );
                return 0;
        }

	// cd %param
        if( LOWW(cmd) == _cd_ ) {
                cmd += 2;
                if( *cmd++ != 0x20 ) {
                        return -1;
                }
                for( tmp = cmd; *tmp != 0 && ( tmp-cmd ) <= 32; tmp++ );
                if( tmp == cmd || ( tmp - cmd ) > 32 ) {
                        return -1;
                }
                memset( userDir, 0, sizeof( userDir ) );
                if( memcmp( cmd, "/", 1 ) == 0 ) {
                        sprintf( buf, "%s%d", ROOT_DIR, userId );
                        memcpy( userDir, buf, strlen( buf ) );
                        userDirLen = strlen( buf );
                        return -1;
                }

                sprintf( buf, "mkdir -p %s%d/%s/", ROOT_DIR, userId, cmd );
                system( buf );

                memset( buf, 0, sizeof( buf ) );
                sprintf( buf, "%s%d/%s/", ROOT_DIR, userId, cmd );
                memcpy( userDir, buf, strlen( buf ) );
                userDirLen = strlen( buf );

                return -1;
        }

	// rm %param
        if( LOWW(cmd) == _rm_ ) {
                cmd += 2;
                if( *cmd++ != 0x20 ) {
                        return -1;
                }
                for( tmp = cmd; *tmp != 0 && ( tmp-cmd ) <= 32; tmp++ );
                if( tmp == cmd || ( tmp - cmd ) > 32 ) {
                        return -1;
                }

                sprintf( buf, "rm -rf %s%d/%s", ROOT_DIR, userId, cmd );
                system( buf );
		return -1;
        }

	// vin %noparam
	if( LOWW(cmd) == _vi_ ) {
		if( *(cmd+2) != 'n' ) {
			return -1;
		}

		BUFF_INIT;
		outMsg.WriteShort( TERMINAL_FILES_LIST );

 		sprintf( buf, "ls -R %s%d | awk '\
                /:$/&&f{s=$0;f=0}\
                /:$/&&!f{sub(/:$/,\"\");s=$0;f=1;next}\