Skip to content

Commit 51b412e

Browse files
committed
Added ability to add more ASE master servers to announce to
1 parent f6afb35 commit 51b412e

File tree

11 files changed

+121
-65
lines changed

11 files changed

+121
-65
lines changed

MTA10/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575

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

MTA10_Server/mods/deathmatch/Config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ class CVaPassNext{
149149
#define MAX_GARAGES 50
150150

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

154154
// MTA master server query URL (Inputs: game port, ase port, http port, version, extra, serverip)
155-
#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"
155+
#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%"
156156

157157
// MTA port tester URL
158158
#define PORT_TESTER_URL "http://nightly.mtasa.com/ports/"

MTA10_Server/mods/deathmatch/logic/CGame.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ class CGame
264264
inline CBuildingRemovalManager* GetBuildingRemovalManager ( void ) { return m_pBuildingRemovalManager; }
265265
inline CCustomWeaponManager* GetCustomWeaponManager ( void ) { return m_pCustomWeaponManager; }
266266
inline CFunctionUseLogger* GetFunctionUseLogger ( void ) { return m_pFunctionUseLogger; }
267+
inline CMasterServerAnnouncer* GetMasterServerAnnouncer ( void ) { return m_pMasterServerAnnouncer; }
267268

268269
void JoinPlayer ( CPlayer& Player );
269270
void InitialDataStream ( CPlayer& Player );

MTA10_Server/mods/deathmatch/logic/common/CBitStream.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
class CBitStream
1919
{
2020
public:
21-
inline CBitStream ( void ) { pBitStream = g_pNetServer->AllocateNetServerBitStream ( 0 ); };
21+
inline CBitStream ( const void* pData = nullptr, uint uiDataSize = 0, bool bCopyData = false ) { pBitStream = g_pNetServer->AllocateNetServerBitStream ( 0, pData, uiDataSize, bCopyData ); }
2222
inline ~CBitStream ( void ) { g_pNetServer->DeallocateNetServerBitStream ( (NetBitStreamInterface*)pBitStream ); };
23+
NetBitStreamInterfaceNoVersion* operator-> ( void ) { return pBitStream; }
2324

2425
NetBitStreamInterfaceNoVersion* pBitStream;
2526
};
@@ -30,6 +31,7 @@ class CPlayerBitStream
3031
public:
3132
CPlayerBitStream ( class CPlayer* pPlayer );// { pBitStream = g_pNetServer->AllocateNetServerBitStream ( pPlayer->GetBitStreamVersion() ); };
3233
inline ~CPlayerBitStream ( void ) { g_pNetServer->DeallocateNetServerBitStream ( (NetBitStreamInterface*)pBitStream ); };
34+
NetBitStreamInterface* operator-> ( void ) { return pBitStream; }
3335

3436
NetBitStreamInterface* pBitStream;
3537
};

MTA10_Server/mods/deathmatch/logic/net/CNetBuffer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,9 +482,9 @@ void CNetServerBuffer::GetPingStatus ( SFixedString < 32 >* pstrStatus )
482482
// Thread safe
483483
//
484484
///////////////////////////////////////////////////////////////////////////
485-
NetBitStreamInterface* CNetServerBuffer::AllocateNetServerBitStream ( unsigned short usBitStreamVersion )
485+
NetBitStreamInterface* CNetServerBuffer::AllocateNetServerBitStream ( unsigned short usBitStreamVersion, const void* pData, uint uiDataSize, bool bCopyData )
486486
{
487-
return m_pRealNetServer->AllocateNetServerBitStream ( usBitStreamVersion );
487+
return m_pRealNetServer->AllocateNetServerBitStream ( usBitStreamVersion, pData, uiDataSize, bCopyData );
488488
}
489489

490490

MTA10_Server/mods/deathmatch/logic/net/CNetBuffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class CNetServerBuffer : public CNetServer
7676
virtual void GetPingStatus ( SFixedString < 32 >* pstrStatus );
7777
virtual bool GetSyncThreadStatistics ( SSyncThreadStatistics* pDest, bool bResetCounters );
7878

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

MTA10_Server/mods/deathmatch/utils/CHqComms.h

Lines changed: 79 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,26 @@ class CHqComms : public CRefCountable
4343
m_CheckTimer.Reset();
4444
m_Stage = HQCOMMS_STAGE_QUERY;
4545

