-
Notifications
You must be signed in to change notification settings - Fork 270
/
Copy pathgcclient.cpp
601 lines (501 loc) · 20.6 KB
/
gcclient.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Holds the CGCClient class
//
//=============================================================================
#include "stdafx.h"
#include "gcclient.h"
#include "steam/isteamgamecoordinator.h"
#include "gcsdk_gcmessages.pb.h"
namespace GCSDK
{
//#define SOCDebug(...) Msg( __VA_ARGS__ )
#define SOCDebug(...) ((void)0)
//------------------------------------------------------------------------------
// Purpose: Constructor
//------------------------------------------------------------------------------
CGCClient::CGCClient( ISteamGameCoordinator *pSteamGameCoordinator, bool bGameserver )
: m_pSteamGameCoordinator( NULL ),
m_memMsg( 0, 1024 ),
#ifndef STEAM
m_callbackGCMessageAvailable( NULL, NULL ),
#endif
m_mapSOCache( DefLessFunc(CSteamID) )
{
#ifndef STEAM
if( bGameserver )
{
m_callbackGCMessageAvailable.SetGameserverFlag();
}
#endif
if( pSteamGameCoordinator )
{
DbgVerify( BInit( pSteamGameCoordinator ) );
}
}
//------------------------------------------------------------------------------
// Purpose: Constructor
//------------------------------------------------------------------------------
CGCClient::~CGCClient( )
{
Uninit();
FOR_EACH_MAP_FAST( m_mapSOCache, i )
{
delete m_mapSOCache[i];
}
m_mapSOCache.RemoveAll();
}
//------------------------------------------------------------------------------
// Purpose: Performs the every-frame work required by the GC Client. Mostly that
// means running yielding jobs.
// Inputs: ulLimitMicroseconds - The target number of microseconds worth of
// work to do this time through the loop.
// Outputs: Returns true if there is still work to do that was skipped because
// time ran out.
//------------------------------------------------------------------------------
bool CGCClient::BMainLoop( uint64 ulLimitMicroseconds, uint64 ulFrameTimeMicroseconds )
{
// Don't do any work if not initialized
if ( !m_pSteamGameCoordinator )
return false;
CLimitTimer limitTimer;
limitTimer.SetLimit( ulLimitMicroseconds );
CJobTime::UpdateJobTime( ulFrameTimeMicroseconds ? ulFrameTimeMicroseconds : k_cMicroSecPerShellFrame );
bool bWorkRemaining = m_JobMgr.BFrameFuncRunSleepingJobs( limitTimer );
bWorkRemaining |= m_JobMgr.BFrameFuncRunYieldingJobs( limitTimer );
return bWorkRemaining;
}
//------------------------------------------------------------------------------
// Purpose: Sends a message to the GC
// Inputs: unMsgType - the type ID of the message to send
// pubData - The data for the message we're sending
// cubData - The number of bytes of data in this message including any
// variable-lengthed data.
// Outputs: Returns false if the send failed. A return value of true doesn't
// mean that the message was necessarily received by the GC just that
// it didn't fail in obvious ways on the client.
//------------------------------------------------------------------------------
bool CGCClient::BSendMessage( uint32 unMsgType, const uint8 *pubData, uint32 cubData )
{
if( m_pSteamGameCoordinator )
return m_pSteamGameCoordinator->SendMessage( unMsgType, pubData, cubData ) == k_EGCResultOK;
else
return false;
}
//------------------------------------------------------------------------------
// Purpose: Sends a message to the GC
// Inputs: msg - The message to send
// Outputs: Returns false if the send failed. A return value of true doesn't
// mean that the message was necessarily received by the GC just that
// it didn't fail in obvious ways on the client.
//------------------------------------------------------------------------------
bool CGCClient::BSendMessage( const CGCMsgBase& msg )
{
return BSendMessage( msg.Hdr().m_eMsg, msg.PubPkt() + sizeof(GCMsgHdr_t), msg.CubPkt() - sizeof(GCMsgHdr_t) );
}
//-----------------------------------------------------------------------------
// Purpose: Used to send protobuf messages to the GC
//-----------------------------------------------------------------------------
class CProtoBufGCClientSendHandler : public CProtoBufMsgBase::IProtoBufSendHandler
{
public:
CProtoBufGCClientSendHandler( CGCClient *pGCClient )
: m_pClient( pGCClient ) {}
virtual bool BAsyncSend( MsgType_t eMsg, const uint8 *pubMsgBytes, uint32 cubSize )
{
g_theMessageList.TallySendMessage( eMsg & ~k_EMsgProtoBufFlag, cubSize );
VPROF_BUDGET( "CGCClient", VPROF_BUDGETGROUP_STEAM );
{
VPROF_BUDGET( "CGCClient - BSendGCMsgToClient (ProtoBuf)", VPROF_BUDGETGROUP_STEAM );
return m_pClient->BSendMessage( eMsg | k_EMsgProtoBufFlag, pubMsgBytes, cubSize );
}
}
private:
CGCClient *m_pClient;
};
//-----------------------------------------------------------------------------
// Purpose: Sends a message to the given SteamID
//-----------------------------------------------------------------------------
bool CGCClient::BSendMessage( const CProtoBufMsgBase& msg )
{
CProtoBufGCClientSendHandler sender( this );
return msg.BAsyncSend( sender );
}
//------------------------------------------------------------------------------
// Purpose: Callback handler for the GCMessageAvailable_t callback. Handles
// incoming messages.
// Inputs: pCallback - the callback from Steam
//------------------------------------------------------------------------------
void CGCClient::OnGCMessageAvailable( GCMessageAvailable_t *pCallback )
{
uint32 cubData;
uint32 unMsgType;
while( m_pSteamGameCoordinator && m_pSteamGameCoordinator->IsMessageAvailable( &cubData ) )
{
// Get the size of the full message. sizeof( GCMsgHdr_t ) was not sent in the binary data
uint32 unFullSize = cubData + sizeof( GCMsgHdr_t );
m_memMsg.EnsureCapacity( unFullSize );
uint8 *pFullPacket = m_memMsg.Base();
uint8 *pPacketFromGC = pFullPacket+sizeof(GCMsgHdr_t);
EGCResults eResult = m_pSteamGameCoordinator->RetrieveMessage( &unMsgType, pPacketFromGC, m_memMsg.Count() - sizeof( GCMsgHdr_t ), &cubData );
Assert( eResult == k_EGCResultOK );
if( eResult == k_EGCResultOK )
{
if( unMsgType & k_EMsgProtoBufFlag )
{
CNetPacket *pGCPacket = CNetPacketPool::AllocNetPacket();
pGCPacket->Init( cubData, pPacketFromGC );
CIMsgNetPacketAutoRelease pMsgNetPacket( pGCPacket );
// Safety check against malformed packet
if ( pMsgNetPacket.Get() != NULL )
{
// dispatch the packet
GetJobMgr().BRouteMsgToJob( this, pMsgNetPacket.Get(), JobMsgInfo_t( pMsgNetPacket->GetEMsg(), pMsgNetPacket->GetSourceJobID(), pMsgNetPacket->GetTargetJobID(), k_EServerTypeGCClient ) );
// keep track of how much we've sent/received this message
g_theMessageList.TallySendMessage( pMsgNetPacket->GetEMsg(), cubData );
}
// release the packet
pGCPacket->Release();
}
else
{
Assert( 0 == (unMsgType & k_EMsgProtoBufFlag ) );
// get the header so we can fix it up
GCMsgHdrEx_t *pHdr = (GCMsgHdrEx_t *)pFullPacket;
pHdr->m_eMsg = unMsgType;
pHdr->m_ulSteamID = CSteamID().ConvertToUint64();
// make a new packet for the message so we can dispatch it
// The CNetPacket takes ownership of the buffer allocated above
CNetPacket *pGCPacket = CNetPacketPool::AllocNetPacket();
pGCPacket->Init( unFullSize, pFullPacket );
CIMsgNetPacketAutoRelease pMsgNetPacket( pGCPacket );
// Safety check against malformed packet
if ( pMsgNetPacket.Get() != NULL )
{
// dispatch the packet
GetJobMgr().BRouteMsgToJob( this, pMsgNetPacket.Get(), JobMsgInfo_t( pMsgNetPacket->GetEMsg(), pMsgNetPacket->GetSourceJobID(), pMsgNetPacket->GetTargetJobID(), k_EServerTypeGCClient ) );
// keep track of how much we've sent/received this message
g_theMessageList.TallySendMessage( pMsgNetPacket->GetEMsg(), cubData );
}
// release the packet
pGCPacket->Release();
}
}
}
}
//------------------------------------------------------------------------------
// Purpose: Performs all the initialization for the GC Client instance
// Outputs: Returns false if the initialization failed
//------------------------------------------------------------------------------
bool CGCClient::BInit( ISteamGameCoordinator *pSteamGameCoordinator )
{
// Set the job pool size. Threads get lazily created so if no code
// is using the thread pool, no threads will be created.
m_JobMgr.SetThreadPoolSize( GetCPUInformation()->m_nLogicalProcessors - 1 );
MsgRegistrationFromEnumDescriptor( EGCSystemMsg_descriptor(), GCSDK::MT_GC );
m_pSteamGameCoordinator = pSteamGameCoordinator;
#ifndef STEAM
m_callbackGCMessageAvailable.Register( this, &CGCClient::OnGCMessageAvailable );
#endif
// process any messages that are already waiting
if( m_pSteamGameCoordinator )
{
OnGCMessageAvailable( NULL );
}
return true;
}
//------------------------------------------------------------------------------
// Purpose: Performs all the uninitialization for the GC Client instance
//------------------------------------------------------------------------------
void CGCClient::Uninit( )
{
#ifndef STEAM
m_callbackGCMessageAvailable.Unregister();
#endif
m_pSteamGameCoordinator = NULL;
// Clear and remove the SO caches
unsigned short nMapIndex = m_mapSOCache.FirstInorder();
while ( m_mapSOCache.IsValidIndex( nMapIndex ) )
{
unsigned short nNextMapIndex = m_mapSOCache.NextInorder( nMapIndex );
CGCClientSharedObjectCache *pSOCache = m_mapSOCache[nMapIndex];
Assert( pSOCache );
if ( pSOCache )
{
// Send notifications, but only if we were actually subscribed
if ( pSOCache->BIsSubscribed() )
{
pSOCache->NotifyUnsubscribe();
}
// Delete the entry
delete pSOCache;
m_mapSOCache.RemoveAt( nMapIndex );
}
nMapIndex = nNextMapIndex;
}
}
//------------------------------------------------------------------------------
// Purpose: Finds the SO cache for this steam ID. If bCreateIfMissing is false,
// NULL will be returned if the cache can't be found
//------------------------------------------------------------------------------
CGCClientSharedObjectCache *CGCClient::FindSOCache( const CSteamID & steamID, bool bCreateIfMissing )
{
CUtlMap< CSteamID, CGCClientSharedObjectCache * >::IndexType_t nCache = m_mapSOCache.Find( steamID );
if( m_mapSOCache.IsValidIndex( nCache ) )
return m_mapSOCache[nCache];
else
{
if( bCreateIfMissing )
{
Assert( steamID.IsValid() );
if ( !steamID.IsValid() )
return NULL;
CGCClientSharedObjectCache *pCache = new CGCClientSharedObjectCache( steamID );
m_mapSOCache.Insert( steamID, pCache );
return pCache;
}
else
{
return NULL;
}
}
}
//------------------------------------------------------------------------------
// Purpose: Add a listener to the SO cache, creating it if necessary
//------------------------------------------------------------------------------
void CGCClient::AddSOCacheListener( const CSteamID &ownerID, ISharedObjectListener *pListener )
{
Assert( ownerID.IsValid() );
CGCClientSharedObjectCache *pCache = FindSOCache( ownerID, true );
Assert( pCache );
pCache->AddListener( pListener );
}
//------------------------------------------------------------------------------
// Purpose: Remove listener from the SO cache, if he is listening
//------------------------------------------------------------------------------
bool CGCClient::RemoveSOCacheListener( const CSteamID &ownerID, ISharedObjectListener *pListener )
{
Assert ( this != NULL ); // Damn people - check your pointers before calling!
Assert( ownerID.IsValid() );
CGCClientSharedObjectCache *pCache = FindSOCache( ownerID, false );
if ( pCache == NULL )
return false; // cache doesn't exist, so we could't have ben listening
return pCache->RemoveListener( pListener );
}
//------------------------------------------------------------------------------
// Purpose: Notify that the given SO cache has been unsubscribed
//------------------------------------------------------------------------------
void CGCClient::NotifySOCacheUnsubscribed( const CSteamID & ownerID )
{
CUtlMap< CSteamID, CGCClientSharedObjectCache * >::IndexType_t nCache = m_mapSOCache.Find( ownerID );
if( m_mapSOCache.IsValidIndex( nCache ) )
{
CGCClientSharedObjectCache *pSOCache = m_mapSOCache[nCache];
// Ignore requests to remove caches that were never subscribed
if ( pSOCache->BIsSubscribed() )
{
SOCDebug( "NotifySOCacheUnsubscribed(%s) [in cache, subscribed]\n", ownerID.Render() );
pSOCache->NotifyUnsubscribe();
}
else
{
SOCDebug( "NotifySOCacheUnsubscribed(%s) [in cache, not subscribed]\n", ownerID.Render() );
}
}
else
{
SOCDebug( "NotifySOCacheUnsubscribed(%s) [not in cache]\n", ownerID.Render() );
}
}
//------------------------------------------------------------------------------
// Purpose: Dump everything about everyone
//------------------------------------------------------------------------------
void CGCClient::Dump()
{
FOR_EACH_MAP( m_mapSOCache, idx )
{
m_mapSOCache[ idx ]->Dump();
}
}
//------------------------------------------------------------------------------
// Purpose: Finds the shared object for this steam ID and key object
//------------------------------------------------------------------------------
CSharedObject *CGCClient::FindSharedObject( const CSteamID & ownerID, const CSharedObject & soIndex )
{
CGCClientSharedObjectCache *pCache = FindSOCache( ownerID, false );
if( pCache )
return pCache->FindSharedObject( soIndex );
else
return NULL;
}
//------------------------------------------------------------------------------
// Purpose: Validates all the statics in the GCSDKLib that need to be validated
// when linked directly into the steam servers.
//------------------------------------------------------------------------------
#ifdef DBGFLAG_VALIDATE
void CGCClient::ValidateStatics( CValidator &validator )
{
// Validate the global message list
g_theMessageList.Validate( validator, "g_theMessageList" );
// Validate the network global memory pool
g_MemPoolMsg.Validate( validator, "g_MemPoolMsg" );
CNetPacketPool::ValidateGlobals( validator );
CJobMgr::ValidateStatics( validator, "CJobMgr" );
CJob::ValidateStatics( validator, "CJob" );
ValidateTempTextBuffers( validator );
CSharedObject::ValidateStatics( validator );
// validate the SQL access layer
CRecordBase::ValidateStatics( validator, "CRecordBase" );
GSchemaFull().Validate( validator, "GSchemaFull" );
CRecordInfo::ValidateStatics( validator, "CRecordInfo" );
}
#endif // DBGFLAG_VALIDATE
class CGCSOCreateJob : public CGCClientJob
{
public:
CGCSOCreateJob( CGCClient *pClient ) : CGCClientJob( pClient ) {}
virtual bool BYieldingRunGCJob( GCSDK::IMsgNetPacket *pNetPacket )
{
CProtoBufMsg<CMsgSOSingleObject> msg( pNetPacket );
SOCDebug( "CGCSOCreateJob(owner=%s, type=%d)\n", CSteamID( msg.Body().owner() ).Render(), msg.Body().type_id() );
CGCClientSharedObjectCache *pSOCache = m_pGCClient->FindSOCache( msg.Body().owner() );
if ( pSOCache )
{
pSOCache->BCreateFromMsg( msg.Body().type_id(), msg.Body().object_data().data(), msg.Body().object_data().size() );
Assert( msg.Body().has_version() );
pSOCache->SetVersion( msg.Body().version() );
}
return true;
}
};
GC_REG_JOB( CGCClient, CGCSOCreateJob, "CGCSOCreateJob", k_ESOMsg_Create, GCSDK::k_EServerTypeGCClient );
class CGCSODestroyJob : public CGCClientJob
{
public:
CGCSODestroyJob( CGCClient *pClient ) : CGCClientJob( pClient ) {}
virtual bool BYieldingRunGCJob( GCSDK::IMsgNetPacket *pNetPacket )
{
CProtoBufMsg<CMsgSOSingleObject> msg( pNetPacket );
SOCDebug( "CGCSODestroyJob(owner=%s, type=%d)\n", CSteamID( msg.Body().owner() ).Render(), msg.Body().type_id() );
CGCClientSharedObjectCache *pCache = m_pGCClient->FindSOCache( msg.Body().owner(), false );
if( pCache )
{
pCache->BDestroyFromMsg( msg.Body().type_id(), msg.Body().object_data().data(), msg.Body().object_data().size() );
Assert( msg.Body().has_version() );
pCache->SetVersion( msg.Body().version() );
}
return true;
}
};
GC_REG_JOB( CGCClient, CGCSODestroyJob, "CGCSODestroyJob", k_ESOMsg_Destroy, GCSDK::k_EServerTypeGCClient );
class CGCSOUpdateJob : public CGCClientJob
{
public:
CGCSOUpdateJob( CGCClient *pClient ) : CGCClientJob( pClient ) {}
virtual bool BYieldingRunGCJob( GCSDK::IMsgNetPacket *pNetPacket )
{
CProtoBufMsg<CMsgSOSingleObject> msg( pNetPacket );
SOCDebug( "CGCSOUpdateJob(owner=%s, type=%d)\n", CSteamID( msg.Body().owner() ).Render(), msg.Body().type_id() );
CGCClientSharedObjectCache *pSOCache = m_pGCClient->FindSOCache( msg.Body().owner() );
if ( pSOCache )
{
pSOCache->BUpdateFromMsg( msg.Body().type_id(), msg.Body().object_data().data(), msg.Body().object_data().size() );
Assert( msg.Body().has_version() );
pSOCache->SetVersion( msg.Body().version() );
}
return true;
}
};
GC_REG_JOB( CGCClient, CGCSOUpdateJob, "CGCSOUpdateJob", k_ESOMsg_Update, GCSDK::k_EServerTypeGCClient );
class CGCSOUpdateMultipleJob : public CGCClientJob
{
public:
CGCSOUpdateMultipleJob( CGCClient *pClient ) : CGCClientJob( pClient ) {}
virtual bool BYieldingRunGCJob( GCSDK::IMsgNetPacket *pNetPacket )
{
CProtoBufMsg<CMsgSOMultipleObjects> msg( pNetPacket );
SOCDebug( "CGCSOUpdateJob(owner=%s)\n", CSteamID( msg.Body().owner() ).Render() );
CGCClientSharedObjectCache *pSOCache = m_pGCClient->FindSOCache( msg.Body().owner() );
if ( pSOCache )
{
pSOCache->m_context.PreSOUpdate( eSOCacheEvent_Incremental );
for ( int i = 0; i < msg.Body().objects_size(); ++i )
{
const CMsgSOMultipleObjects_SingleObject &objMessage = msg.Body().objects( i );
SOCDebug( " type %d\n", objMessage.type_id() );
pSOCache->BUpdateFromMsg( objMessage.type_id(), objMessage.object_data().data(), objMessage.object_data().size() );
}
pSOCache->m_context.PostSOUpdate( eSOCacheEvent_Incremental );
pSOCache->SetVersion( msg.Body().version() );
}
return true;
}
};
GC_REG_JOB( CGCClient, CGCSOUpdateMultipleJob, "CGCSOUpdateMultipleJob", k_ESOMsg_UpdateMultiple, GCSDK::k_EServerTypeGCClient );
class CGCSOCacheSubscribedJob : public CGCClientJob
{
public:
CGCSOCacheSubscribedJob( CGCClient *pClient ) : CGCClientJob( pClient ) {}
virtual bool BYieldingRunGCJob( GCSDK::IMsgNetPacket *pNetPacket )
{
CProtoBufMsg< CMsgSOCacheSubscribed > msg ( pNetPacket );
CGCClientSharedObjectCache *pSOCache = m_pGCClient->FindSOCache( msg.Body().owner(), true );
Assert( pSOCache );
if( pSOCache )
{
SOCDebug( "CGCSOCacheSubscribedJob(owner=%s) [in cache]\n", CSteamID( msg.Body().owner() ).Render() );
DbgVerify( pSOCache->BParseCacheSubscribedMsg( msg.Body() ) );
}
else
{
SOCDebug( "CGCSOCacheSubscribedJob(owner=%s) [not in cache]\n", CSteamID( msg.Body().owner() ).Render() );
}
m_pGCClient->Test_CacheSubscribed( pSOCache->GetOwner() );
return true;
}
};
GC_REG_JOB( CGCClient, CGCSOCacheSubscribedJob, "CGCSOCacheSubscribedJob", k_ESOMsg_CacheSubscribed, GCSDK::k_EServerTypeGCClient );
class CGCSOCacheUnsubscribedJob : public CGCClientJob
{
public:
CGCSOCacheUnsubscribedJob( CGCClient *pClient ) : CGCClientJob( pClient ) {}
virtual bool BYieldingRunGCJob( GCSDK::IMsgNetPacket *pNetPacket )
{
CProtoBufMsg< CMsgSOCacheUnsubscribed > msg( pNetPacket );
SOCDebug( "CGCSOCacheUnsubscribedJob(owner=%s)\n", CSteamID( msg.Body().owner() ).Render() );
m_pGCClient->NotifySOCacheUnsubscribed( msg.Body().owner() );
return true;
}
};
GC_REG_JOB( CGCClient, CGCSOCacheUnsubscribedJob, "CGCSOCacheUnsubscribedJob", k_ESOMsg_CacheUnsubscribed, GCSDK::k_EServerTypeGCClient );
class CGCSOCacheSubscriptionCheck : public CGCClientJob
{
public:
CGCSOCacheSubscriptionCheck( CGCClient *pClient ) : CGCClientJob( pClient ) {}
virtual bool BYieldingRunGCJob( GCSDK::IMsgNetPacket *pNetPacket )
{
CProtoBufMsg< CMsgSOCacheSubscriptionCheck > msg ( pNetPacket );
CGCClientSharedObjectCache *pSOCache = m_pGCClient->FindSOCache( msg.Body().owner(), false );
// if we do not have the cache or it is out-of-date, request a refresh
if ( pSOCache == NULL || !pSOCache->BIsInitialized() || pSOCache->GetVersion() != msg.Body().version() )
{
SOCDebug( "CGCSOCacheSubscriptionCheck(owner=%s) -- need refresh\n", CSteamID( msg.Body().owner() ).Render() );
CProtoBufMsg< CMsgSOCacheSubscriptionRefresh > msg_response( k_ESOMsg_CacheSubscriptionRefresh );
msg_response.Body().set_owner( msg.Body().owner() );
m_pGCClient->BSendMessage( msg_response );
}
else
{
SOCDebug( "CGCSOCacheSubscriptionCheck(owner=%s) -- up-to-date, no refresh needed\n", CSteamID( msg.Body().owner() ).Render() );
// This is one method by which the GC notifies us that we are subscribed.
if ( !pSOCache->BIsSubscribed() )
{
pSOCache->NotifyResubscribedUpToDate();
Assert( pSOCache->BIsSubscribed() );
}
}
return true;
}
};
GC_REG_JOB( CGCClient, CGCSOCacheSubscriptionCheck, "CGCSOCacheSubscriptionCheck", k_ESOMsg_CacheSubscriptionCheck, GCSDK::k_EServerTypeGCClient );
} // namespace GCSDK