本文整理汇总了C++中NetBitStreamInterface::GetNumberOfBytesUsed方法的典型用法代码示例。如果您正苦于以下问题:C++ NetBitStreamInterface::GetNumberOfBytesUsed方法的具体用法?C++ NetBitStreamInterface::GetNumberOfBytesUsed怎么用?C++ NetBitStreamInterface::GetNumberOfBytesUsed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetBitStreamInterface
的用法示例。
在下文中一共展示了NetBitStreamInterface::GetNumberOfBytesUsed方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetPedRotation
void CPedRPCs::SetPedRotation ( CClientEntity* pSource, NetBitStreamInterface& bitStream )
{
SPedRotationSync rotation;
unsigned char ucTimeContext;
if ( bitStream.Read ( &rotation ) &&
bitStream.Read ( ucTimeContext ) )
{
uchar ucNewWay = 0;
if ( bitStream.GetNumberOfBytesUsed () > 0 )
bitStream.Read ( ucNewWay );
CClientPed* pPed = m_pPedManager->Get ( pSource->GetID (), true );
if ( pPed )
{
if ( ucNewWay == 1 )
pPed->SetCurrentRotationNew ( rotation.data.fRotation );
else
pPed->SetCurrentRotation ( rotation.data.fRotation );
if ( !IS_PLAYER ( pPed ) )
pPed->SetCameraRotation ( rotation.data.fRotation );
pPed->SetSyncTimeContext ( ucTimeContext );
}
}
}
示例2: RecordPacket
void CClientPacketRecorder::RecordPacket(unsigned char ucPacketID, NetBitStreamInterface& bitStream)
{
if (m_bRecording && m_szFilename)
{
// Open our file
FILE* pFile = fopen(m_szFilename, "ab+");
if (pFile)
{
// Write our timestamp
if (m_bFrameBased)
{
long lFrameStamp = m_lFrames - m_lRelative;
fwrite(&lFrameStamp, sizeof(long), 1, pFile);
}
else
{
long lTimeStamp = CClientTime::GetTime() - m_lRelative;
fwrite(&lTimeStamp, sizeof(long), 1, pFile);
}
// fwrite ( &ulTimeStamp, sizeof ( unsigned long), 1, pFile );
// Write the packet ID
fputc(ucPacketID, pFile);
// Write the size of the bitstream
unsigned long ulSize = static_cast<unsigned long>(bitStream.GetNumberOfBytesUsed());
fwrite(&ulSize, sizeof(unsigned long), 1, pFile);
// Write the content of the bitstream to the file
char c = 0;
for (unsigned long i = 0; i < ulSize; i++)
{
bitStream.Read(c);
fputc(c, pFile);
}
// Reset the readpointer so the client can use it
bitStream.ResetReadPointer();
// Close the file
fclose(pFile);
}
}
}
示例3: StaticProcessPacket
bool CConnectManager::StaticProcessPacket ( unsigned char ucPacketID, NetBitStreamInterface& BitStream )
{
// We're working on connecting?
if ( g_pConnectManager->m_bIsConnecting )
{
// The packet we're expecting?
if ( ucPacketID == PACKET_ID_MOD_NAME )
{
// Read out the mod to load
char* szModName = new char [ BitStream.GetNumberOfBytesUsed () + 1 ];
memset ( szModName, 0, BitStream.GetNumberOfBytesUsed () + 1 );
if ( BitStream.Read ( szModName, BitStream.GetNumberOfBytesUsed () ) )
{
// Backward compatibly examine the bytes following the mod name
BitStream.ResetReadPointer ();
BitStream.Read ( szModName, strlen ( szModName ) );
char cPad;
BitStream.Read ( cPad );
unsigned short usServerBitStreamVersion = 0x01;
BitStream.Read ( usServerBitStreamVersion ); // This will silently fail for < 1.0.2 and leave the bitstream version at 0x01
CCore::GetSingleton ().GetNetwork ()->SetServerBitStreamVersion ( usServerBitStreamVersion );
// Limit the nick length for servers that have a problem with max length nicks
if ( usServerBitStreamVersion < 0x06 )
g_pConnectManager->m_strNick = g_pConnectManager->m_strNick.substr ( 0, MAX_PLAYER_NICK_LENGTH - 1 );
// Populate the arguments to pass it (-c host port nick)
SString strArguments ( "%s %s", g_pConnectManager->m_strNick.c_str(), g_pConnectManager->m_strPassword.c_str() );
// Hide the messagebox we're currently showing
CCore::GetSingleton ().RemoveMessageBox ();
// If we connected from quick-connect, get rid of it
CQuickConnect * pQuickConnect = CCore::GetSingleton ().GetLocalGUI ()->GetMainMenu ()->GetQuickConnectWindow ();
if ( pQuickConnect->IsVisible () )
pQuickConnect->SetVisible ( false );
// Save the connection details into the config
CVARS_SET ( "host", g_pConnectManager->m_strHost );
CVARS_SET ( "port", g_pConnectManager->m_usPort );
CVARS_SET ( "password", g_pConnectManager->m_strPassword );
//Conver the Address to an unsigned long
unsigned long ulAddr = inet_addr( g_pConnectManager->m_strHost.c_str() );
//Create an instance of the in_addr structure to store the address
in_addr Address;
//Set the address to the unsigned long we just created
Address.S_un.S_addr = ulAddr;
//Set the current server info and Add the ASE Offset to the Query port)
CCore::GetSingleton().SetCurrentServer ( Address, g_pConnectManager->m_usPort + 123 );
// Kevuwk: Forced the config to save here so that the IP/Port isn't lost on crash
CCore::GetSingleton ().SaveConfig ();
// Reset our variables
g_pConnectManager->m_strNick = "";
g_pConnectManager->m_strHost = "";
g_pConnectManager->m_strPassword = "";
g_pConnectManager->m_usPort = 0;
g_pConnectManager->m_bIsConnecting = false;
g_pConnectManager->m_tConnectStarted = 0;
// Load the mod
if ( !CModManager::GetSingleton ().Load ( szModName, strArguments ) )
{
// Failed loading the mod
strArguments.Format ( "No such mod installed (%s)", szModName );
CCore::GetSingleton ().ShowMessageBox ( "Error", strArguments, MB_BUTTON_OK | MB_ICON_ERROR );
g_pConnectManager->Abort ();
}
}
else
{
// Show failed message and abort the attempt
CCore::GetSingleton ().ShowMessageBox ( "Error", "Bad server response (2)", MB_BUTTON_OK | MB_ICON_ERROR );
g_pConnectManager->Abort ();
}
delete [] szModName;
}
else
{
// Not the player joined packet?
if ( ucPacketID != PACKET_ID_SERVER_JOIN && ucPacketID != PACKET_ID_SERVER_JOIN_DATA )
{
// Show failed message and abort the attempt
CCore::GetSingleton ().ShowMessageBox ( "Error", "Bad server response (1)", MB_BUTTON_OK | MB_ICON_ERROR );
g_pConnectManager->Abort ();
}
}
return true;
}
return false;
}
示例4: DoPulse
///////////////////////////////////////////////////////////////
//
// CLatentSendQueue::DoPulse
//
// Send next part of the active transfer
//
///////////////////////////////////////////////////////////////
void CLatentSendQueue::DoPulse ( int iTimeMsBetweenCalls )
{
if ( m_TxQueue.empty () )
{
m_iBytesOwing = 0;
return;
}
// Check if previous tx has completed
if ( m_TxQueue.front ().uiReadPosition == m_TxQueue.front ().bufferRef->GetSize () && m_TxQueue.front ().bSendFinishing )
{
m_TxQueue.pop_front ();
PostQueueRemove ();
if ( m_TxQueue.empty () )
{
m_iBytesOwing = 0;
return;
}
}
m_uiCurrentRate = Max < uint > ( MIN_SEND_RATE, m_uiCurrentRate );
// How many bytes to send this pulse
int iBytesToSendThisPulse = iTimeMsBetweenCalls * m_uiCurrentRate / 1000;
// Add bytes owing from last pulse
iBytesToSendThisPulse += m_iBytesOwing;
// Calc packet size depending on rate
uint uiMaxPacketSize = Lerp ( MIN_PACKET_SIZE, UnlerpClamped ( MIN_PACKET_SIZE * 10, m_uiCurrentRate, MAX_PACKET_SIZE * 15 ), MAX_PACKET_SIZE );
// Calc how many packets to do this pulse
uint uiNumPackets = iBytesToSendThisPulse / uiMaxPacketSize;
// Update carry over
m_iBytesOwing = iBytesToSendThisPulse % uiMaxPacketSize;
// Process item at front of queue
SSendItem& activeTx = m_TxQueue.front ();
for ( uint i = 0 ; i < uiNumPackets && !activeTx.bSendFinishing ; i++ )
{
// Send next part of data
NetBitStreamInterface* pBitStream = DoAllocateNetBitStream ( m_RemoteId, m_usBitStreamVersion );
pBitStream->WriteBits ( &activeTx.uiId, 15 );
// Next bit indicates if it has a special flag
if ( activeTx.uiReadPosition == 0 )
{
// Head
pBitStream->WriteBit ( 1 );
pBitStream->Write ( (uchar)FLAG_HEAD );
pBitStream->Write ( activeTx.usCategory );
pBitStream->Write ( activeTx.bufferRef->GetSize () );
pBitStream->Write ( activeTx.uiRate );
if ( pBitStream->Version () >= 0x31 )
pBitStream->Write ( activeTx.usResourceNetId );
activeTx.bSendStarted = true;
}
else
if ( activeTx.bufferRef->GetSize () == activeTx.uiReadPosition )
{
// Tail
pBitStream->WriteBit ( 1 );
pBitStream->Write ( (uchar)FLAG_TAIL );
activeTx.bSendFinishing = true;
}
else
{
// Body
pBitStream->WriteBit ( 0 );
}
// Align to next boundary
pBitStream->AlignWriteToByteBoundary ();
uint uiMaxDataSize = Max < int > ( 10, uiMaxPacketSize - pBitStream->GetNumberOfBytesUsed () );
// Calc how much data to send
uint uiDataOffset = activeTx.uiReadPosition;
uint uiSizeToSend = Min ( uiMaxDataSize, activeTx.bufferRef->GetSize () - activeTx.uiReadPosition );
activeTx.uiReadPosition += uiSizeToSend;
pBitStream->Write ( (ushort)uiSizeToSend );
pBitStream->Write ( activeTx.bufferRef->GetData () + uiDataOffset, uiSizeToSend );
// Send
DoSendPacket ( PACKET_ID_LATENT_TRANSFER, m_RemoteId, pBitStream, PACKET_PRIORITY_LOW, PACKET_RELIABILITY_RELIABLE_ORDERED, PACKET_ORDERING_DATA_TRANSFER );
DoDeallocateNetBitStream ( pBitStream );
}
}
示例5: StaticProcessPacket
bool CConnectManager::StaticProcessPacket ( unsigned char ucPacketID, NetBitStreamInterface& BitStream )
{
// We're working on connecting?
if ( g_pConnectManager->m_bIsConnecting )
{
// The packet we're expecting?
if ( ucPacketID == PACKET_ID_MOD_NAME )
{
// Read out the mod to load
char* szModName = new char [ BitStream.GetNumberOfBytesUsed () + 1 ];
memset ( szModName, 0, BitStream.GetNumberOfBytesUsed () + 1 );
if ( BitStream.Read ( szModName, BitStream.GetNumberOfBytesUsed () ) )
{
// Backward compatibly examine the bytes following the mod name
BitStream.ResetReadPointer ();
BitStream.Read ( szModName, strlen ( szModName ) );
char cPad;
BitStream.Read ( cPad );
unsigned short usServerBitStreamVersion = 0x01;
BitStream.Read ( usServerBitStreamVersion ); // This will silently fail for < 1.0.2 and leave the bitstream version at 0x01
CCore::GetSingleton ().GetNetwork ()->SetServerBitStreamVersion ( usServerBitStreamVersion );
// Populate the arguments to pass it (-c host port nick)
SString strArguments ( "%s %s", g_pConnectManager->m_strNick.c_str(), g_pConnectManager->m_strPassword.c_str() );
// Hide the messagebox we're currently showing
CCore::GetSingleton ().RemoveMessageBox ();
// If we connected from quick-connect, get rid of it
CQuickConnect * pQuickConnect = CCore::GetSingleton ().GetLocalGUI ()->GetMainMenu ()->GetQuickConnectWindow ();
if ( pQuickConnect->IsVisible () )
pQuickConnect->SetVisible ( false );
// Save the connection details into the config
CVARS_SET ( "host", g_pConnectManager->m_strHost );
CVARS_SET ( "port", g_pConnectManager->m_usPort );
CVARS_SET ( "password", g_pConnectManager->m_strPassword );
// Save the connection details into the recently played servers list
in_addr Address;
if ( CServerListItem::Parse ( g_pConnectManager->m_strHost.c_str (), Address ) )
{
CServerBrowser* pServerBrowser = CCore::GetSingleton ().GetLocalGUI ()->GetMainMenu ()->GetServerBrowser ();
CServerList* pRecentList = pServerBrowser->GetRecentList ();
CServerListItem RecentServer ( Address, g_pConnectManager->m_usPort + SERVER_LIST_QUERY_PORT_OFFSET );
if ( !pRecentList->Exists ( RecentServer ) )
{
pRecentList->Add ( RecentServer );
}
// Set as our current server for xfire
if ( XfireIsLoaded () )
{
const char *szKey[2], *szValue[2];
szKey[0] = "Gamemode";
szValue[0] = RecentServer.strType.c_str();
szKey[1] = "Map";
szValue[1] = RecentServer.strMap.c_str();
XfireSetCustomGameData ( 2, szKey, szValue );
}
}
// Kevuwk: Forced the config to save here so that the IP/Port isn't lost on crash
CCore::GetSingleton ().SaveConfig ();
// Reset our variables
g_pConnectManager->m_strNick = "";
g_pConnectManager->m_strHost = "";
g_pConnectManager->m_strPassword = "";
g_pConnectManager->m_usPort = 0;
g_pConnectManager->m_bIsConnecting = false;
g_pConnectManager->m_tConnectStarted = 0;
// Load the mod
if ( !CModManager::GetSingleton ().Load ( szModName, strArguments ) )
{
// Failed loading the mod
strArguments.Format ( "No such mod installed (%s)", szModName );
CCore::GetSingleton ().ShowMessageBox ( "Error", strArguments, MB_BUTTON_OK | MB_ICON_ERROR );
g_pConnectManager->Abort ();
}
}
else
{
// Show failed message and abort the attempt
CCore::GetSingleton ().ShowMessageBox ( "Error", "Bad server response (2)", MB_BUTTON_OK | MB_ICON_ERROR );
g_pConnectManager->Abort ();
}
delete [] szModName;
}
else
{
// Not the player joined packet?
if ( ucPacketID != PACKET_ID_SERVER_JOIN && ucPacketID != PACKET_ID_SERVER_JOIN_DATA )
{
//.........这里部分代码省略.........