void Connect()
    {
        if (isEnable)
        {
            if (InRoom.GetInRoomInstantiate().ServerConnected)
            {
                InRoom.GetInRoomInstantiate().SendID(BtnGameManager.yt.Rows[0]["PlayerID"].YuanColumnText, BtnGameManager.yt.Rows[0]["ProID"].YuanColumnText, BtnGameManager.yt.Rows[0]["PlayerName"].YuanColumnText, true, PlayerPrefs.GetString("Language", "CH"), SystemInfo.deviceUniqueIdentifier, PlayerUtil.mapInstanceID, playerPostion.x, playerPostion.y, playerPostion.z);    //,BtnGameManagerBack.teaminstensid);
                isConnecting        = false;
                lblConnectInfo.text = "";
                lblConnectInfo.gameObject.active = false;
                CancelInvoke("Connect");
            }
            //Debug.Log ("------------------:"+time%5);
            if ((time % 100) == 0 || time == 0)
            {
                ZealmConnector.closeConnection();
                //InRoom.GetInRoomInstantiate().peer.Disconnect();
                //while(InRoom.GetInRoomInstantiate ().peer.PeerState!=ExitGames.Client.Photon.PeerStateValue.Disconnected)
                //{
                //	yield return new WaitForSeconds(0.1f);
                //}
                try
                {
                    PhotonHandler.ShowLog("GameReonline");
                    InRoom.NewInRoomInstantiate().SetAddress(PlayerPrefs.GetString("InAppServerIP"));
                    InRoom.GetInRoomInstantiate().ServerApplication  = PlayerPrefs.GetString("InAppServer");
                    InRoom.GetInRoomInstantiate().btnGameManagerBack = this.btnGameManagerBack;
                    InRoom.GetInRoomInstantiate().SM = this.sendManager;
                    InRoom.GetInRoomInstantiate().Connect();
                    reTime++;
                }
                catch (System.Exception ex)
                {
                    Debug.LogError(ex.ToString());
                }
            }
            if (reTime >= 5)
            {
                if (isStart)
                {
                    //uiCon.SendMessage("UIDisconnect", SendMessageOptions.DontRequireReceiver);
                    lblConnectInfo.text = StaticLoc.Loc.Get("info356");
                }
                else
                {
                    lblConnectInfo.text = StaticLoc.Loc.Get("info357");
                }
                CancelInvoke("Connect");

                isStart = false;
                //PanelStatic.StaticWarnings.warningAllEnter.Show (StaticLoc.Loc.Get("info358"),StaticLoc.Loc.Get("info649"));
                PanelStatic.StaticBtnGameManager.OffLine();
            }
            time++;
        }
    }
示例#2
0
    public void runWriter()
    {
        while (parent.IsConnected)
        {
            try
            {
                while (ZealmSocketConnection.netDataList.Count != 0)
                {
                    // ZMNetData zmNetData = (ZMNetData)ZealmSocketConnection.netDataList[0];
                    // ZealmSocketConnection.netDataList.RemoveAt(0);
                    // try
                    // {
                    //     parent.write(zmNetData);
                    //       parent.lastWriteTime = Utils.DateTimeExtensions.currentTimeMillis();
                    // }
                    // catch (Exception ex)
                    // {
                    //     KDebug.WriteLog("WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW=========WWWWWWWWWW----------------"+ zmNetData.type +"==========" +ex.Message);
                    //     break;
                    // }
                }
            }
            catch (Exception ex)
            {
//				KDebug.WriteLog("%%%%%%%%%%%%%%%%%%%%runWriter%%%%%%%%%%%%%%%%%%%%%%%" + ex.Message);
                MonoBehaviour.print("#############runWriter#############" + ex.Message);
                try
                {
                    if (parent.IsConnected)
                    {
                        ZealmConnector.closeConnection();
                        parent.tryReconnect();
                    }
                }
                catch (Exception e)
                {
                    throw new Exception(ex.Message);
                }
                break;
            }
            finally
            {
                try
                {
                    Thread.Sleep(50);
                }
                catch (Exception e)
                {
                }
            }
        }
    }
