private void OnRemotePlayerJoinedListener(object sender, PlayFabPlayer player) { // this listener should only work for Quick Match flow if (!ApplicationModel.IsQuickMatchFlow) { return; } var remotePlayers = partyNetworkHandler.RemotePlayers; // note: remote players property doesn't consider the current player. if (IsPartyNetworkCreator() && (remotePlayers.Count + 1) == Constants.NUMBER_OF_PLAYERS) { ApplicationModel.JoinedPlayerId = player.EntityKey.Id; ApplicationModel.StartMatch = true; partyNetworkHandler.SendDataMessage( new PartyNetworkMessageWrapper <string> { MessageType = PartyNetworkMessageEnum.PlayersReady, MessageData = "Players ready to play." } ); } }
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 RemotePlayer GetRemotePlayer(PlayFabPlayer player) { // This method will be improved later for adding useful information as the // player NAME return(new RemotePlayer { playFabPlayer = player }); }
public void AddPlayer(PlayFabPlayer player) { var playerId = player?.EntityKey?.Id ?? string.Empty; if (!string.IsNullOrWhiteSpace(playerId) && !players.Exists(p => p.playFabPlayer.EntityKey.Id == playerId)) { players.Add(GetRemotePlayer(player)); } }
public void RemovePlayer(PlayFabPlayer player) { var playerId = player?.EntityKey?.Id ?? string.Empty; if (!string.IsNullOrWhiteSpace(playerId)) { var result = players.Find(p => p.playFabPlayer.EntityKey.Id == playerId); players.Remove(result); } }
public void OnRemotePlayerLeftListener(object sender, PlayFabPlayer player) { if (ApplicationModel.RemotePlayersHandler != null) { ApplicationModel.RemotePlayersHandler.RemovePlayer(player); } ApplicationModel.JoinedPlayerId = string.Empty; playerLeft = true; EnsureGetMatchLobbyPlayerListPopulate()?.RenderList(ApplicationModel.RemotePlayersHandler.players); }
public void OnRemotePlayerJoinedListener(object sender, PlayFabPlayer player) { if (ApplicationModel.RemotePlayersHandler != null) { ApplicationModel.RemotePlayersHandler.AddPlayer(player); } ApplicationModel.JoinedPlayerId = player.EntityKey.Id; playerJoined = true; EnsureGetMatchLobbyPlayerListPopulate()?.RenderList(ApplicationModel.RemotePlayersHandler.players); }
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 PlayFabPlayer GetPlayerByXuid(ulong xuid) { PlayFabPlayer player = null; foreach (PlayFabPlayer currentPlayer in _multiplayerManager.RemotePlayers) { ulong currentPlayerXuid = Convert.ToUInt64(currentPlayer._platformSpecificUserId); if (currentPlayerXuid != 0 && xuid != 0 && currentPlayerXuid == xuid) { player = currentPlayer; break; } } return(player); }
private void OnDataMessageNoCopyReceivedListener(object sender, PlayFabPlayer from, IntPtr buffer, uint bufferSize) { // this listener should only work for Quick Match flow if (!ApplicationModel.IsQuickMatchFlow) { return; } var parsedData = PartyNetworkMessageHelper.GetParsedDataFromBuffer <PartyNetworkMessageWrapper <string> >(buffer, bufferSize); Debug.Log($"OnDataMessageNoCopyReceivedListener: {parsedData.MessageType}"); if (parsedData.MessageType == PartyNetworkMessageEnum.PlayersReady) { ApplicationModel.StartMatch = true; } }
private void Manager_OnDataMessageNoCopyReceived(object sender, PlayFabPlayer from, IntPtr buffer, uint bufferSize) { var messageType = PartyNetworkMessageHelper.GetTypeFromMessageWrapper(buffer, bufferSize); switch (messageType) { case PartyNetworkMessageEnum.GameState: OnGameStateReceived?.Invoke(PartyNetworkMessageHelper.GetDataFromMessageWrapper <GameState>(buffer, bufferSize)); break; case PartyNetworkMessageEnum.Move: OnMoveReceived?.Invoke(from.EntityKey.Id, PartyNetworkMessageHelper.GetDataFromMessageWrapper <TicTacToeMove>(buffer, bufferSize)); break; case PartyNetworkMessageEnum.MatchAbandonment: OnMatchAbandonment?.Invoke(); break; } }
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 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 OnDataMessageNoCopyReceivedListener(object sender, PlayFabPlayer from, IntPtr buffer, uint bufferSize) { var parsedData = PartyNetworkMessageHelper.GetParsedDataFromBuffer <PartyNetworkMessageWrapper <string> >(buffer, bufferSize); switch (parsedData.MessageType) { case PartyNetworkMessageEnum.PlayersReady: ProcessPlayersReadyMessage(); break; case PartyNetworkMessageEnum.MatchLobbyCancelled: ProcessMatchLobbyCancelledMessage(); break; case PartyNetworkMessageEnum.PlayerKicked: ProcessPlayerKickedMessage(parsedData.MessageData); break; default: break; } }
private PlayFabPlayer GetPlayerByXuid(ulong xuid) { if (xuid == 0) { return(null); } // check local player first if (_multiplayerManager.LocalPlayer != null && !string.IsNullOrEmpty(_multiplayerManager.LocalPlayer._platformSpecificUserId)) { ulong localPlayerXuid = Convert.ToUInt64(_multiplayerManager.LocalPlayer._platformSpecificUserId); if (localPlayerXuid == xuid) { return(_multiplayerManager.LocalPlayer); } } // then check all remote players PlayFabPlayer player = null; foreach (PlayFabPlayer currentPlayer in _multiplayerManager.RemotePlayers) { if (string.IsNullOrEmpty(currentPlayer._platformSpecificUserId)) { continue; } ulong currentPlayerXuid = Convert.ToUInt64(currentPlayer._platformSpecificUserId); if (currentPlayerXuid == xuid) { player = currentPlayer; break; } } return(player); }
private void OnDataMessageNoCopyReceived(object sender, PlayFabPlayer from, System.IntPtr buffer, uint bufferSize) { Debug.Log("Got a message (no copy)."); output.text += "\r\n Got a message (no copy)."; }
private void OnDataMessageReceived(object sender, PlayFabPlayer from, byte[] buffer) { Debug.Log("Got a message (simple)."); output.text += "\r\n Got a message (simple)."; }
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); } }