From b691c43c44ff180d10e7d4a9afc83b98551ff586 Mon Sep 17 00:00:00 2001 From: daoge_cmd <3523206925@qq.com> Date: Sun, 1 Mar 2026 12:16:08 +0800 Subject: Initial commit --- .../Durango/Network/ChatIntegrationLayer.h | 244 +++++++++++++++++++++ 1 file changed, 244 insertions(+) create mode 100644 Minecraft.Client/Durango/Network/ChatIntegrationLayer.h (limited to 'Minecraft.Client/Durango/Network/ChatIntegrationLayer.h') diff --git a/Minecraft.Client/Durango/Network/ChatIntegrationLayer.h b/Minecraft.Client/Durango/Network/ChatIntegrationLayer.h new file mode 100644 index 00000000..80b4e10a --- /dev/null +++ b/Minecraft.Client/Durango/Network/ChatIntegrationLayer.h @@ -0,0 +1,244 @@ +//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF +//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO +//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A +//// PARTICULAR PURPOSE. +//// +//// Copyright (c) Microsoft Corporation. All rights reserved +#pragma once + +//#include "UserController.h" + +class DQRNetworkManager; + +enum ChatPacketType +{ + IncomingPacket = 0, + OutgoingPacket = 1 +}; + +class ChatIntegrationLayer + : public std::enable_shared_from_this // shared_from_this is needed to use a weak ref to 'this' when handling delegate callbacks +{ +public: + ChatIntegrationLayer(); + + DQRNetworkManager *m_pDQRNet; + /// + /// Initializes the chat manager + /// + void InitializeChatManager( + __in bool combineCaptureBuffersIntoSinglePacketEnabled, + __in bool useKinectAsCaptureSource, + __in bool applySoundEffectToCapture, + __in bool applySoundEffectToRender, + DQRNetworkManager *pDQRNet + ); + + /// + /// Shuts down the chat manager + /// + void Shutdown(); + + class AddedUser + { + public: + AddedUser(Windows::Xbox::System::IUser^ user, bool canCaptureAudio); + Windows::Xbox::System::IUser^ m_user; + bool m_canCaptureAudio; + }; + + void AddLocalUser( __in Windows::Xbox::System::IUser^ user ); + void RemoveLocalUser( __in Windows::Xbox::System::IUser^ user ); + void EvaluateDevicesForUser(__in Windows::Xbox::System::IUser^ user ); + + vector m_addedUsers; + CRITICAL_SECTION m_csAddedUsers; + +private: + /// + /// Adds a local user to a specific channel + /// This is helper function waits for the task to complete so shouldn't be called from the UI thread + /// + /// The channel to add the user to + /// The local user to add + void AddLocalUserToChatChannel( + __in uint8 channelIndex, + __in Windows::Xbox::System::IUser^ user + ); + + /// + /// Removes a local user from a specific channel + /// This is helper function waits for the task to complete so shouldn't be called from the UI thread + /// + /// The channel to remove the user from + /// The local user to remove + void RemoveUserFromChatChannel( + __in uint8 channelIndex, + __in Windows::Xbox::System::IUser^ user + ); +public: + + /// + /// Removes a remote console from chat + /// This is helper function waits for the task to complete so shouldn't be called from the UI thread + /// + /// A unique ID for the remote console + void RemoveRemoteConsole( + unsigned int address + ); + + /// + /// Handles incoming chat messages from the game's network layer + /// + /// A buffer containing the chat message + /// A unique ID for the remote console + void OnIncomingChatMessage( + unsigned int sessionAddress, + Platform::Array^ message + ); + + /// + /// Returns a list of chat users in the chat session + /// + Windows::Foundation::Collections::IVectorView^ GetChatUsers(); + + /// + /// Returns true if the game has mic focus. Otherwise another app has mic focus + /// + bool HasMicFocus(); + + /// + /// Helper function to swap the mute state of a specific chat user + /// + void ChangeChatUserMuteState( + __in Microsoft::Xbox::GameChat::ChatUser^ chatUser + ); + + /// + /// Helper function to change the channel of a specific chat user + /// + void HandleChatChannelChanged( + __in uint8 oldChatChannelIndex, + __in uint8 newChatChannelIndex, + __in Microsoft::Xbox::GameChat::ChatUser^ chatUser + ); + + /// + /// Call this when a new console connects. + /// This adds this console to the chat layer + /// + void OnNewSessionAddressAdded( + __in unsigned int address + ); + + /// + /// Adds a list of locally signed in users that have intent to play to the chat session on a specific channel index. + /// Avoid adding any user who is signed in that doesn't have intent to play otherwise users who are biometrically + /// signed in automatically will be added to the chat session + /// + /// The channel to add the users to + /// A list of locally signed in users that have intent to play + void AddAllLocallySignedInUsersToChatClient( + __in uint8 channelIndex, + __in Windows::Foundation::Collections::IVectorView^ locallySignedInUsers + ); + + /// + /// Handles when a debug message is received. Send this to the UI and OutputDebugString. Games should integrate with their existing log system. + /// + /// Contains the debug message to log + void OnDebugMessageReceived( + __in Microsoft::Xbox::GameChat::DebugMessageEventArgs^ args + ); + + /// + /// Send the chat packet to all connected consoles + /// + /// To integrate the Chat DLL in your game, change the following code to use your game's network layer. + /// You will need to isolate chat messages to be unique from the rest of you game's other message types. + /// When args->SendPacketToAllConnectedConsoles is true, your game should send the chat message to each connected console using the game's network layer. + /// It should send the chat message with Reliable UDP if args->SendReliable is true. + /// It should send the chat message in order (if that feature is available) if args->SendInOrder is true + /// + /// Describes the packet to send + void OnOutgoingChatPacketReady( + __in Microsoft::Xbox::GameChat::ChatPacketEventArgs^ args + ); + + /// + /// Example of how to cast an int to a Platform::Object^ + /// + Platform::Object^ IntToPlatformObject( + __in int val + ); + + /// + /// Example of how to cast an Platform::Object^ to an int + /// + int PlatformObjectToInt( + __in Platform::Object^ obj + ); + + /// + /// Helper function to get specific ChatUser by xboxUserId + /// + Microsoft::Xbox::GameChat::ChatUser^ GetChatUserByXboxUserId( + __in Platform::String^ xboxUserId + ); + + /// + /// Helper function to get specific ChatUser by xboxUserId + /// + bool ChatIntegrationLayer::CompareUniqueConsoleIdentifiers( + __in Platform::Object^ uniqueRemoteConsoleIdentifier1, + __in Platform::Object^ uniqueRemoteConsoleIdentifier2 + ); + + /// + /// Helper function to return the ChatPerformanceCounters^ from the ChatManager so perf numbers can be shown on the UI + /// These numbers will only be valid if m_chatManager->ChatSettings->PerformanceCountersEnabled is set to true. + /// + Microsoft::Xbox::GameChat::ChatPerformanceCounters^ GetChatPerformanceCounters(); + + /// + /// Returns a count of the number of chat packets of a specific type that have been either sent or received. + /// It is useful to monitor this number in the UI / logs to debug network issues. + /// + int GameUI_GetPacketStatistic( + __in Microsoft::Xbox::GameChat::ChatMessageType messageType, + __in ChatPacketType chatPacketType + ); + + void OnControllerPairingChanged( + __in Windows::Xbox::Input::ControllerPairingChangedEventArgs^ args + ); + + void ToggleRenderTargetVolume(); + +private: + void GetBufferBytes( __in Windows::Storage::Streams::IBuffer^ buffer, __out byte** ppOut ); + Windows::Storage::Streams::IBuffer^ ArrayToBuffer( __in Platform::Array^ array ); + + Concurrency::critical_section m_lock; + Microsoft::Xbox::GameChat::ChatManager^ m_chatManager; + Windows::Foundation::EventRegistrationToken m_tokenOnDebugMessage; + Windows::Foundation::EventRegistrationToken m_tokenOnOutgoingChatPacketReady; + Windows::Foundation::EventRegistrationToken m_tokenOnCompareUniqueConsoleIdentifiers; + Windows::Foundation::EventRegistrationToken m_tokenResourceAvailabilityChanged; + Windows::Foundation::EventRegistrationToken m_tokenOnPreEncodeAudioBuffer; + Windows::Foundation::EventRegistrationToken m_tokenOnPostDecodeAudioBuffer; + Windows::Foundation::EventRegistrationToken m_tokenUserAudioDeviceAdded; + Windows::Foundation::EventRegistrationToken m_tokenUserAudioDeviceRemoved; + Windows::Foundation::EventRegistrationToken m_tokenUserAudioDeviceChanged; + + // Debug stats for chat packets. Use Debug_GetPacketStatistic() to get the values. + /// It is useful to monitor this number in the UI / logs to debug network issues. + void GameUI_RecordPacketStatistic( + __in Microsoft::Xbox::GameChat::ChatMessageType messageType, + __in ChatPacketType chatPacketType + ); + Concurrency::critical_section m_chatPacketStatsLock; + int m_chatVoicePacketsStatistic[2][(int)Microsoft::Xbox::GameChat::ChatMessageType::InvalidMessage+1]; +}; + +std::shared_ptr GetChatIntegrationLayer(); \ No newline at end of file -- cgit v1.2.3