bool CPlayerConnectCompletePacket::Write ( NetBitStreamInterface& BitStream ) const
{
    // Send the connection string
    SString strConnText ( "%s %s [%s]", MTA_DM_FULL_STRING, MTA_DM_VERSIONSTRING, MTA_OS_STRING );
    BitStream.WriteString ( strConnText.Left ( MAX_CONN_TEXT_LEN ) );

    // Send the full server version
    if ( BitStream.Version () >= 0x29 )
        BitStream.WriteString ( CStaticFunctionDefinitions::GetVersionSortable () );

    return true;
}
bool CResourceClientScriptsPacket::Write ( NetBitStreamInterface& BitStream ) const
{
    if ( m_vecItems.size() == 0 )
        return false;

    BitStream.Write ( m_pResource->GetNetID() );

    unsigned short usItemCount = m_vecItems.size();
    BitStream.Write ( usItemCount );

    for ( std::vector<CResourceClientScriptItem*>::const_iterator iter = m_vecItems.begin ();
          iter != m_vecItems.end();
          ++iter )
    {
        if ( BitStream.Version() >= 0x50 )
            BitStream.WriteString( (*iter)->GetName() );

        const SString& data = (*iter)->GetSourceCode ();
        unsigned int len = data.length ();
        BitStream.Write ( len );
        BitStream.Write ( data.c_str(), len );
    }

    return true;
}
bool CPlayerJoinCompletePacket::Write ( NetBitStreamInterface& BitStream ) const
{
    BitStream.Write ( m_PlayerID );
    BitStream.Write ( m_ucNumberOfPlayers );
    BitStream.Write ( m_RootElementID );

    // Transmit server requirement for the client to check settings
    BitStream.Write ( m_iEnableClientChecks );

    // Transmit whether or not the Voice is enabled
    BitStream.WriteBit ( m_bVoiceEnabled );

    // Transmit the sample rate for voice
    SIntegerSync < unsigned char, 2 > sampleRate ( m_ucSampleRate );
    BitStream.Write ( &sampleRate );

    // Transmit the quality for voice
    SIntegerSync < unsigned char, 4 > voiceQuality ( m_ucQuality );
    BitStream.Write ( &voiceQuality );

    // Transmit the max bitrate for voice
    BitStream.WriteCompressed ( m_uiBitrate );

    // Tellclient about maybe throttling back http client requests
    BitStream.Write ( m_iHTTPMaxConnectionsPerClient );

    BitStream.Write ( static_cast < unsigned char > ( m_ucHTTPDownloadType ) );

    switch ( m_ucHTTPDownloadType )
    {
    case HTTP_DOWNLOAD_ENABLED_PORT:
        {
            BitStream.Write ( m_usHTTPDownloadPort );
        }

        break;
    case HTTP_DOWNLOAD_ENABLED_URL:
        {
            // Internal http server port
            if ( BitStream.Version() >= 0x48 )
                BitStream.Write( m_usHTTPDownloadPort );

            // External http server URL
            BitStream.WriteString ( m_strHTTPDownloadURL );
        }

        break;
    default:
        break;
    }

    return true;
}
 void CPositionRotationAnimation::ToBitStream( NetBitStreamInterface& a_rBitStream, bool a_bResumeMode ) const
 {
     a_rBitStream.WriteBit ( a_bResumeMode );
     if ( a_bResumeMode )
     {
        unsigned long ulNow = _GetTime ();
        unsigned long ulElaspedTime = ulNow - m_ulStartTime;
        unsigned long ulTimeLeft = 0;
        if ( m_ulEndTime > ulNow )
        {
            ulTimeLeft = m_ulEndTime - ulNow;
        }
        a_rBitStream.WriteCompressed ( ulElaspedTime );
        a_rBitStream.WriteCompressed ( ulTimeLeft );
     }
     else
     {
         a_rBitStream.WriteCompressed ( m_ulDuration );
     }

     SPositionSync positionSync;
     positionSync.data.vecPosition = m_SourceValue.m_vecPosition;
     a_rBitStream.Write ( &positionSync );

     SRotationRadiansSync rotationSync ( true ); //RPC function used floats when join time packet didn't, let's go for float
     rotationSync.data.vecRotation = m_SourceValue.m_vecRotation;
     a_rBitStream.Write ( &rotationSync );
    
     positionSync.data.vecPosition = m_TargetValue.m_vecPosition;
     a_rBitStream.Write ( &positionSync );

     a_rBitStream.WriteBit ( m_bDeltaRotationMode );
     if ( m_bDeltaRotationMode )
     {
        rotationSync.data.vecRotation = m_DeltaValue.m_vecRotation; //We serialize DELTA
     }
     else
     {
         rotationSync.data.vecRotation = m_TargetValue.m_vecRotation;
     }
     a_rBitStream.Write ( &rotationSync );

     ////We write the string directly to allow new types without changing netcode (since integer values of enum might change)
     a_rBitStream.WriteString ( CEasingCurve::GetStringFromEasingType( m_easingCurve.GetType() ) );
     double fEasingPeriod, fEasingAmplitude, fEasingOvershoot;
     m_easingCurve.GetParams ( fEasingPeriod, fEasingAmplitude, fEasingOvershoot );
     a_rBitStream.Write ( fEasingPeriod );
     a_rBitStream.Write ( fEasingAmplitude );
     a_rBitStream.Write ( fEasingOvershoot );
 }
