3 //// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
4 //// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
5 //// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
6 //// PARTICULAR PURPOSE.
8 //// Copyright (c) Microsoft Corporation. All rights reserved
10 #ifndef __CRYDURANGOCHAT_H__
11 #define __CRYDURANGOCHAT_H__
15 #if CRY_PLATFORM_DURANGO && USE_DURANGOLIVE
17 #include <CryLobby/ICryLobby.h>
19 #include "../CryDurangoLiveMatchMaking.h"
20 #include "../CryDurangoLiveLobbyPacket.h"
22 class ChatIntegrationLayer
25 ChatIntegrationLayer();
26 ~ChatIntegrationLayer();
28 ECryLobbyError
Initialize(bool jitterBufferEnabled
, CCryDurangoLiveMatchMaking
* pMatchMaking
, DWORD cpuCore
= 5);
32 void AddRemoteConnection(CryLobbySessionHandle h
, CryMatchMakingConnectionID connectionID
, uint32 consoleId
);
33 void RemoveRemoteConnection(CryLobbySessionHandle h
, CryMatchMakingConnectionID connectionID
, uint32 consoleID
);
35 void AddLocalUserToChatChannel(
36 __in uint8 channelIndex
,
37 __in
Windows::Xbox::System::IUser
^ user
40 void RemoveUserFromChatChannel(
41 __in uint8 channelIndex
,
42 __in
Windows::Xbox::System::IUser
^ user
45 void RemoveRemoteConsole(
46 Platform::Object
^ uniqueRemoteConsoleIdentifier
49 void ReceivePacket(CCryDurangoLiveLobbyPacket
* pPacket
);
51 void OnIncomingChatMessage(
52 Windows::Storage::Streams::IBuffer
^ chatPacket
,
53 Platform::Object
^ uniqueRemoteConsoleIdentifier
56 Windows::Foundation::Collections::IVectorView
<Microsoft::Xbox::GameChat::ChatUser
^>^ GetChatUsers();
58 void HandleChatUserMuteStateChanged(
59 __in INT chatUserIndex
62 void HandleChatChannelChanged(
63 __in uint8 oldChatChannelIndex
,
64 __in uint8 newChatChannelIndex
,
67 void OnSecureDeviceAssocationConnectionEstablished(__in
Platform::Object
^ uniqueConsoleIdentifier
);
70 void AddAllLocallySignedInUsersToChatClient(
71 __in uint8 channelIndex
,
72 __in
Windows::Foundation::Collections::IVectorView
<Windows::Xbox::System::User
^>^ locallySignedInUsers
74 void RegisterChatManagerEventHandlers();
76 void OnDebugMessageReceived(
77 __in
Microsoft::Xbox::GameChat::DebugMessageEventArgs
^ args
80 void OnOutgoingChatPacketReady(
81 __in
Microsoft::Xbox::GameChat::ChatPacketEventArgs
^ args
84 static inline Platform::Object
^ Uint32ToPlatformObject(__in uint32 val
) { return Windows::Foundation::PropertyValue::CreateUInt32(val
); }
85 static inline uint32
PlatformObjectToUint32(__in
Platform::Object
^ obj
) { return safe_cast
<Windows::Foundation::IPropertyValue
^>(obj
)->GetUInt32(); }
87 Microsoft::Xbox::GameChat::ChatUser
^ GetChatUserByXboxUserId(
88 __in
Platform::String
^ xboxUserId
91 inline bool ChatIntegrationLayer::CompareUniqueConsoleIdentifiers(
92 __in
Platform::Object
^ uniqueRemoteConsoleIdentifier1
,
93 __in
Platform::Object
^ uniqueRemoteConsoleIdentifier2
96 if (uniqueRemoteConsoleIdentifier1
== nullptr || uniqueRemoteConsoleIdentifier2
== nullptr)
101 return (PlatformObjectToUint32(uniqueRemoteConsoleIdentifier1
) == PlatformObjectToUint32(uniqueRemoteConsoleIdentifier2
));
104 void OnUserAudioDeviceAdded(Windows::Xbox::System::AudioDeviceAddedEventArgs
^ eventArgs
);
106 Concurrency::critical_section m_lock
;
107 Microsoft::Xbox::GameChat::ChatManager
^ m_chatManager
;
108 Windows::Foundation::EventRegistrationToken m_tokenOnDebugMessage
;
109 Windows::Foundation::EventRegistrationToken m_tokenOnOutgoingChatPacketReady
;
110 Windows::Foundation::EventRegistrationToken m_tokenOnCompareUniqueConsoleIdentifiers
;
111 Windows::Foundation::EventRegistrationToken m_tokenResourceAvailabilityChanged
;
112 Windows::Foundation::EventRegistrationToken m_tokenAudioDeviceAdded
;
114 CCryDurangoLiveMatchMaking
* m_pMatchMaking
;
116 struct ConnectionData
118 CryLobbySessionHandle sessionHandle
;
119 CryMatchMakingConnectionID connectionID
;
120 uint32 remoteConsoleId
;
122 std::vector
<ConnectionData
> m_remoteConsoleConnections
;
124 void CreatePacket(_Inout_ CCryDurangoLiveLobbyPacket
* pPacket
, _In_
Windows::Storage::Streams::IBuffer
^ pBuffer
, _In_
bool reliable
);
125 void UnwrapPacket(_In_ CCryDurangoLiveLobbyPacket
* pPacket
, _Out_ byte
** ppData
, _Out_ uint
* size
);
129 static ChatIntegrationLayer
* GetChatIntegrationLayer()
131 static ChatIntegrationLayer
* pChatIntegrationLayerInstance
;
132 if (pChatIntegrationLayerInstance
== nullptr)
134 pChatIntegrationLayerInstance
= new ChatIntegrationLayer();
137 return pChatIntegrationLayerInstance
;
140 static void ShutdownChatIntegrationLayer()
142 delete GetChatIntegrationLayer();
146 #endif // __CRYDURANGOCHAT_H__