示例#1
0
    /// <summary>
    /// 重新连接服务器
    /// </summary>
    private void ReLogin()
    {
        if (Globe.SelectedServer != null)
        {
            bool bConnect = ClientNetMgr.GetSingle().StartConnect(Globe.SelectedServer.ip, Globe.SelectedServer.port);

            if (bConnect)
            {
                Control.ShowGUI(UIPanleID.UIWaitForSever, EnumOpenUIType.DefaultUIOrSecond);
                ClientSendDataMgr.GetSingle().GetLoginSend().SendCheckAccount();
                //Hide();
                Control.HideGUI(this.GetUIKey());
            }
            else
            {
                //ShowLabel("重连失败,请检查网络重启游戏!");
                RefreshData("重连失败,请检查网络重启游戏!");
            }
        }
        else
        {
            //Hide();
            Control.HideGUI(this.GetUIKey());
        }
    }
示例#2
0
 void OnApplicationQuit()
 {
     // Debug.LogError("程序退出函数");
     ClientSendDataMgr.GetSingle().GetHeroSend().SendQuitGame();//通知服务器存盘
     //   Application.Quit();
     if (ClientNetMgr.GetSingle().IsConnect())
     {
         ClientNetMgr.GetSingle().Close();
     }
 }
示例#3
0
    void OnSureBtn()
    {
        if (string.IsNullOrEmpty(nicknameInput.text))
        {
            //UIPromptBox.Instance.ShowLabel("请输入昵称!");
            Control.ShowGUI(UIPanleID.UIPromptBox, EnumOpenUIType.DefaultUIOrSecond, false, "请输入昵称!");
            return;
        }
        if (Regex.IsMatch(nicknameInput.text, @"^\d"))
        {
            //UIPromptBox.Instance.ShowLabel("不能以数字开头");
            Control.ShowGUI(UIPanleID.UIPromptBox, EnumOpenUIType.DefaultUIOrSecond, false, "不能以数字开头");
            return;
        }
        if (Regex.IsMatch(nicknameInput.text, @"\s+"))
        {
            //UIPromptBox.Instance.ShowLabel("不能有空格");
            Control.ShowGUI(UIPanleID.UIPromptBox, EnumOpenUIType.DefaultUIOrSecond, false, "不能有空格");
            return;
        }
        if (nicknameInput.text.Length < 2)
        {
            //UIPromptBox.Instance.ShowLabel("角色名称至少要2个字符哟~");
            Control.ShowGUI(UIPanleID.UIPromptBox, EnumOpenUIType.DefaultUIOrSecond, false, "角色名称至少要2个字符哟~");
            return;
        }
        if (nicknameInput.text.Length > 7)
        {
            //UIPromptBox.Instance.ShowLabel("角色名称最多7个字符~");
            Control.ShowGUI(UIPanleID.UIPromptBox, EnumOpenUIType.DefaultUIOrSecond, false, "角色名称最多7个字符~");
            return;
        }
        sureBtn.isEnabled = false;
        playerData.GetInstance().selfData.playeName = nicknameInput.text;
        serverMgr.GetInstance().SetName(nicknameInput.text);
        GameLibrary.nickName = nicknameInput.text;
        if (!ClientNetMgr.GetSingle().IsConnect())//如果网络没有连接连下
        {
            ClientNetMgr.GetSingle().StartConnect(Globe.SelectedServer.ip, Globe.SelectedServer.port);
        }
        ClientSendDataMgr.GetSingle().GetLoginSend().SendCheckAccount();
        //string heroId = StringUtil.StrReplace((SelectCard.selectCardId).ToString(), "201", 0, 3);
        //GameLibrary.player = long.Parse(heroId);

        //SendMeg();
        //ClientSendDataMgr.GetSingle().GetLoginSend().SendCreateRole(nicknameInput.text, heroId, Globe.SelectedServer.areaId.ToString());
        //ClientSendDataMgr.GetSingle().GetLoginSend().SendCreateRole(nicknameInput.text, heroId, SelectCard.selectAreaId);

        //serverMgr.GetInstance().SetCurrentPoint(UI_HeroDetail.skillCount);
        //serverMgr.GetInstance().SetFullTime(Auxiliary.GetNowTime() + (20 - UI_HeroDetail.skillCount) * 600);
    }
