예제 #1
0
        private IEnumerator JoinMatchLobby()
        {
            ApplicationModel.JoinToMatchLobby = false;
            var cancel = false;

            if (ApplicationModel.CurrentMatchLobbyToJoin.locked)
            {
                InvitationCodeModal.InvitationCodeModalResult modalResult = null;
                yield return(AskForInvitationCode((result) => { modalResult = result; }));

                cancel = modalResult.OptionSelected != InvitationCodeModal.OptionSelected.OK;

                if (!cancel)
                {
                    yield return(StartCoroutine(ConnectMatchLobby(ApplicationModel.CurrentMatchLobbyToJoin.matchLobbyId, invitationCodeModal.Result.InvitationCode)));
                }
            }
            else
            {
                yield return(StartCoroutine(ConnectMatchLobby(ApplicationModel.CurrentMatchLobbyToJoin.matchLobbyId)));
            }

            if (!cancel && ApplicationModel.CurrentMatchLobby != null)
            {
                // HACK: set that the lobby players list has changed in order to trigger the players renderization
                ApplicationModel.CreateRemotePlayersHandler(PlayFabMultiplayerManager.Get());
                ApplicationModel.MatchLobbyJoinedPlayerListHasChanged = true;
                SceneManager.LoadScene("MatchLobby");
            }
        }
        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;
                        }
                    }
                }
            }
        }
예제 #3
0
        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;
                    }
                }
            }
        }
예제 #4
0
            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);
                }
            }
예제 #5
0
        private IEnumerator TryCreateMatchLobby(string sessionName)
        {
            var error = Constants.CREATE_MATCH_LOBBY_ERROR;

            UpdateGameStatus(Constants.MATCH_LOBBY_CREATING + sessionName);

            try
            {
                IsLobbyCreated = true;
                yield return(StartCoroutine(CreateMatchLobby(sessionName, true)));

                if (ApplicationModel.CurrentMatchLobby == null)
                {
                    error = Constants.MATCH_LOBBY_REPEATED;
                }
                else
                {
                    ApplicationModel.CreateRemotePlayersHandler(PlayFabMultiplayerManager.Get());
                    SceneManager.LoadScene("MatchLobby");
                    error = string.Empty;
                }
            }
            finally
            {
                if (!string.IsNullOrWhiteSpace(error))
                {
                    IsLobbyCreated = false;
                    UpdateGameStatus(error);
                }
            }
        }
예제 #6
0
 private void HandleUserAuthenticated()
 {
     Logger.Instance.Log("Party  -   HandleUserAuthenticated");
     PlayFabMultiplayerManager.Get().CreateAndJoinNetwork();
     PlayFabMultiplayerManager.Get().OnNetworkJoined += OnNetworkJoined;
     PlayFabMultiplayerManager.Get().OnError         += OnError;
 }
예제 #7
0
        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);
            }
        }
예제 #9
0
        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);
        }
예제 #10
0
            private void _ResolveUserIssueWithUICompleted(int hresult)
            {
                PlayFabMultiplayerManager._LogInfo("PlayFabChatXboxLivePolicyProvider:_ResolveUserIssueWithUICompleted(), hr: " + hresult);

                if (_pendingResolveIssueWithUICallback)
                {
                    return;
                }
                _pendingResolveIssueWithUICallback = true;

                if (Get().HrSucceeded(hresult))
                {
                    Get().SignIn();
                }
            }
예제 #11
0
        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);
        }
예제 #12
0
        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);
            }
        }
예제 #13
0
        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
                };
            }
        }
예제 #14
0
        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);
        }
예제 #15
0
        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);
        }
예제 #16
0
    private void OnNetworkJoined(object sender, string networkId)
    {
        Debug.Log("Joined the network.");
        output.text += "\r\n Joined the network.";

        networkIdTextBox.text = networkId;

        // Simple send message.
        byte[] buffer = Encoding.ASCII.GetBytes("Hello world (simple message).");
        PlayFabMultiplayerManager.Get().SendDataMessageToAllPlayers(buffer);

        // Send a data message. There is a simpler version of this API available as well.
        byte[] buffer2          = Encoding.ASCII.GetBytes("Hello world (no garbage collection method).");
        IntPtr unmanagedPointer = Marshal.AllocHGlobal(buffer2.Length);

        Marshal.Copy(buffer2, 0, unmanagedPointer, buffer2.Length);
        PlayFabMultiplayerManager.Get().SendDataMessage(unmanagedPointer, (uint)buffer2.Length, PlayFabMultiplayerManager.Get().RemotePlayers, DeliveryOption.BestEffort);
        Marshal.FreeHGlobal(unmanagedPointer);
    }
예제 #17
0
        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);
            }
        }
예제 #18
0
        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);
        }
예제 #19
0
        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);
            }
        }
예제 #20
0
        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);
            }
        }
예제 #21
0
        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;
                            }
                        }
                    }
                }
            }
        }
예제 #22
0
    // Start is called before the first frame update
    void Start()
    {
        var playFabMultiplayerManager = PlayFabMultiplayerManager.Get();

        // This will turn on verbose logging that is useful when debugging the SDK.
        //playFabMultiplayerManager.LogLevel = PlayFabMultiplayerManager.LogLevelType.Verbose;

        // Log into playfab. The SDK will use the logged in user when connecting to the network.
        var request = new LoginWithCustomIDRequest {
            CustomId = UnityEngine.Random.value.ToString(), CreateAccount = true
        };

        PlayFabClientAPI.LoginWithCustomID(request, OnLoginSuccess, OnLoginFailure);

        // Listen for this event to know when the SDK has joined the network and can start sending messages.
        playFabMultiplayerManager.OnNetworkJoined += OnNetworkJoined;

        // The simple way to receive data messages.
        playFabMultiplayerManager.OnDataMessageReceived += OnDataMessageReceived;

        // A more complex, but no copy way of recieving data messages.
        playFabMultiplayerManager.OnDataMessageNoCopyReceived += OnDataMessageNoCopyReceived;
    }
예제 #23
0
 private void SendDataMessage <T>(T message)
 {
     PartyNetworkMessageHelper.BufferData(message, out byte[] buffer, out IntPtr unmanagedPointer);
     Manager.SendDataMessage(unmanagedPointer, (uint)buffer.Length, PlayFabMultiplayerManager.Get().RemotePlayers, DeliveryOption.BestEffort);
 }
예제 #24
0
 public void JoinNetwork()
 {
     PlayFabMultiplayerManager.Get().JoinNetwork(networkIdTextBox.text);
 }
예제 #25
0
 public void CreateAndJoinToNetwork()
 {
     // Create and join a network
     PlayFabMultiplayerManager.Get().CreateAndJoinNetwork();
 }
예제 #26
0
 public RemotePlayersHandler(PlayFabMultiplayerManager multiplayerManager)
 {
     players = multiplayerManager.RemotePlayers?.Select(p => GetRemotePlayer(p)).ToList() ?? new List <RemotePlayer>();;
 }
예제 #27
0
        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));
            }
        }
예제 #28
0
        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);
            }
        }