sys_voicechat.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __SYS_VOICECHATMGR_H__
  21. #define __SYS_VOICECHATMGR_H__
  22. #include "sys_lobby_backend.h"
  23. /*
  24. ================================================
  25. idVoiceChatMgr
  26. ================================================
  27. */
  28. class idVoiceChatMgr {
  29. public:
  30. idVoiceChatMgr() : activeLobbyType( -1 ), activeGroupIndex( 0 ), sendFrame( 0 ), disableVoiceReasons( 0 ), sendGlobal( false ) {}
  31. virtual void Init( void * pXAudio2 );
  32. virtual void Shutdown();
  33. void RegisterTalker( lobbyUser_t * user, int lobbyType, bool isLocal );
  34. void UnregisterTalker( lobbyUser_t * user, int lobbyType, bool isLocal );
  35. void GetActiveLocalTalkers( idStaticList< int, MAX_PLAYERS > & localTalkers );
  36. void GetRecipientsForTalker( int talkerIndex, idStaticList< const lobbyAddress_t *, MAX_PLAYERS > & recipients );
  37. void SetTalkerGroup( const lobbyUser_t * user, int lobbyType, int groupIndex );
  38. void SetActiveLobby( int lobbyType );
  39. void SetActiveChatGroup( int groupIndex );
  40. int FindTalkerByUserId( lobbyUserID_t lobbyUserID, int lobbyType );
  41. bool GetLocalChatData( int talkerIndex, byte * data, int & dataSize );
  42. void SubmitIncomingChatData( const byte * data, int dataSize );
  43. voiceState_t GetVoiceState( const lobbyUser_t * user );
  44. bool CanSendVoiceTo( int talkerFromIndex, int talkerToIndex );
  45. bool IsRestrictedByPrivleges();
  46. void SetHeadsetState( int talkerIndex, bool state );
  47. bool GetHeadsetState( int talkerIndex ) const { return talkers[ talkerIndex ].hasHeadset; }
  48. bool HasHeadsetStateChanged( int talkerIndex );
  49. enum disableVoiceReason_t {
  50. REASON_GENERIC = BIT( 0 ),
  51. REASON_PRIVILEGES = BIT( 1 ),
  52. };
  53. void SetDisableVoiceReason( disableVoiceReason_t reason );
  54. void ClearDisableVoiceReason( disableVoiceReason_t reason );
  55. virtual bool GetLocalChatDataInternal( int talkerIndex, byte * data, int & dataSize ) = 0;
  56. virtual void SubmitIncomingChatDataInternal( int talkerIndex, const byte * data, int dataSize ) = 0;
  57. virtual bool TalkerHasData( int talkerIndex ) = 0;
  58. virtual void Pump() {}
  59. virtual void FlushBuffers() {}
  60. virtual void ToggleMuteLocal( const lobbyUser_t * src, const lobbyUser_t * target );
  61. protected:
  62. struct remoteMachine_t {
  63. int lobbyType;
  64. lobbyAddress_t address;
  65. int refCount;
  66. int sendFrame;
  67. };
  68. struct talker_t {
  69. talker_t() :
  70. user( NULL ),
  71. isLocal( false ),
  72. lobbyType( -1 ),
  73. groupIndex( -1 ),
  74. registered( false ),
  75. registeredSuccess( false ),
  76. machineIndex( -1 ),
  77. isMuted( false ),
  78. hasHeadset( true ),
  79. hasHeadsetChanged( false ),
  80. talking( false ),
  81. talkingGlobal( false ),
  82. talkingTime( 0 )
  83. {}
  84. lobbyUser_t * user;
  85. bool isLocal;
  86. int lobbyType;
  87. int groupIndex;
  88. bool registered; // True if this user is currently registered with the XHV engine
  89. bool registeredSuccess; // True if this user is currently successfully registered with the XHV engine
  90. int machineIndex; // Index into remote machines array (-1 if this is a local talker)
  91. bool isMuted; // This machine is not allowed to hear or talk to this player
  92. bool hasHeadset; // This user has a headset connected
  93. bool hasHeadsetChanged; // This user's headset state has changed
  94. bool talking;
  95. bool talkingGlobal;
  96. int talkingTime;
  97. bool IsLocal() const { return isLocal; }
  98. };
  99. virtual bool RegisterTalkerInternal( int index ) = 0;
  100. virtual void UnregisterTalkerInternal( int index ) = 0;
  101. int FindTalkerIndex( const lobbyUser_t * user, int lobbyType );
  102. int FindMachine( const lobbyAddress_t & address, int lobbyType );
  103. int AddMachine( const lobbyAddress_t & address, int lobbyType );
  104. void RemoveMachine( int machineIndex, int lobbyType );
  105. void UpdateRegisteredTalkers();
  106. idStaticList< talker_t, MAX_PLAYERS * 2 > talkers; // * 2 to account for handling both session types
  107. idStaticList< remoteMachine_t, MAX_PLAYERS * 2 > remoteMachines; // * 2 to account for handling both session types
  108. int activeLobbyType;
  109. int activeGroupIndex;
  110. int sendFrame;
  111. uint32 disableVoiceReasons;
  112. bool sendGlobal;
  113. };
  114. #endif // __SYS_VOICECHATMGR_H__