示例#4
0
    // Update is called once per frame
    void Update()
    {
        ClientNetMgr.GetSingle().Update();
        Globe.lastNetTime += Time.deltaTime;
        currtime          += Time.deltaTime;
        if (!ClientNetMgr.GetSingle().m_bServerNet&& !isShowMessageDlg)
        {
            //if (UIPromptBox.Instance != null)
            //{
            //	UIPromptBox.Instance.ShowLabel("与服务器链接丢失,将重新与服务器建立链接");
            //}
            Control.ShowGUI(UIPanleID.UIPromptBox, EnumOpenUIType.DefaultUIOrSecond, false, "与服务器链接丢失,将重新与服务器建立链接");
            isShowMessageDlg = true;
        }
        if (currtime > count)
        {
            if (ClientNetMgr.GetSingle().IsConnect() && ClientSendDataMgr.GetSingle().GetWalkSend().ping)
            {
                ClientSendDataMgr.GetSingle().GetWalkSend().Ping();
                Debug.Log("ping包发送");
            }
            currtime = 0;
        }
        if (Input.GetKeyDown(KeyCode.Escape) || Input.GetKey(KeyCode.Home))
        {
            // ClientSendDataMgr.GetSingle().GetHeroSend().SendQuitGame();//通知服务器存盘
            //  Application.LoadLevel(0);
            //退出游戏
            Application.Quit();
        }

        if (UISelectServer.Instance != null && UISelectServer.Instance.isLoading != 0)
        {
            if (UISelectServer.Instance.isLoading == 1)
            {
                UISelectServer.Instance.SendLogin(Globe.SelectedServer.playerId, Globe.SelectedServer.heroId, Globe.SelectedServer.playerName, Globe.SelectedServer.areaId);
                UISelectServer.Instance.isLoading = 0;
            }
            else if (UISelectServer.Instance.isLoading == 2)
            {
                UISelectServer.Instance.SendCreate(Globe.SelectedServer.playerId, Globe.SelectedServer.heroId, Globe.SelectedServer.playerName, Globe.SelectedServer.areaId);
                UISelectServer.Instance.isLoading = 0;
            }
        }
    }
示例#5
0
    //send data from list
    private void SendDataFromList()
    {
        try
        {
            while (true)
            {
                if (ClientNetMgr.GetSingle().IsConnect())
                {
                    if (m_SendDataList.Count <= 0)
                    {
                        Thread.Sleep(30);
                        continue;
                    }
                    //Debug.Log("SendData:Send Count!"+m_SendDataList.Count);
                    System.Net.Sockets.NetworkStream netStream = ClientNetMgr.GetSingle().GetNetworkStream();
                    lock (netStream)
                    {
                        if (netStream != null && netStream.CanWrite)
                        {
                            lock (m_SendDataList)
                            {
                                CSendData data = (CSendData)m_SendDataList[0];
                                netStream.Write(data.m_bDataList, 0, data.m_nLength);
                                m_SendDataList.RemoveAt(0);
                                //Debug.Log( "<color=#FFc900>Send packet:</color>"+ data.m_nMessageID);


                                //Debug.Log("Send packet:" + data.m_nMessageID);
                            }
                        }
                    }
                }
                else
                {
                    //CloseSendThread();
                    break;
                }
            }
        }
        catch (System.Exception ex)
        {
            Debug.Log(ex.Message);
        }
    }
