Skip to content

Commit

Permalink
Added ability to add more ASE master servers to announce to
Browse files Browse the repository at this point in the history
  • Loading branch information
ccw808 committed Oct 25, 2015
1 parent ec8db3b commit a0f15cb
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 65 deletions.
2 changes: 1 addition & 1 deletion MTA10/version.h
Expand Up @@ -75,7 +75,7 @@

#define _ASE_VERSION QUOTE_DEFINE(MTASA_VERSION_MAJOR) "." QUOTE_DEFINE(MTASA_VERSION_MINOR)
#define _NETCODE_VERSION_BRANCH_ID 0x4 // Use 0x1 - 0xF to indicate an incompatible branch is being used (0x0 is reserved, 0x4 is trunk)
#define _CLIENT_NET_MODULE_VERSION 0x095 // (0x000 - 0xfff) Lvl9 wizards only
#define _CLIENT_NET_MODULE_VERSION 0x097 // (0x000 - 0xfff) Lvl9 wizards only
#define _NETCODE_VERSION 0x1DA // (0x000 - 0xfff) Increment when net messages change (pre-release)
#define MTA_DM_BITSTREAM_VERSION 0x064 // (0x000 - 0xfff) Increment when net messages change (post-release). (Changing will also require additional backward compatibility code).

Expand Down
4 changes: 2 additions & 2 deletions MTA10_Server/mods/deathmatch/Config.h
Expand Up @@ -149,10 +149,10 @@ class CVaPassNext{
#define MAX_GARAGES 50

// Game-monitor.com query URL (use %u for port input)
#define QUERY_URL_GAME_MONITOR "http://master.game-monitor.com/heartbeat.php?p=%u&e=3"
#define QUERY_URL_GAME_MONITOR "http://master.game-monitor.com/heartbeat.php?p=%ASE%&e=3"

// MTA master server query URL (Inputs: game port, ase port, http port, version, extra, serverip)
#define QUERY_URL_MTA_MASTER_SERVER "http://master.mtasa.com/ase/add.php?g=%u&a=%u&h=%u&v=%s&x=%s&ip=%s"
#define QUERY_URL_MTA_MASTER_SERVER "http://master.mtasa.com/ase/add.php?g=%GAME%&a=%ASE%&h=%HTTP%&v=%VER%&x=%EXTRA%&ip=%IP%"

// MTA port tester URL
#define PORT_TESTER_URL "http://nightly.mtasa.com/ports/"
Expand Down
1 change: 1 addition & 0 deletions MTA10_Server/mods/deathmatch/logic/CGame.h
Expand Up @@ -264,6 +264,7 @@ class CGame
inline CBuildingRemovalManager* GetBuildingRemovalManager ( void ) { return m_pBuildingRemovalManager; }
inline CCustomWeaponManager* GetCustomWeaponManager ( void ) { return m_pCustomWeaponManager; }
inline CFunctionUseLogger* GetFunctionUseLogger ( void ) { return m_pFunctionUseLogger; }
inline CMasterServerAnnouncer* GetMasterServerAnnouncer ( void ) { return m_pMasterServerAnnouncer; }

void JoinPlayer ( CPlayer& Player );
void InitialDataStream ( CPlayer& Player );
Expand Down
4 changes: 3 additions & 1 deletion MTA10_Server/mods/deathmatch/logic/common/CBitStream.h
Expand Up @@ -18,8 +18,9 @@
class CBitStream
{
public:
inline CBitStream ( void ) { pBitStream = g_pNetServer->AllocateNetServerBitStream ( 0 ); };
inline CBitStream ( const void* pData = nullptr, uint uiDataSize = 0, bool bCopyData = false ) { pBitStream = g_pNetServer->AllocateNetServerBitStream ( 0, pData, uiDataSize, bCopyData ); }
inline ~CBitStream ( void ) { g_pNetServer->DeallocateNetServerBitStream ( (NetBitStreamInterface*)pBitStream ); };
NetBitStreamInterfaceNoVersion* operator-> ( void ) { return pBitStream; }

NetBitStreamInterfaceNoVersion* pBitStream;
};
Expand All @@ -30,6 +31,7 @@ class CPlayerBitStream
public:
CPlayerBitStream ( class CPlayer* pPlayer );// { pBitStream = g_pNetServer->AllocateNetServerBitStream ( pPlayer->GetBitStreamVersion() ); };
inline ~CPlayerBitStream ( void ) { g_pNetServer->DeallocateNetServerBitStream ( (NetBitStreamInterface*)pBitStream ); };
NetBitStreamInterface* operator-> ( void ) { return pBitStream; }

NetBitStreamInterface* pBitStream;
};
Expand Down
4 changes: 2 additions & 2 deletions MTA10_Server/mods/deathmatch/logic/net/CNetBuffer.cpp
Expand Up @@ -482,9 +482,9 @@ void CNetServerBuffer::GetPingStatus ( SFixedString < 32 >* pstrStatus )
// Thread safe
//
///////////////////////////////////////////////////////////////////////////
NetBitStreamInterface* CNetServerBuffer::AllocateNetServerBitStream ( unsigned short usBitStreamVersion )
NetBitStreamInterface* CNetServerBuffer::AllocateNetServerBitStream ( unsigned short usBitStreamVersion, const void* pData, uint uiDataSize, bool bCopyData )
{
return m_pRealNetServer->AllocateNetServerBitStream ( usBitStreamVersion );
return m_pRealNetServer->AllocateNetServerBitStream ( usBitStreamVersion, pData, uiDataSize, bCopyData );
}


