Exemple #1
0
    bool CreateChunkCmdData(DownloadData dd, DownChunkData dcd)
    {
        MultiFileDownData mfdd   = (MultiFileDownData)dd.Data;
        DownResData       curDrd = mfdd.FileList[dcd.FileIdx];

        try
        {
            //1.封装命令
            if (dd.Type == DownloadType.DOWNLOAD_CHECK_VER)
            {
                NetCmdCheckVer cmd = new NetCmdCheckVer();
                cmd.SetCmdType(NetCmdType.CMD_EXTRA_CHECK_VER);
                cmd.Version      = ServerSetting.ClientVer;
                cmd.Plateform    = (byte)RuntimeInfo.GetPlatform();
                cmd.ScreenWidth  = (ushort)Resolution.GetScreenWidth();
                cmd.ScreenHeight = (ushort)Resolution.GetScreenHeight();
                cmd.FileName     = System.Text.Encoding.ASCII.GetBytes(curDrd.ResUrl);
                cmd.Length       = (ushort)mfdd.FileList[0].ResUrl.Length;
                SetPcakgeMac(cmd, m_PackageName, m_MacAddress);
                dcd.SendCmdData = NetCmdHelper.CmdToBytes <NetCmdCheckVer>(cmd, 0);
            }
            else
            {
                byte[] data1    = System.BitConverter.GetBytes(dcd.Offset);
                byte[] data2    = System.BitConverter.GetBytes(dcd.Length);
                byte[] dataUrl  = System.Text.Encoding.ASCII.GetBytes(curDrd.ResUrl);
                byte[] sendData = new byte[data1.Length + data2.Length + dataUrl.Length + 1];
                System.Array.Copy(data1, 0, sendData, 0, 4);
                System.Array.Copy(data2, 0, sendData, 4, 4);
                System.Array.Copy(dataUrl, 0, sendData, 8, dataUrl.Length);

                NetCmdFileRequest ncf = new NetCmdFileRequest();
                ncf.FileName = sendData;
                ncf.Count    = (ushort)(mfdd.FileList.Count | ((int)dcd.XOR << 15)); //高位是1表示要异或
                ncf.Length   = (ushort)sendData.Length;
                ncf.SetCmdType(NetCmdType.CMD_EXTRA_FILE_EX);
                dcd.SendCmdData = NetCmdHelper.CmdToBytes <NetCmdFileRequest>(ncf, 0);
            }
        }
        catch (System.Exception e)
        {
            throw new System.Exception("CreateChunkCmdData Err:" + e.ToString());
            return(false);
        }
        return(true);
    }
    bool SaveClient(MultiFileOK dd)
    {
        //验证crc
        DownResData drd = dd.Drd;

        if (drd.ResSize != dd.Data.Length)
        {
            LogMgr.Log("Client:" + drd.ResType + "大小不匹配,localSize:" + dd.Data.Length + ", serverSize:" + drd.ResSize);
            return(false);
        }
        uint crc = Crc.Crc32(dd.Data, 0, dd.Data.Length);

        if (crc != drd.ResCrc)
        {
            LogMgr.Log("Client:" + drd.ResType + "资源检验失败, size:" + dd.Data.Length + ", localCrc:" + crc + ", serverCrc:" + drd.ResCrc);
            return(false);
        }
        if (RuntimeInfo.GetPlatform() == GamePlatformType.Windows)
        {
            SaveWindowClientRes(dd.Data);
            return(true);
        }
        string path = GetClientPath();

        try
        {
            File.Delete(path);
        }
        catch
        {
        }
        FileStream fs = File.Create(path);

        if (fs == null)
        {
            LogMgr.Log("Client文件创建失败:" + drd.ResType);
            return(false);
        }
        fs.Write(dd.Data, 0, dd.Data.Length);
        fs.Flush();
        fs.Close();

        return(true);
    }
    public void Init(Object obj)
    {
        if (m_Handle != null)
        {
            return;
        }
        ThirdLogon.Instance.m_blogon = false;

        m_Handle        = GameObject.Instantiate(obj) as GameObject;
        m_BaseTransform = m_Handle.transform;
        m_BaseTransform.SetParent(SceneObjMgr.Instance.UIPanelTransform, false);
        m_NoticeTrans     = m_BaseTransform.GetChild(6);
        m_NoticeObj       = m_NoticeTrans.gameObject;
        m_NoticeLabelItem = m_NoticeTrans.GetChild(1).GetChild(0).gameObject;
        for (byte i = 0; i < m_BtnObject.Length; ++i)
        {
            m_BtnObject[i] = m_BaseTransform.GetChild(i).gameObject;
            // if (i > 0)
            // m_BtnTrans[i - 1] = m_BtnObject[i].transform;
            UIEventListener.Get(m_BtnObject[i]).onClick = OnBtnOnclickMsg;
        }
        m_LabelObject = m_BaseTransform.GetChild(7).gameObject;
        m_UITips      = m_LabelObject.GetComponent <UILabel>();
        UIEventListener.Get(m_LabelObject).onClick = OnClickChannelLogon;
        UIEventListener.Get(m_BaseTransform.GetChild(4).gameObject).onClick           = ContentServiceEvent;
        UIEventListener.Get(m_BaseTransform.GetChild(5).gameObject).onClick           = ContentNoticeEvnet;
        UIEventListener.Get(m_NoticeTrans.GetChild(0).gameObject).onClick             = CloseNoticeEvent;
        UIEventListener.Get(m_NoticeTrans.GetChild(2).GetChild(0).gameObject).onClick = BackNoticeEvent;


        ////return;
        //if (SDKMgr.IS_SDK_CHANNEL || ServerSetting.ShowThirdLoginBtn == false || RuntimeInfo.GetPlatform() == PlatformType.Windows)
        //{
        //    m_BaseTransform.GetChild(2).gameObject.SetActive(false);
        //    m_BaseTransform.GetChild(3).gameObject.SetActive(false);
        //}



        if (SDKMgr.IS_SDK_CHANNEL)
        {
            m_LabelObject.SetActive(true);
            m_UITips.text = StringTable.GetString("sdkchannel");

            for (byte i = 0; i < m_BtnObject.Length; ++i)
            {
                m_BtnObject[i].SetActive(false);
            }
            return;
        }
        else if (ServerSetting.ShowThirdLoginBtn == false || RuntimeInfo.GetPlatform() == GamePlatformType.Windows)//隐藏后面两个,并调整前面两个位置
        {
            m_BaseTransform.GetChild(1).position = Vector3.Lerp(m_BaseTransform.GetChild(0).position, m_BaseTransform.GetChild(1).position, 0.5f);
            m_BaseTransform.GetChild(2).position = Vector3.Lerp(m_BaseTransform.GetChild(2).position, m_BaseTransform.GetChild(3).position, 0.5f);

            m_BaseTransform.GetChild(0).gameObject.SetActive(false); //账号
            m_BaseTransform.GetChild(1).gameObject.SetActive(true);  //手机号
            m_BaseTransform.GetChild(2).gameObject.SetActive(true);  //微信
            m_BaseTransform.GetChild(3).gameObject.SetActive(false); //QQ
        }
        else
        {
            if (!m_BaseTransform.GetChild(3).gameObject.activeSelf)//根据第4个调整位置
            {
                m_BaseTransform.GetChild(1).position = Vector3.Lerp(m_BaseTransform.GetChild(0).position, m_BaseTransform.GetChild(3).position, 0.5f);
                m_BaseTransform.GetChild(2).position = m_BaseTransform.GetChild(3).position;
            }
        }


        //        m_BackgroundTex = m_BaseTransform.GetChild(3).GetComponent<UITexture>();
        //       m_BackgroundTex.mainTexture = SceneObjMgr.Instance.BackgroundTex;
        //effect
        //Object objEffect = ResManager.Instance.LoadObject("UIEf_Start", "LogonRes/Effect/", ResType.LogonRes);
        //m_goEffect = GameObject.Instantiate(objEffect) as GameObject;
        //m_goEffect.transform.SetParent(SceneObjMgr.Instance.UIPanelTransform, false);

        if (GlobalLogon.Instance.AccountData != null)
        {
            //m_BtnObject[0].SetActive(false);
            //m_BtnTrans[1].localPosition = m_BtnTrans[0].localPosition;
            //m_BtnTrans[0].localPosition = new Vector3(m_BtnTrans[0].localPosition.x, m_BtnTrans[0].localPosition.y + 75, m_BtnTrans[0].localPosition.z);
        }
    }
    public bool CheckVersion(string xml)
    {
        XmlDocument doc = new XmlDocument();

        if (doc == null)
        {
            return(false);
        }
        doc.LoadXml(xml);
        XmlElement ele = doc.DocumentElement;

        if (ele == null)
        {
            return(false);
        }
        XmlNode nodeVer = ele.SelectSingleNode("Net");

        if (nodeVer == null)
        {
            return(false);
        }
        string resftp    = nodeVer.Attributes["resftp"].Value;
        string runftp    = nodeVer.Attributes["runftp"].Value;
        string clientUrl = nodeVer.Attributes["clienturl"].Value;

        if (nodeVer.Attributes["ftpport"] != null)
        {
            ServerSetting.ResFtpPort = ushort.Parse(nodeVer.Attributes["ftpport"].Value);
        }
        ServerSetting.SetRunFTP(runftp);
        ServerSetting.ServerList.Clear();
        for (int i = 0; i < nodeVer.ChildNodes.Count; ++i)
        {
            XmlNode node = nodeVer.ChildNodes[i];
            if (node.Name == "IP")
            {
                ServerIPData sid = new ServerIPData();
                sid.IP   = node.FirstChild.Value;
                sid.Port = ushort.Parse(node.Attributes["port"].Value);
                ServerSetting.ServerList.Add(sid);
            }
            else if (node.Name == "FTP")
            {
                ServerIPData rfd = new ServerIPData();
                rfd.IP   = node.FirstChild.Value;
                rfd.Port = ushort.Parse(node.Attributes["port"].Value);
                rfd.ISP  = byte.Parse(node.Attributes["dx"].Value);
                m_ResFtpList.Add(rfd);
            }
        }

        ServerSetting.SERVICES_URL = "";// ele.SelectSingleNode("Services").FirstChild.Value;
        XmlNode reporterNode = ele.SelectSingleNode("Reporter");

        if (reporterNode != null)
        {
            ServerSetting.ReporterIP   = reporterNode.FirstChild.Value;
            ServerSetting.ReporterPort = ushort.Parse(reporterNode.Attributes["port"].Value);
        }
        XmlNode ShareNode = ele.SelectSingleNode("Share");

        if (ShareNode != null)
        {
            string  wxid = "", wxpwd = "", sinaid = "", sinapwd = "", qqid = "", qqpwd = "";
            XmlNode xn = ShareNode.ChildNodes[0];
            if (xn != null)
            {
                wxid  = xn.Attributes["id"].Value;
                wxpwd = xn.Attributes["pwd"].Value;
            }
            xn = ShareNode.ChildNodes[1];
            if (xn != null)
            {
                sinaid  = xn.Attributes["id"].Value;
                sinapwd = xn.Attributes["pwd"].Value;
            }
            xn = ShareNode.ChildNodes[2];
            if (xn != null)
            {
                qqid  = xn.Attributes["id"].Value;
                qqpwd = xn.Attributes["pwd"].Value;
            }
            NativeInterface.InitShare(wxid, wxpwd, sinaid, sinapwd, qqid, qqpwd);
            xn = ShareNode.ChildNodes[3];
            if (xn != null)
            {
                ServerSetting.ShareWebUrl = xn.Attributes["weburl"].Value;
                ServerSetting.ShareTxt    = xn.Attributes["txt"].Value;
                ServerSetting.ShareImgUrl = xn.Attributes["imgurl"].Value;
            }
        }
        //读取现有的资源,进行比较
        XmlNode clientNode = ele.SelectSingleNode("Client");
        string  clientVer  = clientNode.FirstChild.Value;;
        uint    clientCrc  = uint.Parse(clientNode.Attributes["crc"].Value);
        uint    clientSize = uint.Parse(clientNode.Attributes["size"].Value);

        if (clientNode.Attributes["resver"] != null)
        {
            ServerSetting.RES_VERSION = uint.Parse(clientNode.Attributes["resver"].Value);
        }
        if (clientNode.Attributes["ping"] != null)
        {
            ServerSetting.SHOW_PING = uint.Parse(clientNode.Attributes["ping"].Value) != 0;
        }
        if (clientNode.Attributes["extrabtn"] != null)
        {
            ServerSetting.ShowExtraBtn = uint.Parse(clientNode.Attributes["extrabtn"].Value) != 0;
        }
        if (clientNode.Attributes["ftp_newftp"] != null)
        {
            FTPClient.USE_NEW_FTP = byte.Parse(clientNode.Attributes["ftp_newftp"].Value);
        }
        if (clientNode.Attributes["showgame"] != null)
        {
            ServerSetting.ShowGame = byte.Parse(clientNode.Attributes["showgame"].Value) != 0;
        }
        if (clientNode.Attributes["ftp_chunkcount"] != null)
        {
            FTPClient.MAX_CHUNK_COUNT = byte.Parse(clientNode.Attributes["ftp_chunkcount"].Value);
        }
        if (clientNode.Attributes["ftp_chunksize"] != null)
        {
            FTPClient.CHUNK_SIZE = int.Parse(clientNode.Attributes["ftp_chunksize"].Value);
        }
        if (clientNode.Attributes["thirdbtn"] != null)
        {
            ServerSetting.ShowHallThirdBtn = int.Parse(clientNode.Attributes["thirdbtn"].Value) != 0;
        }
        if (clientNode.Attributes["exchange"] != null)
        {
            ServerSetting.ShowExchange = int.Parse(clientNode.Attributes["exchange"].Value) != 0;
        }
        if (clientNode.Attributes["showjbp"] != null)
        {
            ServerSetting.ShowJBP = int.Parse(clientNode.Attributes["showjbp"].Value) != 0;
        }
        if (clientNode.Attributes["showmatch"] != null)
        {
            ServerSetting.ShowMatch = int.Parse(clientNode.Attributes["showmatch"].Value) != 0;
        }
        if (clientNode.Attributes["showthirdlogin"] != null)
        {
            ServerSetting.ShowThirdLoginBtn = int.Parse(clientNode.Attributes["showthirdlogin"].Value) != 0;
        }

        m_State = UpdateState.UPDATE_COMPLETE;
        //检查客户端版本号
        if (clientVer == null)
        {
            return(false);
        }
        uint ver = Utility.VersionToUint(clientVer);

        if (ver > ServerSetting.ClientVer)
        {
            //clientUrl = ReplaceFTPAddress(clientUrl);
            //版本更新
            if (RuntimeInfo.GetPlatform() == GamePlatformType.Android)
            {
                if (CheckClientFile(clientCrc))
                {
                    //文件已经下载完成。
                    //NativeInterface.DownNewClientVersion(GetClientPath());
                }
                else
                {
                    //下载资源文件
                    DownResData drd = new DownResData();
                    drd.ResType = ResType.MAX;
                    drd.ResUrl  = clientUrl;
                    drd.ResCrc  = clientCrc;
                    drd.ResSize = clientSize;
                    m_DownList.Add(drd);
                    m_State             = UpdateState.UPDATE_DOWNLOAD_RES;
                    m_AllDownloadBytes += clientSize;
                }
                m_bNewClient = true;
            }
            else if (RuntimeInfo.GetPlatform() == GamePlatformType.Windows)
            {
                m_WinSizeList = new int[5];
                for (int i = 0; i < 5; ++i)
                {
                    string str = "winsize" + (i + 1).ToString();
                    if (clientNode.Attributes[str] != null)
                    {
                        m_WinSizeList[i] = int.Parse(clientNode.Attributes[str].Value);
                    }
                }
                DownResData drd = new DownResData();
                drd.ResType = ResType.MAX;
                drd.ResUrl  = clientUrl;
                drd.ResCrc  = clientCrc;
                drd.ResSize = clientSize;
                m_DownList.Add(drd);
                m_State             = UpdateState.UPDATE_DOWNLOAD_RES;
                m_AllDownloadBytes += clientSize;
                m_bNewClient        = true;
            }
            else
            {
                NativeInterface.DownNewClientVersion(clientUrl);
                m_State = UpdateState.UPDATE_NEW_CLIENT;
                return(true);
            }
        }
        for (int i = 0; i < (int)ResManager.RES_NUM; ++i)
        {
            ResType     rt   = (ResType)i;
            XmlNode     node = ele.SelectSingleNode(rt.ToString());
            DownResData vd   = new DownResData();
            vd.ResCrc       = uint.Parse(node.Attributes["crc"].Value);
            vd.ResUnzipSize = uint.Parse(node.Attributes["unzipsize"].Value);
            if (ResManager.Instance.VersionMgr.CheckVerAndCrc(rt, vd.ResCrc, vd.ResUnzipSize))
            {
                //下载资源文件
                vd.ResType = rt;
                vd.ResUrl  = resftp + node.Attributes["url"].Value;
                vd.ResSize = uint.Parse(node.Attributes["size"].Value);
                m_DownList.Add(vd);
                m_AllDownloadBytes += vd.ResSize;
            }
        }

        //保存当前的RES_VERSION
        if (m_DownList.Count > 0)
        {
            m_State = UpdateState.UPDATE_DOWNLOAD_RES;
            return(true);
        }
        else
        {
            return(true);
        }
    }
    public void Update(float delta)
    {
        if (m_bError)
        {
            NativeInterface.ShowMsgAndExit("res_save_error", 109);
            return;
        }
        if (m_ActiveDown != null)
        {
            if (m_ActiveDown.Type == DownloadType.DOWNLOAD_MULTI_FILE && m_ActiveDown.DownloadBytes != 0)
            {
            }
            else
            {
                m_UpdateUI.SetIsQueue(m_ActiveDown.IsQueue, m_ActiveDown.Type == DownloadType.DOWNLOAD_CHECK_VER);
            }
            if (m_ActiveDown.IsQueue)
            {
                m_UpdateTick = Utility.GetTickCount();
            }
        }
        switch (m_State)
        {
        case UpdateState.UPDATE_CHECK_LOCALVER:
            CheckLocalFile();
            break;

        case UpdateState.UPDATE_UNZIPING_FILE:
            CheckUnzipping();
            break;

        case UpdateState.UPDATE_INIT:
            m_UpdateTick = Utility.GetTickCount();
            string ftpurl = RuntimeInfo.GetFTPVersionURL();
            m_ActiveDown = FTPClient.Instance.AddDownload(DownloadType.DOWNLOAD_CHECK_VER, ftpurl, null);
            m_State      = UpdateState.UPDATE_DOWNLOAD_VERSION;
            break;

        case UpdateState.UPDATE_DOWNLOAD_VERSION:
            if (m_ActiveDown.IsOK)
            {
                m_RetryCount = 0;
                string xml = m_ActiveDown.Text;
                m_ActiveDown = null;
                if (!CheckVersion(xml))
                {
                    NativeInterface.ShowMsgAndExit("update_error", 101);
                }
            }
            else if (m_ActiveDown.HasError)
            {
                //出错了
                if (++m_RetryCount > MAX_RETRY_COUNT)
                {
                    NativeInterface.ShowMsgAndExit("res_connect_error", 102);
                }
                else
                {
                    m_State      = UpdateState.UPDATE_INIT;
                    m_ActiveDown = null;
                }
            }
            else
            {
                if (m_ActiveDown.IsQueue == false && Utility.GetTickCount() - m_UpdateTick > UPDATE_VERSION_TIME_OUT)
                {
                    NativeInterface.ShowMsgAndExit("res_connect_error", 103);
                }
            }
            break;

        case UpdateState.UPDATE_DOWNLOAD_RES:
            if (m_ActiveDown == null)
            {
                if (m_DownList.Count > 0)
                {
                    m_DownloadBytes = 0;
                    m_UpdateTick    = Utility.GetTickCount();
                    m_UpdateUI.BeginDown(ResType.FishRes);
                    m_ActiveDown    = FTPClient.Instance.AddMultiResDownload(DownloadType.DOWNLOAD_MULTI_FILE, m_ResFtpList, m_DownList);
                    m_RecvFileCount = m_DownList.Count;
                    m_DownList.Clear();
                }
                else
                {
                    m_State = UpdateState.UPDATE_COMPLETE;
                }
            }
            else if (m_ActiveDown.IsOK)
            {
                m_RetryCount            = 0;
                m_CurrentDownloadBytes += m_ActiveDown.DownloadBytes;
                m_DownloadBytes         = 0;
                //m_ThreadList.AddItem(m_ActiveDown);
                SaveDownloadData(m_ActiveDown);

                m_ActiveDown = null;
            }
            else if (m_ActiveDown.HasError)
            {
                NativeInterface.ShowMsgAndExit("update_error", 105);
            }
            else
            {
                if (m_ActiveDown.IsQueue)
                {
                    //排队中
                }
                else if (m_DownloadBytes != m_ActiveDown.DownloadBytes)
                {
                    m_DownloadBytes = m_ActiveDown.DownloadBytes;
                    m_UpdateTick    = Utility.GetTickCount();
                    MultiFileDownData mfdd = (MultiFileDownData)m_ActiveDown.Data;
                    if (mfdd.OutsideRecvIndex < mfdd.RecvCount)
                    {
                        SaveDownloadData(m_ActiveDown);
                    }
                }
                else if (Utility.GetTickCount() - m_UpdateTick > UPDATE_RES_TIME_OUT)
                {
                    NativeInterface.ShowMsgAndExit("update_error", 106);
                }
            }
            break;

        case UpdateState.UPDATE_COMPLETE:
            //if (m_DownloadCompletionCount != m_DownloadOrgCount)
            //{
            //    m_UpdateUI.SetUnzipping();
            //    return;
            //}
            //更新完成,进入下一个逻辑
            if (m_SaveCount != m_RecvFileCount)
            {
                return;
            }
            if (m_bNewClient)
            {
                if (RuntimeInfo.GetPlatform() == GamePlatformType.Android)
                {
                    NativeInterface.DownNewClientVersion(GetClientPath());
                }
                else if (RuntimeInfo.GetPlatform() == GamePlatformType.Windows)
                {
                    NativeInterface.ShowMsgAndExit("update_restart", 0);
                }
                else
                {
                    NativeInterface.DownNewClientVersion(m_NewClientURL);
                }
            }
            else
            {
                LogicManager.Instance.Forward(null);
            }
            break;

        case UpdateState.UPDATE_NEW_CLIENT:
            LogicManager.Instance.Shutdown();
            break;
        }
    }