Пример #1
0
///////////////////////////////////////////////////////////////
//
// CPerfStatSqliteTimingImpl::UpdateSqliteTiming
//
//
//
///////////////////////////////////////////////////////////////
void CPerfStatSqliteTimingImpl::UpdateSqliteTiming(CRegistry* pRegistry, const char* szQuery, TIMEUS timeUs)
{
    // Only record stats if requested
    if (GetTickCount64_() > m_llRecordStatsEndTime)
        return;

    CTimingInfo info;
    info.strQuery = szQuery;
    info.timeUs = timeUs;
    info.timeStamp = GetTickCount64_();

    // Get resource name
    if (m_currentluaVM)
        if (CResource* pResource = g_pGame->GetResourceManager()->GetResourceFromLuaState(m_currentluaVM))
            info.resourceName = pResource->GetName();
    m_currentluaVM = NULL;

    // Use registry name if resource name empty
    if (info.resourceName.empty())
        if (SString* pRegistryName = MapFind(m_RegistryMap, pRegistry))
            info.resourceName = *pRegistryName;

    info.resourceName = info.resourceName.SplitRight("/", NULL, -1);

    m_TimingList.push_back(info);
}
///////////////////////////////////////////////////////////////
//
// CRemoteMasterServer::Refresh
//
//
//
///////////////////////////////////////////////////////////////
void CRemoteMasterServer::Refresh ( void )
{
    // If it's been less than a minute and we has data, don't send a new request
    if ( GetTickCount64_ () - m_llLastRefreshTime < 60000 && m_strStage == "hasdata" )
        return;

    // Send new request
    m_strStage = "waitingreply";
    m_llLastRefreshTime = GetTickCount64_ ();
    AddRef();   // Keep alive
    GetHTTP()->QueueFile( m_strURL, NULL, 0, NULL, 0, false, this, &CRemoteMasterServer::StaticDownloadFinished, false, 1 );
}
void CAccessControlListManager::ClearReadCache ( void )
{
    m_bReadCacheDirty = false;
    m_llLastTimeReadCacheCleared = GetTickCount64_ ();
    m_ReadCacheMap.clear ();
    m_uiGlobalRevision++;
}
Пример #4
0
     CPerModuleTickCount ( void )
     {
 #ifdef _DEBUG
         m_TimeSinceUpdated.SetMaxIncrement ( 500 );
 #endif
         m_ResultValue.Initialize ( GetTickCount64_ () );
     }
Пример #5
0
     void Update ( void )
     {
 #ifdef _DEBUG
         m_TimeSinceUpdated.Reset ();
 #endif
         m_ResultValue.SetValue ( GetTickCount64_ () );
     }