Expand Down
2 changes: 1 addition & 1 deletion MTA10_Server/mods/deathmatch/logic/net/CNetBuffer.h
Expand Up @@ -76,7 +76,7 @@ class CNetServerBuffer : public CNetServer
virtual void GetPingStatus ( SFixedString < 32 >* pstrStatus );
virtual bool GetSyncThreadStatistics ( SSyncThreadStatistics* pDest, bool bResetCounters );

virtual NetBitStreamInterface* AllocateNetServerBitStream ( unsigned short usBitStreamVersion );
virtual NetBitStreamInterface* AllocateNetServerBitStream ( unsigned short usBitStreamVersion, const void* pData = nullptr, uint uiDataSize = 0, bool bCopyData = false );
virtual void DeallocateNetServerBitStream ( NetBitStreamInterface* bitStream );
virtual bool SendPacket ( unsigned char ucPacketID, const NetServerPlayerID& playerID, NetBitStreamInterface* bitStream, bool bBroadcast, NetServerPacketPriority packetPriority, NetServerPacketReliability packetReliability, ePacketOrdering packetOrdering = PACKET_ORDERING_DEFAULT );

Expand Down
122 changes: 79 additions & 43 deletions MTA10_Server/mods/deathmatch/utils/CHqComms.h
Expand Up @@ -43,25 +43,26 @@ class CHqComms : public CRefCountable
m_CheckTimer.Reset();
m_Stage = HQCOMMS_STAGE_QUERY;

SString strUrlParams;
strUrlParams += SString( "?ip=%s", *g_pGame->GetConfig()->GetServerIP() );
strUrlParams += SString( "&gport=%d", g_pGame->GetConfig()->GetServerPort() );
strUrlParams += SString( "&version=%s", *CStaticFunctionDefinitions::GetVersionSortable() );
strUrlParams += SString( "&minclientautoupdate=%d", g_pGame->GetConfig()->GetMinClientVersionAutoUpdate() );
strUrlParams += SString( "&minclientversion=%s", *g_pGame->GetConfig()->GetMinClientVersion() );
strUrlParams += SString( "&badscriptrev=%d", m_iPrevBadFileHashesRev );
strUrlParams += SString( "&maxplayers=%d", g_pGame->GetConfig()->GetHardMaxPlayers() );
strUrlParams += SString( "&numplayers=%d", g_pGame->GetPlayerManager()->Count() );
strUrlParams += SString( "&asepush=%d", g_pGame->GetConfig()->GetAseInternetPushEnabled() );
strUrlParams += SString( "&aselisten=%d", g_pGame->GetConfig()->GetAseInternetListenEnabled() );
CBitStream bitStream;
bitStream->Write( (char)1 );
bitStream->WriteStr( g_pGame->GetConfig()->GetServerIP() );
bitStream->Write( g_pGame->GetConfig()->GetServerPort() );
bitStream->WriteStr( CStaticFunctionDefinitions::GetVersionSortable() );
bitStream->Write( g_pGame->GetConfig()->GetMinClientVersionAutoUpdate() );
bitStream->WriteStr( g_pGame->GetConfig()->GetMinClientVersion() );
bitStream->Write( m_iPrevBadFileHashesRev );
bitStream->Write( g_pGame->GetConfig()->GetHardMaxPlayers() );
bitStream->Write( g_pGame->GetPlayerManager()->Count() );
bitStream->Write( g_pGame->GetConfig()->GetAseInternetPushEnabled() ? 1 : 0 );
bitStream->Write( g_pGame->GetConfig()->GetAseInternetListenEnabled() ? 1 : 0 );

