Beispiel #1
0
size_t GlobalsArray::Vsize(const ArrayData* ad) {
  // We need to iterate to find out the actual size, since kNamedLocalDataType
  // elements in the array may have been set to KindOfUninit.
  auto a = asGlobals(ad);
  size_t count = 0;
  auto iter_limit = IterEnd(a);
  for (auto iter = IterBegin(a);
       iter != iter_limit;
       iter = IterAdvance(a, iter)) {
    ++count;
  }
  return count;
}
size_t NameValueTableWrapper::Vsize(const ArrayData* ad) {
  // We need to iterate to find out the actual size, since
  // KindOfIndirect elements in the array may have been set to
  // KindOfUninit.
  auto a = asNVTW(ad);
  size_t count = 0;
  for (auto iter = IterBegin(a);
      iter != invalid_index;
      iter = IterAdvance(a, iter)) {
    ++count;
  }
  return count;
}
Beispiel #3
0
std::string ASE::QueryFull ( void )
{
    std::stringstream reply;
    std::stringstream temp;

    reply << "EYE1";
    // game
    reply << ( unsigned char ) 4;
    reply << "mta";
    // port
    reply << ( unsigned char ) ( m_strPort.length() + 1 );
    reply << m_strPort;
    // server name
    reply << ( unsigned char ) ( m_pMainConfig->GetServerName ().length() + 1 );
    reply << m_pMainConfig->GetServerName ();
    // game type
    reply << ( unsigned char ) ( m_strGameType.length() + 1 );
    reply << m_strGameType;
    // map name
    reply << ( unsigned char ) ( m_strMapName.length() + 1 );
    reply << m_strMapName;
    // version
    temp << MTA_DM_ASE_VERSION;
    reply << ( unsigned char ) ( temp.str().length() + 1 );
    reply << temp.str();
    // passworded
    reply << ( unsigned char ) 2;
    reply << ( ( m_pMainConfig->HasPassword () ) ? 1 : 0 );
    // players count
    temp.str ( "" );
    temp << m_pPlayerManager->CountJoined ();
    reply << ( unsigned char ) ( temp.str().length () + 1 );
    reply << temp.str();
    // players max
    temp.str ( "" );
    temp << m_pMainConfig->GetMaxPlayers ();
    reply << ( unsigned char ) ( temp.str().length () + 1 );
    reply << temp.str();

    // rules
    list < CASERule* > ::iterator rIter = IterBegin ();
    for ( ; rIter != IterEnd () ; rIter++ )
    {
        // maybe use a map and std strings for rules?
        reply << ( unsigned char ) ( strlen ( (*rIter)->GetKey () ) + 1 );
        reply << (*rIter)->GetKey ();
        reply << ( unsigned char ) ( strlen ( (*rIter)->GetValue () ) + 1 );
        reply << (*rIter)->GetValue ();
    }
    reply << ( unsigned char ) 1;

    // players

    // the flags that tell what data we carry per player ( apparently we need all set cause of GM atm )
    unsigned char ucFlags = 0;
    ucFlags |= 0x01; // nick
    ucFlags |= 0x02; // team
    ucFlags |= 0x04; // skin
    ucFlags |= 0x08; // score
    ucFlags |= 0x16; // ping
    ucFlags |= 0x32; // time

    char szTemp[256] = { '\0' };
    CPlayer* pPlayer = NULL;

    list < CPlayer* > ::const_iterator pIter = m_pPlayerManager->IterBegin ();
    for ( ; pIter != m_pPlayerManager->IterEnd (); pIter++ )
    {
        pPlayer = *pIter;
        if ( pPlayer->IsJoined () )
        {
            reply << ucFlags;
            // nick
            std::string strPlayerName = RemoveColorCodes ( pPlayer->GetNick () );
            if ( strPlayerName.length () == 0 )
                strPlayerName = pPlayer->GetNick ();
            reply << ( unsigned char ) ( strPlayerName.length () + 1 );
            reply << strPlayerName.c_str ();
            // team (skip)
            reply << ( unsigned char ) 1;
            // skin (skip)
            reply << ( unsigned char ) 1;
            // score
            const std::string& strScore = pPlayer->GetAnnounceValue ( "score" );
            reply << ( unsigned char ) ( strScore.length () + 1 );
            reply << strScore.c_str ();
            // ping
            snprintf ( szTemp, 255, "%u", pPlayer->GetPing () );
            reply << ( unsigned char ) ( strlen ( szTemp ) + 1 );
            reply << szTemp;
            // time (skip)
            reply << ( unsigned char ) 1;
        }
    }

    return reply.str();
}