46-
SString strUrlParams;
47-
strUrlParams += SString( "?ip=%s", *g_pGame->GetConfig()->GetServerIP() );
48-
strUrlParams += SString( "&gport=%d", g_pGame->GetConfig()->GetServerPort() );
49-
strUrlParams += SString( "&version=%s", *CStaticFunctionDefinitions::GetVersionSortable() );
50-
strUrlParams += SString( "&minclientautoupdate=%d", g_pGame->GetConfig()->GetMinClientVersionAutoUpdate() );
51-
strUrlParams += SString( "&minclientversion=%s", *g_pGame->GetConfig()->GetMinClientVersion() );
52-
strUrlParams += SString( "&badscriptrev=%d", m_iPrevBadFileHashesRev );
53-
strUrlParams += SString( "&maxplayers=%d", g_pGame->GetConfig()->GetHardMaxPlayers() );
54-
strUrlParams += SString( "&numplayers=%d", g_pGame->GetPlayerManager()->Count() );
55-
strUrlParams += SString( "&asepush=%d", g_pGame->GetConfig()->GetAseInternetPushEnabled() );
56-
strUrlParams += SString( "&aselisten=%d", g_pGame->GetConfig()->GetAseInternetListenEnabled() );
46+
CBitStream bitStream;
47+
bitStream->Write( (char)1 );
48+
bitStream->WriteStr( g_pGame->GetConfig()->GetServerIP() );
49+
bitStream->Write( g_pGame->GetConfig()->GetServerPort() );
50+
bitStream->WriteStr( CStaticFunctionDefinitions::GetVersionSortable() );
51+
bitStream->Write( g_pGame->GetConfig()->GetMinClientVersionAutoUpdate() );
52+
bitStream->WriteStr( g_pGame->GetConfig()->GetMinClientVersion() );
53+
bitStream->Write( m_iPrevBadFileHashesRev );
54+
bitStream->Write( g_pGame->GetConfig()->GetHardMaxPlayers() );
55+
bitStream->Write( g_pGame->GetPlayerManager()->Count() );
56+
bitStream->Write( g_pGame->GetConfig()->GetAseInternetPushEnabled() ? 1 : 0 );
57+
bitStream->Write( g_pGame->GetConfig()->GetAseInternetListenEnabled() ? 1 : 0 );
5758

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

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

@@ -85,15 +86,15 @@ class CHqComms : public CRefCountable
8586
if ( bComplete )
8687
{
8788
m_Stage = HQCOMMS_STAGE_TIMER;
88-
CArgMap argMap;
89-
argMap.SetFromString( data );
89+
CBitStream bitStream( data, dataLength );
9090

9191
// Process various parts of returned data
92-
ProcessPollInterval( argMap );
93-
ProcessMinClientVersion( argMap );
94-
ProcessMessage( argMap );
95-
ProcessBadFileHashes( argMap );
96-
ProcessCrashInfo( argMap );
92+
ProcessPollInterval( bitStream );
93+
ProcessMinClientVersion( bitStream );
94+
ProcessMessage( bitStream );
95+
ProcessBadFileHashes( bitStream );
96+
ProcessCrashInfo( bitStream );
97+
ProcessAseServers( bitStream );
9798
}
9899
else
99100
if ( iError )
@@ -103,20 +104,22 @@ class CHqComms : public CRefCountable
103104
}
104105

105106
// Interval until next HQ check
106-
void ProcessPollInterval( const CArgMap& argMap )
107+
void ProcessPollInterval( CBitStream& bitStream )
107108
{
108-
int iPollInterval;
109-
argMap.Get( "PollInterval", iPollInterval, m_iPollInterval );
109+
int iPollInterval = 0;
110+
bitStream->Read( iPollInterval );
110111
if ( iPollInterval )
111112
m_iPollInterval = Max( TICKS_FROM_MINUTES( 5 ), iPollInterval );
112113
}
113114