SString strCrashInfo;
FileLoad( m_strCrashInfoFilename, strCrashInfo, 50000 );
strUrlParams += SString( "&crashinfosize=%d", strCrashInfo.length() );
bitStream->WriteStr( strCrashInfo );

// Send request
this->AddRef(); // Keep object alive
GetDownloadManager()->QueueFile( m_strURL + strUrlParams, NULL, 0, strCrashInfo, strCrashInfo.length(), true, this, StaticProgressCallback, false, 1 );
GetDownloadManager()->QueueFile( m_strURL, NULL, 0, (const char*)bitStream->GetData(), bitStream->GetNumberOfBytesUsed(), true, this, StaticProgressCallback, false, 1 );
}
}

Expand All @@ -85,15 +86,15 @@ class CHqComms : public CRefCountable
if ( bComplete )
{
m_Stage = HQCOMMS_STAGE_TIMER;
CArgMap argMap;
argMap.SetFromString( data );
CBitStream bitStream( data, dataLength );

// Process various parts of returned data
ProcessPollInterval( argMap );
ProcessMinClientVersion( argMap );
ProcessMessage( argMap );
ProcessBadFileHashes( argMap );
ProcessCrashInfo( argMap );
ProcessPollInterval( bitStream );
ProcessMinClientVersion( bitStream );
ProcessMessage( bitStream );
ProcessBadFileHashes( bitStream );
ProcessCrashInfo( bitStream );
ProcessAseServers( bitStream );
}
else
if ( iError )
Expand All @@ -103,20 +104,22 @@ class CHqComms : public CRefCountable
}

// Interval until next HQ check
void ProcessPollInterval( const CArgMap& argMap )
void ProcessPollInterval( CBitStream& bitStream )
{
int iPollInterval;
argMap.Get( "PollInterval", iPollInterval, m_iPollInterval );
int iPollInterval = 0;
bitStream->Read( iPollInterval );
if ( iPollInterval )
m_iPollInterval = Max( TICKS_FROM_MINUTES( 5 ), iPollInterval );
}