示例#6
0
    public void SendLogin(long PlayerId, long HeroId, string Name, int AreaId)
    {
        if (DataDefine.isConectSocket)
        {
            if (Globe.SelectedServer != null)
            {
                SelectCard.selectAreaId = Globe.SelectedServer.areaId.ToString();
            }

            if (Globe.SelectedServer != null)
            {
                //string name = serverMgr.GetInstance().GetPlayNameDataByName( Globe.SelectedServer.name );
                string name = Name;
                if (name != null)
                {
                    GameLibrary.nickName = name;
                    serverMgr.GetInstance().SetName(name);
                }
                //long hId = serverMgr.GetInstance().GetServerDataByName( Globe.SelectedServer.name ).heroId;
                long hId = HeroId;
                if (hId != 0)
                {
                    //if (!ClientNetMgr.GetSingle().IsConnect())
                    //Globe.playHeroList[0] = playerData.GetInstance().FindOrNewHeroDataById(hId);
                    //GameLibrary.player = Globe.playHeroList[0].id;
                    if (!ClientNetMgr.GetSingle().IsConnect())
                    {
                        ClientNetMgr.GetSingle().StartConnect(Globe.SelectedServer.ip, Globe.SelectedServer.port);
                    }
                    ClientSendDataMgr.GetSingle().GetLoginSend().SendPlayerLogin(Globe.SelectedServer.playerId, Globe.SelectedServer.heroId, Globe.SelectedServer.areaId, 1);
                }
            }
            transform.parent.Find("Effect").gameObject.SetActive(false);
            serverMgr.GetInstance().SetServer(serverName.text); serverMgr.GetInstance().saveData();
        }
    }
示例#7
0
    void OnEnterClick()
    {
        if (!isstart)
        {
            if (!ClientNetMgr.GetSingle().IsConnect())
            {
                ClientNetMgr.GetSingle().StartConnect(Globe.SelectedServer.ip, Globe.SelectedServer.port);
                ClientNetMgr.GetSingle().bReConnect = true;
            }

            ClientSendDataMgr.GetSingle().GetLoginSend().SendCheckAccount();
            //   CLoginHandle.myLogin = SendLogin;
            // CLoginHandle.myCreate = SendCreate;
            isstart = true;
        }

        //if ( DataDefine.isConectSocket )
        //{
        //    if ( Globe.SelectedServer != null )
        //    {
        //        SelectCard.selectAreaId = Globe.SelectedServer.areaId.ToString();
        //    }

        //    if ( Globe.SelectedServer != null && Globe.SelectedServer.playerId != 0 )
        //    {
        //        string name = serverMgr.GetInstance().GetPlayNameDataByName( Globe.SelectedServer.name );
        //        if ( name != null )
        //        {
        //            GameLibrary.nickName = name;
        //            serverMgr.GetInstance().SetName( name );

        //        }
        //        long hId = serverMgr.GetInstance().GetServerDataByName( Globe.SelectedServer.name ).heroId;
        //        if ( hId != 0 )
        //        {
        //            Globe.playHeroList [ 0 ] = playerData.GetInstance().FindOrNewHeroDataById( hId );
        //            GameLibrary.player = Globe.playHeroList [ 0 ].id;
        //            if ( !ClientNetMgr.GetSingle().IsConnect() )
        //            {
        //                ClientNetMgr.GetSingle().StartConnect( Globe.SelectedServer.ip , Globe.SelectedServer.port );
        //            }
        //            //ClientSendDataMgr.GetSingle().GetLoginSend().SendPlayerLogin(Globe.SelectedServer.playerId, Globe.SelectedServer.heroId, Globe.SelectedServer.areaId, 1);
        //        }
        //        else
        //        {
        //            //没有英雄 ---应该到选择英雄面板

        //            Control.ShowGUI( GameLibrary.UI_ServerList );
        //            Hide();
        //            // SelectCard.selectAreaId = dic.Key.ToString();
        //        }

        //        // transform.root.Find( "UICreateRole" ).gameObject.SetActive( true );

        //        //GameLibrary.nickName = serverMgr.GetInstance().GetName();

        //    }
        //    else
        //    {
        //        Control.ShowGUI( GameLibrary.UI_CreateRole );
        //        Hide();
        //    }
        //    serverMgr.GetInstance().SetServer( serverName.text );
        //    serverMgr.GetInstance().saveData();
        //}
        //else
        //{
        //    //TODO:不联网读本地配置
        //    //serverMgr.GetInstance().SetServer(serverName.text);
        //    //serverMgr.GetInstance().saveData();
        //    //UI_Loading.LoadScene(GameLibrary.UI_Major, 3);
        //}
    }