示例#3
0
    //public void processNetData(ZMNetData netData)
    //{
    //    if (netData.hand[0] == 90 && netData.hand[1] == 77)
    //    {
    //        NetDataManager.addNetData(netData);
    //    }
    //    else
    //    {
    //        Debug.Log("--------数据非法,不做处理---------");
    //    }
    //}

    public void runReader()
    {
        while (parent.IsConnected)
        {
            //  Thread.Sleep(500);
            try
            {
                byte[] CZnetData = parent.CZreadNetData();
                if (CZnetData == null)
                {
                    continue;
                }
                parent.CZprocessNetData(CZnetData);//==================================================================
            }
            catch (Exception ex)
            {
//				KDebug.WriteLog("%%%%%%%%%%%%%%%%%%%%runReader%%%%%%%%%%%%%%%%%%%%%%%" + ex.Message);
                //  MonoBehaviour.print("%%%%%%%%%%%%%%%%%%%%runReader%%%%%%%%%%%%%%%%%%%%%%%" + ex.Message);
                Debug.Log("%%%%%%%%%%%%%%%%%%%%runReader%%%%%%%%%%%%%%%%%%%%%%%" + ex.Message);

                try
                {
                    if (parent.IsConnected)
                    {
                        ZealmConnector.closeConnection();
                        parent.tryReconnect();
                        //EventManager.addEvent(Const.EVENT_DISCONNECTED, 0);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError(e.ToString());
                    Debug.LogError(ex.ToString());
                    throw new Exception(ex.Message);
                }
                break;
            }
        }
    }
示例#4
0
    IEnumerator Connect()
    {
        //  serverAddress = serverAddress2;
        tableRead.strInfo = StaticLoc.Loc.Get("meg0101");
        Ping ping    = new Ping(serverAddress.Split(':')[0]);
        Ping ping2   = new Ping(serverAddress2.Split(':')[0]);
        int  timeOut = 0;

        int p1 = 0;
        int p2 = 0;

        while (true)
        {
            if (ping.isDone || ping2.isDone)
            {
                break;
            }
            if (timeOut > 30)
            {
                break;
            }

            timeOut++;
            Debug.Log(string.Format("---------------------Ping:{0},{1};Ping2:{2},{3}", ping.isDone, ping.time, ping2.isDone, ping2.time));
            yield return(new WaitForSeconds(0.1f));
        }
        p1 = ping.time;
        p2 = ping2.time;
        Debug.Log(string.Format("---------------------PingEnd:{0},{1};Ping2:{2},{3}", ping.isDone, p1, ping2.isDone, p2));
        if (p1 == -1 && p2 == -1)
        {
            tableRead.strInfo = StaticLoc.Loc.Get("meg0096");
            //ShowConnectFail(StaticLoc.Loc.Get("meg0096")+StaticLoc.Loc.Get("meg0103"));

            tableRead.ReadTimeOut(StaticLoc.Loc.Get("meg0096") + StaticLoc.Loc.Get("meg0103"));
        }
        else if (p2 != -1 && p1 != -1)
        {
            if (p1 > p2)
            {
                serverAddress = serverAddress2;
            }
        }
        else if (p2 != -1)
        {
            serverAddress = serverAddress2;
        }

        ping.DestroyPing();
        ping2.DestroyPing();

        Debug.Log("===============ConnectIP:" + serverAddress);
        tableRead.strInfo = StaticLoc.Loc.Get("meg0095");
        //NGUIDebug.Log ("--------------------------RadyConnect");
        yuan.YuanClass.SwitchList(listBtnServer, false, true);
//		if(YuanUnityPhoton.GetYuanUnityPhotonInstantiate().ServerConnected)
//		{
//
//          //YuanUnityPhoton.GetYuanUnityPhotonInstantiate().peer.Disconnect();
//			ZealmConnector.closeConnection();
//			while(YuanUnityPhoton.GetYuanUnityPhotonInstantiate().ServerConnected)
//			{
//				yield return new WaitForSeconds(0.1f);
//			}
//		}
//
//			if(InRoom.GetInRoomInstantiate ().ServerConnected)
//			{
//		        //InRoom.GetInRoomInstantiate().peer.Disconnect();
//			ZealmConnector.closeConnection();
//				while(InRoom.GetInRoomInstantiate ().ServerConnected)
//				{
//					yield return new WaitForSeconds(0.1f);
//				}
//			}

        ZealmConnector.closeConnection();
        //try
        //{
        //NGUIDebug.Log ("-------------------------------IP:"+serverAddress);
        YuanUnityPhoton.NewYuanUnityPhotonInstantiate().ServerAddress = serverAddress;
//	        YuanUnityPhoton.NewYuanUnityPhotonInstantiate().ServerAddress = "117.131.207.219" + ":5059";
//        YuanUnityPhoton.NewYuanUnityPhotonInstantiate().ServerAddress = "192.168.1.100" + ":5059";
        YuanUnityPhoton.GetYuanUnityPhotonInstantiate().ServerApplication = "YuanPhotonServerRoom";
        YuanUnityPhoton.GetYuanUnityPhotonInstantiate().MMManage          = this.mmManage;
        YuanUnityPhoton.GetYuanUnityPhotonInstantiate().tableRead         = this.tableRead;
        //NGUIDebug.Log ("--------------------------StratConnect");

        YuanUnityPhoton.GetYuanUnityPhotonInstantiate().Connect();
        PhotonHandler.ShowLog("SetConnectionIP:" + serverAddress);
        PlayerPrefs.SetString("ConnectionIP", serverAddress);
        while (!YuanUnityPhoton.GetYuanUnityPhotonInstantiate().ServerConnected)
        {
            yield return(new WaitForSeconds(0.1f));
        }
        //NGUIDebug.Log ("--------------------------Connected");
        if (StartGame)
        {
            StartGame = false;
            YuanUnityPhoton.GetYuanUnityPhotonInstantiate().SetPlayerBehavior(yuan.YuanPhoton.ConsumptionType.GameSchedule, ((int)GameScheduleType.OpenGame).ToString(), SystemInfo.deviceUniqueIdentifier);
        }
//			Debug.Log("Con2222222");
        //}
        //catch(System.Exception ex)
        //{
        //Debug.LogError (ex.ToString ());
        //}

/**************************************************
 *      //	if(InRoom.GetInRoomInstantiate ().peer.PeerState==ExitGames.Client.Photon.PeerStateValue.Connected)
 *      //	{
 *  //      InRoom.GetInRoomInstantiate().peer.Disconnect();
 *      //		while(InRoom.GetInRoomInstantiate ().peer.PeerState!=ExitGames.Client.Photon.PeerStateValue.Disconnected)
 *      //		{
 *      //			yield return new WaitForSeconds(0.1f);
 *      //		}
 *      //	}
 *******************************************************/
        try
        {
            InRoom.NewInRoomInstantiate();
        }
        catch (System.Exception ex)
        {
            Debug.LogError(ex.ToString());
        }
        PhotonNetwork.Disconnect();
    }
 void OnApplicationQuit()
 {
     ZealmConnector.closeConnection();
 }