// Auto update of min client check
void ProcessMinClientVersion( const CArgMap& argMap )
void ProcessMinClientVersion( CBitStream& bitStream )
{
int iForceSetting;
argMap.Get( "ForceMinClientVersion", iForceSetting );
SString strResultMinClientVersion = argMap.Get( "AutoMinClientVersion" );
int iForceSetting = 0;
SString strResultMinClientVersion;

bitStream->Read( iForceSetting );
bitStream->ReadStr( strResultMinClientVersion );
SString strSetttingsMinClientVersion = g_pGame->GetConfig ()->GetMinClientVersion();
if ( strResultMinClientVersion > strSetttingsMinClientVersion || iForceSetting )
{
Expand All @@ -125,11 +128,13 @@ class CHqComms : public CRefCountable
}

// Messsage for this server from HQ
void ProcessMessage( const CArgMap& argMap )
void ProcessMessage( CBitStream& bitStream )
{
int iMessageAlwaysPrint;
argMap.Get( "MessageAlwaysPrint", iMessageAlwaysPrint );
SString strMessage = argMap.Get( "Message" );
int iMessageAlwaysPrint = 0;
SString strMessage;

bitStream->Read( iMessageAlwaysPrint );
bitStream->ReadStr( strMessage );
if ( !strMessage.empty() && ( strMessage != m_strPrevMessage || iMessageAlwaysPrint ) )
{
m_strPrevMessage = strMessage;
Expand All @@ -138,37 +143,68 @@ class CHqComms : public CRefCountable
}

// Block script hashes
void ProcessBadFileHashes( const CArgMap& argMap )
void ProcessBadFileHashes( CBitStream& bitStream )
{
int iBadFileHashesRev;
argMap.Get( "BadFileHashesRev", iBadFileHashesRev );
int iBadFileHashesRev = 0;
uint uiNumHashes = 0;
struct SHashItem { SString strHash, strReason; };
std::vector < SHashItem > itemList;

bitStream->Read( iBadFileHashesRev );
bitStream->Read( uiNumHashes );
for( uint i = 0 ; i < uiNumHashes ; i++ )
{
SString strHash, strReason;
bitStream->ReadStr( strHash );
if ( !bitStream->ReadStr( strReason ) )
break;
itemList.push_back( { strHash, strReason } );
}

if ( iBadFileHashesRev && ( iBadFileHashesRev == 1 || iBadFileHashesRev != m_iPrevBadFileHashesRev ) )
{
m_iPrevBadFileHashesRev = iBadFileHashesRev;
g_pGame->GetResourceManager()->ClearBlockedFileReason( "" );
std::vector < SString > itemList;
argMap.Get( "BadFileHashes" ).Split( ",", itemList );
for ( uint i = 0 ; i < itemList.size() ; i++ )
for ( auto item : itemList )
{
SString strHash, strReason;
itemList[i].Split( "|", &strHash, &strReason );
g_pGame->GetResourceManager()->AddBlockedFileReason( strHash, strReason );
g_pGame->GetResourceManager()->AddBlockedFileReason( item.strHash, item.strReason );
}
g_pGame->GetResourceManager()->SaveBlockedFileReasons();
}
}

// Got crashinfo recpt
void ProcessCrashInfo( const CArgMap& argMap )
void ProcessCrashInfo( CBitStream& bitStream )
{
int iGotCrashInfo;
argMap.Get( "GotCrashInfo", iGotCrashInfo );
int iGotCrashInfo = 0;
bitStream->Read( iGotCrashInfo );
if ( iGotCrashInfo )
{
FileDelete( m_strCrashInfoFilename );
}
}

// Extra ASE servers
void ProcessAseServers( CBitStream& bitStream )
{
uint uiNumServers = 0;
bitStream->Read( uiNumServers );
for( uint i = 0 ; i < uiNumServers ; i++ )
{
char bAcceptsPush, bDoReminders, bHideProblems;
uint uiReminderIntervalMins;
SString strDesc, strUrl;
bitStream->Read( bAcceptsPush );
bitStream->Read( bDoReminders );
bitStream->Read( bHideProblems );
bitStream->Read( uiReminderIntervalMins );
bitStream->ReadStr( strDesc );
if ( !bitStream->ReadStr( strUrl ) )
break;
g_pGame->GetMasterServerAnnouncer()->AddServer( bAcceptsPush != 0, bDoReminders != 0, bHideProblems != 0, Max( 5U, uiReminderIntervalMins ), strDesc, strUrl );
}
}


//
// Get http downloader used for hq comms etc.
Expand Down
41 changes: 28 additions & 13 deletions MTA10_Server/mods/deathmatch/utils/CMasterServerAnnouncer.h
Expand Up @@ -13,6 +13,7 @@ struct SMasterServerDefinition
bool bAcceptsPush;
bool bDoReminders;
bool bHideProblems;
uint uiReminderIntervalMins;
SString strDesc;
SString strURL;
};
Expand Down Expand Up @@ -41,7 +42,6 @@ class CMasterServer : public CRefCountable
m_Stage = ANNOUNCE_STAGE_INITIAL;
m_uiInitialAnnounceRetryAttempts = 5;
m_uiInitialAnnounceRetryInterval = 1000 * 60 * 5; // 5 mins initial announce retry interval
m_uiReminderAnnounceInterval = 1000 * 60 * 60 * 24; // 24 hrs reminder announce interval
m_uiPushInterval = 1000 * 60 * 10; // 10 mins push interval
}

Expand All @@ -67,7 +67,7 @@ class CMasterServer : public CRefCountable
bIsTimeForAnnounce = true;
if ( m_Stage == ANNOUNCE_STAGE_INITIAL_RETRY && m_Definition.bDoReminders && llTickCountNow - m_llLastAnnounceTime > m_uiInitialAnnounceRetryInterval )
bIsTimeForAnnounce = true;
if ( m_Stage == ANNOUNCE_STAGE_REMINDER && m_Definition.bDoReminders && llTickCountNow - m_llLastAnnounceTime > m_uiReminderAnnounceInterval )
if ( m_Stage == ANNOUNCE_STAGE_REMINDER && m_Definition.bDoReminders && llTickCountNow - m_llLastAnnounceTime > TICKS_FROM_MINUTES( m_Definition.uiReminderIntervalMins ) )
bIsTimeForAnnounce = true;

if ( bIsTimeForAnnounce )
Expand Down Expand Up @@ -173,6 +173,11 @@ class CMasterServer : public CRefCountable
}
}

const SMasterServerDefinition& GetDefinition( void ) const
{
return m_Definition;
}

//
// Get http downloader used for master server comms etc.
//
Expand All @@ -186,7 +191,6 @@ class CMasterServer : public CRefCountable
uint m_Stage;
uint m_uiInitialAnnounceRetryAttempts;
uint m_uiInitialAnnounceRetryInterval;
uint m_uiReminderAnnounceInterval;
uint m_uiPushInterval;
long long m_llLastAnnounceTime;
long long m_llLastPushTime;
Expand Down Expand Up @@ -219,29 +223,40 @@ class CMasterServerAnnouncer
void InitServerList( void )
{
assert( m_MasterServerList.empty() );
AddServer( true, true, false, 60 * 24, "Querying MTA master server...", QUERY_URL_MTA_MASTER_SERVER );
}

