Esempio n. 1
0
        public void JoinRoom(string userToken, string roomName)
        {
            if (XRSocialSDK.InLobby() == false)
            {
                Debug.LogError("You can join the room only when you are in the lobby");
                SalinCallbacks.OnPhotonCallbackError(new PhotonEvent(PhotonAction.JoinRoom, ErrorCode.NotInTheLobby));
                return;
            }

            RoomInfo roomInfo = XRSocialSDK.GetCachedRoomInfo(roomName);

            if (roomInfo != null)
            {
                if (string.IsNullOrEmpty(roomInfo.Password) == false)
                {
                    Debug.LogError("Target room has a password. \n" +
                                   "You must enter the password.");

                    SalinCallbacks.OnPhotonCallbackError(new PhotonEvent(PhotonAction.JoinRoom, ErrorCode.InvalidPassword));
                    return;
                }

                if (roomInfo.BlockedPlayerIdList.ContainsKey(UserManager.Instance.userID))
                {
                    Debug.LogError("You are blocked from target room. \n" +
                                   "You can't join the room");

                    SalinCallbacks.OnPhotonCallbackError(new PhotonEvent(PhotonAction.JoinRoom, ErrorCode.BlockedFromRoom));
                    return;
                }
            }

            PhotonNetwork.JoinRoom(roomName);
        }
Esempio n. 2
0
        public void JoinRoomWithPassword(string userToken, string roomName, string password)
        {
            if (XRSocialSDK.InLobby() == false)
            {
                Debug.LogError("You can join the room only when you are in the lobby");
                SalinCallbacks.OnPhotonCallbackError(new PhotonEvent(PhotonAction.JoinRoom, ErrorCode.NotInTheLobby));
                return;
            }

            RoomInfo roomInfo = XRSocialSDK.GetCachedRoomInfo(roomName);

            if (roomInfo != null)
            {
                if (roomInfo.BlockedPlayerIdList.ContainsKey(UserManager.Instance.userID))
                {
                    Debug.LogError("You are blocked from target room. \n" +
                                   "You can't join the room");

                    SalinCallbacks.OnPhotonCallbackError(new PhotonEvent(PhotonAction.JoinRoom, ErrorCode.BlockedFromRoom));
                    return;
                }
            }

            Hashtable enterRoomInfo = new Hashtable()
            {
                { RoomOptionKey.RoomName, roomName },
                { RoomOptionKey.Password, password },
            };

            PhotonNetwork.JoinRandomRoom(enterRoomInfo, 0);
        }
Esempio n. 3
0
        public void OnConnectedToMaster()
        {
            isConnected = true;

            SetMyPlayer();

            SalinCallbacks.OnPhotonCallbackEvent(new PhotonEvent(PhotonAction.Connect));

            if (AutoJoinLobby == true)
            {
                XRSocialSDK.JoinLobby();
            }
        }
Esempio n. 4
0
        public void OnPlayerPropertiesUpdate(Photon.Realtime.Player targetPlayer, Hashtable changedProps)
        {
            if (targetPlayer.CustomProperties.ContainsKey(PlayerKey.UserId) == false)
            {
                return;
            }

            string userId = targetPlayer.CustomProperties[PlayerKey.UserId].ToString();
            Player player = XRSocialSDK.GetUser(userId);

            if (player == null)
            {
                Debug.Log("Can't find user.");
                return;
            }

            if (changedProps.ContainsKey(PlayerKey.UserId))
            {
                changedProps.Remove(PlayerKey.UserId);
            }

            if (changedProps.ContainsKey(PlayerKey.AllowInvite))
            {
                bool allow = (bool)changedProps[PlayerKey.AllowInvite];
                player.SetAllowInvite(allow, false);

                changedProps.Remove(PlayerKey.AllowInvite);
            }

            var eProp = changedProps.GetEnumerator();

            while (eProp.MoveNext() == true)
            {
                if (eProp.Current.Value == null)
                {
                    player.RemoveUserProperties(eProp.Current.Key.ToString(), false);
                }
                else
                {
                    player.AddUserProperties(new KeyValuePair <object, object>(eProp.Current.Key, eProp.Current.Value), false);
                }
            }
        }
