Exemple #1
0
 /// <summary>
 /// ChatManage가 Disconnect를 호출 한뒤 _chatListener를 바로 null값을 넣어주면
 /// OnDisconnect를 넣어 줄수 없기 때문에 _chatListener초기화 하는 함수를 여기서 불러줌
 /// </summary>
 public void OnDisconnected()
 {
     SalinCallbacks.OnDisconnectChat();
     chatClient = null;
     isConnect  = false;
     ChatManager.Reset();
 }
Exemple #2
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);
        }
Exemple #3
0
 public void OnGetMessages(string channelName, string[] senders, object[] messages)
 {
     if (channelName.Equals(this.channelName))
     {
         SalinCallbacks.OnReceiveMessage(senders, messages, true);
     }
 }
        public void RecvRPCData(string data, string action)
        {
            string typeName = this.GetType().Namespace + "." + action;
            var    obj      = MessageSenderUtil.Decode(data, Type.GetType(typeName));

            SalinCallbacks.OnPhotonCallbackEvent(new PhotonEvent(PhotonAction.Message, obj));
        }
Exemple #5
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);
        }
        private void OnReciveEvent(string jsonString)
        {
            Debug.Log("OnReciveEvent (message) : " + jsonString);

            string actionName = GetActionName(jsonString);

            Debug.Log("ActionName=" + actionName);

            SalinCallbacks.OnRelayServerCallbackEvent(actionName, jsonString);
        }
Exemple #7
0
        public void OnPlayerLeftRoom(Photon.Realtime.Player otherPlayer)
        {
            Player player = new Player(otherPlayer);

            RemovePlayerFromList(otherPlayer);

            if (room.BlockedPlayerIdList.ContainsKey(player.userId) == false)
            {
                SalinCallbacks.OnPhotonCallbackEvent(new PhotonEvent(PhotonAction.PlayerLeftRoom, otherPlayer));
            }
        }
Exemple #8
0
        public void OnPlayerEnteredRoom(Photon.Realtime.Player newPlayer)
        {
            Player player = new Player(newPlayer);

            if (room.BlockedPlayerIdList.ContainsKey(player.userId))
            {
                return;
            }

            AddPlayerToList(newPlayer);
            SalinCallbacks.OnPhotonCallbackEvent(new PhotonEvent(PhotonAction.PlayerEnteredRoom, player.userId));
        }
Exemple #9
0
        public void OnRoomListUpdate(List <Photon.Realtime.RoomInfo> roomList)
        {
            foreach (var photonRoomInfo in roomList)
            {
                RoomInfo roomInfo = new RoomInfo(photonRoomInfo);


                if (photonRoomInfo.RemovedFromList == true)
                {
                    if (RoomList.ContainsKey(photonRoomInfo.Name) == true)
                    {
                        RoomList.Remove(photonRoomInfo.Name);
                    }

                    if (CachedRoomList.ContainsKey(photonRoomInfo.Name) == true)
                    {
                        CachedRoomList.Remove(photonRoomInfo.Name);
                    }
                }
                else
                {
                    if (roomInfo.IsVisible == true)
                    {
                        if (RoomList.ContainsKey(photonRoomInfo.Name) == true)
                        {
                            RoomList[photonRoomInfo.Name] = roomInfo;
                        }
                        else
                        {
                            RoomList.Add(photonRoomInfo.Name, roomInfo);
                        }
                    }

                    if (CachedRoomList.ContainsKey(photonRoomInfo.Name) == true)
                    {
                        CachedRoomList[photonRoomInfo.Name] = roomInfo;
                    }
                    else
                    {
                        CachedRoomList.Add(photonRoomInfo.Name, roomInfo);
                    }
                }
            }

            if (InitLobby == false)
            {
                InitLobby = true;
                SalinCallbacks.OnPhotonCallbackEvent(new PhotonEvent(PhotonAction.JoinLobby));
            }

            SalinCallbacks.OnPhotonCallbackEvent(new PhotonEvent(PhotonAction.UpdateRoomList));
        }
Exemple #10
0
        public void OnConnectedToMaster()
        {
            isConnected = true;

            SetMyPlayer();

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

            if (AutoJoinLobby == true)
            {
                XRSocialSDK.JoinLobby();
            }
        }