Ejemplo n.º 5
0
bool CResourceStartPacket::Write(NetBitStreamInterface& BitStream) const
{
    if (!m_strResourceName.empty())
    {
        // Write the resource name
        unsigned char sizeResourceName = static_cast<unsigned char>(m_strResourceName.size());
        BitStream.Write(sizeResourceName);
        if (sizeResourceName > 0)
        {
            BitStream.Write(m_strResourceName.c_str(), sizeResourceName);
        }

        // Write the resource id
        BitStream.Write(m_pResource->GetNetID());

        // Write the resource element id
        BitStream.Write(m_pResource->GetResourceRootElement()->GetID());

        // Write the resource dynamic element id
        BitStream.Write(m_pResource->GetDynamicElementRoot()->GetID());

        // Count the amount of 'no client cache' scripts
        unsigned short usNoClientCacheScriptCount = 0;
        if (m_pResource->IsClientScriptsOn() == true)
        {
            list<CResourceFile*>::iterator iter = m_pResource->IterBegin();
            for (; iter != m_pResource->IterEnd(); ++iter)
            {
                if ((*iter)->GetType() == CResourceScriptItem::RESOURCE_FILE_TYPE_CLIENT_SCRIPT &&
                    static_cast<CResourceClientScriptItem*>(*iter)->IsNoClientCache() == true)
                {
                    ++usNoClientCacheScriptCount;
                }
            }
        }
        BitStream.Write(usNoClientCacheScriptCount);

        // Write the declared min client version for this resource
        if (BitStream.Version() >= 0x32)
        {
            BitStream.WriteString(m_pResource->GetMinServerReqFromMetaXml());
            BitStream.WriteString(m_pResource->GetMinClientReqFromMetaXml());
        }
        if (BitStream.Version() >= 0x45)
        {
            BitStream.WriteBit(m_pResource->IsOOPEnabledInMetaXml());
        }

        if (BitStream.Version() >= 0x62)
        {
            BitStream.Write(m_pResource->GetDownloadPriorityGroup());
        }

        // Send the resource files info
        list<CResourceFile*>::iterator iter = m_pResource->IterBegin();
        for (; iter != m_pResource->IterEnd(); iter++)
        {
            if (((*iter)->GetType() == CResourceScriptItem::RESOURCE_FILE_TYPE_CLIENT_CONFIG && m_pResource->IsClientConfigsOn()) ||
                ((*iter)->GetType() == CResourceScriptItem::RESOURCE_FILE_TYPE_CLIENT_SCRIPT && m_pResource->IsClientScriptsOn() &&
                 static_cast<CResourceClientScriptItem*>(*iter)->IsNoClientCache() == false) ||
                ((*iter)->GetType() == CResourceScriptItem::RESOURCE_FILE_TYPE_CLIENT_FILE && m_pResource->IsClientFilesOn()))
            {
                // Write the Type of chunk to read (F - File, E - Exported Function)
                BitStream.Write(static_cast<unsigned char>('F'));

                // Write the map name
                const char* szFileName = (*iter)->GetWindowsName();
                size_t      sizeFileName = strlen(szFileName);

                // Make sure we don't have any backslashes in the name
                char* szCleanedFilename = new char[sizeFileName + 1];
                strcpy(szCleanedFilename, szFileName);
                for (unsigned int i = 0; i < sizeFileName; i++)
                {
                    if (szCleanedFilename[i] == '\\')
                        szCleanedFilename[i] = '/';
                }

                BitStream.Write(static_cast<unsigned char>(sizeFileName));
                if (sizeFileName > 0)
                {
                    BitStream.Write(szCleanedFilename, sizeFileName);
                }

                // ChrML: Don't forget this...
                delete[] szCleanedFilename;

                BitStream.Write(static_cast<unsigned char>((*iter)->GetType()));
                CChecksum checksum = (*iter)->GetLastChecksum();
                BitStream.Write(checksum.ulCRC);
                BitStream.Write((const char*)checksum.md5.data, sizeof(checksum.md5.data));
                BitStream.Write((*iter)->GetApproxSize());
                if ((*iter)->GetType() == CResourceScriptItem::RESOURCE_FILE_TYPE_CLIENT_FILE)
                {
                    CResourceClientFileItem* pRCFItem = reinterpret_cast<CResourceClientFileItem*>(*iter);
                    // write bool whether to download or not
                    BitStream.WriteBit(pRCFItem->IsAutoDownload());
                }
            }
        }

        // Loop through the exported functions
        list<CExportedFunction>::iterator iterExportedFunction = m_pResource->IterBeginExportedFunctions();
        for (; iterExportedFunction != m_pResource->IterEndExportedFunctions(); iterExportedFunction++)
        {
            // Check to see if the exported function is 'client'
            if (iterExportedFunction->GetType() == CExportedFunction::EXPORTED_FUNCTION_TYPE_CLIENT)
            {
                // Write the Type of chunk to read (F - File, E - Exported Function)
                BitStream.Write(static_cast<unsigned char>('E'));

                // Write the exported function
                std::string strFunctionName = iterExportedFunction->GetFunctionName();
                size_t      sizeFunctionName = strFunctionName.length();

                BitStream.Write(static_cast<unsigned char>(sizeFunctionName));
                if (sizeFunctionName > 0)
                {
                    BitStream.Write(strFunctionName.c_str(), sizeFunctionName);
                }
            }
        }

        return true;
    }

    return false;
}