bool CUnoccupiedVehicleSyncPacket::Read(NetBitStreamInterface& BitStream)
{
    uint uiMaxCount = g_pGame->GetVehicleManager()->Count() * 2 + 10;
    // While we're not out of bytes
    for (uint i = 0; BitStream.GetNumberOfUnreadBits() >= 8; i++)
    {
        if (i > uiMaxCount)
        {
            CLogger::LogPrintf("WARN: Received excess unoccupied vehicle sync data (%d bytes)", BitStream.GetNumberOfUnreadBits() / 8);
            break;
        }

        // Read out the sync data
        SyncData data;
        data.bSend = false;

        SUnoccupiedVehicleSync vehicle;
        if (BitStream.Read(&vehicle))
        {
            data.syncStructure = vehicle;

            // Add it to our list. We no longer check if it's valid here
            // because CUnoccupiedVehicleSync does and it won't write bad ID's
            // back to clients.
            m_Syncs.push_back(data);
        }
    }

    return m_Syncs.size() > 0;
}
Ejemplo n.º 2
0
void CUnoccupiedVehicleSync::Packet_UnoccupiedVehicleSync ( NetBitStreamInterface& BitStream )
{
    // While we're not out of vehicles
    while ( BitStream.GetNumberOfUnreadBits () >= 8 )
    {
        SUnoccupiedVehicleSync vehicle;
        if ( BitStream.Read ( &vehicle ) )
        {
            CClientVehicle* pVehicle = m_pVehicleManager->Get ( vehicle.data.vehicleID );
            if ( pVehicle && pVehicle->CanUpdateSync ( vehicle.data.ucTimeContext ) )
            {
                if ( vehicle.data.bSyncPosition )       pVehicle->SetTargetPosition ( vehicle.data.vecPosition, UNOCCUPIED_VEHICLE_SYNC_RATE, vehicle.data.bSyncVelocity, vehicle.data.vecVelocity.fZ );
                if ( vehicle.data.bSyncRotation )       pVehicle->SetTargetRotation ( vehicle.data.vecRotation, UNOCCUPIED_VEHICLE_SYNC_RATE );
                if ( vehicle.data.bSyncVelocity )       pVehicle->SetMoveSpeed ( vehicle.data.vecVelocity );
                if ( vehicle.data.bSyncTurnVelocity )   pVehicle->SetTurnSpeed ( vehicle.data.vecTurnVelocity );
                if ( vehicle.data.bSyncHealth )         pVehicle->SetHealth ( vehicle.data.fHealth );
                pVehicle->SetEngineOn ( vehicle.data.bEngineOn );
                if ( pVehicle->GetVehicleType() == CLIENTVEHICLE_TRAIN )
                    pVehicle->SetDerailed ( vehicle.data.bDerailed );
#ifdef MTA_DEBUG
                pVehicle->m_pLastSyncer = NULL;
                pVehicle->m_ulLastSyncTime = GetTickCount32 ();
                pVehicle->m_szLastSyncType = "unoccupied";
#endif
            }
        }
        else
            break;
    }
}
Ejemplo n.º 3
0
bool CObjectSyncPacket::Read(NetBitStreamInterface& BitStream)
{
    // While we're not out of bytes
    while (BitStream.GetNumberOfUnreadBits() > 8)
    {
        // Read out the sync data
        SyncData* pData = new SyncData;
        pData->bSend = false;

        // Read out the ID
        if (!BitStream.Read(pData->ID))
            return false;

        // Read the sync time context
        if (!BitStream.Read(pData->ucSyncTimeContext))
            return false;

        // Read out flags
        SIntegerSync<unsigned char, 3> flags;
        if (!BitStream.Read(&flags))
            return false;
        pData->ucFlags = flags;

        // Read out the position if we need
        if (flags & 0x1)
        {
            SPositionSync position;
            if (!BitStream.Read(&position))
                return false;
            pData->vecPosition = position.data.vecPosition;
        }

        // Read out the rotation
        if (flags & 0x2)
        {
            SRotationRadiansSync rotation;
            if (!BitStream.Read(&rotation))
                return false;
            pData->vecRotation = rotation.data.vecRotation;
        }

        // Read out the health
        if (flags & 0x4)
        {
            SObjectHealthSync health;
            if (!BitStream.Read(&health))
                return false;
            pData->fHealth = health.data.fValue;
        }

        // Add it to our list
        m_Syncs.push_back(pData);
    }

    return m_Syncs.size() > 0;
}
Ejemplo n.º 4
0
void CPedSync::Packet_PedSync ( NetBitStreamInterface& BitStream )
{
    // While we're not out of peds
    while ( BitStream.GetNumberOfUnreadBits () > 32 )
    {
        // Read out the ped id
        ElementID ID;
        if ( BitStream.Read ( ID ) )
        {
            // Read out the sync time context. See CClientEntity for documentation on that.
            unsigned char ucSyncTimeContext = 0;
            BitStream.Read ( ucSyncTimeContext );

            unsigned char ucFlags = 0;
            BitStream.Read ( ucFlags );

            CVector vecPosition, vecMoveSpeed;
            float fRotation, fHealth, fArmor;

            // Read out the position
            if ( ucFlags & 0x01 )
            {
                BitStream.Read ( vecPosition.fX );
                BitStream.Read ( vecPosition.fY );
                BitStream.Read ( vecPosition.fZ );
            }

            // And rotation
            if ( ucFlags & 0x02 ) BitStream.Read ( fRotation );

            // And the move speed
            if ( ucFlags & 0x04 )
            {
                BitStream.Read ( vecMoveSpeed.fX );
                BitStream.Read ( vecMoveSpeed.fY );
                BitStream.Read ( vecMoveSpeed.fZ );
            }

            // And health with armour
            if ( ucFlags & 0x08 ) BitStream.Read ( fHealth );
            if ( ucFlags & 0x10 ) BitStream.Read ( fArmor );

            // Grab the ped. Only update the sync if this packet is from the same context.
            CClientPed* pPed = m_pPedManager->Get ( ID );
            if ( pPed && pPed->CanUpdateSync ( ucSyncTimeContext ) )
            {
                if ( ucFlags & 0x01 ) pPed->SetPosition ( vecPosition );
                if ( ucFlags & 0x02 ) pPed->SetCurrentRotation ( fRotation );
                if ( ucFlags & 0x04 ) pPed->SetMoveSpeed ( vecMoveSpeed );
                if ( ucFlags & 0x08 ) pPed->LockHealth ( fHealth );
                if ( ucFlags & 0x10 ) pPed->LockArmor ( fArmor );
            }
        }
    }
}
Ejemplo n.º 5
0
void CObjectSync::Packet_ObjectSync ( NetBitStreamInterface& BitStream )
{
    // While we're not out of bytes
    while ( BitStream.GetNumberOfUnreadBits () > 8 )
    {
        // Read out the ID
        ElementID ID;
        if ( !BitStream.Read ( ID ) )
            return;

        // Read out the sync time context. See CClientEntity for documentation on that.
        unsigned char ucSyncTimeContext;
        if ( !BitStream.Read ( ucSyncTimeContext ) )
            return;
            
        // Read out flags
        SIntegerSync < unsigned char, 3 > flags ( 0 );
        if ( !BitStream.Read ( &flags ) )
            return;
                    
        // Read out the position if we need
        SPositionSync position;
        if ( flags & 0x1 )
        {
            if ( !BitStream.Read ( &position ) )
                return;
        }

        // Read out the rotation
        SRotationRadiansSync rotation;
        if ( flags & 0x2 )
        {
            if ( !BitStream.Read ( &rotation ) )
                return;
        }

        // Read out the health
        SObjectHealthSync health;
        if ( flags & 0x4 )
        {
            if ( !BitStream.Read ( &health ) )
                return;
        }

        // Grab the object
        CDeathmatchObject* pObject = static_cast < CDeathmatchObject* > ( m_pObjectManager->Get ( ID ) );
        // Only update the sync if this packet is from the same context
        if ( pObject && pObject->CanUpdateSync ( ucSyncTimeContext ) )
        {
            if ( flags & 0x1 ) pObject->SetPosition ( position.data.vecPosition );
            if ( flags & 0x2 ) pObject->SetRotationRadians ( rotation.data.vecRotation );
            if ( flags & 0x4 ) pObject->SetHealth ( health.data.fValue );
        }
    }
}
Ejemplo n.º 6
0
//
// Should do the same this as what CPedTaskPacket::Read() does
//
bool CSimPedTaskPacket::Read ( NetBitStreamInterface& BitStream )
{
    // Read and save packet data
    m_Cache.uiNumBitsInPacketBody = BitStream.GetNumberOfUnreadBits();
    uint uiNumBytes = ( m_Cache.uiNumBitsInPacketBody + 1 ) / 8;
    dassert( uiNumBytes < sizeof( m_Cache.DataBuffer ) );
    if( uiNumBytes < sizeof( m_Cache.DataBuffer ) )
        if ( BitStream.ReadBits( m_Cache.DataBuffer, m_Cache.uiNumBitsInPacketBody ) )
            return true;

    return false;
}
Ejemplo n.º 7
0
void CPlayerRPCs::SetPlayerMoney ( NetBitStreamInterface& bitStream )
{
    // Read out the new money amount
    long lMoney;
    bool bInstant = false;
    if ( bitStream.Read ( lMoney ) )
    {
        if (bitStream.GetNumberOfUnreadBits() > 0)
            bitStream.ReadBit(bInstant);

        // Set it
        m_pClientGame->SetMoney ( lMoney, bInstant );
    }
}
Ejemplo n.º 8
0
void CRPCFunctions::KeyBind ( NetBitStreamInterface & bitStream )
{
    unsigned char ucType;
    bool bHitState = false;
    if ( bitStream.ReadBit () == true )
        ucType = 1;
    else
        ucType = 0;
    bitStream.ReadBit ( bHitState );

    unsigned char ucKeyLength = bitStream.GetNumberOfUnreadBits () >> 3;
    if ( ucKeyLength < 256 )
    {
        char szKey [ 256 ];
        bitStream.Read ( szKey, ucKeyLength );
        szKey [ ucKeyLength ] = 0;

        m_pSourcePlayer->GetKeyBinds ()->ProcessKey ( szKey, bHitState, ( eKeyBindType ) ucType );
    }
}
Ejemplo n.º 9
0
void CElementRPCs::SetElementModel ( CClientEntity* pSource, NetBitStreamInterface& bitStream )
{
    unsigned short usModel;
    if ( bitStream.Read ( usModel ) )
    {
        switch ( pSource->GetType () )
        {
            case CCLIENTPED:
            case CCLIENTPLAYER:
            {
                CClientPed* pPed = static_cast < CClientPed * > ( pSource );
                pPed->SetModel ( usModel );
                break;
            }

            case CCLIENTVEHICLE:
            {
                uchar ucVariant = 255, ucVariant2 = 255;
                if ( bitStream.GetNumberOfUnreadBits () >= sizeof ( ucVariant ) + sizeof ( ucVariant2 ) )
                {
                    bitStream.Read ( ucVariant );
                    bitStream.Read ( ucVariant2 );
                }
                CClientVehicle* pVehicle = static_cast < CClientVehicle * > ( pSource );
                pVehicle->SetModelBlocking ( usModel, ucVariant, ucVariant2 );
                break;
            }

            case CCLIENTOBJECT:
            case CCLIENTWEAPON:
            {
                CClientObject* pObject = static_cast < CClientObject * > ( pSource );
                pObject->SetModel ( usModel );
                break;
            }
        }
    }
}
Ejemplo n.º 10
0
bool CUnoccupiedVehicleSyncPacket::Read ( NetBitStreamInterface& BitStream )
{
    // While we're not out of bytes
    while ( BitStream.GetNumberOfUnreadBits () >= 8 )
    {
        // Read out the sync data
        SyncData data;
        data.bSend = false;

        SUnoccupiedVehicleSync vehicle;
        if ( BitStream.Read ( &vehicle ) )
        {
            data.syncStructure = vehicle;

            // Add it to our list. We no longer check if it's valid here
            // because CUnoccupiedVehicleSync does and it won't write bad ID's
            // back to clients.
            m_Syncs.push_back ( data );
        }
    }

    return m_Syncs.size () > 0;
}