114115
// Auto update of min client check
115-
void ProcessMinClientVersion( const CArgMap& argMap )
116+
void ProcessMinClientVersion( CBitStream& bitStream )
116117
{
117-
int iForceSetting;
118-
argMap.Get( "ForceMinClientVersion", iForceSetting );
119-
SString strResultMinClientVersion = argMap.Get( "AutoMinClientVersion" );
118+
int iForceSetting = 0;
119+
SString strResultMinClientVersion;
120+
121+
bitStream->Read( iForceSetting );
122+
bitStream->ReadStr( strResultMinClientVersion );
120123
SString strSetttingsMinClientVersion = g_pGame->GetConfig ()->GetMinClientVersion();
121124
if ( strResultMinClientVersion > strSetttingsMinClientVersion || iForceSetting )
122125
{
@@ -125,11 +128,13 @@ class CHqComms : public CRefCountable
125128
}
126129

127130
// Messsage for this server from HQ
128-
void ProcessMessage( const CArgMap& argMap )
131+
void ProcessMessage( CBitStream& bitStream )
129132
{
130-
int iMessageAlwaysPrint;
131-
argMap.Get( "MessageAlwaysPrint", iMessageAlwaysPrint );
132-
SString strMessage = argMap.Get( "Message" );
133+
int iMessageAlwaysPrint = 0;
134+
SString strMessage;
135+
136+
bitStream->Read( iMessageAlwaysPrint );
137+
bitStream->ReadStr( strMessage );
133138
if ( !strMessage.empty() && ( strMessage != m_strPrevMessage || iMessageAlwaysPrint ) )
134139
{
135140
m_strPrevMessage = strMessage;
@@ -138,37 +143,68 @@ class CHqComms : public CRefCountable
138143
}
139144

140145
// Block script hashes
141-
void ProcessBadFileHashes( const CArgMap& argMap )
146+
void ProcessBadFileHashes( CBitStream& bitStream )
142147
{
143-
int iBadFileHashesRev;
144-
argMap.Get( "BadFileHashesRev", iBadFileHashesRev );
148+
int iBadFileHashesRev = 0;
149+
uint uiNumHashes = 0;
150+
struct SHashItem { SString strHash, strReason; };
151+
std::vector < SHashItem > itemList;
152+
153+
bitStream->Read( iBadFileHashesRev );
154+
bitStream->Read( uiNumHashes );
155+
for( uint i = 0 ; i < uiNumHashes ; i++ )
156+
{
157+
SString strHash, strReason;
158+
bitStream->ReadStr( strHash );
159+
if ( !bitStream->ReadStr( strReason ) )
160+
break;
161+
itemList.push_back( { strHash, strReason } );
162+
}
163+
145164
if ( iBadFileHashesRev && ( iBadFileHashesRev == 1 || iBadFileHashesRev != m_iPrevBadFileHashesRev ) )
146165
{
147166
m_iPrevBadFileHashesRev = iBadFileHashesRev;
148167
g_pGame->GetResourceManager()->ClearBlockedFileReason( "" );
149-
std::vector < SString > itemList;
150-
argMap.Get( "BadFileHashes" ).Split( ",", itemList );
151-
for ( uint i = 0 ; i < itemList.size() ; i++ )
168+
for ( auto item : itemList )
152169
{
153-
SString strHash, strReason;
154-
itemList[i].Split( "|", &strHash, &strReason );
155-
g_pGame->GetResourceManager()->AddBlockedFileReason( strHash, strReason );
170+
g_pGame->GetResourceManager()->AddBlockedFileReason( item.strHash, item.strReason );
156171
}
157172
g_pGame->GetResourceManager()->SaveBlockedFileReasons();
158173
}
159174
}
160175

161176
// Got crashinfo recpt
162-
void ProcessCrashInfo( const CArgMap& argMap )
177+
void ProcessCrashInfo( CBitStream& bitStream )
163178
{
164-
int iGotCrashInfo;
165-
argMap.Get( "GotCrashInfo", iGotCrashInfo );
179+
int iGotCrashInfo = 0;
180+
bitStream->Read( iGotCrashInfo );
166181
if ( iGotCrashInfo )
167182
{
168183
FileDelete( m_strCrashInfoFilename );
169184
}
170185
}
171186

187+
// Extra ASE servers
188+
void ProcessAseServers( CBitStream& bitStream )
189+
{
190+
uint uiNumServers = 0;
191+
bitStream->Read( uiNumServers );
192+
for( uint i = 0 ; i < uiNumServers ; i++ )
193+
{
194+
char bAcceptsPush, bDoReminders, bHideProblems;
195+
uint uiReminderIntervalMins;
196+
SString strDesc, strUrl;
197+
bitStream->Read( bAcceptsPush );
198+
bitStream->Read( bDoReminders );
199+
bitStream->Read( bHideProblems );
200+
bitStream->Read( uiReminderIntervalMins );
201+
bitStream->ReadStr( strDesc );
202+
if ( !bitStream->ReadStr( strUrl ) )
203+
break;
204+
g_pGame->GetMasterServerAnnouncer()->AddServer( bAcceptsPush != 0, bDoReminders != 0, bHideProblems != 0, Max( 5U, uiReminderIntervalMins ), strDesc, strUrl );
205+
}
206+
}
207+
172208

173209
//
174210
// Get http downloader used for hq comms etc.

MTA10_Server/mods/deathmatch/utils/CMasterServerAnnouncer.h

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct SMasterServerDefinition
1313
bool bAcceptsPush;
1414
bool bDoReminders;
1515
bool bHideProblems;
16+
uint uiReminderIntervalMins;
1617
SString strDesc;
1718
SString strURL;
1819
};
@@ -41,7 +42,6 @@ class CMasterServer : public CRefCountable
4142
m_Stage = ANNOUNCE_STAGE_INITIAL;
4243
m_uiInitialAnnounceRetryAttempts = 5;
4344
m_uiInitialAnnounceRetryInterval = 1000 * 60 * 5; // 5 mins initial announce retry interval
44-
m_uiReminderAnnounceInterval = 1000 * 60 * 60 * 24; // 24 hrs reminder announce interval
4545
m_uiPushInterval = 1000 * 60 * 10; // 10 mins push interval
4646
}
4747

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

