本文整理汇总了C++中BYTEARRAY::size方法的典型用法代码示例。如果您正苦于以下问题:C++ BYTEARRAY::size方法的具体用法?C++ BYTEARRAY::size怎么用?C++ BYTEARRAY::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BYTEARRAY
的用法示例。
在下文中一共展示了BYTEARRAY::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
uint32_t CGameProtocol :: RECEIVE_W3GS_PONG_TO_HOST( BYTEARRAY data )
{
// DEBUG_Print( "RECEIVED W3GS_PONG_TO_HOST" );
// DEBUG_Print( data );
// 2 bytes -> Header
// 2 bytes -> Length
// 4 bytes -> Pong
// the pong value is just a copy of whatever was sent in SEND_W3GS_PING_FROM_HOST which was GetTicks( ) at the time of sending
// so as long as we trust that the client isn't trying to fake us out and mess with the pong value we can find the round trip time by simple subtraction
// (the subtraction is done elsewhere because the very first pong value seems to be 1 and we want to discard that one)
if( ValidateLength( data ) && data.size( ) >= 8 )
return UTIL_ByteArrayToUInt32( data, false, 4 );
return 1;
}
示例2:
BYTEARRAY CBNETProtocol :: SEND_SID_AUTH_ACCOUNTLOGONPROOF( BYTEARRAY clientPasswordProof )
{
BYTEARRAY packet;
if( clientPasswordProof.size( ) == 20 )
{
packet.push_back( BNET_HEADER_CONSTANT ); // BNET header constant
packet.push_back( SID_AUTH_ACCOUNTLOGONPROOF ); // SID_AUTH_ACCOUNTLOGONPROOF
packet.push_back( 0 ); // packet length will be assigned later
packet.push_back( 0 ); // packet length will be assigned later
UTIL_AppendByteArrayFast( packet, clientPasswordProof ); // Client Password Proof
AssignLength( packet );
}
else
cout << "[BNETPROTO] invalid parameters passed to SEND_SID_AUTH_ACCOUNTLOGON\n";
return packet;
}
示例3: BYTEARRAY
bool CBNETProtocol :: RECEIVE_SID_AUTH_ACCOUNTLOGONPROOF( BYTEARRAY data )
{
// DEBUG_Print( "RECEIVED SID_AUTH_ACCOUNTLOGONPROOF" );
// DEBUG_Print( data );
// 2 bytes -> Header
// 2 bytes -> Length
// 4 bytes -> Status
if( ValidateLength( data ) && data.size( ) >= 8 )
{
uint32_t Status = UTIL_ByteArrayToUInt32( BYTEARRAY( data.begin( ) + 4, data.begin( ) + 8 ), false );
if( Status == 0 || Status == 0xE )
return true;
}
return false;
}
示例4: string
string CPotentialPlayer :: GetExternalIPString( )
{
BYTEARRAY IP;
string EIP;
if( m_Socket )
{
bool local=m_LAN;
if (!m_LANSet)
{
IP= m_Socket->GetIP( );
if (IP.size()>=2)
{
if (IP[0]==10 && IP[1]==0)
local=true;
if (IP[0]==10 && IP[1]==1)
local=true;
if (IP[0]==192 && IP[1]==168)
local=true;
if (IP[0]==169 && IP[1]==254)
local=true;
if (IP[0]==8 && IP[1]==0)
local=true;
if (IP[0]==5)
local=true;
}
if (UTIL_IsLocalIP(IP, m_Game->m_GHost->m_LocalAddresses))
local = true;
m_LANSet = true;
m_LAN = local;
}
EIP=m_Socket->GetIPString( );
if (local && !m_Game->m_Config->m_ExternalIP.empty())
{
EIP = m_Game->m_Config->m_ExternalIP;
}
return EIP;
}
return string( );
}
示例5: CFwdData
BYTEARRAY CBNETProtocol :: SEND_SID_PING( BYTEARRAY pingValue )
{
BYTEARRAY packet;
if( pingValue.size( ) == 4 )
{
packet.push_back( BNET_HEADER_CONSTANT ); // BNET header constant
packet.push_back( SID_PING ); // SID_PING
packet.push_back( 0 ); // packet length will be assigned later
packet.push_back( 0 ); // packet length will be assigned later
UTIL_AppendByteArrayFast( packet, pingValue ); // Ping Value
AssignLength( packet );
}
else
{
CONSOLE_Print( "[BNETPROTO] invalid parameters passed to SEND_SID_PING" );
forward(new CFwdData(FWD_GENERAL, "Invalid parameters passed to SEND_SID_PING", 6, 0));
}
// DEBUG_Print( "SENT SID_PING" );
// DEBUG_Print( packet );
return packet;
}
示例6: string
void CReplay :: AddTimeSlot2( queue<CIncomingAction *> actions )
{
BYTEARRAY Block;
Block.push_back( REPLAY_TIMESLOT2 );
UTIL_AppendByteArray( Block, (uint16_t)0, false );
UTIL_AppendByteArray( Block, (uint16_t)0, false );
while( !actions.empty( ) )
{
CIncomingAction *Action = actions.front( );
actions.pop( );
Block.push_back( Action->GetPID( ) );
UTIL_AppendByteArray( Block, (uint16_t)Action->GetAction( )->size( ), false );
UTIL_AppendByteArrayFast( Block, *Action->GetAction( ) );
}
// assign length
BYTEARRAY LengthBytes = UTIL_CreateByteArray( (uint16_t)( Block.size( ) - 3 ), false );
Block[1] = LengthBytes[0];
Block[2] = LengthBytes[1];
m_CompiledBlocks += string( Block.begin( ), Block.end( ) );
}
示例7:
BYTEARRAY CGameProtocol :: SEND_W3GS_CHAT_FROM_HOST( unsigned char fromPID, BYTEARRAY toPIDs, unsigned char flag, BYTEARRAY flagExtra, string message )
{
BYTEARRAY packet;
if( !toPIDs.empty( ) && !message.empty( ) && message.size( ) < 255 )
{
packet.push_back( W3GS_HEADER_CONSTANT ); // W3GS header constant
packet.push_back( W3GS_CHAT_FROM_HOST ); // W3GS_CHAT_FROM_HOST
packet.push_back( 0 ); // packet length will be assigned later
packet.push_back( 0 ); // packet length will be assigned later
packet.push_back( toPIDs.size( ) ); // number of receivers
UTIL_AppendByteArrayFast( packet, toPIDs ); // receivers
packet.push_back( fromPID ); // sender
packet.push_back( flag ); // flag
UTIL_AppendByteArrayFast( packet, flagExtra ); // extra flag
UTIL_AppendByteArrayFast( packet, message ); // message
AssignLength( packet );
}
else
cout << "[GAMEPROTO] invalid parameters passed to SEND_W3GS_CHAT_FROM_HOST\n";
return packet;
}
示例8: if
void CGamePlayer :: ProcessPackets( )
{
if( !m_Socket )
return;
CIncomingAction *Action = NULL;
CIncomingChatPlayer *ChatPlayer = NULL;
CIncomingMapSize *MapSize = NULL;
uint32_t CheckSum = 0;
uint32_t Pong = 0;
// process all the received packets in the m_Packets queue
while( !m_Packets.empty( ) )
{
CCommandPacket *Packet = m_Packets.front( );
m_Packets.pop( );
if( Packet->GetPacketType( ) == W3GS_HEADER_CONSTANT )
{
switch( Packet->GetID( ) )
{
case CGameProtocol :: W3GS_LEAVEGAME:
m_Game->EventPlayerLeft( this, m_Protocol->RECEIVE_W3GS_LEAVEGAME( Packet->GetData( ) ) );
break;
case CGameProtocol :: W3GS_GAMELOADED_SELF:
if( m_Protocol->RECEIVE_W3GS_GAMELOADED_SELF( Packet->GetData( ) ) )
{
if( !m_FinishedLoading && m_Game->GetGameLoading( ) )
{
m_FinishedLoading = true;
m_FinishedLoadingTicks = GetTicks( );
m_Game->EventPlayerLoaded( this );
}
else
{
// we received two W3GS_GAMELOADED_SELF packets from this player!
}
}
break;
case CGameProtocol :: W3GS_OUTGOING_ACTION:
Action = m_Protocol->RECEIVE_W3GS_OUTGOING_ACTION( Packet->GetData( ), m_PID );
if( Action )
m_Game->EventPlayerAction( this, Action );
// don't delete Action here because the game is going to store it in a queue and delete it later
break;
case CGameProtocol :: W3GS_OUTGOING_KEEPALIVE:
CheckSum = m_Protocol->RECEIVE_W3GS_OUTGOING_KEEPALIVE( Packet->GetData( ) );
m_CheckSums.push( CheckSum );
m_SyncCounter++;
m_Game->EventPlayerKeepAlive( this, CheckSum );
break;
case CGameProtocol :: W3GS_CHAT_TO_HOST:
ChatPlayer = m_Protocol->RECEIVE_W3GS_CHAT_TO_HOST( Packet->GetData( ) );
if( ChatPlayer )
{
// determine if we should auto-mute this player
if( ChatPlayer->GetType( ) == CIncomingChatPlayer :: CTH_MESSAGE || ChatPlayer->GetType( ) == CIncomingChatPlayer :: CTH_MESSAGEEXTRA )
{
m_MuteMessages.push_back( GetTicks( ) );
if( m_MuteMessages.size( ) > 7 )
m_MuteMessages.erase( m_MuteMessages.begin( ) );
uint32_t RecentCount = 0;
for( unsigned int i = 0; i < m_MuteMessages.size( ); ++i )
{
if( GetTicks( ) - m_MuteMessages[i] < 7000 )
RecentCount++;
}
if( !GetMuted( ) && RecentCount >= 7 )
{
SetMuted( true );
m_MutedAuto = true;
m_Game->SendAllChat( "[" + m_Name + "] has been automatically muted for spamming. (You will be unmuted momentarily, but please do not spam again!)" );
m_MuteMessages.clear( );
}
//now check for flamers
if( m_Game->m_GHost->FlameCheck( ChatPlayer->GetMessage( ) ) )
{
m_FlameMessages.push_back( GetTicks( ) );
if( m_FlameMessages.size( ) > 10 )
m_FlameMessages.erase( m_FlameMessages.begin( ) );
RecentCount = 0;
for( unsigned int i = 0; i < m_FlameMessages.size( ); ++i )
//.........这里部分代码省略.........
示例9: if
//.........这里部分代码省略.........
ChatPlayer = NULL;
break;
case CGameProtocol :: W3GS_DROPREQ:
// todotodo: no idea what's in this packet
if( !m_DropVote )
{
m_DropVote = true;
m_Game->EventPlayerDropRequest( this );
}
break;
case CGameProtocol :: W3GS_MAPSIZE:
MapSize = m_Protocol->RECEIVE_W3GS_MAPSIZE( Packet->GetData( ), m_Game->m_GHost->m_Map->GetMapSize( ) );
if( MapSize )
m_Game->EventPlayerMapSize( this, MapSize );
delete MapSize;
MapSize = NULL;
break;
case CGameProtocol :: W3GS_PONG_TO_HOST:
Pong = m_Protocol->RECEIVE_W3GS_PONG_TO_HOST( Packet->GetData( ) );
// we discard pong values of 1
// the client sends one of these when connecting plus we return 1 on error to kill two birds with one stone
if( Pong != 1 )
{
// we also discard pong values when we're downloading because they're almost certainly inaccurate
// this statement also gives the player a 5 second grace period after downloading the map to allow queued (i.e. delayed) ping packets to be ignored
if( !m_DownloadStarted || ( m_DownloadFinished && GetTime( ) - m_FinishedDownloadingTime >= 5 ) )
{
// we also discard pong values when anyone else is downloading if we're configured to
if( m_Game->m_GHost->m_PingDuringDownloads || !m_Game->IsDownloading( ) )
{
m_Pings.push_back( GetTicks( ) - Pong );
if( m_Pings.size( ) > 20 )
m_Pings.erase( m_Pings.begin( ) );
}
}
}
m_Game->EventPlayerPongToHost( this, Pong );
break;
}
}
else if( Packet->GetPacketType( ) == GPS_HEADER_CONSTANT )
{
BYTEARRAY Data = Packet->GetData( );
if( Packet->GetID( ) == CGPSProtocol :: GPS_INIT )
{
if( m_Game->m_GHost->m_Reconnect )
{
m_GProxy = true;
m_Socket->PutBytes( m_Game->m_GHost->m_GPSProtocol->SEND_GPSS_INIT( m_Game->m_GHost->m_ReconnectPort, m_PID, m_GProxyReconnectKey, m_Game->GetGProxyEmptyActions( ) ) );
CONSOLE_Print( "[GAME: " + m_Game->GetGameName( ) + "] player [" + m_Name + "] is using GProxy++" );
}
else
{
// todotodo: send notice that we're not permitting reconnects
// note: GProxy++ should never send a GPS_INIT message if bot_reconnect = 0 because we don't advertise the game with invalid map dimensions
// but it would be nice to cover this case anyway
}
}
else if( Packet->GetID( ) == CGPSProtocol :: GPS_RECONNECT )
{
// this is handled in ghost.cpp
}
else if( Packet->GetID( ) == CGPSProtocol :: GPS_ACK && Data.size( ) == 8 )
{
uint32_t LastPacket = UTIL_ByteArrayToUInt32( Data, false, 4 );
uint32_t PacketsAlreadyUnqueued = m_TotalPacketsSent - m_GProxyBuffer.size( );
if( LastPacket > PacketsAlreadyUnqueued )
{
uint32_t PacketsToUnqueue = LastPacket - PacketsAlreadyUnqueued;
if( PacketsToUnqueue > m_GProxyBuffer.size( ) )
PacketsToUnqueue = m_GProxyBuffer.size( );
while( PacketsToUnqueue > 0 )
{
m_GProxyBuffer.pop( );
--PacketsToUnqueue;
}
}
}
}
delete Packet;
}
}
示例10: Update
//.........这里部分代码省略.........
}
// update battle.net connections
for (auto & bnet : m_BNETs)
{
if (bnet->Update(&fd, &send_fd))
Exit = true;
}
// update irc
if (m_IRC && m_IRC->Update(&fd, &send_fd))
Exit = true;
// update GProxy++ reliable reconnect sockets
CTCPSocket *NewSocket = m_ReconnectSocket->Accept(&fd);
if (NewSocket)
m_ReconnectSockets.push_back(NewSocket);
for (auto i = begin(m_ReconnectSockets); i != end(m_ReconnectSockets);)
{
if ((*i)->HasError() || !(*i)->GetConnected() || GetTime() - (*i)->GetLastRecv() >= 10)
{
delete *i;
i = m_ReconnectSockets.erase(i);
continue;
}
(*i)->DoRecv(&fd);
string *RecvBuffer = (*i)->GetBytes();
const BYTEARRAY Bytes = CreateByteArray((uint8_t *) RecvBuffer->c_str(), RecvBuffer->size());
// a packet is at least 4 bytes
if (Bytes.size() >= 4)
{
if (Bytes[0] == GPS_HEADER_CONSTANT)
{
// bytes 2 and 3 contain the length of the packet
const uint16_t Length = (uint16_t)(Bytes[3] << 8 | Bytes[2]);
if (Bytes.size() >= Length)
{
if (Bytes[1] == CGPSProtocol::GPS_RECONNECT && Length == 13)
{
const uint32_t ReconnectKey = ByteArrayToUInt32(Bytes, false, 5);
const uint32_t LastPacket = ByteArrayToUInt32(Bytes, false, 9);
// look for a matching player in a running game
CGamePlayer *Match = nullptr;
for (auto & game : m_Games)
{
if (game->GetGameLoaded())
{
CGamePlayer *Player = game->GetPlayerFromPID(Bytes[4]);
if (Player && Player->GetGProxy() && Player->GetGProxyReconnectKey() == ReconnectKey)
{
Match = Player;
break;
示例11: BuildReplay
void CReplay :: BuildReplay( string gameName, string statString )
{
CONSOLE_Print( "[REPLAY] building replay" );
uint32_t LanguageID = 0x0012F8B0;
BYTEARRAY Replay;
Replay.push_back( 16 ); // Unknown (4.0)
Replay.push_back( 1 ); // Unknown (4.0)
Replay.push_back( 0 ); // Unknown (4.0)
Replay.push_back( 0 ); // Unknown (4.0)
Replay.push_back( 0 ); // Host RecordID (4.1)
Replay.push_back( m_HostPID ); // Host PlayerID (4.1)
UTIL_AppendByteArray( Replay, m_HostName ); // Host PlayerName (4.1)
Replay.push_back( 1 ); // Host AdditionalSize (4.1)
Replay.push_back( 0 ); // Host AdditionalData (4.1)
UTIL_AppendByteArray( Replay, gameName ); // GameName (4.2)
Replay.push_back( 0 ); // Null (4.0)
UTIL_AppendByteArray( Replay, statString ); // StatString (4.3)
UTIL_AppendByteArray( Replay, (uint32_t)m_Slots.size( ), false ); // PlayerCount (4.6)
Replay.push_back( m_MapGameType ); // GameType (4.7)
Replay.push_back( 32 ); // GameType (4.7)
Replay.push_back( 73 ); // GameType (4.7)
Replay.push_back( 0 ); // GameType (4.7)
UTIL_AppendByteArray( Replay, LanguageID, false ); // LanguageID (4.8)
// PlayerList (4.9)
for( vector<ReplayPlayer> :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ )
{
if( (*i).first != m_HostPID )
{
Replay.push_back( 22 ); // Player RecordID (4.1)
Replay.push_back( (*i).first ); // Player PlayerID (4.1)
UTIL_AppendByteArray( Replay, (*i).second ); // Player PlayerName (4.1)
Replay.push_back( 1 ); // Player AdditionalSize (4.1)
Replay.push_back( 0 ); // Player AdditionalData (4.1)
UTIL_AppendByteArray( Replay, (uint32_t)0, false ); // Unknown
}
}
// GameStartRecord (4.10)
Replay.push_back( 25 ); // RecordID (4.10)
UTIL_AppendByteArray( Replay, (uint16_t)( 7 + m_Slots.size( ) * 9 ), false ); // Size (4.10)
Replay.push_back( m_Slots.size( ) ); // NumSlots (4.10)
for( unsigned char i = 0; i < m_Slots.size( ); i++ )
UTIL_AppendByteArray( Replay, m_Slots[i].GetByteArray( ) );
UTIL_AppendByteArray( Replay, m_RandomSeed, false ); // RandomSeed (4.10)
Replay.push_back( m_SelectMode ); // SelectMode (4.10)
Replay.push_back( m_StartSpotCount ); // StartSpotCount (4.10)
// ReplayData (5.0)
Replay.push_back( REPLAY_FIRSTSTARTBLOCK );
UTIL_AppendByteArray( Replay, (uint32_t)1, false );
Replay.push_back( REPLAY_SECONDSTARTBLOCK );
UTIL_AppendByteArray( Replay, (uint32_t)1, false );
// leavers during loading need to be stored between the second and third start blocks
while( !m_LoadingBlocks.empty( ) )
{
UTIL_AppendByteArray( Replay, m_LoadingBlocks.front( ) );
m_LoadingBlocks.pop( );
}
Replay.push_back( REPLAY_THIRDSTARTBLOCK );
UTIL_AppendByteArray( Replay, (uint32_t)1, false );
// initialize replay length to zero
// we'll accumulate the replay length as we iterate through the timeslots
// this is necessary because we might be discarding some timeslots due to not enough checksums and the replay length needs to be accurate
m_ReplayLength = 0;
uint32_t TimeSlotsDiscarded = 0;
while( !m_Blocks.empty( ) )
{
BYTEARRAY Block = m_Blocks.front( );
m_Blocks.pop( );
if( Block.size( ) >= 5 && Block[0] == REPLAY_TIMESLOT )
{
if( m_CheckSums.empty( ) )
{
TimeSlotsDiscarded++;
continue;
}
// append timeslot
UTIL_AppendByteArray( Replay, Block );
// append checksum
BYTEARRAY CheckSum;
CheckSum.push_back( REPLAY_CHECKSUM );
//.........这里部分代码省略.........
示例12: ISS
void CMap :: Load( CConfig *CFG, string nCFGFile )
{
m_Valid = true;
m_CFGFile = nCFGFile;
m_GHost->UDPChatSend("|cfg "+nCFGFile);
// load the map data
m_MapLocalPath = CFG->GetString( "map_localpath", string( ) );
m_MapData.clear( );
if( !m_MapLocalPath.empty( ) )
m_MapData = UTIL_FileRead( m_GHost->m_MapPath + m_MapLocalPath );
// load the map MPQ
string MapMPQFileName = m_GHost->m_MapPath + m_MapLocalPath;
HANDLE MapMPQ;
bool MapMPQReady = false;
if( SFileOpenArchive( MapMPQFileName.c_str( ), 0, MPQ_OPEN_FORCE_MPQ_V1, &MapMPQ ) )
{
CONSOLE_Print( "[MAP] loading MPQ file [" + MapMPQFileName + "]" );
MapMPQReady = true;
}
else
CONSOLE_Print( "[MAP] warning - unable to load MPQ file [" + MapMPQFileName + "]" );
// try to calculate map_size, map_info, map_crc, map_sha1
BYTEARRAY MapSize;
BYTEARRAY MapInfo;
BYTEARRAY MapCRC;
BYTEARRAY MapSHA1;
if( !m_MapData.empty( ) )
{
m_GHost->m_SHA->Reset( );
// calculate map_size
MapSize = UTIL_CreateByteArray( (uint32_t)m_MapData.size( ), false );
CONSOLE_Print( "[MAP] calculated map_size = " + UTIL_ToString( MapSize[0] ) + " " + UTIL_ToString( MapSize[1] ) + " " + UTIL_ToString( MapSize[2] ) + " " + UTIL_ToString( MapSize[3] ) );
// calculate map_info (this is actually the CRC)
MapInfo = UTIL_CreateByteArray( (uint32_t)m_GHost->m_CRC->FullCRC( (unsigned char *)m_MapData.c_str( ), m_MapData.size( ) ), false );
CONSOLE_Print( "[MAP] calculated map_info = " + UTIL_ToString( MapInfo[0] ) + " " + UTIL_ToString( MapInfo[1] ) + " " + UTIL_ToString( MapInfo[2] ) + " " + UTIL_ToString( MapInfo[3] ) );
// calculate map_crc (this is not the CRC) and map_sha1
// a big thank you to Strilanc for figuring the map_crc algorithm out
string CommonJ = UTIL_FileRead( m_GHost->m_MapCFGPath + "common.j" );
if( CommonJ.empty( ) )
CONSOLE_Print( "[MAP] unable to calculate map_crc/sha1 - unable to read file [" + m_GHost->m_MapCFGPath + "common.j]" );
else
{
string BlizzardJ = UTIL_FileRead( m_GHost->m_MapCFGPath + "blizzard.j" );
if( BlizzardJ.empty( ) )
CONSOLE_Print( "[MAP] unable to calculate map_crc/sha1 - unable to read file [" + m_GHost->m_MapCFGPath + "blizzard.j]" );
else
{
uint32_t Val = 0;
// update: it's possible for maps to include their own copies of common.j and/or blizzard.j
// this code now overrides the default copies if required
bool OverrodeCommonJ = false;
bool OverrodeBlizzardJ = false;
if( MapMPQReady )
{
HANDLE SubFile;
// override common.j
if( SFileOpenFileEx( MapMPQ, "Scripts\\common.j", 0, &SubFile ) )
{
uint32_t FileLength = SFileGetFileSize( SubFile, NULL );
if( FileLength > 0 && FileLength != 0xFFFFFFFF )
{
char *SubFileData = new char[FileLength];
DWORD BytesRead = 0;
if( SFileReadFile( SubFile, SubFileData, FileLength, &BytesRead ) )
{
CONSOLE_Print( "[MAP] overriding default common.j with map copy while calculating map_crc/sha1" );
OverrodeCommonJ = true;
Val = Val ^ XORRotateLeft( (unsigned char *)SubFileData, BytesRead );
m_GHost->m_SHA->Update( (unsigned char *)SubFileData, BytesRead );
}
delete [] SubFileData;
}
SFileCloseFile( SubFile );
}
//.........这里部分代码省略.........
示例13: CIncomingGameHost
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 )>1)
{
string sIP ="";
string GN ="";
uint32_t PR;
uint32_t GF = UTIL_ByteArrayToUInt32( GamesFound, false );
uint32_t Idx = 18;
uint32_t Idx2 = 0;
for (uint32_t i=0;i<GF;i++)
{
BYTEARRAY Port = BYTEARRAY( data.begin( ) + Idx, data.begin( ) + 2+Idx );
BYTEARRAY IP = BYTEARRAY( data.begin( ) + 2+Idx, data.begin( ) + 6+Idx );
BYTEARRAY GameName = UTIL_ExtractCString( data, 6+Idx );
Idx2 = GameName.size( );
Idx = Idx + Idx2+ 11;
GN = string( GameName.begin( ), GameName.end( ) );
PR = UTIL_ByteArrayToUInt16( Port, false );
CONSOLE_Print("[GHOST] Game "+UTIL_ToString(i)+ " "+ GN + " "+sIP+" "+UTIL_ToString(PR));
}
}
else
*/
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: UTIL_ToString
string CPotentialPlayer :: GetExternalIPString( )
{
BYTEARRAY IP;
string EIP;
if( m_Socket )
{
if( m_IncomingGarenaUser != NULL )
{
BYTEARRAY GarenaIP = GetGarenaIP( );
return UTIL_ToString(GarenaIP[0]) + "." + UTIL_ToString(GarenaIP[1]) + "." + UTIL_ToString(GarenaIP[2]) + "." + UTIL_ToString(GarenaIP[3]);
} else {
bool local=m_LAN;
if (!m_LANSet)
{
IP= m_Socket->GetIP( );
if (IP.size()>=2)
{
if (IP[0]==10)
local=true;
else if (IP[0]==192 && IP[1]==168)
local=true;
else if (IP[0]==169 && IP[1]==254)
local=true;
else if (IP[0]==172 && IP[1]==16)
local=true;
else if (IP[0]==172 && IP[1]==17)
local=true;
else if (IP[0]==172 && IP[1]==18)
local=true;
else if (IP[0]==172 && IP[1]==19)
local=true;
else if (IP[0]==172 && IP[1]==20)
local=true;
else if (IP[0]==172 && IP[1]==21)
local=true;
else if (IP[0]==172 && IP[1]==22)
local=true;
else if (IP[0]==172 && IP[1]==23)
local=true;
else if (IP[0]==172 && IP[1]==24)
local=true;
else if (IP[0]==172 && IP[1]==25)
local=true;
else if (IP[0]==172 && IP[1]==26)
local=true;
else if (IP[0]==172 && IP[1]==27)
local=true;
else if (IP[0]==172 && IP[1]==28)
local=true;
else if (IP[0]==172 && IP[1]==29)
local=true;
else if (IP[0]==172 && IP[1]==30)
local=true;
else if (IP[0]==172 && IP[1]==31)
local=true;
}
if (UTIL_IsLocalIP(IP, m_Game->m_GHost->m_LocalAddresses))
local = true;
m_LANSet = true;
m_LAN = local;
}
EIP=m_Socket->GetIPString( );
if (local && m_Game->m_GHost->m_ExternalIP!="")
{
EIP=m_Game->m_GHost->m_ExternalIP;
}
if( !EIP.empty( ) && EIP != "0.0.0.0" )
return EIP;
else
return m_CachedIP;
}
}
return m_CachedIP;
}
示例15: if
void CGamePlayer :: ProcessPackets( )
{
if( !m_Socket )
return;
CIncomingAction *Action = NULL;
CIncomingChatPlayer *ChatPlayer = NULL;
CIncomingMapSize *MapSize = NULL;
bool HasMap = false;
uint32_t CheckSum = 0;
uint32_t Pong = 0;
// process all the received packets in the m_Packets queue
while( !m_Packets.empty( ) )
{
CCommandPacket *Packet = m_Packets.front( );
m_Packets.pop( );
if( Packet->GetPacketType( ) == W3GS_HEADER_CONSTANT )
{
switch( Packet->GetID( ) )
{
case CGameProtocol :: W3GS_LEAVEGAME:
m_Game->EventPlayerLeft( this, m_Protocol->RECEIVE_W3GS_LEAVEGAME( Packet->GetData( ) ) );
break;
case CGameProtocol :: W3GS_GAMELOADED_SELF:
if( m_Protocol->RECEIVE_W3GS_GAMELOADED_SELF( Packet->GetData( ) ) )
{
if( !m_FinishedLoading && m_Game->GetGameLoading( ) )
{
m_FinishedLoading = true;
m_FinishedLoadingTicks = GetTicks( );
m_Game->EventPlayerLoaded( this );
}
else
{
// we received two W3GS_GAMELOADED_SELF packets from this player!
}
}
break;
case CGameProtocol :: W3GS_OUTGOING_ACTION:
Action = m_Protocol->RECEIVE_W3GS_OUTGOING_ACTION( Packet->GetData( ), m_PID );
if( Action )
{
// don't delete Action here because the game is going to store it in a queue and delete it later
m_Game->EventPlayerAction( this, Action );
}
break;
case CGameProtocol :: W3GS_OUTGOING_KEEPALIVE:
CheckSum = m_Protocol->RECEIVE_W3GS_OUTGOING_KEEPALIVE( Packet->GetData( ) );
m_CheckSums.push( CheckSum );
++m_SyncCounter;
m_Game->EventPlayerKeepAlive( this, CheckSum );
break;
case CGameProtocol :: W3GS_CHAT_TO_HOST:
ChatPlayer = m_Protocol->RECEIVE_W3GS_CHAT_TO_HOST( Packet->GetData( ) );
if( ChatPlayer )
{
// determine if we should auto-mute this player
if( ChatPlayer->GetType( ) == CIncomingChatPlayer :: CTH_MESSAGE || ChatPlayer->GetType( ) == CIncomingChatPlayer :: CTH_MESSAGEEXTRA )
{
if( m_Level <= 1 &&! GetMuted( ) )
{
m_MuteMessages.push_back( GetTicks( ) );
if( m_MuteMessages.size( ) > 7 )
m_MuteMessages.erase( m_MuteMessages.begin( ) );
uint32_t RecentCount = 0;
for( unsigned int i = 0; i < m_MuteMessages.size( ); ++i )
{
if( GetTicks( ) - m_MuteMessages[i] < 5000 )
{
RecentCount++;
}
}
if( m_Game->m_OHBot->m_AutoMuteSpammer && RecentCount >= 7 )
{
m_Count++;
if( m_Count == 1 )
{
SetMuted( true );
m_MutedAuto = true;
m_Game->SendChat( m_PID, "["+m_Game->m_OHBot->m_BotManagerName+"] "+m_Game->m_OHBot->m_Language->SpamWarning( ) );
m_MuteMessages.clear( );
m_Game->SendAllChat( "["+m_Game->m_OHBot->m_BotManagerName+"] " + m_Game->m_OHBot->m_Language->UserWasMutedForReason( m_Name, "spamming" ) );
}
if( m_Count == 2 )
{
m_Game->SendAllChat( m_Game->m_OHBot->m_Language->UserIgnoerNotify( m_Name ) );
//.........这里部分代码省略.........