Beispiel #1
0
    public void Connect(int socketID, string host, int port)
    {
        NSocket nSocket = null;

        if (ConnSockets.ContainsKey(socketID))
        {
            nSocket = ConnSockets[socketID];
        }
        else
        {
            nSocket = new NSocket(socketID);
            ConnSockets.Add(socketID, nSocket);
        }

        if (GApp.Ins.GMode == GameMode.Debug)
        {
            host = "127.0.0.1";
        }
        nSocket.ConnAsync(host, port);
    }
Beispiel #2
0
        /// <summary>
        /// 构建连接
        /// </summary>
        public NSocket CreateConnect(SocketType socketType, string server, int port, Action connectSucess = null)
        {
            var connention = new NSocket(new IPEndPoint(IPAddress.Parse(server), port), 0);

            connention.MaxReConnectNums = 0;
            connention.OnConnectFailed  = OnConnectFailed;
            if (connectSucess != null)
            {
                connention.OnConnectSuccessful = connectSucess;
            }
            else
            {
                connention.OnConnectSuccessful = OnConnectSuccessful;
            }
            connention.OnDisconnect    = delegate { Timer.Instance.AddTimer(0, 1, 0, () => { OnDisconnect(connention); }); };
            connention.OnReceiveBuff   = OnReceiveBuff;
            connention.OnRquestTimeOut = OnSendBuffTimeOut;
            ConnentionDic.Add(socketType, connention);
            connention.StartTcpConnection();
            return(connention);
        }
Beispiel #3
0
 private void OnClick(GameObject go)
 {
     if (go == commonBtn.gameObject)
     {
         CardTeamInfo info = new CardTeamInfo
         {
             id   = HeroTeamMediator.heroTeamMediator.heroListMsg.id,
             name = heroTeamName.label.text,
         };
         NSocket.GetInstance().SendData(Request.ChangeTeamName, info);
         Main.blurCamera.gameObject.SetActive(false);
         Main.CameraUI.GetComponent <Blur>().enabled = false;
         MonoBehaviour.DestroyImmediate(this.gameObject);
     }
     else if (go == cancelBtn.gameObject)
     {
         Main.blurCamera.gameObject.SetActive(true);
         Main.CameraUI.GetComponent <Blur>().enabled = false;
         MonoBehaviour.DestroyImmediate(this.gameObject);
     }
 }
Beispiel #4
0
        /// <summary>
        /// 当连接断开
        /// </summary>
        void OnDisconnect(NSocket socket)
        {
            if (!ConnentionDic.ContainsValue(socket))
            {
                return;
            }
            if (isShowTimeOut)
            {
                return;
            }
            isShowTimeOut = true;
            DialogMsgVO dialogMsgVO = new DialogMsgVO();

            dialogMsgVO.title           = "连接提示";
            dialogMsgVO.content         = "您已断开连接是否重新连接";
            dialogMsgVO.dialogType      = DialogType.CONFIRM;
            dialogMsgVO.confirmCallBack = delegate { ConfirmReConnect(); };
            dialogMsgVO.cancelCallBack  = delegate { CancelReConnect(); };
            DialogView dialogView = UIManager.Instance.ShowUI(UIViewID.DIALOG_VIEW) as DialogView;

            dialogView.data = dialogMsgVO;
        }
Beispiel #5
0
 /// <summary>
 /// 点击事件
 /// </summary>
 private void OnClick(GameObject go)
 {
     if (go == panel.backBtn.gameObject)
     {
         ClosePanel(null);
     }
     else if (go == panel.createTeamBtn.gameObject)
     {
         GUIManager.ShowPromptPanel(TextManager.GetUIString("UI1032"), "", PromtType.CreateTeam, null, CeateTeam, CopyTeam);
     }
     else if (go == panel.changeNameBtn.gameObject)
     {
         ResourceManager.Instance.LoadPrefab("changeteamnamepanel", ChangeTeamNamePanelComplete, LoadFail);
     }
     else if (go == panel.showTeamUIBtn.gameObject)
     {
         NSocket.GetInstance().SendData(Request.TeamListReq);
     }
     else if (go == panel.reset.gameObject)
     {
         GUIManager.ShowPromptPanel(TextManager.GetUIString("UI1012"), TextManager.GetUIString("UI1031"), PromtType.Normal, ResetTeam, null, null);
     }
 }
Beispiel #6
0
 /// <summary>
 /// 点击事件
 /// </summary>
 private void OnClick(GameObject go)
 {
     if (go == panel.pveBtn.gameObject)
     {
         FightProxy.Instance.SendMatchFight(PlayerProxy.Instance.Info.selectTeamId);
     }
     else if (go == panel.pvpBtn.gameObject)
     {
         // 选择默认小队
         NSocket.GetInstance().SendData(Request.CardAssemblyList);
         //SendNotification(NotificationID.ChooseCardOpen);
     }
     else if (go == panel.pvpInBtn.gameObject)
     {
         if (Define.VSTest)
         {
             SendNotification(NotificationID.VSLoadingOpen);
         }
     }
     else
     {
     }
 }
Beispiel #7
0
 void Destroy()
 {
     NSocket.GetInstance().Destroy();
 }
Beispiel #8
0
 void FixedUpdate()
 {
     NSocket.GetInstance().Update();
 }