7373
if ( bIsTimeForAnnounce )
@@ -173,6 +173,11 @@ class CMasterServer : public CRefCountable
173173
}
174174
}
175175

176+
const SMasterServerDefinition& GetDefinition( void ) const
177+
{
178+
return m_Definition;
179+
}
180+
176181
//
177182
// Get http downloader used for master server comms etc.
178183
//
@@ -186,7 +191,6 @@ class CMasterServer : public CRefCountable
186191
uint m_Stage;
187192
uint m_uiInitialAnnounceRetryAttempts;
188193
uint m_uiInitialAnnounceRetryInterval;
189-
uint m_uiReminderAnnounceInterval;
190194
uint m_uiPushInterval;
191195
long long m_llLastAnnounceTime;
192196
long long m_llLastPushTime;
@@ -219,29 +223,40 @@ class CMasterServerAnnouncer
219223
void InitServerList( void )
220224
{
221225
assert( m_MasterServerList.empty() );
226+
AddServer( true, true, false, 60 * 24, "Querying MTA master server...", QUERY_URL_MTA_MASTER_SERVER );
227+
}
228+
229+
void AddServer( bool bAcceptsPush, bool bDoReminders, bool bHideProblems, uint uiReminderIntervalMins, const SString& strDesc, const SString& strInUrl )
230+
{
231+
// Check if server is already present
232+
for( auto pMasterServer : m_MasterServerList )
233+
{
234+
if ( pMasterServer->GetDefinition().strURL.BeginsWithI( strInUrl.SplitLeft( "%" ) ) )
235+
return;
236+
}
222237

223238
CMainConfig* pMainConfig = g_pGame->GetConfig();
224239
SString strServerIP = pMainConfig->GetServerIP();
225240
ushort usServerPort = pMainConfig->GetServerPort();
226241
ushort usHTTPPort = pMainConfig->GetHTTPPort();
227-
uint uiPlayerCount = g_pGame->GetPlayerManager()->Count ();
228242
uint uiMaxPlayerCount = pMainConfig->GetMaxPlayers();
229243
bool bPassworded = pMainConfig->HasPassword();
230244
SString strAseMode = pMainConfig->GetSetting( "ase" );
231245
bool bAseLanListen = pMainConfig->GetAseLanListenEnabled();
232246

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

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

241-
for ( uint i = 0 ; i < NUMELMS( masterServerDefinitionList ) ; i++ )
242-
{
243-
m_MasterServerList.push_back( new CMasterServer( masterServerDefinitionList[i] ) );
244-
}
258+
SMasterServerDefinition masterServerDefinition = { bAcceptsPush, bDoReminders, bHideProblems, uiReminderIntervalMins, strDesc, strUrl };
259+
m_MasterServerList.push_back( new CMasterServer( masterServerDefinition ) );
245260
}
246261

247262
//

MTA10_Server/sdk/net/CNetServer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class CNetServer
112112
virtual void GetPingStatus ( SFixedString < 32 >* pstrStatus ) = 0;
113113
virtual bool GetSyncThreadStatistics ( SSyncThreadStatistics* pDest, bool bResetCounters ) = 0;
114114

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

0 commit comments

Comments
 (0)