Esempio n. 1
0
    /*
     * public void Replay()
     * {
     *      SendAll("Replay");
     *
     *      m_ClientController.SendEndGame();
     *      m_ClientController.SetPlayerState(UXUser.LobbyState.Wait);
     *      Application.LoadLevel("LobbyClient");
     * }
     */

    public void OnPurchaseSuccess()
    {
        //////////////SendToHost ("PREMIUM,");
        UXPlayerController player = UXPlayerController.Instance;

        player.IsPremium = true;
    }
        /** Send message to server
         *      @param data left,right - Scroll direction, click - click index
         *      @param buttonType "ok", "up", "down", "left", "right", "back", "click"
         */
        public void SendData(string data, string buttonType)
        {
            UXPlayerController player     = UXPlayerController.Instance;
            string             sendString = "{\"cmd\":\"pad_button_touch\",\"u_code\":\"" + player.GetCode() + "\",\"l_code\":\"" + UXConnectController.GetRoomNumber() + "\",\"data\":\"" + data + "\",\"button_type\":\"" + buttonType + "\"}" + DATA_DELIMITER;

            Send(sendString);
        }
Esempio n. 3
0
        /** Set user code and room number
         *      @param aUcode user code
         *      @param roomNumber room number
         *      @return True if codes are valid, false otherwise
         */
        public bool SetCode(int aUcode, int roomNumber)
        {
            UXPlayerController player = UXPlayerController.Instance;

            int lcode = GetRoomNumber();
            int ucode = -1;

            if (lcode != -1)
            {
                ucode = player.GetCode();
            }
            else
            {
                lcode = roomNumber;
                ucode = aUcode;
            }

            if (lcode == -1 || ucode == -1)
            {
                return(false);
            }

            launcherCode = lcode;

            player.SetCode(ucode);

            return(true);
        }
Esempio n. 4
0
    IEnumerator Start()
    {
                #if UNITY_ANDROID && !UNITY_EDITOR
        GameObject go = GameObject.Find("AndroidManager");
        androidManager = go.GetComponent <UXAndroidManager> ();
        androidManager.InitAndroid();
                #endif
        //CommonUtil.ScreenSettingsPortrait();

        if (UXPlayerLauncherController.Instance.IsConnected() == true)
        {
            if (UXConnectController.GetRoomNumber() != -1)
            {
                UXConnectController.SetRoomNumber(-1);
            }
            UXPlayerLauncherController.Instance.Clear();
        }

        playerController = UXPlayerController.Instance;

        yield return(CommonLang.instance);

        //chineseButton.SetActive(true);
        //englishButton.SetActive(true);
        //logoImage.SetActive(true);
        //ChinaButton ();
        EnglishButton();

                #if UNITY_ANDROID && !UNITY_EDITOR
        infoText.text = androidManager.GetVersionName("com.cspmedia.gamepartyplayer") + "/" + ((ServerList)PlayerPrefs.GetInt("ServerList"));
                #endif
    }
        /** Send leave message */
        public void Leave()
        {
            UXPlayerController player = UXPlayerController.Instance;

            string sendString = "{\"cmd\":\"leave_user\",\"u_code\":\"" + player.GetCode() + "\",\"l_code\":\"" + UXConnectController.GetRoomNumber() + "\"}" + DATA_DELIMITER;

            Send(sendString);
        }
Esempio n. 6
0
        /** Request for user list
         *  @see OnUserListReceived
         */
        public void RefreshUserListFromServer()
        {
            UXPlayerController player = UXPlayerController.Instance;

            string msg = "{\"cmd\":\"get_user_list\",\"u_code\":\"" + player.GetCode() + "\",\"l_code\":\"" + room.RoomNumber + "\"}" + DATA_DELIMITER;

            Send(msg);//{"cmd":"get_user_list","l_code":"launcherCode"}232
            Debug.Log("RefreshUserListFromServer!!");
        }
Esempio n. 7
0
 public UXConnectController()
     : base("UXConnectController")
 {
     receiveQueue = new List <string>();
     systemUID    = SystemInfo.deviceUniqueIdentifier;
     connect      = UXRoomConnect.Instance;
     room         = UXRoom.Instance;
     player       = UXPlayerController.Instance;
     PlayerPrefs.SetInt("ServerList", 0); //china
     ServerCheck((ServerList)PlayerPrefs.GetInt("ServerList"));
 }