示例#8
0
    private void OnEnsureClick()
    {
        if (UISelectServer.Instance != null)
        {
            UISelectServer.Instance.isstart = false;
        }
        ClientNetMgr.GetSingle().m_bServerNet = true;

        //Application.LoadLevel(0);
        if (str == "网络已中断请重新连接")
        {
            Control.HideGUI(this.GetUIKey());
            //Hide();
//           // GameLibrary.Instance().isReconect = true;
//           // ReLogin();
//			if (UISelectServer.Instance != null)
//				UISelectServer.Instance.isstart = false;
//			ClientNetMgr.GetSingle ().m_bServerNet = true;
//			ClientSendDataMgr.GetSingle ().GetWalkSend ().ping = false;
//            ClientNetMgr.GetSingle().Close();
//            //Globe.isEnterScence = false;
//            //Destroy (StartLandingShuJu.GetInstance ().gameObject);
//            playerData.GetInstance ().NearRIarr.Clear ();
//			playerData.GetInstance ().selfData.oldMapID = 0;
//			Application.LoadLevel(0);
//#if QiHuRelease
//            SDKMgr.Instance.Login();
//#endif
        }
        else if (str == "想去野外吗?来吧!")
        {
            Singleton <SceneManage> .Instance.Current = EnumSceneID.LGhuangyuan;
            ClientSendDataMgr.GetSingle().GetBattleSend().SendGetHerosBattleAttr(Globe.fightHero);
            ClientSendDataMgr.GetSingle().GetLoginSend().SendChengeScene(20000, 20100, 2);
            //Hide();
            Control.HideGUI(this.GetUIKey());
        }
        else if (str == "服务器维护中!请重新登录")
        {
            Application.Quit();
        }
        else if (str == "与服务器链接丢失,将重新与服务器建立链接")
        {
            //GameLibrary.Instance().isReconect = true;
            //ReLogin();
            if (UISelectServer.Instance != null)
            {
                UISelectServer.Instance.isstart = false;
            }

            ClientNetMgr.GetSingle().m_bServerNet = true;
            ClientNetMgr.GetSingle().Close();
            ClientSendDataMgr.GetSingle().GetWalkSend().ping = false;
            playerData.GetInstance().NearRIarr.Clear();
            playerData.GetInstance().selfData.oldMapID = 0;
            playerData.GetInstance().worldMap.Clear();
            Application.LoadLevel(0);
#if QiHuRelease
            SDKMgr.Instance.Login();
#endif
        }
        else if (str == "正在与服务器做版本比较,请稍后")
        {
        }
        else if (str == "您的版本号与服务器不一致,请更新新包")
        {
            Application.Quit();
        }
        else
        {
            Control.HideGUI(this.GetUIKey());
            //Hide();
        }
    }