Exemple #11
0
        public void OnDisconnected(Photon.Realtime.DisconnectCause cause)
        {
            if (isConnected == true)
            {
                SalinCallbacks.OnPhotonCallbackEvent(new PhotonEvent(PhotonAction.Disconnect, (DisconnectCause)cause));
            }
            else
            {
                SalinCallbacks.OnPhotonCallbackError(new PhotonEvent(PhotonAction.Connect, (DisconnectCause)cause));
            }

            isConnected = false;
        }
        public bool Connect(string appId, string userid, Action <bool> connnectCheckAction = null)
        {
            this.userId = userid;
            Protocol.VersionInfo verinfo = new Protocol.VersionInfo();
            verinfo.OS       = Protocol.VersionInfo.eOS.Android;
            verinfo.Major    = 0;
            verinfo.Minor    = 0;
            verinfo.BuildRev = 0;
            verinfo.VC       = 0;
            verinfo.PtVer    = Protocol.Definition.Ver;

            Protocol.ConnectReq req = new Protocol.ConnectReq(this.userId, verinfo);
            string url = "http://" + "54.250.244.221:8080/?" + req.GetQueryString();      // live for softbank

            socket = Socket.Connect(url);
            if (socket)
            {
                socket.On(SystemEvents.connect, () => {
                    Debug.Log("Connected RelayServer");

                    connnectCheckAction(true);

                    SalinCallbacks.OnRelayServerCallbackEvent(RelayServerKey.Connect);

                    socket.On("error", (string data) => {
                        Debug.Log("error : " + data);
                    });

                    socket.On("server-error", OnReciveError);

                    socket.On("event", OnReciveEvent);
                });

                socket.On(SystemEvents.disconnect, () => {
                    Debug.Log("Disconnect RelayServer");

                    connnectCheckAction(false);

                    SalinCallbacks.OnRelayServerCallbackEvent(RelayServerKey.Disconnect);

                    socket.On("error", (string data) => {
                        Debug.Log("error : " + data);
                    });

                    socket.On("server-error", OnReciveError);

                    socket.On("event", OnReciveEvent);
                });
            }
            return(socket != null ? true : false);
        }
Exemple #13
0
        public void OnCreatedRoom()
        {
            InitRoomInfo();

            string userId   = UserManager.Instance.userInfo.userID;
            string userName = UserManager.Instance.userInfo.userNickname;

            room.SetHostPlayerInfo(userId, userName);
            room.SetKeyPlayerInfo(userId, userName);

            room.SetRoomPropertiesForLobby();

            SalinCallbacks.OnPhotonCallbackEvent(new PhotonEvent(PhotonAction.CreateRoom));
        }
Exemple #14
0
        public void OnJoinedRoom()
        {
            XRSocialSDK.myPlayer.UpdatePlayerInfo(PhotonNetwork.LocalPlayer);

            InitRoomInfo();

            if (room.BlockedPlayerIdList.ContainsKey(UserManager.Instance.userID))
            {
                LeaveRoom(SalinTokens.UserToken);
                return;
            }

            SalinCallbacks.OnPhotonCallbackEvent(new PhotonEvent(PhotonAction.JoinRoom));
        }
Exemple #15
0
        public void UserKick(string userToken, Player player)
        {
            Photon.Realtime.Player photonPlayer = PhotonNetwork.CurrentRoom.GetPlayer(player.dynamicCodeInRoom);

            if (PhotonNetwork.CloseConnection(photonPlayer) == true)
            {
                UserBlocking(SalinTokens.UserToken, player);

                if (XRSocialSDK.currentRoom.PlayerList.ContainsKey(player.userId) == true)
                {
                    XRSocialSDK.currentRoom.PlayerList.Remove(player.userId);
                }

                SalinCallbacks.OnPhotonCallbackEvent(new PhotonEvent(PhotonAction.KickPlayer, photonPlayer));
                SalinCallbacks.OnPhotonCallbackEvent(new PhotonEvent(PhotonAction.PlayerLeftRoom, photonPlayer));
            }
        }
Exemple #16
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);
        }
        private void OnReciveError(string jsonString)
        {
            Debug.Log("OnReciveError (message) : " + jsonString);

            string actionName = GetActionName(jsonString);

            Debug.Log("ActionName=" + actionName);

            Debug.Log("received (server-error) : " + jsonString);

            string ID = null;
            int    idx;

            idx = jsonString.IndexOf(":");
            ID  = jsonString.Substring(idx + 2);
            idx = ID.IndexOf(",");
            ID  = ID.Remove(idx - 1);

            idx = jsonString.IndexOf("error") + 8;
            string errorCode = jsonString.Substring(idx, jsonString.Length - (idx + 2));

            SalinCallbacks.OnRelayServerCallbackError(actionName, errorCode);
        }
Exemple #18
0
        public void UserBlocking(string userToken, string userId)
        {
            XRSocialSDK.currentRoom.AddBlockedPlayer(userId);

            SalinCallbacks.OnPhotonCallbackEvent(new PhotonEvent(PhotonAction.BlockPlayer));
        }