Esempio n. 8
0
        /** Send join message */
        public override void Join(string packageName)           //data는쓰레기 호출할때도 "none"
        {
            Debug.Log("Join");
            UXPlayerController playerController = UXPlayerController.Instance;

            int    userCode = playerController.GetCode();
            string name     = playerController.GetName();

            string msg = "{\"cmd\":\"join\",\"type\":\"user\",\"l_code\":\"" + room.RoomNumber + "\",\"u_code\":\"" + userCode + "\",\"name\":\"" + name + "\",\"max_user\":\"0\", \"package_name\" : \"" + packageName + "\"}" + DATA_DELIMITER;

            Debug.Log(msg);
            Send(msg);            //{"cmd":"join","type":"user","l_code":"launcherCode","u_code":"userCode","name":"name","max_user":"******"}232
        }
Esempio n. 9
0
    public void AfterJoin()
    {
        Debug.Log("AfterJoin " + inapp.IsPremiumVersion());
        if (inapp.IsPremiumVersion())
        {
            ////////////SendToHost("PREMIUM,");
            UXPlayerController player = UXPlayerController.Instance;
            player.IsPremium = true;
        }
        inapp.OnPurchaseSuccess += OnPurchaseSuccess;

        Destroy(backDrop);
    }
Esempio n. 10
0
        void ProcessReceivedMessage(string data)
        {
            if (string.IsNullOrEmpty(data) == true || data.Length <= 0)             //data가 비어있따면
            {
                return;
            }

            var    N       = JSON.Parse(data);
            string command = N["cmd"];

            bool isRunBaseProcess = false;

            if (command == "join_result")
            {
                int result = N["ack"].AsInt;
                if (result != UXRoomConnect.ACK_RESULT_OK)
                {
                    int errCode = ProcessConnectError(result);

                    if (OnJoinFailed != null)
                    {
                        OnJoinFailed(result);
                    }
                    return;
                }

                isJoined = true;

                string temp = N["user"];
                isHostJoined = N["is_host"].AsBool;

                string[] infos = temp.Split('.');

                UXPlayerController player = UXPlayerController.Instance;

                player.SetCode(Int32.Parse(infos[0]));
                player.SetName(infos[1]);

                if (OnJoinSucceeded != null)
                {
                    OnJoinSucceeded(isHostJoined);
                }
            }
            else                  //cmd != join_result
            {
                base.ProcessReceivedMessage(data);
                Debug.Log("ProcessReceivedMessage : " + data);
            }
        }
        /** Send join message
         *      @param roomNumber room number
         */
        public override void Join(string data)
        {
            Debug.Log("Join");
            UXPlayerController player = UXPlayerController.Instance;

            if (player.IsUserLogin() == false)
            {
                OnJoinFailed(JOIN_ERROR_NOT_LOGIN);
                return;
            }

            string sendString = "{\"cmd\":\"join_user\",\"u_code\":\"" + player.GetCode() + "\",\"u_name\":\"" + player.GetName() + "\",\"l_code\":\"" + launcherCode + "\"}" + DATA_DELIMITER;

            Debug.Log("sen " + sendString);
            Send(sendString);
        }
Esempio n. 12
0
        /** Test network speed and send the data to host
         *  @param count sending count
         *  @param sendResult True if want to broadcat the result, false otherwise
         */
        public void NetworkTest(int count, bool sendResult = false)
        {//안쓰는듯
            UXPlayerController player = UXPlayerController.Instance;

            isSendNetWorkResult = sendResult;
            networkCheckCount   = count;
            networkCheckValues  = new long[count];

            for (int i = 0; i < count; i++)
            {
                string sendString = "{\"cmd\":\"check_network_state\",\"u_code\":\"" + player.GetCode() + "\",\"l_code\":\"" + launcherCode + "\",\"count\":\"" + (i + 1) + "\",\"time\":\"" + DateTime.Now.Ticks + "\"}" + DATA_DELIMITER;
                connect.Send(sendString);
                //{"cmd":"check_network_state","u_code":"player.GetCode()","l_code":"launcherCode","count":"(i+1)","time":"DataTime.Now.Ticks"}232

                System.Threading.Thread.Sleep(50);
            }
        }
Esempio n. 13
0
        /** Set player's lobby state
         *      @param state lobby state
         *      @see UXUser.LobbyState
         */
        public void SetPlayerState(UXUser.LobbyState state)
        {
            UXPlayerController player = UXPlayerController.Instance;

            player.SetLobbyState(state);

            string stateString = "";

            if (state == UXUser.LobbyState.Ready)
            {
                stateString = "ready";
            }
            else
            {
                stateString = "wait";
            }

            string sendString = "{\"cmd\":\"change_lobby_state\",\"u_code\":\"" + player.GetCode() + "\",\"l_code\":\"" + room.RoomNumber + "\",\"state\":\"" + stateString + "\"}" + UXConnectController.DATA_DELIMITER; //<-?

            Send(sendString);                                                                                                                                                                                             //{"cmd":change_lobby_state","u_code":player.GetCode()","l_code":"GetRoomNumber()","state":stateString"}232
        }