示例#9
0
    void OnSureBtn()
    {
        GameLibrary.dungeonId = 10000;
        string heroId = StringUtil.StrReplace((SelectCard.selectCardId).ToString(), "201", 0, 3);

        GameLibrary.player = long.Parse(heroId);
        Globe.isFightGuide = true;
        //UI_Loading.LoadScene("xinshou", 3);
        GameLibrary.LastScene = SceneManager.GetActiveScene().name;//记录前一个场景名
        SceneNode sceneNode = FSDataNodeTable <SceneNode> .GetSingleton().FindDataByType(GameLibrary.dungeonId);

        serverMgr.GetInstance().SetCreateAccountTime("", true);
        if (null != sceneNode)
        {
            StartLandingShuJu.GetInstance().GetLoadingData(sceneNode.MapName, 3);
            SceneManager.LoadScene("Loding");
        }

        return;

        if (string.IsNullOrEmpty(nicknameInput.text))
        {
            //UIPromptBox.Instance.ShowLabel("请输入昵称!");
            Control.ShowGUI(UIPanleID.UIPromptBox, EnumOpenUIType.DefaultUIOrSecond, false, "请输入昵称!");
            return;
        }
        if (Regex.IsMatch(nicknameInput.text, @"^\d"))
        {
            //UIPromptBox.Instance.ShowLabel("不能以数字开头");
            Control.ShowGUI(UIPanleID.UIPromptBox, EnumOpenUIType.DefaultUIOrSecond, false, "不能以数字开头");
            return;
        }
        if (Regex.IsMatch(nicknameInput.text, @"\s+"))
        {
            //UIPromptBox.Instance.ShowLabel("不能有空格");
            Control.ShowGUI(UIPanleID.UIPromptBox, EnumOpenUIType.DefaultUIOrSecond, false, "不能有空格");
            return;
        }
        if (Encoding.Default.GetBytes(nicknameInput.text).Length < 4)
        {
            //UIPromptBox.Instance.ShowLabel("角色名称至少要4个字符哟~");
            Control.ShowGUI(UIPanleID.UIPromptBox, EnumOpenUIType.DefaultUIOrSecond, false, "角色名称至少要4个字符哟~");
            return;
        }
        if (nicknameInput.text.Length > 14)//if (Encoding.Default.GetBytes(nicknameInput.text).Length > 14)
        {
            //UIPromptBox.Instance.ShowLabel("角色名称最多14个字符~");
            Control.ShowGUI(UIPanleID.UIPromptBox, EnumOpenUIType.DefaultUIOrSecond, false, "角色名称最多14个字符~");
            return;
        }
        sureBtn.isEnabled    = false;
        backBtn.isEnabled    = false;
        GameLibrary.nickName = nicknameInput.text;
        //switch (SelectCard.selectCardName.Substring(3))
        //{
        //    case "Jiansheng":
        //        GameLibrary.player = 201001100;
        //        break;
        //    case "Huonv":
        //        GameLibrary.player = 201001400;
        //        break;
        //    case "Xiongmao":
        //        GameLibrary.player = 201001000;
        //        break;
        //}

        //GameLibrary.player = SelectCard.selectCardName.Substring( 3 );

        //UI_Loading.LoadScene( GameLibrary.UI_Major , 3 );
        if (!ClientNetMgr.GetSingle().IsConnect())//如果网络没有连接连下
        {
            ClientNetMgr.GetSingle().StartConnect(Globe.SelectedServer.ip, Globe.SelectedServer.port);
        }

        //初始默认上阵英雄
        //Globe.playHeroList[0] = playerData.GetInstance().FindOrNewHeroDataById(long.Parse(heroId));
        ClientSendDataMgr.GetSingle().GetLoginSend().SendCreateRole(nicknameInput.text, heroId, Globe.SelectedServer.areaId.ToString());
        //ClientSendDataMgr.GetSingle().GetLoginSend().SendCreateRole(nicknameInput.text, heroId, SelectCard.selectAreaId);

        serverMgr.GetInstance().SetName(nicknameInput.text);
        //serverMgr.GetInstance().SetCurrentPoint(UI_HeroDetail.skillCount);
        //serverMgr.GetInstance().SetFullTime(Auxiliary.GetNowTime() + (20 - UI_HeroDetail.skillCount) * 600);
        serverMgr.GetInstance().saveData();
        //this.gameObject.SetActive( false );
    }
