Beispiel #1
0
        private void RecvAndParseData()
        {
            while (true)
            {
                if (nQuitTimes >= 999)
                {
                    Debug.Log("Please check your internet,you might disconnected! The QuitTimes is :" + nQuitTimes + " now!");
                    return;
                }

                if (NetworkManager.GetSingleton().RecvPackFromServer(ref RecvData) <= 0)
                {
                    nQuitTimes += 1;
                    Thread.Sleep(5);
                    Debug.Log("Here the nQuitTimes is : " + nQuitTimes + "When it comes to 999,end the thread!");
                    continue;
                }
                nQuitTimes = 0;

                Debug.Log("Here we receive a package from server and parse it!");
                PackageMetaData RecvPackage = RecvPackage = ParsePackageService.Parse(RecvData);

                //这里获取一下包的类型,以便于选择是否创建新的队列
                var PackageType = RecvPackage.Get("Type");
                if (!RecvDataPool.ContainsKey(PackageType))
                {
                    var TypeQueue = new Queue <PackageMetaData>();
                    RecvDataPool.Add(PackageType, TypeQueue);
                    Debug.Log("Here we create a new queue!");
                }

                if (firstTimeRecvOtherPlayer == false)
                {
                    nOtherID = Convert.ToInt32(RecvPackage.Get("ID"));
                    if (nOtherID > 0)
                    {
                        firstTimeRecvOtherPlayer = true;
                    }
                }

                if (RecvDataPool[PackageType].Count > nQueueMaxLen)
                {
                    Debug.Log("Too many packages in the queue, let's delete the front one!");
                    RecvDataPool[PackageType].Dequeue();
                }
                Debug.Log("Here we add a parsed package to the queue!");
                RecvDataPool[PackageType].Enqueue(RecvPackage);
            }
        }
Beispiel #2
0
    public void OnLoginClicked()
    {
        SendData LoginData = new SendData(-1);

        LoginData.GetDataPackage().AddLoginInfo(AccountInput.text, PasswordInput.text);
        int sendNum = LoginData.Send();

        Debug.Log("Here we send the login data to the server! The send Num is: " + sendNum);



        PackageMetaData LoginRecvPackage = ReceiveData.GetSingleton().GetLatestPackage("Login");

        int times = 0;

        while (true)
        {
            if (times >= 3)
            {
                break;
            }
            if (LoginRecvPackage == null)
            {
                Thread.Sleep(1000);
            }
            else
            {
                break;
            }
            LoginRecvPackage = ReceiveData.GetSingleton().GetLatestPackage("Login");
            times           += 1;
            Debug.Log("Waitting for server login message!");
        }

        if (LoginRecvPackage == null)
        {
            Debug.Log("Please check you internet ,it's seems disconnected!");
            return;
        }

        if (Convert.ToBoolean(LoginRecvPackage.Get("LoginReturn")) == true)
        {
            //if (AccountInput.text == "123456" && PasswordInput.text == "654321")
            //{
            SceneManager.LoadScene("GameScene", LoadSceneMode.Single);
        }
        else
        {
            Debug.Log("密码错误");
        }
    }