Beispiel #9
0
    void Update()
    {
        if (null == m_netHelp)
        {
            m_netHelp = Instance.Get <NetHelper>();
        }

        Define.VSTest = Test;
        //if (Input.GetKey(KeyCode.F1))
        //{
        //    PureMVC.Patterns.Facade.Instance.SendNotification(NotificationID.Hide_Main);
        //    PureMVC.Patterns.Facade.Instance.SendNotification(NotificationID.CHANGE_SCENE, new SceneVO("s_match1", "s_match1", false, EScene.PVE));
        //}
        //else if(Input.GetKey(KeyCode.F2))
        //{
        //    GUIManager.CloseAllUI();
        //    UnityEngine.SceneManagement.SceneManager.LoadScene("S_ShootTest");
        //}
        //else if(Input.GetKey(KeyCode.A) && !Define.WaiWangDebug)
        //{
        //    SandTableMediator.IsEdit = true;
        //    PureMVC.Patterns.Facade.Instance.SendNotification(NotificationID.SandTable_Show);
        //}
        //else if (Input.GetKey(KeyCode.F))
        //{
        //    PureMVC.Patterns.Facade.Instance.SendNotification(NotificationID.SandTable_Show);
        //}

        //当网络不可用时
        if (Application.internetReachability == NetworkReachability.NotReachable)
        {
            //GUIManager.BrokenNetWork();
            Debug.LogError("Not Have Net!");
        }

        if (null != NoNetLab)
        {
            NoNetLab.gameObject.SetActive(!NSocket.GetInstance().IsConnected());
        }

        //当用户使用WiFi时
        else if (Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork)
        {
            //if (GUIManager.CurrentNetState != NetState.Wifi && GUIManager.IsConnect)
            //{
            //    TimerManager.Destroy("reloginApp");
            //}

            //GUIManager.CurrentNetState = NetState.Wifi;
        }

        //当用户使用移动网络时
        else if (Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork)
        {
            //if (GUIManager.CurrentNetState != NetState.Phone && GUIManager.IsConnect)
            //{
            //    TimerManager.Destroy("reloginApp");
            //}

            //GUIManager.CurrentNetState = NetState.Phone;
        }
    }
Beispiel #10
0
 /// <summary>
 /// 客户端模拟接到消息
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="channel"></param>
 /// <param name="type"></param>
 /// <param name="msg"></param>
 public void OnClientReceiveBuff <T>(int channel, int type, T msg)
 {
     byte[] buffs = NSocket.Serialize <T>(msg);
     OnReceiveBuff(channel, type, buffs, 0);
 }
Beispiel #11
0
    /// <summary>
    /// 上阵英雄
    /// </summary>
    public void SetHeroFight(int fightIndex, int index)
    {
        HeroInfo info      = panel.heroGrid.GetCustomDataItem(index) as HeroInfo;
        HeroInfo downInfo  = panel.cardGrid.GetCustomDataItem(fightIndex) as HeroInfo;
        int      replaceId = 0;

        replaceId = info.heroUUId;
        bool haveFight = false;

        for (int i = 0; i < panel.heroGrid.mDataSource.Count; ++i)
        {
            if ((panel.heroGrid.GetCustomDataItem(i) as HeroInfo).configId == downInfo.configId)
            {
                if (index == i)
                {
                    continue;
                }
                haveFight = true;
                break;
            }
        }
        if (haveFight || downInfo.pos > 0)
        {
            Debug.LogError("已经存在");
            panel.cardGrid.UpdateCustomData(downInfo);
            return;
        }
        TD_Hero hero = HeroConfig.GetItem(downInfo.configId);

        if (downInfo.skillID.Count < hero.deck_build || downInfo.arcaneId == 0)
        {
            Debug.LogError("技能没有全或者奥义没有选奥义");
            panel.cardGrid.UpdateCustomData(downInfo);
            return;
        }
        if (info.heroUUId != 0)
        {
            HeroInfo infos = null;
            for (int i = 0; i < panel.cardGrid.mDataSource.Count; ++i)
            {
                infos = panel.cardGrid.GetCustomDataItem(i) as HeroInfo;
                if (infos.heroUUId == info.heroUUId)
                {
                    infos.pos = 0;
                    panel.cardGrid.UpdateCustomData(infos);
                    break;
                }
            }
        }
        info.heroUUId     = downInfo.heroUUId;
        info.configId     = downInfo.configId;
        info.cardTeamName = downInfo.cardTeamName;
        panel.heroGrid.UpdateCustomData(info);
        downInfo.pos = index + 1;
        panel.cardGrid.UpdateCustomData(downInfo);
        HeroOnFightMsg msg = new HeroOnFightMsg
        {
            teamId    = heroListMsg.id,
            heroId    = downInfo.heroUUId,
            replaceId = replaceId,
            pos       = downInfo.pos,
        };

        NSocket.GetInstance().SendData(Request.HeroOnFight, msg);
    }
Beispiel #12
0
 /// <summary>
 /// 创建英雄卡组
 /// </summary>
 /// <param name="go"></param>
 void CreateCardTeam(GameObject go)
 {
     dropInfo = go.GetComponentInParent <UIGridItem>().oData as HeroInfo;
     NSocket.GetInstance().SendData(Request.HeroListReq);
 }