Esempio n. 14
0
        protected void ProcessReceivedMessage(string data)
        {
            if (string.IsNullOrEmpty(data) == true || data.Length <= 0)
            {
                Debug.Log("Empty"); //data 비어있떠
                return;
            }

            Debug.Log("UXConnectController ProcessReceivedMessage data : " + data);

            var    N       = JSON.Parse(data);
            string command = N["cmd"];

            if (command == "ack_result")
            {
                if (isSendAck == true && ackSender != null)                   //x
                {
                    ackSender.ReceiveResult();
                }
            }
            else if (command == "user_add")
            {
                int    code    = N ["u_code"].AsInt;
                string name    = ParseUser(N ["name"]);
                UXUser userObj = new UXUser(name, code);

                Debug.Log("UserAdd : " + name);

                room.AddUser(userObj);

                var array = N ["user_list"];

                if (array != null)
                {
                    List <UXUser> list = ParseUserList((JSONArray)array);                     //리스트 갱신

                    room.UpdateUserList(list);
                }

                if (OnUserAdded != null)
                {
                    int userIndex = GetUserIndexFromCode(code);
                    OnUserAdded(userIndex, code);                      //playerCount 갱신, index 증가 -> index는 접속할 유저에게 할당할 index  +이벤트 하나더 (로비매니저)
                }
            }
            else if (command == "user_del")
            {
                int code      = N ["u_code"].AsInt;
                int userIndex = GetUserIndexFromCode(code);

                Debug.Log("UserDel: " + userIndex);
                if (OnGetRemovedIndex != null)
                {
                    OnGetRemovedIndex(userIndex);
                }

                room.RemoveUser(userIndex);

                var array = N ["user_list"];

                if (array != null)
                {
                    List <UXUser> list = ParseUserList((JSONArray)array);
                    room.UpdateUserList(list);
                }

                if (!isGameStarted)
                {
                    if (OnUserRemoved != null)
                    {
                        OnUserRemoved(name, code);
                    }
                }
                else
                {
                    if (OnUserLeavedInGame != null)
                    {
                        OnUserLeavedInGame(userIndex, code);
                    }
                }
            }
            else if (command == "update_user_index_result")                 // 사용되고 있음
            {
                int index = N ["index"].AsInt;

                UXPlayerController player = UXPlayerController.Instance;
                player.SetIndex(index);
                if (OnIndexChanged != null)
                {
                    UXLog.SetLogMessage(" onindexchanged");
                    OnIndexChanged(index);
                }
            }
            else if (command == "send_error")
            {
            }
            else if (command == "exit_result")
            {
                if (OnExit != null)
                {
                    OnExit();
                }
            }
            else if (command == "host_close")
            {
                if (OnHostDisconnected != null)
                {
                    OnHostDisconnected();
                }
            }
            else if (command == "data")
            {
                string val = N ["data"].Value.ToString();

                if (val == "")
                {
                    val = N ["data"].ToString();
                }

                int senderCode = N ["sender"].AsInt;
                int userIndex  = GetUserIndexFromCode(senderCode);

                if (OnReceived != null)
                {
                    //OnReceived (userIndex, val);
                    OnReceived(senderCode, val);
                }
            }
            else if (command == "check_network_state_result")                   //이거 안올듯. 위에서 cmd:check_network_state를안보내
            {
                int    cur   = N ["count"].AsInt;
                string temp  = N ["time"];
                long   stime = long.Parse(temp);

                networkCheckValues [cur - 1] = DateTime.Now.Ticks - stime;

                if (cur >= networkCheckCount)
                {
                    float totalTime = 0;
                    for (int i = 0; i < networkCheckCount; i++)
                    {
                        totalTime += networkCheckValues [i];
                    }

                    if (OnNetworkReported != null)
                    {
                        OnNetworkReported(networkCheckCount, totalTime);
                    }

                    UXPlayerController player = UXPlayerController.Instance;

                    if (isSendNetWorkResult == true)
                    {
                        string sendString = "{\"cmd\":\"report_network_state\",\"u_code\":\"" + player.GetCode() + "\",\"l_code\":\"" + launcherCode + "\",\"count\":\"" + networkCheckCount + "\",\"time\":\"" + totalTime + "\"}&";
                        Send(sendString);
                    }
                }
            }
            else if (command == "start_game_result")
            {
                isGameStarted = true;

                if (OnGameStart != null)
                {
                    OnGameStart();
                }
            }
            else if (command == "restart_game_result")
            {
                isGameStarted = true;

                if (OnGameRestart != null)
                {
                    OnGameRestart();
                }
            }
            else if (command == "result_game_result")                //안쓰일듯
            {
                if (OnGameResult != null)
                {
                    OnGameResult();
                }
            }
            else if (command == "end_game_result")
            {
                isGameStarted = false;

                if (OnGameEnd != null)
                {
                    OnGameEnd();
                }
            }
            else if (command == "host_joined")
            {
                isHostJoined = true;

                if (OnHostJoined != null)
                {
                    OnHostJoined();
                }
            }
            else if (command == "get_user_list_result")
            {
                Debug.Log("UserList: ");
                List <UXUser>    userList       = ParseUserList((JSONArray)N ["user_list"]);
                UXUserController userController = UXUserController.Instance;


                if (userController.IsEqual(userList) == false)
                {
                    userController.CopyList(userList);

                    if (OnUserListReceived != null)
                    {
                        OnUserListReceived(userList);                          //log찍는듯
                    }
                }

                /*
                 * if (connectMode == UXConnectController.Mode.Client) { //PAD면
                 *      UXPlayerController playerController = UXPlayerController.Instance;
                 *      for (int i = 0; i < userController.GetCount (); i++) {
                 *              UXUser user = (UXUser)userController.GetAt (i); //유저마다
                 *              if (playerController.GetCode () == user.GetCode ()) { //코드를 비교 해서 나를 찾는거
                 *                      if (i != playerController.GetIndex ()) {
                 *                              if (OnIndexChanged != null) {
                 *                                      OnIndexChanged (i);
                 *                              }
                 *
                 *                              playerController.SetIndex (i);
                 *                              Debug.Log ("SetInedx : " + i);
                 *                      }
                 *                      break;
                 *              }
                 *      }
                 * }
                 */
            }
            else if (command == "update_ready_count_result")
            {
                int ready = N ["ready"].AsInt;
                int total = N ["total"].AsInt;

                if (OnUpdateReadyCount != null)
                {
                    OnUpdateReadyCount(ready, total);
                }
            }
        }
