コード例 #1
0
ファイル: GameNetConnect.cpp プロジェクト: uvbs/GameProject
bool EvalCommand( UdpChain& chain , ComEvaluator& evaluator , SBuffer& buffer , ComConnection* con /*= NULL */ )
{
    unsigned size;
    while( chain.readPacket( buffer , size ) )
    {
        size_t oldSize = buffer.getAvailableSize();

        if ( oldSize < size )
            throw ComException( "error UDP Packet" );

        do
        {
            if ( !evaluator.evalCommand( buffer , con ) )
            {
                ::Msg( "readPacket Error Need Fix" );
                return false;
            }
        }
        while( oldSize - buffer.getAvailableSize() < size );

        if ( oldSize - buffer.getAvailableSize() != size )
            throw ComException( "error UDP Packet" );
    }

    return true;
}
コード例 #2
0
ファイル: GameNetConnect.cpp プロジェクト: uvbs/GameProject
bool UdpChain::readPacket( SBuffer& buffer , unsigned& readSize )
{
    if ( !buffer.getAvailableSize() )
        return false;

    uint32  incoming;
    uint32  outgoing;

    int count = 0;

    uint32 maxOutgoing = 0;
    while( buffer.getAvailableSize() )
    {
        buffer.take( incoming );
        buffer.take( outgoing );
        buffer.take( readSize );

        if ( maxOutgoing < outgoing )
            maxOutgoing = outgoing;

        if ( incoming <= mIncomingAck )
        {

            if ( readSize > buffer.getAvailableSize() )
            {
                ::Msg( "UdpChain::error incoming data" );
                return false;
            }

            {
                //::Msg( "UdpChain::old incoming data" );
                buffer.shiftUseSize( readSize );
            }
        }
        else if ( incoming > mIncomingAck )
        {
            mIncomingAck = incoming;

            if ( readSize )
                break;
        }

        ++count;
    }

    refrushReliableData( maxOutgoing );
    //Msg( "readPacket %u %u %u" , outgoing , incoming , readSize );
    return buffer.getAvailableSize() != 0;
}