void AddServer( bool bAcceptsPush, bool bDoReminders, bool bHideProblems, uint uiReminderIntervalMins, const SString& strDesc, const SString& strInUrl )
{
// Check if server is already present
for( auto pMasterServer : m_MasterServerList )
{
if ( pMasterServer->GetDefinition().strURL.BeginsWithI( strInUrl.SplitLeft( "%" ) ) )
return;
}

CMainConfig* pMainConfig = g_pGame->GetConfig();
SString strServerIP = pMainConfig->GetServerIP();
ushort usServerPort = pMainConfig->GetServerPort();
ushort usHTTPPort = pMainConfig->GetHTTPPort();
uint uiPlayerCount = g_pGame->GetPlayerManager()->Count ();
uint uiMaxPlayerCount = pMainConfig->GetMaxPlayers();
bool bPassworded = pMainConfig->HasPassword();
SString strAseMode = pMainConfig->GetSetting( "ase" );
bool bAseLanListen = pMainConfig->GetAseLanListenEnabled();

SString strVersion( "%d.%d.%d-%d.%05d", MTASA_VERSION_MAJOR, MTASA_VERSION_MINOR, MTASA_VERSION_MAINTENANCE, MTASA_VERSION_TYPE, MTASA_VERSION_BUILD );
SString strExtra( "%d_%d_%d_%s_%d", uiPlayerCount, uiMaxPlayerCount, bPassworded, *strAseMode, bAseLanListen );
SString strExtra( "%d_%d_%d_%s_%d", 0, uiMaxPlayerCount, bPassworded, *strAseMode, bAseLanListen );

SMasterServerDefinition masterServerDefinitionList[] = {
// Gone away { false, false, true, "Querying game-monitor.com master server...", SString( QUERY_URL_GAME_MONITOR, usServerPort + 123 ) },
{ true, true, false, "Querying MTA master server...", SString( QUERY_URL_MTA_MASTER_SERVER, usServerPort, usServerPort + 123, usHTTPPort, *strVersion, *strExtra, *strServerIP ) },
};
SString strUrl = strInUrl;
strUrl = strUrl.Replace( "%GAME%", SString( "%u", usServerPort ) );
strUrl = strUrl.Replace( "%ASE%", SString( "%u", usServerPort + 123 ) );
strUrl = strUrl.Replace( "%HTTP%", SString( "%u", usHTTPPort ) );
strUrl = strUrl.Replace( "%VER%", strVersion );
strUrl = strUrl.Replace( "%EXTRA%", strExtra );
strUrl = strUrl.Replace( "%IP%", strServerIP );

for ( uint i = 0 ; i < NUMELMS( masterServerDefinitionList ) ; i++ )
{
m_MasterServerList.push_back( new CMasterServer( masterServerDefinitionList[i] ) );
}
SMasterServerDefinition masterServerDefinition = { bAcceptsPush, bDoReminders, bHideProblems, uiReminderIntervalMins, strDesc, strUrl };
m_MasterServerList.push_back( new CMasterServer( masterServerDefinition ) );
}

//
Expand Down
2 changes: 1 addition & 1 deletion MTA10_Server/sdk/net/CNetServer.h
Expand Up @@ -112,7 +112,7 @@ class CNetServer
virtual void GetPingStatus ( SFixedString < 32 >* pstrStatus ) = 0;
virtual bool GetSyncThreadStatistics ( SSyncThreadStatistics* pDest, bool bResetCounters ) = 0;

virtual NetBitStreamInterface* AllocateNetServerBitStream ( unsigned short usBitStreamVersion ) = 0;
virtual NetBitStreamInterface* AllocateNetServerBitStream ( unsigned short usBitStreamVersion, const void* pData = nullptr, uint uiDataSize = 0, bool bCopyData = false ) = 0;
virtual void DeallocateNetServerBitStream ( NetBitStreamInterface* bitStream ) = 0;
virtual bool SendPacket ( unsigned char ucPacketID, const NetServerPlayerID& playerID, NetBitStreamInterface* bitStream, bool bBroadcast, NetServerPacketPriority packetPriority, NetServerPacketReliability packetReliability, ePacketOrdering packetOrdering = PACKET_ORDERING_DEFAULT ) = 0;

Expand Down

0 comments on commit a0f15cb

Please sign in to comment.