Esempio n. 15
0
    void Start()
    {
        Screen.orientation = ScreenOrientation.Portrait;
        Screen.SetResolution(720, 1280, true);

        //blackOut.SetActive(true);

        m_ClientController = UXClientController.Instance;
        m_PlayerController = UXPlayerController.Instance;

        PopupManager_RaS.IsFreeSetter(false);             // TOOD : PopupManager 공통 모듈로 바꿔야함

        userCode   = m_PlayerController.GetCode();        // 유저 코드 가져옴
        roomNumber = UXConnectController.GetRoomNumber(); // 방 번호 가져옴

        //blackOut.SetActive(false);

        //userCode = m_PlayerController.GetCode ();
        //launcherCode = UXClientController.GetRoomNumber();

        i_PlayerID = m_PlayerController.GetIndex();

        m_ClientController.OnConnected     += OnConnected;
        m_ClientController.OnConnectFailed += OnConnectFailed;
        m_ClientController.OnJoinSucceeded += OnJoinSucceeded;
        m_ClientController.OnJoinFailed    += OnJoinFailed;
        m_ClientController.OnDisconnected  += OnDisconnected;

        m_ClientController.OnUserAdded        += OnUserAdded;
        m_ClientController.OnUserRemoved      += OnUserRemoved;
        m_ClientController.OnUserLeavedInGame += OnUserLeaved;
        m_ClientController.OnNetworkReported  += OnNetworkReported;
        m_ClientController.OnUpdateReadyCount += OnUpdateReadyCount;

        m_ClientController.OnGameStart    += OnGameStart;
        m_ClientController.OnGameRestart  += OnGameRestart;
        m_ClientController.OnGameResult   += OnGameResult;
        m_ClientController.OnIndexChanged += OnIndexChanged;

        m_ClientController.OnUserListReceived += OnUserListReceived;
        m_ClientController.OnGameEnd          += OnGameEnd;
        m_ClientController.OnExit             += OnExit;
        m_ClientController.OnAckFailed        += OnAckFailed;
        m_ClientController.OnHostDisconnected += OnHostDisconnected;

        //inapp.OnPurchaseSuccess += OnPurchaseSuccess;

        //==========================================
        m_ClientController.OnHostJoined += OnHostJoined;
        m_ClientController.OnError      += OnError;
        m_ClientController.OnReceived   += OnReceived;
        //==========================================

        if (m_ClientController.IsConnected() == false)
        {
            m_ClientController.Connect();
        }
        else
        {
            //m_ClientController.Join("none");
            m_ClientController.Join(GAME_PACKAGE_NAME);
        }

        cancelButton.SetActive(false);

        DontDestroyOnLoad(this.gameObject);
    }