bool FileListTransfer::DecodeSetHeader(Packet *packet) { unsigned i; unsigned int frequencyTable[ 256 ]; bool anythingToWrite; unsigned short setID; RakNet::BitStream inBitStream(packet->data, packet->length, false); inBitStream.IgnoreBits(8); inBitStream.Read(setID); FileListReceiver *fileListReceiver; if (fileListReceivers.Has(setID)==false) { #ifdef _DEBUG assert(0); #endif return false; } fileListReceiver=fileListReceivers.Get(setID); if (fileListReceiver->allowedSender!=packet->playerId) { #ifdef _DEBUG assert(0); #endif return false; } #ifdef _DEBUG assert(fileListReceiver->gotSetHeader==false); #endif inBitStream.Read(anythingToWrite); if (anythingToWrite) { inBitStream.Read(fileListReceiver->isCompressed); if (fileListReceiver->isCompressed) { for (i=0; i < 256; i++) inBitStream.ReadCompressed(frequencyTable[i]); fileListReceiver->tree.GenerateFromFrequencyTable(frequencyTable); inBitStream.ReadCompressed(fileListReceiver->setCount); inBitStream.ReadCompressed(fileListReceiver->setTotalFinalLength); if (inBitStream.ReadCompressed(fileListReceiver->setTotalCompressedTransmissionLength)) { fileListReceiver->gotSetHeader=true; return true; } } else { inBitStream.ReadCompressed(fileListReceiver->setCount); inBitStream.ReadCompressed(fileListReceiver->setTotalFinalLength); fileListReceiver->setTotalCompressedTransmissionLength=fileListReceiver->setTotalFinalLength; } } else { fileListReceiver->downloadHandler->OnFile(0, 0, 0, 0, 0, setID, 0, 0, 0, 0); return true; } return false; }
Packet* RakClient::Receive( void ) { Packet * packet = RakPeer::Receive(); // Intercept specific client / server feature packets if ( packet ) { RakNet::BitStream bitStream( ( char* ) packet->data, packet->length, false ); int i; if ( packet->data[ 0 ] == ID_CONNECTION_REQUEST_ACCEPTED ) { // ConnectionAcceptStruct cas; // cas.Deserialize(bitStream); // unsigned short remotePort; // PlayerID externalID; PlayerIndex playerIndex; RakNet::BitStream inBitStream((char*)packet->data, packet->length, false); inBitStream.IgnoreBits(8); // ID_CONNECTION_REQUEST_ACCEPTED inBitStream.IgnoreBits(8 * sizeof(unsigned short)); //inBitStream.Read(remotePort); inBitStream.IgnoreBits(8 * sizeof(unsigned int)); //inBitStream.Read(externalID.binaryAddress); inBitStream.IgnoreBits(8 * sizeof(unsigned short)); //inBitStream.Read(externalID.port); inBitStream.Read(playerIndex); localPlayerIndex = playerIndex; packet->playerIndex = playerIndex; } else if ( packet->data[ 0 ] == ID_REMOTE_NEW_INCOMING_CONNECTION || packet->data[ 0 ] == ID_REMOTE_EXISTING_CONNECTION || packet->data[ 0 ] == ID_REMOTE_DISCONNECTION_NOTIFICATION || packet->data[ 0 ] == ID_REMOTE_CONNECTION_LOST ) { bitStream.IgnoreBits( 8 ); // Ignore identifier bitStream.Read( packet->playerId.binaryAddress ); bitStream.Read( packet->playerId.port ); if ( bitStream.Read( ( unsigned short& ) packet->playerIndex ) == false ) { DeallocatePacket( packet ); return 0; } if ( packet->data[ 0 ] == ID_REMOTE_DISCONNECTION_NOTIFICATION || packet->data[ 0 ] == ID_REMOTE_CONNECTION_LOST ) { i = GetOtherClientIndexByPlayerID( packet->playerId ); if ( i >= 0 ) otherClients[ i ].isActive = false; } } else if ( packet->data[ 0 ] == ID_REMOTE_STATIC_DATA ) { bitStream.IgnoreBits( 8 ); // Ignore identifier bitStream.Read( packet->playerId.binaryAddress ); bitStream.Read( packet->playerId.port ); bitStream.Read( packet->playerIndex ); // ADDED BY KURI i = GetOtherClientIndexByPlayerID( packet->playerId ); if ( i < 0 ) i = GetFreeOtherClientIndex(); if ( i >= 0 ) { otherClients[ i ].playerId = packet->playerId; otherClients[ i ].isActive = true; otherClients[ i ].staticData.Reset(); // The static data is what is left over in the stream otherClients[ i ].staticData.Write( ( char* ) bitStream.GetData() + BITS_TO_BYTES( bitStream.GetReadOffset() ), bitStream.GetNumberOfBytesUsed() - BITS_TO_BYTES( bitStream.GetReadOffset() ) ); } } else if ( packet->data[ 0 ] == ID_BROADCAST_PINGS ) { PlayerID playerId; int index; bitStream.IgnoreBits( 8 ); // Ignore identifier for ( i = 0; i < 32; i++ ) { if ( bitStream.Read( playerId.binaryAddress ) == false ) break; // No remaining data! bitStream.Read( playerId.port ); index = GetOtherClientIndexByPlayerID( playerId ); if ( index >= 0 ) bitStream.Read( otherClients[ index ].ping ); else { index = GetFreeOtherClientIndex(); if ( index >= 0 ) { otherClients[ index ].isActive = true; bitStream.Read( otherClients[ index ].ping ); otherClients[ index ].playerId = playerId; otherClients[ index ].staticData.Reset(); } else bitStream.IgnoreBits( sizeof( short ) * 8 ); } } DeallocatePacket( packet ); return 0; } else if ( packet->data[ 0 ] == ID_TIMESTAMP && packet->length == sizeof(unsigned char)+sizeof(unsigned int)+sizeof(unsigned char)+sizeof(unsigned int)+sizeof(unsigned int) ) { /* RakNet::BitStream s_BitS( (char *)packet->data, SetRandomNumberSeedStruct_Size, false ); SetRandomNumberSeedStruct s; s.Deserialize( s_BitS ); */ RakNet::BitStream inBitStream((char *)packet->data, packet->length, false); /* unsigned char ts; unsigned int timeStamp; unsigned char typeId; unsigned int seed; unsigned int nextSeed; */ unsigned int timeStamp; unsigned char typeId; unsigned int in_seed; unsigned int in_nextSeed; inBitStream.IgnoreBits(8); // ID_TIMESTAMP inBitStream.Read(timeStamp); inBitStream.Read(typeId); // ID_SET_RANDOM_NUMBER_SEED ? // Check to see if this is a user TIMESTAMP message which // accidentally has length SetRandomNumberSeedStruct_Size if ( typeId != ID_SET_RANDOM_NUMBER_SEED ) return packet; inBitStream.Read(in_seed); inBitStream.Read(in_nextSeed); seed = in_seed; nextSeed = in_nextSeed; nextSeedUpdate = timeStamp + 9000; // Seeds are updated every 9 seconds DeallocatePacket( packet ); return 0; } } return packet; }