Exemple #19
0
        public void OnRoomPropertiesUpdate(Hashtable propertiesThatChanged)
        {
            if (propertiesThatChanged.ContainsKey(RoomOptionKey.RoomName))
            {
                propertiesThatChanged.Remove(RoomOptionKey.RoomName);
            }

            if (propertiesThatChanged.ContainsKey(RoomOptionKey.Password))
            {
                string password = propertiesThatChanged[RoomOptionKey.Password].ToString();
                room.SetPassword(password, false);

                propertiesThatChanged.Remove(RoomOptionKey.Password);

                SalinCallbacks.OnPhotonCallbackEvent(new PhotonEvent(PhotonAction.ChangePassword));
            }

            if (propertiesThatChanged.ContainsKey(RoomOptionKey.IsVisible))
            {
                bool isVisible = (bool)propertiesThatChanged[RoomOptionKey.IsVisible];
                room.SetIsVisible(isVisible, false);
                propertiesThatChanged.Remove(RoomOptionKey.IsVisible);
            }

            if (propertiesThatChanged.ContainsKey(RoomOptionKey.BlockedPlayerIdList))
            {
                Dictionary <string, string> blockedSet = propertiesThatChanged[RoomOptionKey.BlockedPlayerIdList] as Dictionary <string, string>;
                room.SetBlockedPlayerList(blockedSet, false);
                propertiesThatChanged.Remove(RoomOptionKey.BlockedPlayerIdList);
            }

            if (propertiesThatChanged.ContainsKey(RoomOptionKey.HostPlayerId) && propertiesThatChanged.ContainsKey(RoomOptionKey.HostPlayerName))
            {
                var userId   = propertiesThatChanged[RoomOptionKey.HostPlayerId].ToString();
                var userName = propertiesThatChanged[RoomOptionKey.HostPlayerName].ToString();
                room.SetHostPlayerInfo(userId, userName, false);
                propertiesThatChanged.Remove(RoomOptionKey.HostPlayerId);
                propertiesThatChanged.Remove(RoomOptionKey.HostPlayerName);
            }

            if (propertiesThatChanged.ContainsKey(RoomOptionKey.KeyPlayerId) && propertiesThatChanged.ContainsKey(RoomOptionKey.KeyPlayerName))
            {
                var userId   = propertiesThatChanged[RoomOptionKey.KeyPlayerId].ToString();
                var userName = propertiesThatChanged[RoomOptionKey.KeyPlayerName].ToString();
                room.SetKeyPlayerInfo(userId, userName, false);
                propertiesThatChanged.Remove(RoomOptionKey.KeyPlayerId);
                propertiesThatChanged.Remove(RoomOptionKey.KeyPlayerName);
            }

            Dictionary <object, object> changeProp = new Dictionary <object, object>();
            var eProp = propertiesThatChanged.GetEnumerator();

            while (eProp.MoveNext() == true)
            {
                if (eProp.Current.Value == null)
                {
                    room.RemoveRoomProperties(eProp.Current.Key.ToString(), false);
                }
                else
                {
                    room.AddRoomProperties(new KeyValuePair <object, object>(eProp.Current.Key, eProp.Current.Value), false);
                    changeProp.Add(eProp.Current.Key, eProp.Current.Value);
                }
            }

            if (changeProp.Count != 0)
            {
                SalinCallbacks.OnPhotonCallbackEvent(new PhotonEvent(PhotonAction.UpdateRoomProperties, changeProp));
            }
        }
Exemple #20
0
 //유저 방 나감
 public void OnUserUnsubscribed(string channel, string user)
 {
     SalinCallbacks.OnUserDisconnectChat(channel, user);
 }
Exemple #21
0
 public void OnSubscribed(string[] channels, bool[] results)
 {
     SalinCallbacks.OnConnectChat();
     isConnect = true;
 }
Exemple #22
0
 public void OnPrivateMessage(string sender, object message, string channelName)
 {
     string[] senders  = { sender, };
     object[] messages = { message, };
     SalinCallbacks.OnReceiveMessage(senders, messages, false);
 }
Exemple #23
0
 public void OnJoinRoomFailed(short returnCode, string message)
 {
     SalinCallbacks.OnPhotonCallbackError(new PhotonEvent(PhotonAction.JoinRoom, (ErrorCode)returnCode));
 }
Exemple #24
0
 public void OnJoinRandomFailed(short returnCode, string message)
 {
     SalinCallbacks.OnPhotonCallbackError(new PhotonEvent(PhotonAction.JoinRoom, ErrorCode.InvalidPassword));
 }
Exemple #25
0
 public void OnLeftRoom()
 {
     room = null;
     SalinCallbacks.OnPhotonCallbackEvent(new PhotonEvent(PhotonAction.LeaveRoom));
 }
Exemple #26
0
 public void OnLeftLobby()
 {
     InitLobby = false;
     SalinCallbacks.OnPhotonCallbackEvent(new PhotonEvent(PhotonAction.LeaveLobby));
 }