Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
5.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Manages CPlayerGroups (A group of players stored on the GC)
  4. //
  5. //=============================================================================
  6. #ifndef PLAYERGROUPMANAGER_H
  7. #define PLAYERGROUPMANAGER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "playergroup.h"
  12. const int k_NoGroupMemberLimit = -1;
  13. namespace GCSDK
  14. {
  15. class CGCJobDestroyPlayerGroup;
  16. class CGCJobFindGroupFromMemcached;
  17. class CPlayerGroupManager
  18. {
  19. public:
  20. CPlayerGroupManager();
  21. static const int kGroupIDGenerationLockType = -1;
  22. virtual void YieldingSessionStartPlaying( CGCUserSession *pSession );
  23. virtual void YieldingSessionStopPlaying( CGCUserSession *pSession ) { }
  24. virtual void YieldingSessionStartServer( CGCGSSession *pSession );
  25. virtual void YieldingSessionStopServer( CGCGSSession *pSession );
  26. IPlayerGroup* YldFindAndLockGroup( PlayerGroupID_t nPlayerGroupID );
  27. IPlayerGroup* YldFindAndLockGroupByMemberID( const CSteamID &steamID );
  28. IPlayerGroup* FindGroup( PlayerGroupID_t nPlayerGroupID );
  29. IPlayerGroup* FindGroupByMemberID( const CSteamID &steamID );
  30. virtual int GetGroupLockType() = 0;
  31. bool IsPlayerWaitingForMemcache( const CSteamID &steamID ) const;
  32. bool BYieldingLockGroupID( PlayerGroupID_t nPlayerGroupID );
  33. void UnlockGroupID( PlayerGroupID_t nPlayerGroupID );
  34. bool IsGroupIDLocked( PlayerGroupID_t nPlayerGroupID );
  35. void StartFrameSchedule();
  36. bool BExpireLocks( CLimitTimer &limitTimer );
  37. void DumpGroups();
  38. virtual void SendGroupStorageAndNetworkUpdate( IPlayerGroup *pPlayerGroup );
  39. // invites
  40. void YldInviteToGroup( const CSteamID &steamIDLeader, const CSteamID &steamIDNewMember );
  41. void YldGroupInviteResponse( const CSteamID &steamID, const PlayerGroupID_t nPlayerGroupID, bool bAccepted );
  42. void YldRequestKickFromGroup( const CSteamID &steamIDLeader, const CSteamID &steamIDNewMember );
  43. bool BYldRequestLeaveGroup( const CSteamID &steamID );
  44. void YldDestroyGroup( PlayerGroupID_t nPlayerGroupID );
  45. virtual int GetMaxGroupMembers() { return k_NoGroupMemberLimit; }
  46. protected:
  47. bool BYldAddMemberToGroup( PlayerGroupID_t nPlayerGroupID, const CSteamID &steamIDNewMember );
  48. void YldRemoveMemberFromGroup( PlayerGroupID_t nPlayerGroupID, const CSteamID &steamIDRemovingMember );
  49. void YldDoFindGroupFromMemcached( const CSteamID &memberSteamID );
  50. virtual IPlayerGroup* YldCreateAndLockPlayerGroup() = 0; // game specific derived class will implement this to create a game specific playergroup
  51. virtual IPlayerGroup* YldCreateAndLockPlayerGroupFromMemcached( const CUtlBuffer &buf ) = 0; // game specific derived class will implement this to create a game specific playergroup
  52. PlayerGroupID_t GeneratePlayerGroupID();
  53. void YldDestroyGroupIfEmpty( PlayerGroupID_t nPlayerGroupID );
  54. void MemcachedUpdateAllMemberAssocation( IPlayerGroup *pPlayerGroup );
  55. void MemcachedRemoveAllMemberAssocation( IPlayerGroup *pPlayerGroup );
  56. void MemcachedUpdateMemberAssocation( PlayerGroupID_t nPlayerGroupID, const CSteamID &steamID );
  57. void MemcachedRemoveMemberAssocation( PlayerGroupID_t nPlayerGroupID, const CSteamID &steamID );
  58. void YldFindGroupFromMemcached( const CSteamID &memberSteamID );
  59. virtual const char *GetMemcachedIdentityKey() const = 0;
  60. // notifications for derived classes
  61. virtual void YldOnPlayerJoinedGroup( IPlayerGroup *pPlayerGroup, const CSteamID& steamIDNewMember ) { }
  62. virtual void YldOnPlayerLeftGroup( IPlayerGroup *pPlayerGroup, const CSteamID& steamIDRemovingMember );
  63. virtual void YldOnGroupDestroyed( IPlayerGroup *pPlayerGroup );
  64. virtual void YldOnGroupLoadedFromMemcached( IPlayerGroup *pPlayerGroup );
  65. // invites
  66. virtual IPlayerGroupInvite* CreateInvite() = 0;
  67. void YldAddPendingInvite( PlayerGroupID_t nPlayerGroupID, const CSteamID &steamIDNewMember );
  68. virtual void YldRemovePendingInvite( PlayerGroupID_t nPlayerGroupID, const CSteamID &steamIDNewMember );
  69. virtual bool YldHasGroupInvite( const CSteamID &steamID, const PlayerGroupID_t nPlayerGroupID ) = 0;
  70. void YldCreateInvitesForGroup( PlayerGroupID_t nPlayerGroupID );
  71. typedef CUtlMap<PlayerGroupID_t, IPlayerGroup*, int32> mapPlayerGroups_t;
  72. typedef CUtlHashMapLarge<PlayerGroupID_t, IPlayerGroup*> hashPlayerGroups_t;
  73. hashPlayerGroups_t m_mapGroups; // map from PlayerGroupID_t to IPlayerGroup
  74. typedef CUtlHashMapLarge<CSteamID, IPlayerGroup*> mapMembersToPlayerGroups_t;
  75. mapMembersToPlayerGroups_t m_mapMemberToGroup; // map from any member's SteamID to IPlayerGroup
  76. CTHash<CLock, PlayerGroupID_t> m_hashPlayerGroupIDLocks;
  77. friend class CGCJobDestroyGroup;
  78. friend class CGCJobFindGroupFromMemcached;
  79. CLock m_GroupIDGenerationLock;
  80. private:
  81. typedef CUtlHashMapLarge<CSteamID, int> mapPlayersMemcacheJobCount_t;
  82. static mapPlayersMemcacheJobCount_t sm_mapPlayersMemcacheJobCount;
  83. };
  84. class CGCJobDestroyGroup : public CGCJob
  85. {
  86. public:
  87. CGCJobDestroyGroup( CGCBase *pGC, CPlayerGroupManager *pGroupManager, PlayerGroupID_t nPlayerGroupID ) : CGCJob( pGC ), m_pGroupManager( pGroupManager ), m_nPlayerGroupID( nPlayerGroupID ) { }
  88. virtual bool BYieldingRunGCJob();
  89. private:
  90. CPlayerGroupManager *m_pGroupManager;
  91. PlayerGroupID_t m_nPlayerGroupID;
  92. };
  93. class CGCJobLeaveGroup : public CGCJob
  94. {
  95. public:
  96. CGCJobLeaveGroup( CGCBase *pGC, CPlayerGroupManager *pGroupManager, const CSteamID &steamID ) : CGCJob( pGC ), m_pGroupManager( pGroupManager ), m_SteamID( steamID ) { }
  97. virtual bool BYieldingRunGCJob();
  98. private:
  99. CPlayerGroupManager *m_pGroupManager;
  100. CSteamID m_SteamID;
  101. };
  102. class CGCJobFindGroupFromMemcached : public CGCJob
  103. {
  104. public:
  105. CGCJobFindGroupFromMemcached( CGCBase *pGC, CPlayerGroupManager *pGroupManager, const CSteamID& memberSteamID ) : CGCJob( pGC ), m_pGroupManager( pGroupManager ), m_memberSteamID( memberSteamID ) { }
  106. virtual bool BYieldingRunGCJob();
  107. private:
  108. CPlayerGroupManager *m_pGroupManager;
  109. CSteamID m_memberSteamID;
  110. };
  111. }
  112. #endif