Esempio n. 5
0
        public void JoinOrCreateRoom(string userToken, string roomName, RoomOption roomOption)
        {
            if (XRSocialSDK.InLobby() == false)
            {
                Debug.LogError("You can create or join the room only when you are in the lobby");
                SalinCallbacks.OnPhotonCallbackError(new PhotonEvent(PhotonAction.CreateRoom, ErrorCode.NotInTheLobby));
                return;
            }

            RoomOptions PhotonRoomOptions = PhotonUtility.ConvertPhotonRoomOption(roomOption);

            if (PhotonRoomOptions != null)
            {
                if (PhotonRoomOptions.CustomRoomProperties == null)
                {
                    PhotonRoomOptions.CustomRoomProperties = new Hashtable();
                }
                PhotonRoomOptions.CustomRoomProperties.Add(RoomOptionKey.RoomName, roomName);
            }

            PhotonNetwork.JoinOrCreateRoom(roomName, PhotonRoomOptions, TypedLobby.Default);
        }
Esempio n. 6
0
        public static void OnPhotonCallbackEvent(PhotonEvent photonEvent)
        {
            switch (photonEvent.action)
            {
            case PhotonAction.Connect:
                foreach (var item in new List <SalinCallbacks>(callbacks))
                {
                    item.OnConnectedSocialServer();
                }
                break;

            case PhotonAction.Disconnect:
                foreach (var item in new List <SalinCallbacks>(callbacks))
                {
                    item.OnDisconnectedSocialServer(photonEvent.disconnectCause);
                }
                break;

            case PhotonAction.CreateRoom:
                foreach (var item in new List <SalinCallbacks>(callbacks))
                {
                    item.OnCreateRoom();
                }
                break;

            case PhotonAction.JoinRoom:
                foreach (var item in new List <SalinCallbacks>(callbacks))
                {
                    item.OnJoinRoom();
                }
                break;

            case PhotonAction.LeaveRoom:
                foreach (var item in new List <SalinCallbacks>(callbacks))
                {
                    item.OnLeaveRoom();
                }
                break;

            case PhotonAction.JoinLobby:
                foreach (var item in new List <SalinCallbacks>(callbacks))
                {
                    item.OnJoinedLobby();
                }
                break;

            case PhotonAction.LeaveLobby:
                foreach (var item in new List <SalinCallbacks>(callbacks))
                {
                    item.OnLeftLobby();
                }
                break;

            case PhotonAction.UpdateRoomList:
                foreach (var item in new List <SalinCallbacks>(callbacks))
                {
                    item.OnRoomListUpdate();
                }
                break;

            case PhotonAction.ChangePassword:
                foreach (var item in new List <SalinCallbacks>(callbacks))
                {
                    item.OnChangePassword();
                }
                break;

            case PhotonAction.BlockPlayer:
                foreach (var item in new List <SalinCallbacks>(callbacks))
                {
                    item.OnUserBlock();
                }
                break;

            case PhotonAction.KickPlayer:
                Player kickedPlayer = new Player(photonEvent.pData);
                foreach (var item in new List <SalinCallbacks>(callbacks))
                {
                    item.OnUserKick(kickedPlayer);
                }
                break;

            case PhotonAction.UpdateRoomProperties:
                foreach (var item in new List <SalinCallbacks>(callbacks))
                {
                    item.OnUpdateRoomProperties(photonEvent.prop);
                }
                break;

            case PhotonAction.PlayerEnteredRoom:
                Player enterPlayer = XRSocialSDK.GetUser(photonEvent.data);
                foreach (var item in new List <SalinCallbacks>(callbacks))
                {
                    item.OnPlayerEnteredRoom(enterPlayer);
                }
                break;

            case PhotonAction.PlayerLeftRoom:
                Player leftPlayer = new Player(photonEvent.pData);
                foreach (var item in new List <SalinCallbacks>(callbacks))
                {
                    item.OnPlayerLeftRoom(leftPlayer);
                }
                break;

            case PhotonAction.Message:
                if (string.IsNullOrEmpty(photonEvent.mData.targetrId) == false &&
                    photonEvent.mData.targetrId != UserManager.Instance.userID)
                {
                    return;
                }
                foreach (var item in new List <SalinCallbacks>(callbacks))
                {
                    item.OnReceiveMessage(photonEvent.mData);
                }
                break;
            }
        }