///////////////////////////////////////////////////////////////
//
// CPerfStatEventPacketUsageImpl::MaybeRecordStats
//
//
//
///////////////////////////////////////////////////////////////
void CPerfStatEventPacketUsageImpl::MaybeRecordStats ( void )
{
    // Someone watching?
    if ( m_TimeSinceGetStats.Get () < 10000 )
    {
        // Time for record update?    // Copy and clear once every 5 seconds
        long long llTime = GetTickCount64_ ();
        if ( llTime >= m_llNextRecordTime )
        {
            m_llNextRecordTime = std::max ( m_llNextRecordTime + 5000, llTime + 5000 / 10 * 9 );

            // Copy into a list and sort
            m_EventUsageSortedList.clear();
            for( std::map < SString, SEventUsage >::iterator iter = m_EventUsageLiveMap.begin() ; iter != m_EventUsageLiveMap.end() ; ++iter )
            {
                iter->second.strName = iter->first;
                m_EventUsageSortedList.push_back( iter->second );
            }

            std::sort ( m_EventUsageSortedList.begin (), m_EventUsageSortedList.end (), 
                [](const SEventUsage& a, const SEventUsage& b)
            {
                return a.iTotal > b.iTotal;
            });

            m_EventUsageLiveMap.clear();
        }
    }
    else
    {
        m_bEnabled = false;
    }
}
///////////////////////////////////////////////////////////////
//
// CPerfStatPlayerPacketUsageImpl::DoPulse
//
//
//
///////////////////////////////////////////////////////////////
void CPerfStatPlayerPacketUsageImpl::DoPulse ( void )
{
    long long llTickCount = GetTickCount64_ ();
    long long llDelta = llTickCount - m_LastTickCount;
    if ( llDelta >= 1000 )
    {
        UpdatePlayerPacketUsage();

        m_LastTickCount = m_LastTickCount + 1000;
        m_LastTickCount = std::max ( m_LastTickCount, llTickCount - 1500 );

        int flags = 0;
        m_SecondCounter++;

        if ( m_SecondCounter % 5 == 0 )         // 5 second
            flags |= 1;
        if ( m_SecondCounter % 60 == 0 )        // 60 seconds
            flags |= 2;
        if ( m_SecondCounter % (5*60) == 0 )    // 5 mins
            flags |= 4;
        if ( m_SecondCounter % (60*60) == 0 )   // 60 mins
            flags |= 8;

        m_AllPlayerPacketUsage.Pulse1s ( flags );
    }
}
Пример #8
0
void CPlayer::SetDamageInfo ( ElementID ElementID, unsigned char ucWeapon, unsigned char ucBodyPart )
{
    m_PlayerAttackerID = ElementID;
    m_ucAttackWeapon = ucWeapon;
    m_ucAttackBodyPart = ucBodyPart;
    m_llSetDamageInfoTime = GetTickCount64_ ();
}
Пример #9
0
CConnectHistoryItem& CConnectHistory::GetHistoryItem ( const string& strIP )
{
    // Find existing
    map < string, CConnectHistoryItem >::iterator iter = m_HistoryItemMap.find ( strIP );

    if ( iter == m_HistoryItemMap.end () )
    {
        // Add if not found
        m_HistoryItemMap[strIP] = CConnectHistoryItem();
        iter = m_HistoryItemMap.find ( strIP );
    }

#if MTA_DEBUG
    // Dump info
    const CConnectHistoryItem& historyItem = iter->second;
    if ( !historyItem.joinTimes.empty () )
    {
        SString strInfo ( "IP:%s  ", strIP.c_str () );
        for ( unsigned int i = 0 ; i < historyItem.joinTimes.size () ; i++ )
        {
            strInfo += SString ( "%u  ", GetTickCount64_ () - historyItem.joinTimes[i] );
        }
        strInfo += "\n";
        OutputDebugString ( strInfo );
    }
#endif

    return iter->second;
}
Пример #10
0
/////////////////////////////////////////////////////////////
//
// CDirect3DEvents9::CheckForScreenShot
//
// Take a screenshot if required and able
//
/////////////////////////////////////////////////////////////
void CDirect3DEvents9::CheckForScreenShot ( void )
{
    // Make a screenshot if needed
    if ( CCore::GetSingleton().bScreenShot && !CScreenShot::IsSaving () )
    {
        // Max one screenshot per second
        if ( GetTickCount64_ () - ms_LastSaveTime < 1000 )
            return;
        ms_LastSaveTime = GetTickCount64_ ();

        uint uiWidth = CDirect3DData::GetSingleton ().GetViewportWidth ();
        uint uiHeight = CDirect3DData::GetSingleton ().GetViewportHeight ();

        // Call the pre-screenshot function 
        SString strFileName = CScreenShot::PreScreenShot ();

        // Try to get the screen data
        SString strError;
        if ( CGraphics::GetSingleton ().GetScreenGrabber ()->GetBackBufferPixels ( uiWidth, uiHeight, ms_ScreenShotBuffer, strError ) )
        {
            // Validate data size
            uint uiDataSize = ms_ScreenShotBuffer.GetSize ();
            uint uiReqDataSize = uiWidth * uiHeight * 4;

            if ( uiDataSize == uiReqDataSize )
            {
                // Start the save thread
                CScreenShot::BeginSave ( strFileName, ms_ScreenShotBuffer.GetData (), uiDataSize, uiWidth, uiHeight );
            }
            else
            {
                g_pCore->GetConsole()->Printf ( _("Screenshot got %d bytes, but expected %d"), uiDataSize, uiReqDataSize );
                strFileName = "";
            }
        }
        else
        {
            g_pCore->GetConsole()->Print ( _("Screenshot failed") + SString( " (%s)", *strError ) );
            strFileName = "";
        }

        // Call the post-screenshot function
        CScreenShot::PostScreenShot ( strFileName );

        CCore::GetSingleton().bScreenShot = false;
    }
}
Пример #11
0
bool CLightsyncPacket::Write(NetBitStreamInterface& BitStream) const
{
    bool bSyncPosition;

    if (Count() == 0)
        return false;

    for (std::vector<CPlayer*>::const_iterator iter = m_players.begin(); iter != m_players.end(); ++iter)
    {
        CPlayer*                       pPlayer = *iter;
        CPlayer::SLightweightSyncData& data = pPlayer->GetLightweightSyncData();
        CVehicle*                      pVehicle = pPlayer->GetOccupiedVehicle();

        // Find the difference between now and the time the position last changed for the player
        long long llTicksDifference = GetTickCount64_() - pPlayer->GetPositionLastChanged();

        // Right we need to sync the position if there is no vehicle or he's in a vehicle and the difference between setPosition is less than or equal to the
        // slow sync rate i.e. make sure his position has been updated more than 0.001f in the last 1500ms plus a small margin for error (probably not needed).
        // This will ensure we only send positions when the position has changed.
        bSyncPosition = (!pVehicle || pPlayer->GetOccupiedVehicleSeat() == 0) && llTicksDifference <= g_TickRateSettings.iLightSync + 100;

        BitStream.Write(pPlayer->GetID());
        BitStream.Write((unsigned char)pPlayer->GetSyncTimeContext());

        unsigned short usLatency = pPlayer->GetPing();
        BitStream.WriteCompressed(usLatency);

        BitStream.WriteBit(data.health.bSync);
        if (data.health.bSync)
        {
            SPlayerHealthSync health;
            health.data.fValue = pPlayer->GetHealth();
            BitStream.Write(&health);

            SPlayerArmorSync armor;
            armor.data.fValue = pPlayer->GetArmor();
            BitStream.Write(&armor);
        }

        BitStream.WriteBit(bSyncPosition);
        if (bSyncPosition)
        {
            SLowPrecisionPositionSync pos;
            pos.data.vecPosition = pPlayer->GetPosition();
            BitStream.Write(&pos);

            bool bSyncVehicleHealth = data.vehicleHealth.bSync && pVehicle;
            BitStream.WriteBit(bSyncVehicleHealth);
            if (bSyncVehicleHealth)
            {
                SLowPrecisionVehicleHealthSync health;
                health.data.fValue = pVehicle->GetHealth();
                BitStream.Write(&health);
            }
        }
    }

    return true;
}
Пример #12
0
static ULONGLONG WINAPI GetTickCount64_resolve(void)
{
    GetTickCount64_ = (GetTickCount64_func *)GetProcAddress(GetModuleHandle("kernel32.dll"), "GetTickCount64");
    if (!GetTickCount64_)
        GetTickCount64_ = GetTickCount64_fallback;

    return GetTickCount64_();
}
Пример #13
0
void CClock::Set(unsigned char ucHour, unsigned char ucMinute)
{
    // Calculate number of seconds from midnight
    unsigned long ulSecondsFromMidnight = ucHour * 60 + ucMinute;

    // Set the midnight time to our current time minus number of seconds since midnight according to the time we were given
    m_ullMidnightTime = GetTickCount64_() - ulSecondsFromMidnight * m_ulMinuteDuration;
}
Пример #14
0
void CAccountManager::DoPulse(void)
{
    // Save it only once in a while whenever something has changed
    if (m_bChangedSinceSaved && GetTickCount64_() > m_llLastTimeSaved + 15000)
    {
        // Save it
        Save();
    }
}
Пример #15
0
void CLightsyncManager::RegisterPlayer ( CPlayer* pPlayer )
{
    SEntry entry;
    entry.ullTime = GetTickCount64_ () + SLOW_SYNCRATE;
    entry.pPlayer = pPlayer;
    entry.eType = SYNC_PLAYER;
    entry.uiContext = 0; // Unused
    m_Queue.push_back ( entry );
}
Пример #16
0
void CPlayer::DoPulse ( void )
{
    if ( GetStatus () == STATUS_JOINED )
    {
        m_pPlayerTextManager->Process ();

        if ( GetTickCount64_ () > m_llNearListUpdateTime + 300 )
            UpdateOthersNearList ();
    }
}
Пример #17
0
void CPlayer::ValidateDamageInfo ( void )
{
    if ( m_llSetDamageInfoTime + 100 < GetTickCount64_ () )
    {
        // Reset if data is too old
        m_PlayerAttackerID = INVALID_ELEMENT_ID;
        m_ucAttackWeapon = 0xFF;
        m_ucAttackBodyPart = 0xFF;
    }
}
void CAccessControlListManager::DoPulse ( void )
{
    // Clear cache every 12 hours or if dirty
    if ( m_bReadCacheDirty || GetTickCount64_ () - m_llLastTimeReadCacheCleared > 1000 * 60 * 60 * 12 )
        ClearReadCache ();

    // Save when needed, but no more than once every 10 seconds
    if ( m_AutoSaveTimer.Get () > 10000 && m_bNeedsSave )
        Save ();
}
Пример #19
0
///////////////////////////////////////////////////////////////
//
// CPerfStatPacketUsageImpl::DoPulse
//
//
//
///////////////////////////////////////////////////////////////
void CPerfStatPacketUsageImpl::DoPulse ( void )
{
    // Copy and clear once every 5 seconds
    long long llTime = GetTickCount64_ ();

    if ( llTime >= m_llNextRecordTime )
    {
        m_llNextRecordTime = Max ( m_llNextRecordTime + 5000, llTime + 5000 / 10 * 9 );
        RecordStats ();
    }
}
///////////////////////////////////////////////////////////////
//
// CPerfStatBandwidthReductionImpl::DoPulse
//
//
//
///////////////////////////////////////////////////////////////
void CPerfStatBandwidthReductionImpl::DoPulse ( void )
{
    long long llTime = GetTickCount64_ ();

    // Record once every 5 seconds
    if ( llTime >= m_llNextRecordTime )
    {
        m_llNextRecordTime = Max ( m_llNextRecordTime + 5000, llTime + 5000 / 10 * 9 );
        RecordStats ();
    }
}
Пример #21
0
// Protect against a flood of server queries.
// Send cached version unless player count has changed, or last re-cache is older than m_lLightMinInterval
const std::string& ASE::QueryLightCached ( void )
{
    long long llTime = GetTickCount64_ ();
    unsigned int uiPlayerCount = m_pPlayerManager->CountJoined ();
    if ( uiPlayerCount != m_uiLightLastPlayerCount || llTime - m_llLightLastTime > m_lLightMinInterval || m_strLightCached == "" )
    {
        m_strLightCached = QueryLight ();
        m_llLightLastTime = llTime;
        m_uiLightLastPlayerCount = uiPlayerCount;
    }
    return m_strLightCached;
}
Пример #22
0
void CLightsyncManager::RegisterPlayer ( CPlayer* pPlayer )
{
    if ( pPlayer->IsBeingDeleted() )
        return;

    SEntry entry;
    entry.ullTime = GetTickCount64_ ();
    entry.pPlayer = pPlayer;
    entry.eType = SYNC_PLAYER;
    entry.uiContext = 0; // Unused
    m_Queue.push_back ( entry );
}
Пример #23
0
void CClock::Get(unsigned char& ucHour, unsigned char& ucMinute)
{
    // Grab how many seconds midnight was from now
    unsigned long long ullSecondsSinceMidnight = (GetTickCount64_() - m_ullMidnightTime) / m_ulMinuteDuration;

    // Grab how many hours that is
    ucMinute = static_cast<unsigned char>(ullSecondsSinceMidnight % 60);
    ullSecondsSinceMidnight /= 60;

    // What's left is the number of hours, limit it to 24 and return it
    ucHour = static_cast<unsigned char>(ullSecondsSinceMidnight % 24);
}
Пример #24
0
///////////////////////////////////////////////////////////////
//
// CPerfStatServerInfoImpl::DoPulse
//
//
//
///////////////////////////////////////////////////////////////
void CPerfStatServerInfoImpl::DoPulse()
{
    long long llTime = GetTickCount64_();

    UpdateThreadCPUTimes(m_MainThreadCPUTimes, &llTime);

    // Record once every 5 seconds
    if (llTime >= m_llNextRecordTime)
    {
        m_llNextRecordTime = std::max(m_llNextRecordTime + 5000, llTime + 5000 / 10 * 9);
        RecordStats();
    }
}
Пример #25
0
///////////////////////////////////////////////////////////////
//
// CPerfStatSqliteTimingImpl::DoPulse
//
//
//
///////////////////////////////////////////////////////////////
void CPerfStatSqliteTimingImpl::DoPulse()
{
    long long llTime = GetTickCount64_();
    // Remove old stats
    while (m_TimingList.size())
    {
        CTimingInfo& info = m_TimingList.front();
        int          iAgeSeconds = static_cast<int>((llTime - info.timeStamp) / 1000);
        if (iAgeSeconds < 2000 && m_TimingList.size() < 1000)
            break;
        m_TimingList.pop_front();
    }
}
Пример #26
0
// Add flood candidate connection attempt and return true if flooding is occurring
bool CConnectHistory::AddConnect ( const string& strIP )
{
    // See if banned first
    if ( IsFlooding ( strIP ) )
        return true;

    // Get history for this IP
    CConnectHistoryItem& historyItem = GetHistoryItem ( strIP );

    // Add time of this allowed connection
    historyItem.joinTimes.push_back ( GetTickCount64_ () );
    return false;
}
Пример #27
0
// Check if IP is currently flooding
bool CConnectHistory::IsFlooding ( const string& strIP )
{
    // Delete the expired entries
    RemoveExpired ();

    // Get history for this IP
    CConnectHistoryItem& historyItem = GetHistoryItem ( strIP );

    // Check if inside ban time
    if ( GetTickCount64_ () < historyItem.llBanEndTime )
        return true;

    // Check if too many connections
    if ( historyItem.joinTimes.size () > m_ulMaxConnections )
    {
        // Begin timed ban
        historyItem.llBanEndTime = GetTickCount64_ () + m_ulBanLength;
        return true;
    }

    return false;
}
Пример #28
0
void CRegistry::BeginAutomaticTransaction ( void )
{
    if ( !m_bInAutomaticTransaction )
    {
        if ( m_llSuspendBatchingEndTime )
        {
            if ( m_llSuspendBatchingEndTime > GetTickCount64_ () )
                return;
            m_llSuspendBatchingEndTime = 0;
        }

        m_bInAutomaticTransaction = true;
        CRegistryResult dummy;
        QueryInternal ( "BEGIN TRANSACTION", &dummy );
    }
}
Пример #29
0
// Is it time to send a pure sync to every other player ?
bool CPlayer::IsTimeForFarSync ( void )
{
    long long llTime = GetTickCount64_ ();
    if ( llTime > m_llNextFarSyncTime )
    {
        int iSlowSyncRate = g_pBandwidthSettings->ZoneUpdateIntervals [ ZONE3 ];
        m_llNextFarSyncTime = llTime + iSlowSyncRate;
        m_llNextFarSyncTime += rand () % ( 1 + iSlowSyncRate / 10 );   // Extra bit to help distribute the load

        // Calc stats
        int iNumPackets = m_FarPlayerList.size ();
        int iNumSkipped = ( iNumPackets * iSlowSyncRate - iNumPackets * 1000 ) / 1000;
        g_pStats->puresync.llSentPacketsByZone [ ZONE3 ] += iNumPackets;
        g_pStats->puresync.llSkippedPacketsByZone [ ZONE3 ] += iNumSkipped;
        return true;
    }
    return false;
}
Пример #30
0
///////////////////////////////////////////////////////////////
//
// CPerfStatSqliteTimingImpl::GetStats
//
//
//
///////////////////////////////////////////////////////////////
void CPerfStatSqliteTimingImpl::GetStats(CPerfStatResult* pResult, const std::map<SString, int>& optionMap, const SString& strFilter)
{
    GetSqliteTimingStats(pResult, optionMap, strFilter);

    uint      uiTicks = 1000 * 10;            // 10 seconds
    long long llTime = GetTickCount64_();

    m_llRecordStatsEndTime = llTime + uiTicks;

    // Update batching setting
    for (std::map<CRegistry*, SString>::iterator iter = m_RegistryMap.begin(); iter != m_RegistryMap.end(); ++iter)
    {
        if (m_bDisableBatching)
            iter->first->SuspendBatching(uiTicks);            // Suspend batching
        else
            iter->first->SuspendBatching(0);            // Unsuspend batching
    }
}