本文整理匯總了C++中BYTEARRAY函數的典型用法代碼示例。如果您正苦於以下問題:C++ BYTEARRAY函數的具體用法?C++ BYTEARRAY怎麽用?C++ BYTEARRAY使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了BYTEARRAY函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: RECEIVE_SID_AUTH_ACCOUNTLOGON
bool CBNETProtocol :: RECEIVE_SID_AUTH_ACCOUNTLOGON( BYTEARRAY data )
{
// DEBUG_Print( "RECEIVED SID_AUTH_ACCOUNTLOGON" );
// DEBUG_Print( data );
// 2 bytes -> Header
// 2 bytes -> Length
// 4 bytes -> Status
// if( Status == 0 )
// 32 bytes -> Salt
// 32 bytes -> ServerPublicKey
if( ValidateLength( data ) && data.size( ) >= 8 )
{
BYTEARRAY status = BYTEARRAY( data.begin( ) + 4, data.begin( ) + 8 );
if( UTIL_ByteArrayToUInt32( status, false ) == 0 && data.size( ) >= 72 )
{
m_Salt = BYTEARRAY( data.begin( ) + 8, data.begin( ) + 40 );
m_ServerPublicKey = BYTEARRAY( data.begin( ) + 40, data.begin( ) + 72 );
return true;
}
}
return false;
}
示例2: RECEIVE_GCBI_INIT
CIncomingGarenaUser *CGCBIProtocol :: RECEIVE_GCBI_INIT( BYTEARRAY data )
{
// 2 bytes -> Header
// 2 bytes -> Length
// 4 bytes -> actual IP address (big endian)
// 4 bytes -> Garena user ID (big endian)
// 4 bytes -> Garena room ID (big endian)
// 4 bytes -> Garena user experience (big endian)
// 2 bytes -> country string from Garena
if( ValidateLength( data ) && data.size( ) == 22 )
{
BYTEARRAY IP = BYTEARRAY( data.begin( ) + 4, data.begin( ) + 8 );
BYTEARRAY UserID = BYTEARRAY( data.begin( ) + 8, data.begin( ) + 12 );
BYTEARRAY RoomID = BYTEARRAY( data.begin( ) + 12, data.begin( ) + 16 );
BYTEARRAY UserExp = BYTEARRAY( data.begin( ) + 16, data.begin( ) + 20 );
BYTEARRAY Country = BYTEARRAY( data.begin( ) + 20, data.begin( ) + 22 );
return new CIncomingGarenaUser(UTIL_ByteArrayToUInt32( IP, true ),
UTIL_ByteArrayToUInt32( UserID, true ),
UTIL_ByteArrayToUInt32( RoomID, true ),
UTIL_ByteArrayToUInt32( UserExp, true ),
string( Country.begin( ), Country.end( ) ) );
}
return NULL;
}
示例3: ExtractPackets
void CBNLSClient :: ExtractPackets( )
{
string *RecvBuffer = m_Socket->GetBytes( );
BYTEARRAY Bytes = UTIL_CreateByteArray( (unsigned char *)RecvBuffer->c_str( ), RecvBuffer->size( ) );
while( Bytes.size( ) >= 3 )
{
uint16_t Length = UTIL_ByteArrayToUInt16( Bytes, false );
if( Length >= 3 )
{
if( Bytes.size( ) >= Length )
{
m_Packets.push( new CCommandPacket( 0, Bytes[2], BYTEARRAY( Bytes.begin( ), Bytes.begin( ) + Length ) ) );
*RecvBuffer = RecvBuffer->substr( Length );
Bytes = BYTEARRAY( Bytes.begin( ) + Length, Bytes.end( ) );
}
else
return;
}
else
{
CONSOLE_Print( "[BNLSC: " + m_Server + ":" + UTIL_ToString( m_Port ) + ":C" + UTIL_ToString( m_WardenCookie ) + "] error - received invalid packet from BNLS server (bad length), disconnecting" );
m_Socket->Disconnect( );
return;
}
}
}
示例4: RECEIVE_SID_AUTH_INFO
bool CBNETProtocol :: RECEIVE_SID_AUTH_INFO( BYTEARRAY data )
{
// DEBUG_Print( "RECEIVED SID_AUTH_INFO" );
// DEBUG_Print( data );
// 2 bytes -> Header
// 2 bytes -> Length
// 4 bytes -> LogonType
// 4 bytes -> ServerToken
// 4 bytes -> ???
// 8 bytes -> MPQFileTime
// null terminated string -> IX86VerFileName
// null terminated string -> ValueStringFormula
if( ValidateLength( data ) && data.size( ) >= 25 )
{
m_LogonType = BYTEARRAY( data.begin( ) + 4, data.begin( ) + 8 );
m_ServerToken = BYTEARRAY( data.begin( ) + 8, data.begin( ) + 12 );
m_MPQFileTime = BYTEARRAY( data.begin( ) + 16, data.begin( ) + 24 );
m_IX86VerFileName = UTIL_ExtractCString( data, 24 );
m_ValueStringFormula = UTIL_ExtractCString( data, m_IX86VerFileName.size( ) + 25 );
return true;
}
return false;
}
示例5: RECEIVE_BNLS_WARDEN
BYTEARRAY CBNLSProtocol :: RECEIVE_BNLS_WARDEN( BYTEARRAY data )
{
// 2 bytes -> Length
// 1 byte -> ID
// (BYTE) -> Usage
// (DWORD) -> Cookie
// (BYTE) -> Result
// (WORD) -> Length of data
// (VOID) -> Data
if( ValidateLength( data ) && data.size( ) >= 11 )
{
unsigned char Usage = data[3];
uint32_t Cookie = UTIL_ByteArrayToUInt32( data, false, 4 );
unsigned char Result = data[8];
uint16_t Length = UTIL_ByteArrayToUInt16( data, false, 10 );
if( Result == 0x00 )
return BYTEARRAY( data.begin( ) + 11, data.end( ) );
else
CONSOLE_Print( "[BNLSPROTO] received error code " + UTIL_ToString( data[8] ) );
}
return BYTEARRAY( );
}
示例6: Update
bool CPotentialPlayer :: Update( void *fd )
{
if( m_DeleteMe )
return true;
if( !m_Socket )
return false;
m_Socket->DoRecv( (fd_set *)fd );
// extract as many packets as possible from the socket's receive buffer and process them
string *RecvBuffer = m_Socket->GetBytes( );
BYTEARRAY Bytes = UTIL_CreateByteArray( (unsigned char *)RecvBuffer->c_str( ), RecvBuffer->size( ) );
// a packet is at least 4 bytes so loop as long as the buffer contains 4 bytes
while( Bytes.size( ) >= 4 )
{
if( Bytes[0] == W3GS_HEADER_CONSTANT || Bytes[0] == GPS_HEADER_CONSTANT )
{
// bytes 2 and 3 contain the length of the packet
uint16_t Length = UTIL_ByteArrayToUInt16( Bytes, false, 2 );
if( Length >= 4 )
{
if( Bytes.size( ) >= Length )
{
if( Bytes[0] == W3GS_HEADER_CONSTANT && Bytes[1] == CGameProtocol :: W3GS_REQJOIN )
{
delete m_IncomingJoinPlayer;
m_IncomingJoinPlayer = m_Protocol->RECEIVE_W3GS_REQJOIN( BYTEARRAY( Bytes.begin( ), Bytes.begin( ) + Length ) );
if( m_IncomingJoinPlayer )
m_Game->EventPlayerJoined( this, m_IncomingJoinPlayer );
// this is the packet which interests us for now, the remaining is left for CGamePlayer
*RecvBuffer = RecvBuffer->substr( Length );
Bytes = BYTEARRAY( Bytes.begin( ) + Length, Bytes.end( ) );
break;
}
*RecvBuffer = RecvBuffer->substr( Length );
Bytes = BYTEARRAY( Bytes.begin( ) + Length, Bytes.end( ) );
}
else
break;
}
}
}
// don't call DoSend here because some other players may not have updated yet and may generate a packet for this player
// also m_Socket may have been set to NULL during ProcessPackets but we're banking on the fact that m_DeleteMe has been set to true as well so it'll short circuit before dereferencing
return m_DeleteMe || !m_Socket->GetConnected( ) || m_Socket->HasError( );
}
示例7: ExtractPackets
void CGamePlayer :: ExtractPackets( )
{
if( !m_Socket )
return;
// extract as many packets as possible from the socket's receive buffer and put them in the m_Packets queue
string *RecvBuffer = m_Socket->GetBytes( );
BYTEARRAY Bytes = UTIL_CreateByteArray( (unsigned char *)RecvBuffer->c_str( ), RecvBuffer->size( ) );
// a packet is at least 4 bytes so loop as long as the buffer contains 4 bytes
while( Bytes.size( ) >= 4 )
{
if( Bytes[0] == W3GS_HEADER_CONSTANT || Bytes[0] == GPS_HEADER_CONSTANT || Bytes[0] == GCBI_HEADER_CONSTANT )
{
// bytes 2 and 3 contain the length of the packet
uint16_t Length = UTIL_ByteArrayToUInt16( Bytes, false, 2 );
if( Length >= 4 )
{
if( Bytes.size( ) >= Length )
{
m_Packets.push( new CCommandPacket( Bytes[0], Bytes[1], BYTEARRAY( Bytes.begin( ), Bytes.begin( ) + Length ) ) );
if( Bytes[0] == W3GS_HEADER_CONSTANT )
++m_TotalPacketsReceived;
*RecvBuffer = RecvBuffer->substr( Length );
Bytes = BYTEARRAY( Bytes.begin( ) + Length, Bytes.end( ) );
}
else
return;
}
else
{
m_Error = true;
m_ErrorString = "received invalid packet from player (bad length)";
return;
}
}
else
{
m_Error = true;
m_ErrorString = "received invalid packet from player (bad header constant)";
return;
}
}
}
示例8: RECEIVE_SID_WARDEN
BYTEARRAY CBNETProtocol :: RECEIVE_SID_WARDEN( BYTEARRAY data )
{
// DEBUG_Print( "RECEIVED SID_WARDEN" );
// DEBUG_PRINT( data );
// 2 bytes -> Header
// 2 bytes -> Length
// n bytes -> Data
if( ValidateLength( data ) && data.size( ) >= 4 )
return BYTEARRAY( data.begin( ) + 4, data.end( ) );
return BYTEARRAY( );
}
示例9: RECEIVE_SID_PING
BYTEARRAY CBNETProtocol :: RECEIVE_SID_PING( BYTEARRAY data )
{
// DEBUG_Print( "RECEIVED SID_PING" );
// DEBUG_Print( data );
// 2 bytes -> Header
// 2 bytes -> Length
// 4 bytes -> Ping
if( ValidateLength( data ) && data.size( ) >= 8 )
return BYTEARRAY( data.begin( ) + 4, data.begin( ) + 8 );
return BYTEARRAY( );
}
示例10: RECEIVE_SID_CHATEVENT
CIncomingChatEvent *CBNETProtocol :: RECEIVE_SID_CHATEVENT( BYTEARRAY data )
{
// DEBUG_Print( "RECEIVED SID_CHATEVENT" );
// DEBUG_Print( data );
// 2 bytes -> Header
// 2 bytes -> Length
// 4 bytes -> EventID
// 4 bytes -> UserFlags
// 4 bytes -> Ping
// 12 bytes -> ???
// null terminated string -> User
// null terminated string -> Message
if( ValidateLength( data ) && data.size( ) >= 29 )
{
BYTEARRAY EventID = BYTEARRAY( data.begin( ) + 4, data.begin( ) + 8 );
BYTEARRAY UserFlags = BYTEARRAY( data.begin( ) + 8, data.begin( ) + 12 );
BYTEARRAY Ping = BYTEARRAY( data.begin( ) + 12, data.begin( ) + 16 );
BYTEARRAY User = UTIL_ExtractCString( data, 28 );
BYTEARRAY Message = UTIL_ExtractCString( data, User.size( ) + 29 );
switch( UTIL_ByteArrayToUInt32( EventID, false ) )
{
case CBNETProtocol :: EID_SHOWUSER:
case CBNETProtocol :: EID_JOIN:
case CBNETProtocol :: EID_LEAVE:
case CBNETProtocol :: EID_WHISPER:
case CBNETProtocol :: EID_TALK:
case CBNETProtocol :: EID_BROADCAST:
case CBNETProtocol :: EID_CHANNEL:
case CBNETProtocol :: EID_USERFLAGS:
case CBNETProtocol :: EID_WHISPERSENT:
case CBNETProtocol :: EID_CHANNELFULL:
case CBNETProtocol :: EID_CHANNELDOESNOTEXIST:
case CBNETProtocol :: EID_CHANNELRESTRICTED:
case CBNETProtocol :: EID_INFO:
case CBNETProtocol :: EID_ERROR:
case CBNETProtocol :: EID_EMOTE:
return new CIncomingChatEvent( (CBNETProtocol :: IncomingChatEvent)UTIL_ByteArrayToUInt32( EventID, false ),
UTIL_ByteArrayToUInt32( UserFlags, false ),
UTIL_ByteArrayToUInt32( Ping, false ),
string( User.begin( ), User.end( ) ),
string( Message.begin( ), Message.end( ) ) );
}
}
return NULL;
}
示例11: RECEIVE_W3GS_REQJOIN
CIncomingJoinPlayer *CGameProtocol :: RECEIVE_W3GS_REQJOIN( BYTEARRAY data )
{
// DEBUG_Print( "RECEIVED W3GS_REQJOIN" );
// DEBUG_Print( data );
// 2 bytes -> Header
// 2 bytes -> Length
// 4 bytes -> Host Counter (Game ID)
// 4 bytes -> Entry Key (used in LAN)
// 1 byte -> ???
// 2 bytes -> Listen Port
// 4 bytes -> Peer Key
// null terminated string -> Name
// 4 bytes -> ???
// 2 bytes -> InternalPort (???)
// 4 bytes -> InternalIP
if( ValidateLength( data ) && data.size( ) >= 20 )
{
uint32_t HostCounter = UTIL_ByteArrayToUInt32( data, false, 4 );
BYTEARRAY Name = UTIL_ExtractCString( data, 19 );
if( !Name.empty( ) && data.size( ) >= Name.size( ) + 30 )
{
BYTEARRAY InternalIP = BYTEARRAY( data.begin( ) + Name.size( ) + 26, data.begin( ) + Name.size( ) + 30 );
return new CIncomingJoinPlayer( HostCounter, string( Name.begin( ), Name.end( ) ), InternalIP );
}
}
return NULL;
}
示例12: RECEIVE_W3GS_OUTGOING_ACTION
CIncomingAction *CGameProtocol :: RECEIVE_W3GS_OUTGOING_ACTION( BYTEARRAY data, unsigned char PID )
{
// DEBUG_Print( "RECEIVED W3GS_OUTGOING_ACTION" );
// DEBUG_Print( data );
// 2 bytes -> Header
// 2 bytes -> Length
// 4 bytes -> CRC
// remainder of packet -> Action
if( PID != 255 && ValidateLength( data ) && data.size( ) >= 8 )
{
BYTEARRAY CRC = BYTEARRAY( data.begin( ) + 4, data.begin( ) + 8 );
BYTEARRAY Action = BYTEARRAY( data.begin( ) + 8, data.end( ) );
return new CIncomingAction( PID, CRC, Action );
}
return NULL;
}
示例13: RECEIVE_SID_GETADVLISTEX
CIncomingGameHost *CBNETProtocol :: RECEIVE_SID_GETADVLISTEX( BYTEARRAY data )
{
// DEBUG_Print( "RECEIVED SID_GETADVLISTEX" );
// DEBUG_Print( data );
// 2 bytes -> Header
// 2 bytes -> Length
// 4 bytes -> GamesFound
// if( GamesFound > 0 )
// 10 bytes -> ???
// 2 bytes -> Port
// 4 bytes -> IP
// null term string -> GameName
// 2 bytes -> ???
// 8 bytes -> HostCounter
if( ValidateLength( data ) && data.size( ) >= 8 )
{
BYTEARRAY GamesFound = BYTEARRAY( data.begin( ) + 4, data.begin( ) + 8 );
if( UTIL_ByteArrayToUInt32( GamesFound, false ) > 0 && data.size( ) >= 25 )
{
BYTEARRAY Port = BYTEARRAY( data.begin( ) + 18, data.begin( ) + 20 );
BYTEARRAY IP = BYTEARRAY( data.begin( ) + 20, data.begin( ) + 24 );
BYTEARRAY GameName = UTIL_ExtractCString( data, 24 );
if( data.size( ) >= GameName.size( ) + 35 )
{
BYTEARRAY HostCounter;
HostCounter.push_back( UTIL_ExtractHex( data, GameName.size( ) + 27, true ) );
HostCounter.push_back( UTIL_ExtractHex( data, GameName.size( ) + 29, true ) );
HostCounter.push_back( UTIL_ExtractHex( data, GameName.size( ) + 31, true ) );
HostCounter.push_back( UTIL_ExtractHex( data, GameName.size( ) + 33, true ) );
return new CIncomingGameHost( IP,
UTIL_ByteArrayToUInt16( Port, false ),
string( GameName.begin( ), GameName.end( ) ),
HostCounter );
}
}
}
return NULL;
}
示例14: RECEIVE_SID_CLANINVITATIONRESPONSE
string CBNETProtocol :: RECEIVE_SID_CLANINVITATIONRESPONSE( BYTEARRAY data )
{
if( ValidateLength( data ) && data.size( ) >= 12 )
{
//skip four bytes cookie
m_ClanLastInviteTag = BYTEARRAY( data.begin( ) + 8, data.begin( ) + 12 );
BYTEARRAY ClanName = UTIL_ExtractCString( data, 12 );
m_ClanLastInviteName = UTIL_ExtractCString( data, 12 + ClanName.size( ) );
return string( m_ClanLastInviteName.begin( ), m_ClanLastInviteName.end( ) );
}
return NULL;
}
示例15: DoSend
void CTCPSocket :: DoSend( fd_set *send_fd )
{
if( m_Socket == INVALID_SOCKET || m_HasError || !m_Connected || m_SendBuffer.empty( ) )
return;
if( FD_ISSET( m_Socket, send_fd ) )
{
// socket is ready, send it
int s = send( m_Socket, m_SendBuffer.c_str( ), (int)m_SendBuffer.size( ), MSG_NOSIGNAL );
if( s == SOCKET_ERROR && GetLastError( ) != EWOULDBLOCK )
{
// send error
m_HasError = true;
m_Error = GetLastError( );
if (m_isConsolePrint)
CONSOLE_Print( "[TCPSOCKET] error (send) - " + GetErrorString( ) );
return;
}
else if( s > 0 )
{
// success! only some of the data may have been sent, remove it from the buffer
if( !m_LogFile.empty( ) )
{
ofstream Log;
Log.open( m_LogFile.c_str( ), ios :: app );
if( !Log.fail( ) )
{
Log << "SEND >>> " << UTIL_ByteArrayToHexString( BYTEARRAY( m_SendBuffer.begin( ), m_SendBuffer.begin( ) + s ) ) << endl;
Log.close( );
}
}
m_SendBuffer = m_SendBuffer.substr( s );
m_LastSend = GetTime( );
}
}
}