@@ -33,6 +33,14 @@ ASE::ASE ( CMainConfig* pMainConfig, CPlayerManager* pPlayerManager, unsigned sh
33
33
m_pMainConfig = pMainConfig;
34
34
m_pPlayerManager = pPlayerManager;
35
35
36
+ m_uiFullLastPlayerCount = 0 ;
37
+ m_llFullLastTime = 0 ;
38
+ m_lFullMinInterval = 10 * 1000 ; // Update full query cache after 10 seconds
39
+
40
+ m_uiLightLastPlayerCount = 0 ;
41
+ m_llLightLastTime = 0 ;
42
+ m_lLightMinInterval = 10 * 1000 ; // Update light query cache after 10 seconds
43
+
36
44
m_strGameType = " MTA:SA" ;
37
45
m_strMapName = " None" ;
38
46
if ( szServerIP )
@@ -107,17 +115,17 @@ void ASE::DoPulse ( void )
107
115
{
108
116
case ' s' :
109
117
{ // ASE protocol query
110
- strReply = QueryFull ();
118
+ strReply = QueryFullCached ();
111
119
break ;
112
120
}
113
121
case ' b' :
114
122
{ // Our own lighter query for ingame browser
115
- strReply = QueryLight ();
123
+ strReply = QueryLightCached ();
116
124
break ;
117
125
}
118
126
case ' r' :
119
127
{ // Our own lighter query for ingame browser - Release version only
120
- strReply = QueryLight ();
128
+ strReply = QueryLightCached ();
121
129
break ;
122
130
}
123
131
case ' v' :
@@ -143,6 +151,22 @@ void ASE::DoPulse ( void )
143
151
}
144
152
145
153
154
+ // Protect against a flood of server queries.
155
+ // Send cached version unless player count has changed, or last re-cache is older than m_lFullMinInterval
156
+ const std::string& ASE::QueryFullCached ( void )
157
+ {
158
+ long long llTime = GetTickCount64_ ();
159
+ unsigned int uiPlayerCount = m_pPlayerManager->CountJoined ();
160
+ if ( uiPlayerCount != m_uiFullLastPlayerCount || llTime - m_llFullLastTime > m_lFullMinInterval || m_strFullCached == " " )
161
+ {
162
+ m_strFullCached = QueryFull ();
163
+ m_llFullLastTime = llTime;
164
+ m_uiFullLastPlayerCount = uiPlayerCount;
165
+ }
166
+ return m_strFullCached;
167
+ }
168
+
169
+
146
170
std::string ASE::QueryFull ( void )
147
171
{
148
172
std::stringstream reply;
@@ -225,8 +249,10 @@ std::string ASE::QueryFull ( void )
225
249
reply << ( unsigned char ) 1 ;
226
250
// skin (skip)
227
251
reply << ( unsigned char ) 1 ;
228
- // score (skip)
229
- reply << ( unsigned char ) 1 ;
252
+ // score
253
+ const std::string& strScore = pPlayer->GetAnnounceValue ( " Score" );
254
+ reply << ( unsigned char ) ( strScore.length () + 1 );
255
+ reply << strScore.c_str ();
230
256
// ping
231
257
_snprintf ( szTemp, 255 , " %u" , pPlayer->GetPing () );
232
258
reply << ( unsigned char ) ( strlen ( szTemp ) + 1 );
@@ -240,6 +266,22 @@ std::string ASE::QueryFull ( void )
240
266
}
241
267
242
268
269
+ // Protect against a flood of server queries.
270
+ // Send cached version unless player count has changed, or last re-cache is older than m_lLightMinInterval
271
+ const std::string& ASE::QueryLightCached ( void )
272
+ {
273
+ long long llTime = GetTickCount64_ ();
274
+ unsigned int uiPlayerCount = m_pPlayerManager->CountJoined ();
275
+ if ( uiPlayerCount != m_uiLightLastPlayerCount || llTime - m_llLightLastTime > m_lLightMinInterval || m_strLightCached == " " )
276
+ {
277
+ m_strLightCached = QueryLight ();
278
+ m_llLightLastTime = llTime;
279
+ m_uiLightLastPlayerCount = uiPlayerCount;
280
+ }
281
+ return m_strLightCached;
282
+ }
283
+
284
+
243
285
std::string ASE::QueryLight ( void )
244
286
{
245
287
std::stringstream reply;
0 commit comments