void ASE::DoPulse ( void ) { sockaddr_in SockAddr; #ifndef WIN32 socklen_t nLen = sizeof ( sockaddr ); #else int nLen = sizeof ( sockaddr ); #endif char szBuffer[2]; int iBuffer = 0; // We set the socket to non-blocking so we can just keep reading iBuffer = recvfrom ( m_Socket, szBuffer, 1, 0, (sockaddr*)&SockAddr, &nLen ); if ( iBuffer > 0 ) { std::string strReply; switch ( szBuffer[0] ) { case 's': { // ASE protocol query strReply = QueryFull (); break; } case 'b': { // Our own lighter query for ingame browser strReply = QueryLight (); break; } case 'r': { // Our own lighter query for ingame browser - Release version only strReply = QueryLight (); break; } case 'v': { // MTA Version (For further possibilities to quick ping, in case we do multiply master servers) strReply = MTA_DM_ASE_VERSION; break; } default: return; } // If our reply buffer isn't empty, send it if ( !strReply.empty() ) { /*int sent =*/ sendto ( m_Socket, strReply.c_str(), strReply.length(), 0, (sockaddr*)&SockAddr, nLen ); } } }
// 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 ) { if ( m_uiCurrentPlayerCount != m_uiLightLastPlayerCount || m_llCurrentTime - m_llLightLastTime > m_lLightMinInterval || m_strLightCached == "" ) { m_strLightCached = QueryLight (); m_llLightLastTime = m_llCurrentTime; m_uiLightLastPlayerCount = m_uiCurrentPlayerCount; } return &m_strLightCached; }
// 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; }