当前位置: 首页>>代码示例>>C++>>正文


C++ bf_read::GetNumBytesLeft方法代码示例

本文整理汇总了C++中bf_read::GetNumBytesLeft方法的典型用法代码示例。如果您正苦于以下问题:C++ bf_read::GetNumBytesLeft方法的具体用法?C++ bf_read::GetNumBytesLeft怎么用?C++ bf_read::GetNumBytesLeft使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bf_read的用法示例。


在下文中一共展示了bf_read::GetNumBytesLeft方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: HandlePacket_LOOKING_FOR_WORKERS

void HandlePacket_LOOKING_FOR_WORKERS( bf_read &buf, const CIPAddr &ipFrom )
{
	// If we're downloading files for a job request, don't process any more "looking for workers" packets.
	if ( g_Waiting_hProcess )
		return;
	
	// This will be a nonzero-length string if patching.
	char versionString[512];
	buf.ReadString( versionString, sizeof( versionString ) );

	int iPort = buf.ReadShort();
	int iPriority = buf.ReadShort();

	// Make sure we don't run the same job more than once.
	if ( !CheckJobID( buf, g_CurJobID ) )
		return;

	CUtlVector<char*> newArgv;
	GetArgsFromBuffer( buf, newArgv, &g_Waiting_bShowAppWindow );

	bool bForcePatch = false;
	if ( buf.GetNumBytesLeft() >= 1 )
		bForcePatch = (buf.ReadByte() != 0);

	int iDownloaderPort = iPort;
	if  ( buf.GetNumBytesLeft() >= 2 )
		iDownloaderPort = buf.ReadShort();

	// Add these arguments after the executable filename to tell the program
	// that it's an MPI worker and who to connect to. 
	char strDownloaderIP[128], strMainIP[128];
	V_snprintf( strDownloaderIP, sizeof( strDownloaderIP ), "%d.%d.%d.%d:%d", ipFrom.ip[0], ipFrom.ip[1], ipFrom.ip[2], ipFrom.ip[3], iDownloaderPort );
	V_snprintf( strMainIP, sizeof( strMainIP ), "%d.%d.%d.%d:%d", ipFrom.ip[0], ipFrom.ip[1], ipFrom.ip[2], ipFrom.ip[3], iPort );

	// (-mpi is already on the command line of whoever ran the app).
	// AppendArg( commandLine, sizeof( commandLine ), "-mpi" );
	newArgv.InsertAfter( 0, CopyString( "-mpi_worker" ) );
	newArgv.InsertAfter( 1, CopyString( strDownloaderIP ) );


	// If the version string is set, then this is a patch.
	bool bPatching = false;
	if ( versionString[0] != 0 )
	{
		bPatching = true;
		
		// Check that we haven't applied this patch version yet. This case usually happens right after we've applied a patch
		// and we're restarting. The vmpi_transfer master is still pinging us telling us to patch, but we don't want to
		// reapply this patch.
		if ( atof( versionString ) <= atof( g_VersionString ) && !bForcePatch )
		{
			newArgv.PurgeAndDeleteElements();
			return;
		}
		
		// Ok, it's a new version. Get rid of whatever was running before.
		KillRunningProcess( "Starting a patch..", true );
	}
								 
	// If there's already a job running, only interrupt it if this new one has a higher priority.
	if ( WaitForProcessToExit() )
	{
		if ( iPriority > g_CurJobPriority )
		{
			KillRunningProcess( "Interrupted by a higher priority process", true );
		}
		else
		{
			// This means we're already running a job with equal to or greater priority than
			// the one that has been requested. We're going to ignore this request.
			newArgv.PurgeAndDeleteElements();
			return;
		}
	}

	// Responses go here.
	g_CurRespondAddr = ipFrom;
	
	// Also look for -mpi_ShowAppWindow in the args to the service.
	if ( !g_Waiting_bShowAppWindow && FindArg( __argc, __argv, "-mpi_ShowAppWindow" ) )
		g_Waiting_bShowAppWindow = true;

	// Copy all the files from the master and put them in our cache dir to run with.
	char cacheDir[MAX_PATH];
	if ( StartDownloadingAppFiles( newArgv, cacheDir, sizeof( cacheDir ), g_Waiting_bShowAppWindow, &g_Waiting_hProcess, bPatching ) )
	{
		// After it's downloaded, we want it to switch to the main connection port.
		if ( newArgv.Count() >= 3 && V_stricmp( newArgv[2], strDownloaderIP ) == 0 )
		{
			delete newArgv[2];
			newArgv[2] = CopyString( strMainIP );
		}
		
		g_Waiting_StartTime = Plat_FloatTime();
		g_Waiting_Argv.PurgeAndDeleteElements();
		g_Waiting_Argv = newArgv;
		g_Waiting_Priority = iPriority;
		g_Waiting_bPatching = bPatching;
		newArgv.Purge();
	}
//.........这里部分代码省略.........
开发者ID:DeadZoneLuna,项目名称:SourceEngine2007,代码行数:101,代码来源:vmpi_service.cpp

示例2: MsgFunc_PlayerStatsUpdate

//-----------------------------------------------------------------------------
// Purpose: Called when we get a stat update for the local player
//-----------------------------------------------------------------------------
void CTFStatPanel::MsgFunc_PlayerStatsUpdate( bf_read &msg )
{
	// get the fixed-size information
	int iClass = msg.ReadByte();
	int iMsgType = msg.ReadByte();
	int iSendBits = msg.ReadLong();

	bool bAlive = true;
	bool bSpawned = false;

	switch ( iMsgType )
	{
	case STATMSG_RESET:
		m_RoundStatsCurrentGame.Reset();
		m_RoundStatsLifeStart.Reset();
		return;
	case STATMSG_PLAYERSPAWN:
	case STATMSG_PLAYERRESPAWN:
		bSpawned = true;
		break;
	case STATMSG_PLAYERDEATH:
		bAlive = false;
		break;
	case STATMSG_UPDATE:
		break;
	default:
		Assert( false );
	}

	Assert( iClass >= TF_FIRST_NORMAL_CLASS && iClass <= TF_LAST_NORMAL_CLASS );
	if ( iClass < TF_FIRST_NORMAL_CLASS || iClass > TF_LAST_NORMAL_CLASS )
		return;
	
	m_iClassCurrentLife = iClass;
	C_TFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer();
	if ( pPlayer )
	{
		m_iTeamCurrentLife = pPlayer->GetTeamNumber();
	}

//	Msg( "Stat update: (msg %d) ", iMsgType );
	// the bitfield indicates which stats are contained in the message.  Set the stats appropriately.
	int iStat = TFSTAT_FIRST;
	while ( iSendBits > 0 )
	{
		if ( iSendBits & 1 )
		{	
			int iVal = msg.ReadLong();
//			Msg( "#%d=%d ", iStat, iVal );
			m_RoundStatsCurrentGame.m_iStat[iStat] = iVal;
		}
		iSendBits >>= 1;
		iStat++;
	}
//	Msg( "\n" );
	// Calculate stat values for current life.  Take current game stats and subtract what the values were at the start of this life
	for ( iStat = TFSTAT_FIRST; iStat < TFSTAT_MAX; iStat++ )
	{
		if ( iStat == TFSTAT_MAXSENTRYKILLS )
		{
			// max sentry kills is special, it is a max value.  Always use absolute value, do not use delta from earlier value.
			m_RoundStatsCurrentLife.m_iStat[TFSTAT_MAXSENTRYKILLS] = m_RoundStatsCurrentGame.m_iStat[TFSTAT_MAXSENTRYKILLS];
			continue;
		}
		int iDelta = m_RoundStatsCurrentGame.m_iStat[iStat] - m_RoundStatsLifeStart.m_iStat[iStat];
		Assert( iDelta >= 0 );
		m_RoundStatsCurrentLife.m_iStat[iStat] = iDelta;
	}

	if ( iMsgType == STATMSG_PLAYERDEATH || iMsgType == STATMSG_PLAYERRESPAWN )
	{
		m_RoundStatsCurrentLife.m_iStat[TFSTAT_PLAYTIME] = gpGlobals->curtime - m_flTimeCurrentLifeStart;
	}

	if ( bSpawned )
	{
		// if the player just spawned, use current stats as baseline to calculate stats for next life
		m_RoundStatsLifeStart = m_RoundStatsCurrentGame;
		m_flTimeCurrentLifeStart = gpGlobals->curtime;
	}

	// sanity check: the message should contain exactly the # of bytes we expect based on the bit field
	Assert( !msg.IsOverflowed() );
	Assert( 0 == msg.GetNumBytesLeft() );
	// if byte count isn't correct, bail out and don't use this data, rather than risk polluting player stats with garbage
	if ( msg.IsOverflowed() || ( 0 != msg.GetNumBytesLeft() ) )
		return;

	UpdateStats( iMsgType );
}
开发者ID:Axitonium,项目名称:SourceEngine2007,代码行数:93,代码来源:tf_hud_statpanel.cpp

示例3: HandleMessage

bool HandleMessage(bf_read &msg, int type)
{

	if (type == 0) // nop
	{
		//	printf("NOP\n");
		return true;
	}

	if (type == 1) // disconnect
	{
		char dcreason[1024];
		msg.ReadString(dcreason, sizeof(dcreason));
		printf("Disconnected: %s\n", dcreason);
		printf("Reconnecting in 5000 ms ...");

		_sleep(5000);
		NET_Reconnect();
		return true;
	}

	if (type == 2)//net_File
	{
		long transferid = msg.ReadUBitLong(32);
		char filename[255];
		msg.ReadString(filename, sizeof(filename));
		bool requested = (bool)(msg.ReadOneBit()==1);

		if (requested)
			printf("net_File: Server requested file: %s::%i\n", filename, transferid);
		else
			printf("net_File: Server is not sending file: %s::%i\n", filename, transferid);

		return true;
	}
	if (type == 3)//net_Tick
	{
		net_tick = msg.ReadLong();
		net_hostframetime = msg.ReadUBitLong(16);
		net_hostframedeviation = msg.ReadUBitLong(16);
		//printf("Tick: %i - hostframetime: %i ( deviation: %i )\n", net_tick, net_hostframedeviation, net_hostframedeviation);

		return true;
	}

	if (type == 4)//net_StringCmd
	{
		char cmd[1024];
		msg.ReadString(cmd, sizeof(cmd));

		printf("net_StringCmd: %s\n", cmd);
		return true;
	}

	if (type == 5)//net_SetConVar
	{

		int count = msg.ReadByte();

		char cmdname[255];
		char cmdval[255];

		printf("net_SetConVar: %i\n", count);
		for (int i = 0; i < count; i++)
		{
			msg.ReadString(cmdname, sizeof(cmdname));
			msg.ReadString(cmdval, sizeof(cmdval));
			printf("%s to: %s\n", cmdname, cmdval);

		}
		printf("net_SetConVar_end, left: %i\n", msg.GetNumBytesLeft());
		return true;

	}

	if (type == 6)// net_SignonState
	{
		int state = msg.ReadByte();
		long aservercount = msg.ReadLong();


		printf("Received net_SignOnState: %i, count: %i\n", state, bconnectstep);

		if (netchan->m_iSignOnState == state)
		{
			printf("Ignored signonstate!\n");
			return true;
		}

		netchan->m_iServerCount = aservercount;
		netchan->m_iSignOnState = state;

		printf("KK __ %i\n", state);
		if (state == 3)
		{

			senddata.WriteUBitLong(8, 6);
			senddata.WriteLong(netchan->m_iServerCount);
			senddata.WriteLong(518790445);//clc_ClientInfo crc
			senddata.WriteOneBit(1);//ishltv
//.........这里部分代码省略.........
开发者ID:Python1320,项目名称:source1_client,代码行数:101,代码来源:leyfakeclient.cpp


注:本文中的bf_read::GetNumBytesLeft方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。