示例#10
0
    //判断屏幕内是否有怪
    void AutoTest()
    {
        GameObject player = CharacterManager.player;

        if (player == null || hideArrowScene())
        {
            HideArrow();
            return;
        }
        if (ClientNetMgr.GetSingle().IsConnect())//如果有网络连接
        {
            if (SceneManager.GetActiveScene().name == GameLibrary.Moba1V1_TP1)
            {
                //GameObject[] ats = CharacterManager.instance.autos;
                //if (ats.Length > 0 && Vector3.Distance(player.transform.position, ats[ats.Length - 1].transform.position) > 3f)
                //{
                //    ShowArrow(ats[ats.Length - 1].transform);
                //}
            }
            else
            {
                if (SceneBaseManager.instance != null)
                {
                    List <SpawnMonster>         spawns      = SceneBaseManager.instance.spwanList;
                    BetterList <CharacterState> enemyList   = SceneBaseManager.instance.enemy;
                    BetterList <Transform>      targetTrans = new BetterList <Transform>();
                    for (int m = 0; m < spawns.Count; m++)
                    {
                        if (!spawns[m].spawnOver)
                        {
                            targetTrans.Add(spawns[m].transform);
                        }
                    }
                    for (int m = 0; m < enemyList.size; m++)
                    {
                        if (enemyList[m] != null)
                        {
                            targetTrans.Add(enemyList[m].transform);
                        }
                    }

                    if (targetTrans.size <= 0)
                    {
                        return;
                    }
                    for (int i = 0; i < targetTrans.size; i++)
                    {
                        Vector2 screenPos = Camera.main.WorldToScreenPoint(targetTrans[i].position);
                        if ((screenPos.x > 0 && screenPos.x < Screen.width) && (screenPos.y > 0 && screenPos.y < Screen.height))
                        {
                            HideArrow();
                            break;
                        }
                        else
                        {
                            mindis = Vector3.Distance(player.transform.position, targetTrans[0].position);
                            for (int j = 0; j < targetTrans.size; j++)
                            {
                                dis = Vector3.Distance(player.transform.position, targetTrans[j].position);
                                if (mindis >= dis)
                                {
                                    mindis  = dis;
                                    monster = targetTrans[j];
                                }
                            }
                            ShowArrow(monster);
                        }
                    }
                }
            }
        }
    }
示例#11
0
    public void SendPacket(CWritePacket packet, C2SMessageType type = C2SMessageType.PASVWait)
    {
        //if (packet.GetPacketID() != MessageID.player_walk && packet.GetPacketID() != MessageID.s_player_attack_req
        //          && packet.GetPacketID() != MessageID.pve_dungeon_list_req && packet.GetPacketID() != MessageID.s_player_revive_req
        //          && packet.GetPacketID() != MessageID.s_player_change_scene)
        //{
        //    Globe.lastNetTime = 0;
        //    Debug.Log(Globe.lastNetTime);
        //    lastmessageid = packet.GetPacketID();
        //}


        if (Singleton <SceneManage> .Instance.Current == EnumSceneID.UI_MajorCity01 || Globe.isFightGuide)
        {
            if (SceneManager.GetActiveScene().name == GameLibrary.UI_Major || Globe.isFightGuide)
            {
                switch (type)
                {
                case C2SMessageType.Active:
                    break;

                case C2SMessageType.ActiveWait:
                    GameLibrary.isSendPackage = true;
                    if (Control.GetUIObject(UIPanleID.UIWaitForSever) != null)
                    {
                        Control.ShowGUI(UIPanleID.UIWaitForSever, EnumOpenUIType.DefaultUIOrSecond);
                    }
                    break;

                case C2SMessageType.PASVWait:
                    // Debug.Log("True服务器正在接收其他消息     " + GameLibrary.isSendPackage);
                    if (GameLibrary.isSendPackage)
                    {
                        return;
                    }
                    GameLibrary.isSendPackage = true;
                    if (Control.GetUIObject(UIPanleID.UIWaitForSever) != null)
                    {
                        Control.ShowGUI(UIPanleID.UIWaitForSever, EnumOpenUIType.DefaultUIOrSecond);
                    }
                    break;
                }
            }
        }

        // Debug.Log("True代表服务器正在接收本次消息     " + GameLibrary.isSendPackage);
        if (ClientNetMgr.GetSingle().IsConnect())
        {
            if (m_Parent != null)
            {
                m_Parent.SendPacket(packet);
                if (DataDefine.isLogMsg && DataDefine.filterWalkMsg(packet.GetPacketID()))
                {
                    Debug.Log("Send msgid:" + packet.GetPacketID() + packet.GetLogPacketID() + " Sender: " + GetType() + " Time:" + Time.realtimeSinceStartup);
                }
            }
        }
        else
        {
            Debug.Log("和服务器已经断开了连接悄悄申请重连");
            //if (UIPromptBox.Instance != null)
            //{
            //    UIPromptBox.Instance.ShowLabel("与服务器链接丢失,将重新与服务器建立链接");
            //}
            Control.ShowGUI(UIPanleID.UIPromptBox, EnumOpenUIType.DefaultUIOrSecond, false, "与服务器链接丢失,将重新与服务器建立链接");
        }
    }