public void CompleteGetXToken(int hresult, XUserGetTokenAndSignatureUtf16Data tokenData) { PlayFabMultiplayerManager._LogInfo("PlayFabChatXboxLivePolicyProvider:CompleteGetXToken(), hr: " + hresult); if (hresult >= 0) { Get().Succeeded(XBLSDK.PartyXblCompleteGetTokenAndSignatureRequest( Get()._xblPartyHandle, correlationId, true, tokenData.Token, tokenData.Signature )); } else if (hresult == _E_GAMEUSER_RESOLVE_USER_ISSUE_REQUIRED) { // We need to resolve #if (MICROSOFT_GAME_CORE || UNITY_GAMECORE) XGamingRuntime.SDK.XUserResolveIssueWithUiUtf16Async( Get()._xblLocalUserHandle, url, _ResolveUserIssueWithUICompleted ); #endif } else { PlayFabMultiplayerManager._LogError(_ErrorMessageCouldNotGetXboxLiveToken); } }
private void TryCreateRemoteXboxLiveChatUser(PlayFabPlayer otherPlayer) { if (string.IsNullOrEmpty(otherPlayer._platformSpecificUserId)) { _queuedCreateRemoteXboxLiveChatUserOps.Add(new QueuedCreateRemoteXboxLiveChatUserOp() { otherPlayer = otherPlayer }); return; } ulong xuid = Convert.ToUInt64(otherPlayer._platformSpecificUserId); PlayFabMultiplayerManager._LogInfo("PlayFabChatXboxLivePolicyProvider:TryCreateRemoteXboxLiveChatUser(), XUID: " + xuid); if (Succeeded(XBLSDK.PartyXblCreateRemoteChatUser( _xblPartyHandle, xuid, out otherPlayer._xblChatUserHandle ))) { for (int i = 0; i < _queuedCreateRemoteXboxLiveChatUserOps.Count; i++) { if (xuid == _queuedCreateRemoteXboxLiveChatUserOps[i].xuid) { _queuedCreateRemoteXboxLiveChatUserOps.RemoveAt(i); break; } } } }
public void ProcessEndpointMessage(PlayFabPlayer fromPlayer, IntPtr messageBuffer, uint messageSize) { // Another client asks for our client's XUID if (messageSize > 0 && messageSize < _INTERNAL_XUID_EXCHANGE_MESSAGE_BUFFER_SIZE) { Marshal.Copy(messageBuffer, _internalXuidExchangeMessageBuffer, 0, (int)messageSize); if (StartsWithSequence(_internalXuidExchangeMessageBuffer, _XUID_EXCHANGE_REQUEST_AS_BYTES)) { PlayFabMultiplayerManager._LogInfo("PlayFabChatXboxLivePolicyProvider: received remote XUID."); // Find the other client and set their XIUD byte[] remoteXuidAsBytes = new byte[_internalXuidExchangeMessageBuffer.Length - _XUID_EXCHANGE_REQUEST_AS_BYTES.Length - 1]; Array.Copy(_internalXuidExchangeMessageBuffer, _XUID_EXCHANGE_REQUEST_AS_BYTES.Length + 1, remoteXuidAsBytes, 0, remoteXuidAsBytes.Length); fromPlayer._platformSpecificUserId = Encoding.Default.GetString(remoteXuidAsBytes); PlayFabMultiplayerManager._LogInfo("PlayFabChatXboxLivePolicyProvider: sent XUID exchange response message."); // Update queued operations for (int i = 0; i < _queuedCreateRemoteXboxLiveChatUserOps.Count; i++) { if (_queuedCreateRemoteXboxLiveChatUserOps[i].otherPlayer.EntityKey.Id == fromPlayer.EntityKey.Id) { ulong remoteXuid = Convert.ToUInt64(fromPlayer._platformSpecificUserId); _queuedCreateRemoteXboxLiveChatUserOps[i].xuid = remoteXuid; break; } } } } }
private void OnPlayFabLoginSuccess(PARTY_XBL_LOGIN_TO_PLAYFAB_COMPLETED_STATE_CHANGE loginResult) { PlayFabMultiplayerManager._LogInfo("PlayFabChatXboxLivePolicyProvider:OnPlayFabLoginSuccess(), EntityId: " + loginResult.entityId); EntityKey entityKey = new EntityKey() { Id = loginResult.entityId, Type = "title_player_account" }; _multiplayerManager._CreateLocalUser(entityKey, loginResult.titlePlayerEntityToken); }
private void UpdateChatPermissionInfoComplete(PARTY_XBL_CHAT_USER_HANDLE localXblChatUser, PARTY_XBL_CHAT_USER_HANDLE targetXblChatUser) { PlayFabMultiplayerManager._LogInfo("PlayFabChatXboxLivePolicyProvider:UpdateChatPermissionInfoComplete()"); ulong localXuid; ulong targetXuid; if (!Succeeded(XBLSDK.PartyXblChatUserGetXboxUserId(localXblChatUser, out localXuid))) { return; } if (!Succeeded(XBLSDK.PartyXblChatUserGetXboxUserId(targetXblChatUser, out targetXuid))) { return; } PlayFabPlayer localPlayer = GetPlayerByXuid(localXuid); PlayFabPlayer targetPlayer = GetPlayerByXuid(targetXuid); PARTY_XBL_CHAT_PERMISSION_INFO chatPermissionInfo; Succeeded(XBLSDK.PartyXblLocalChatUserGetRequiredChatPermissionInfo( localXblChatUser, targetXblChatUser, out chatPermissionInfo )); Succeeded(PartyCSharpSDK.SDK.PartyChatControlSetPermissions( localPlayer._chatControlHandle, targetPlayer._chatControlHandle, chatPermissionInfo.ChatPermissionMask )); var permissionsQuery = chatPermissionInfo.ChatPermissionMask; if (permissionsQuery != _CHAT_PERMISSIONS_ALL) { foreach (var playerKeyPair in _multiplayerManager.RemotePlayers) { if (playerKeyPair.EntityKey.Id == targetPlayer.EntityKey.Id) { playerKeyPair._mutedByPlatform = true; playerKeyPair.IsMuted = true; break; } } } if (!_playerChatPermissions.ContainsKey(targetPlayer)) { _playerChatPermissions.Add(targetPlayer, chatPermissionInfo); } }
public PARTY_CHAT_PERMISSION_OPTIONS GetChatPermissions(PlayFabPlayer targetPlayer) { PlayFabMultiplayerManager._LogInfo("PlayFabChatXboxLivePolicyProvider:GetChatPermissions()"); PARTY_CHAT_PERMISSION_OPTIONS chatPermissions = _CHAT_PERMISSIONS_ALL; if (_playerChatPermissions.ContainsKey(targetPlayer)) { chatPermissions = _playerChatPermissions[targetPlayer].ChatPermissionMask; } PlayFabMultiplayerManager._LogInfo("PlayFabChatXboxLivePolicyProvider:get chat permissions for EntityId: " + targetPlayer.EntityKey.Id + ", chat permissions: " + chatPermissions); return(chatPermissions); }
private void _ResolveUserIssueWithUICompleted(int hresult) { PlayFabMultiplayerManager._LogInfo("PlayFabChatXboxLivePolicyProvider:_ResolveUserIssueWithUICompleted(), hr: " + hresult); if (_pendingResolveIssueWithUICallback) { return; } _pendingResolveIssueWithUICallback = true; if (Get().HrSucceeded(hresult)) { Get().SignIn(); } }
public void SignIn() { PlayFabMultiplayerManager._LogInfo("PlayFabChatXboxLivePolicyProvider:SignIn()"); try { XGamingRuntime.SDK.XUserAddAsync(XUserAddOptions.AddDefaultUserSilently, SignInSilentlyComplete); } catch (NullReferenceException) { PlayFabMultiplayerManager._LogError(_ErrorMessageGamingRuntimeNotInitialized); } catch (Exception ex) { PlayFabMultiplayerManager._LogError(ex.Message); } }
public PlayFabChatXboxLivePolicyProvider() { PlayFabMultiplayerManager._LogInfo("PlayFabChatXboxLivePolicyProvider:PlayFabChatXboxLivePolicyProvider()"); _multiplayerManager = PlayFabMultiplayerManager.Get(); string titleId = PlayFabSettings.staticSettings.TitleId; _playerChatPermissions = new Dictionary <PlayFabPlayer, PARTY_XBL_CHAT_PERMISSION_INFO>(new PlayerComparator()); _queuedCreateRemoteXboxLiveChatUserOps = new List <QueuedCreateRemoteXboxLiveChatUserOp>(); _xblStateChanges = new List <PARTY_XBL_STATE_CHANGE>(); _internalXuidExchangeMessageBuffer = new byte[_INTERNAL_XUID_EXCHANGE_MESSAGE_BUFFER_SIZE]; Succeeded(XBLSDK.PartyXblInitialize(titleId, out _xblPartyHandle)); _XUID_EXCHANGE_REQUEST_AS_BYTES = Encoding.ASCII.GetBytes(_XUID_EXCHANGE_REQUEST_MESSAGE_PREFIX); _XUID_EXCHANGE_RESPONSE_AS_BYTES = Encoding.ASCII.GetBytes(_XUID_EXCHANGE_RESPONSE_MESSAGE_PREFIX); }
private void UpdateChatPermissionInfoStart(PARTY_XBL_CHAT_USER_HANDLE localXblChatUser, PARTY_XBL_CHAT_USER_HANDLE targetXblChatUser) { PlayFabMultiplayerManager._LogInfo("PlayFabChatXboxLivePolicyProvider:UpdateChatPermissionInfoStart()"); if (IsReadyToSetChatPermissions(localXblChatUser, targetXblChatUser)) { UpdateChatPermissionInfoComplete(localXblChatUser, targetXblChatUser); } else { _queuedUpdateChatPermissionsOp = new QueuedUpdateChatPermissionsOp() { queued = true, localXblChatUser = localXblChatUser, targetXblChatUser = targetXblChatUser }; } }
public bool IsTextToSpeechEnabled() { bool isTextToSpeechEnabled = false; PARTY_XBL_ACCESSIBILITY_SETTINGS accessibilitySettings; Succeeded(XBLSDK.PartyXblLocalChatUserGetAccessibilitySettings( _xblLocalChatUserHandle, out accessibilitySettings )); if (accessibilitySettings != null && accessibilitySettings.TextToSpeechEnabled != 0) { isTextToSpeechEnabled = true; } PlayFabMultiplayerManager._LogInfo("PlayFabChatXboxLivePolicyProvider:IsTextToSpeechEnabled(), value: " + isTextToSpeechEnabled); return(isTextToSpeechEnabled); }
public bool CleanUp() { PlayFabMultiplayerManager._LogInfo("PlayFabChatXboxLivePolicyProvider:CleanUp()"); bool succeeded = true; succeeded = Succeeded(XBLSDK.PartyXblCleanup(_xblPartyHandle)); _xblPolicyProvider = null; _playerChatPermissions = null; _xblStateChanges = null; _queuedCreateRemoteXboxLiveChatUserOps = null; _internalXuidExchangeMessageBuffer = null; _XUID_EXCHANGE_REQUEST_AS_BYTES = null; _XUID_EXCHANGE_RESPONSE_AS_BYTES = null; _xblLocalChatUserHandle = null; _xblPartyHandle = null; return(succeeded); }
public void CreateOrUpdatePlatformUser(PlayFabPlayer player, bool isLocal) { PlayFabMultiplayerManager._LogInfo("PlayFabChatXboxLivePolicyProvider:CreateOrUpdatePlatformUser()"); if (isLocal) { ulong xuid; #if (MICROSOFT_GAME_CORE || UNITY_GAMECORE) if (HrSucceeded(XGamingRuntime.SDK.XUserGetId(_xblLocalUserHandle, out xuid))) #endif { player._platformSpecificUserId = xuid.ToString(); } } else { TryCreateRemoteXboxLiveChatUser(player); } }
public PARTY_VOICE_CHAT_TRANSCRIPTION_OPTIONS GetPlatformUserChatTranscriptionPreferences() { PARTY_XBL_ACCESSIBILITY_SETTINGS accessibilitySettings; PARTY_VOICE_CHAT_TRANSCRIPTION_OPTIONS partyChatTranscriptionOptions = PARTY_VOICE_CHAT_TRANSCRIPTION_OPTIONS.PARTY_VOICE_CHAT_TRANSCRIPTION_OPTIONS_NONE; Succeeded(XBLSDK.PartyXblLocalChatUserGetAccessibilitySettings( _xblLocalChatUserHandle, out accessibilitySettings )); if (accessibilitySettings != null && accessibilitySettings.SpeechToTextEnabled != 0) { partyChatTranscriptionOptions = PARTY_VOICE_CHAT_TRANSCRIPTION_OPTIONS.PARTY_VOICE_CHAT_TRANSCRIPTION_OPTIONS_TRANSCRIBE_OTHER_CHAT_CONTROLS_WITH_MATCHING_LANGUAGES | PARTY_VOICE_CHAT_TRANSCRIPTION_OPTIONS.PARTY_VOICE_CHAT_TRANSCRIPTION_OPTIONS_TRANSCRIBE_SELF; } PlayFabMultiplayerManager._LogInfo("PlayFabChatXboxLivePolicyProvider:GetPlatformUserChatTranscriptionPreferences(), transcription options: " + partyChatTranscriptionOptions); return(partyChatTranscriptionOptions); }
private void SignInSilentlyComplete(int hresult, XUserHandle userHandle) { if (HrSucceeded(hresult)) { _xblLocalUserHandle = userHandle; } else { PlayFabMultiplayerManager._LogError(_ErrorMessageXboxLiveSignInFailed); } ulong xuid; int hr = 0; #if (MICROSOFT_GAME_CORE || UNITY_GAMECORE) hr = XGamingRuntime.SDK.XUserGetId(_xblLocalUserHandle, out xuid); #endif PlayFabMultiplayerManager._LogInfo("PlayFabChatXboxLivePolicyProvider:SignInSilentlyComplete(), XUID: " + xuid); if (HrSucceeded(hresult)) { if (_xblLocalChatUserHandle == null) { Succeeded(XBLSDK.PartyXblCreateLocalChatUser( _xblPartyHandle, xuid, null, out _xblLocalChatUserHandle )); } Succeeded(XBLSDK.PartyXblLoginToPlayFab( _xblLocalChatUserHandle, null )); } else { PlayFabMultiplayerManager._LogError(_ErrorMessageCouldNotGetXuid); } }
public void SendPlatformSpecificUserId(List <PlayFabPlayer> targetPlayers) { PlayFabMultiplayerManager._LogInfo("PlayFabChatXboxLivePolicyProvider:SendPlatformSpecificUserId()"); // Broadcast XUID to other endpoints in the network. ulong xuid; #if (MICROSOFT_GAME_CORE || UNITY_GAMECORE) if (HrSucceeded(XGamingRuntime.SDK.XUserGetId(_xblLocalUserHandle, out xuid))) #endif { string xuidMessageString = _XUID_EXCHANGE_REQUEST_MESSAGE_PREFIX + ":" + xuid; byte[] xuidMessageBytes = Encoding.ASCII.GetBytes(xuidMessageString); _multiplayerManager._SendDataMessage(xuidMessageBytes, targetPlayers, DeliveryOption.Guaranteed); } else { PlayFabMultiplayerManager._LogError(_ErrorMessageCouldNotGetXuid); } }
public void ProcessEndpointMessage(PlayFabPlayer fromPlayer, IntPtr messageBuffer, uint messageSize) { // Another client asks for our client's XUID if (messageSize > 0 && messageSize < _INTERNAL_XUID_EXCHANGE_MESSAGE_BUFFER_SIZE) { Marshal.Copy(messageBuffer, _internalXuidExchangeMessageBuffer, 0, (int)messageSize); if (StartsWithSequence(_internalXuidExchangeMessageBuffer, _XUID_EXCHANGE_REQUEST_AS_BYTES)) { PlayFabMultiplayerManager._LogInfo("PlayFabChatXboxLivePolicyProvider: received remote XUID."); // Find the other client and set their XIUD // The buffer can contain trailing bytes if the application has received any message // that passed the first if check in this function. (messageSize > 0 && messageSize < _INTERNAL_XUID_EXCHANGE_MESSAGE_BUFFER_SIZE) // Alternative to this would be to clear _internalXuidExchangeMessageBuffer before copying the messageBuffer into it. uint remoteXuidAsBytesLength = messageSize - (uint)_XUID_EXCHANGE_REQUEST_AS_BYTES.Length - 1; if (remoteXuidAsBytesLength >= 0) { byte[] remoteXuidAsBytes = new byte[remoteXuidAsBytesLength]; Array.Copy(_internalXuidExchangeMessageBuffer, _XUID_EXCHANGE_REQUEST_AS_BYTES.Length + 1, remoteXuidAsBytes, 0, remoteXuidAsBytes.Length); fromPlayer._platformSpecificUserId = Encoding.ASCII.GetString(remoteXuidAsBytes); PlayFabMultiplayerManager._LogInfo("PlayFabChatXboxLivePolicyProvider: sent XUID exchange response message."); // Update queued operations for (int i = 0; i < _queuedCreateRemoteXboxLiveChatUserOps.Count; i++) { if (_queuedCreateRemoteXboxLiveChatUserOps[i].otherPlayer.EntityKey.Id == fromPlayer.EntityKey.Id) { ulong remoteXuid = Convert.ToUInt64(fromPlayer._platformSpecificUserId); _queuedCreateRemoteXboxLiveChatUserOps[i].xuid = remoteXuid; break; } } } } } }
private void UpdateChatPermissionInfoComplete(PARTY_XBL_CHAT_USER_HANDLE localXblChatUser, PARTY_XBL_CHAT_USER_HANDLE targetXblChatUser) { PlayFabMultiplayerManager._LogInfo("PlayFabChatXboxLivePolicyProvider:UpdateChatPermissionInfoComplete()"); // UpdateChatPermissionInfoComplete() is called when we are finally ready to set permissions, // and thus the cached operation in _queuedUpdateChatPermissionsOp is no longer needed // (if it was created then localXblChatUser and targetXblChatUser from it will be used in this method // to set permissions). It needs to be reset to prevent unnecessary continuous re-entrance to this method. if (_queuedUpdateChatPermissionsOp.queued) { _queuedUpdateChatPermissionsOp = new QueuedUpdateChatPermissionsOp(); // reset _queuedUpdateChatPermissionsOp to its initial (default) state } ulong localXuid; ulong targetXuid; if (!Succeeded(XBLSDK.PartyXblChatUserGetXboxUserId(localXblChatUser, out localXuid))) { return; } if (!Succeeded(XBLSDK.PartyXblChatUserGetXboxUserId(targetXblChatUser, out targetXuid))) { return; } PlayFabPlayer localPlayer = GetPlayerByXuid(localXuid); PlayFabPlayer targetPlayer = GetPlayerByXuid(targetXuid); if (localPlayer == null || targetPlayer == null) { return; } PARTY_XBL_CHAT_PERMISSION_INFO chatPermissionInfo; Succeeded(XBLSDK.PartyXblLocalChatUserGetRequiredChatPermissionInfo( localXblChatUser, targetXblChatUser, out chatPermissionInfo )); Succeeded(PartyCSharpSDK.SDK.PartyChatControlSetPermissions( localPlayer._chatControlHandle, targetPlayer._chatControlHandle, chatPermissionInfo.ChatPermissionMask )); var permissionsQuery = chatPermissionInfo.ChatPermissionMask; if (permissionsQuery != _CHAT_PERMISSIONS_ALL) { foreach (var playerKeyPair in _multiplayerManager.RemotePlayers) { if (playerKeyPair.EntityKey.Id == targetPlayer.EntityKey.Id) { playerKeyPair._mutedByPlatform = true; playerKeyPair.IsMuted = true; break; } } } if (!_playerChatPermissions.ContainsKey(targetPlayer)) { _playerChatPermissions.Add(targetPlayer, chatPermissionInfo); } }
public void ProcessStateChanges() { if (Succeeded(XBLSDK.PartyXblStartProcessingStateChanges(_xblPartyHandle, out _xblStateChanges))) { foreach (PARTY_XBL_STATE_CHANGE stateChange in _xblStateChanges) { PlayFabMultiplayerManager._LogInfo("XBL State change: " + stateChange.StateChangeType.ToString()); switch (stateChange.StateChangeType) { case PARTY_XBL_STATE_CHANGE_TYPE.PARTY_XBL_STATE_CHANGE_TYPE_TOKEN_AND_SIGNATURE_REQUESTED: { var stateChangeConverted = (PARTY_XBL_TOKEN_AND_SIGNATURE_REQUESTED_STATE_CHANGE)stateChange; TrackableGetXTokenCompletedWrapper trackableGetXTokenCompletedWrapper = new TrackableGetXTokenCompletedWrapper(); trackableGetXTokenCompletedWrapper.correlationId = stateChangeConverted.correlationId; trackableGetXTokenCompletedWrapper.url = stateChangeConverted.url; trackableGetXTokenCompletedWrapper.method = stateChangeConverted.method; trackableGetXTokenCompletedWrapper.headers = stateChangeConverted.headers; trackableGetXTokenCompletedWrapper.body = stateChangeConverted.body; XUserGetTokenAndSignatureOptions options = XUserGetTokenAndSignatureOptions.None; if (stateChangeConverted.allUsers) { options |= XUserGetTokenAndSignatureOptions.AllUsers; } if (stateChangeConverted.forceRefresh) { options |= XUserGetTokenAndSignatureOptions.ForceRefresh; } XUserGetTokenAndSignatureUtf16HttpHeader[] tokenRequestHeaders = new XUserGetTokenAndSignatureUtf16HttpHeader[stateChangeConverted.headers.Length]; for (uint i = 0; i < stateChangeConverted.headers.Length; i++) { string tokenRequestHeaderName = stateChangeConverted.headers[i].name; string tokenRequestHeaderValue = stateChangeConverted.headers[i].value; tokenRequestHeaders[i] = new XUserGetTokenAndSignatureUtf16HttpHeader(tokenRequestHeaderName, tokenRequestHeaderValue); } var headers = tokenRequestHeaders; if (stateChangeConverted.headers.Length == 0) { headers = null; } var body = stateChangeConverted.body; if (stateChangeConverted.body.Length == 0) { body = null; } #if (MICROSOFT_GAME_CORE || UNITY_GAMECORE) XGamingRuntime.SDK.XUserGetTokenAndSignatureUtf16Async( _xblLocalUserHandle, options, stateChangeConverted.method, stateChangeConverted.url, headers, body, trackableGetXTokenCompletedWrapper.CompleteGetXToken ); #endif break; } case PARTY_XBL_STATE_CHANGE_TYPE.PARTY_XBL_STATE_CHANGE_TYPE_CREATE_LOCAL_CHAT_USER_COMPLETED: { var stateChangeConverted = (PARTY_XBL_CREATE_LOCAL_CHAT_USER_COMPLETED_STATE_CHANGE)stateChange; _multiplayerManager.InternalCheckStateChangeSucceededOrLogErrorIfFailed(stateChangeConverted.result, stateChangeConverted.errorDetail); break; } case PARTY_XBL_STATE_CHANGE_TYPE.PARTY_XBL_STATE_CHANGE_TYPE_LOGIN_TO_PLAYFAB_COMPLETED: { var stateChangeConverted = (PARTY_XBL_LOGIN_TO_PLAYFAB_COMPLETED_STATE_CHANGE)stateChange; if (_multiplayerManager.InternalCheckStateChangeSucceededOrLogErrorIfFailed(stateChangeConverted.result, stateChangeConverted.errorDetail)) { OnPlayFabLoginSuccess(stateChangeConverted); } break; } case PARTY_XBL_STATE_CHANGE_TYPE.PARTY_XBL_STATE_CHANGE_TYPE_LOCAL_CHAT_USER_DESTROYED: break; case PARTY_XBL_STATE_CHANGE_TYPE.PARTY_XBL_STATE_CHANGE_TYPE_REQUIRED_CHAT_PERMISSION_INFO_CHANGED: { var stateChangeConverted = (PARTY_XBL_REQUIRED_CHAT_PERMISSION_INFO_CHANGED_STATE_CHANGE)stateChange; PARTY_XBL_CHAT_USER_HANDLE localXblChatUser = stateChangeConverted.localChatUser; PARTY_XBL_CHAT_USER_HANDLE targetXblChatUser = stateChangeConverted.targetChatUser; UpdateChatPermissionInfoStart(localXblChatUser, targetXblChatUser); } break; default: break; } } Succeeded(XBLSDK.PartyXblFinishProcessingStateChanges(_xblPartyHandle, _xblStateChanges)); } }