Пример #1
0
    FTPConnectData CreateConnectData(ServerIPData sid)
    {
        FTPConnectData fcd = new FTPConnectData();
        Socket         s   = TCPClient.CreateSocket(true, true);

        s.ReceiveBufferSize = 65536 * 2;
        s.ReceiveTimeout    = 10000000;
        fcd.connected       = false;
        fcd.socket          = s;
        fcd.ippoint         = new IPEndPoint(IPAddress.Parse(sid.IP), sid.Port);
        Thread th = new Thread(new ParameterizedThreadStart(ThreadConnect));

        th.Start(fcd);
        return(fcd);
    }
Пример #2
0
 public DownloadData AddDownload(DownloadType dt, string fileURL, object obj, string ip = null, ushort port = ushort.MaxValue)
 {
     //fileURL = "ftp://61.153.110.167/FishPublish/test/test_version/android_hd_version_com.leduo.buyu.test.xml";
     if (m_DownList.HasSpace() == false)
     {
         return(null);
     }
     try
     {
         if (ip == null)
         {
             //兼容旧格式,要从fileURL中解析网址
             int idx = fileURL.IndexOf("ftp://");
             if (idx == -1)
             {
                 return(null);
             }
             idx += 6;
             int idx2 = fileURL.IndexOf("/", idx);
             if (idx2 == -1)
             {
                 return(null);
             }
             ip      = fileURL.Substring(idx, idx2 - idx);
             port    = ServerSetting.ResFtpPort;
             fileURL = fileURL.Substring(idx2 + 1);
             //fileURL = "fishpublish/test/test_version/windows_hd_version.xml";
         }
         List <ServerIPData> serverList = new List <ServerIPData>();
         List <DownResData>  resList    = new List <DownResData>();
         ServerIPData        sid        = new ServerIPData();
         sid.IP   = ip;
         sid.Port = port;
         serverList.Add(sid);
         DownResData drd = new DownResData();
         drd.ResUrl  = fileURL;
         drd.ResSize = 0;
         resList.Add(drd);
         return(AddMultiResDownload(dt, serverList, resList, obj));
     }
     catch (System.Exception e)
     {
         ReportException.Instance.AddException("AddDownload Exception:" + e.ToString());
         return(null);
     }
 }
Пример #3
0
 bool InitChunk(DownloadData dd, DownChunkData dcd, ServerIPData sid)
 {
     if (dcd.SendCmdData == null)
     {
         if (!CreateChunkCmdData(dd, dcd))
         {
             Debug.Log("创建FTP命令失败1!");
             return(false);
         }
     }
     dcd.Fcd   = CreateConnectData(sid);
     dcd.State = ChunkState.CHUNK_CONNECT;
     if (dcd.RecvData == null || dcd.RecvData.Length < dcd.Length)
     {
         dcd.RecvData = new byte[dcd.Length];
     }
     return(true);
 }
Пример #4
0
    public void Test()
    {
        return;

        List <ServerIPData> ipList  = new List <ServerIPData>();
        List <DownResData>  resList = new List <DownResData>();
        ServerIPData        sip     = new ServerIPData();

        sip.IP   = "127.0.0.1"; //"61.153.110.167";//"192.168.1.150";//
        sip.Port = 45045;
        sip.ISP  = 0;
        ipList.Add(sip);
        for (int i = 1; i <= 6; ++i)
        {
            DownResData drd = new DownResData();
            drd.ResUrl = "ftp://127.0.0.1/FishPublish/rar/" + i + ".rar";
            resList.Add(drd);
        }

        AddMultiResDownload(DownloadType.DOWNLOAD_MULTI_FILE, ipList, resList);
        //AddDownload(DownloadType.DOWNLOAD_DEFAULT, "ftp://127.0.0.1/FishPublish/test.rar", null);
        //AddDownload(DownloadType.DOWNLOAD_DEFAULT, "ftp://101.64.233.10/FishPublish/test.rar", null);
        //AddDownload(DownloadType.DOWNLOAD_DEFAULT, "ftp://61.153.110.167/FishPublish/test.rar", null);
    }
Пример #5
0
    public void LoadInnerVersion()
    {
        TextAsset   ta  = (TextAsset)Resources.Load("InnerRes/Version", typeof(TextAsset));
        XmlDocument doc = new XmlDocument();

        doc.LoadXml(ta.text);
        XmlElement ele       = doc.DocumentElement;
        string     verstr    = ele.SelectSingleNode("Params/Version").FirstChild.Value;
        string     resverstr = ele.SelectSingleNode("Params/Resource").FirstChild.Value;
        uint       editor    = uint.Parse(ele.SelectSingleNode("Params/Editor").FirstChild.Value);

        ServerSetting.SHOW_PING   = uint.Parse(ele.SelectSingleNode("Params/Ping").FirstChild.Value) != 0;
        ServerSetting.RES_VERSION = Utility.VersionToUint(resverstr);
        ServerSetting.ClientVer   = Utility.VersionToUint(verstr);
        SceneObjMgr.Instance.SetVerText("Version:" + verstr.Replace("_", ".").Remove(0, 2));
        int sdkType = int.Parse(ele.SelectSingleNode("Params/Sdk").FirstChild.Value);

#if UNITY_EDITOR
        editor = 1;
#endif
        if (int.Parse(ele.SelectSingleNode("Params/Test").FirstChild.Value) != 0)
        {
            ServerSetting.IS_TEST = true;
        }
        else
        {
            ServerSetting.IS_TEST = false;
        }
        XmlNode serverNode;
        if (editor == 1)
        {
            SDKMgr.SDK_TYPE             = SdkType.SDK_SELF;
            serverNode                  = ele.SelectSingleNode("Server/Editor");
            ResManager.ENABLE_RESOURCES = true;
        }
        else
        {
            SDKMgr.SDK_TYPE = (SdkType)sdkType;
            if (ServerSetting.IS_TEST)
            {
                serverNode = ele.SelectSingleNode("Server/Test");
            }
            else
            {
                serverNode = ele.SelectSingleNode("Server/Publish");
            }
        }
        ServerSetting.VERSION_DIR = serverNode.Attributes["verdir"].Value;
        string  resftp       = serverNode.Attributes["resftp"].Value;
        string  runftp       = serverNode.Attributes["runftp"].Value;
        XmlNode reporterNode = ele.SelectSingleNode("Reporter");
        if (reporterNode != null)
        {
            ServerSetting.ReporterIP   = reporterNode.FirstChild.Value;
            ServerSetting.ReporterPort = ushort.Parse(reporterNode.Attributes["port"].Value);
        }
        ServerSetting.SetResAndRunFTP(resftp, runftp);
        ServerSetting.SERVICES_URL = ele.SelectSingleNode("Services").FirstChild.Value;
        for (int i = 0; i < serverNode.ChildNodes.Count; ++i)
        {
            XmlNode node = serverNode.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);
            }
        }
        ServerSetting.IS_TEST = false;
        Resources.UnloadAsset(ta);
    }
Пример #6
0
    void DownMultiFile_OldFTP(DownloadData dd)
    {
        byte[]            buffer = new byte[65536];
        MultiFileDownData mfdd   = (MultiFileDownData)dd.Data;

        for (int i = 0; i < mfdd.FTPIPList.Count; ++i)
        {
            ServerIPData sid = mfdd.FTPIPList[i];
            if (sid.ISP == (int)ISPType.ISP_DX)
            {
                LogMgr.Log("<电信FTP:" + sid.IP + ">");
            }
            else if (sid.ISP == (int)ISPType.ISP_LT)
            {
                LogMgr.Log("<联通FTP:" + sid.IP + ">");
            }
            else
            {
                LogMgr.Log("<移动FTP:" + sid.IP + ">");
            }
            int retryCount = 0;
            while (mfdd.RecvCount < mfdd.FileList.Count)
            {
                DownResData drd      = mfdd.FileList[mfdd.RecvCount];
                string      url      = "ftp://" + sid.IP + "/" + drd.ResUrl;
                int         readSize = 0;
                try
                {
                    FtpWebRequest ftpRequest = (FtpWebRequest)FtpWebRequest.Create(url);
                    if (ftpRequest == null)
                    {
                        if (retryCount >= MAX_RETRY_COUNT)
                        {
                            break;
                        }
                        else
                        {
                            ++retryCount;
                            Thread.Sleep(500);
                            continue;
                        }
                    }
                    ftpRequest.Method    = WebRequestMethods.Ftp.DownloadFile;
                    ftpRequest.UseBinary = true;
                    ftpRequest.KeepAlive = false;
                    FtpWebResponse response  = (FtpWebResponse)ftpRequest.GetResponse();
                    Stream         ftpStream = null;
                    if (response == null || (ftpStream = response.GetResponseStream()) == null)
                    {
                        if (retryCount >= MAX_RETRY_COUNT)
                        {
                            break;
                        }
                        else
                        {
                            ++retryCount;
                            Thread.Sleep(500);
                            continue;
                        }
                    }
                    MemoryStream ms = new MemoryStream();
                    while (true)
                    {
                        int s = ftpStream.Read(buffer, 0, buffer.Length);
                        if (s <= 0)
                        {
                            break;
                        }
                        ms.Write(buffer, 0, s);
                        readSize             += s;
                        mfdd.CurrentRecvSize += s;
                        dd.DownloadBytes     += (uint)s;
                    }
                    try
                    {
                        ftpStream.Close();
                        response.Close();
                    }
                    catch
                    {
                    }
                    if (mfdd.CurrentRecvSize == drd.ResSize)
                    {
                        MultiFileOK mfo = new MultiFileOK();
                        mfo.Data = ms.ToArray();
                        mfo.Drd  = mfdd.FileList[mfdd.RecvCount];
                        mfdd.CompletionList[mfdd.RecvCount] = mfo;
                        ++mfdd.RecvCount;
                        if (mfdd.RecvCount == mfdd.FileList.Count)
                        {
                            dd.DownState = DownloadState.DS_DOWNLOADED_OK;
                            if (dd.Type != DownloadType.DOWNLOAD_DEFAULT)
                            {
                                m_CompletionList.AddItem(dd);
                            }
                            return;
                        }
                        else
                        {
                            mfdd.CurrentRecvSize = 0;
                        }
                    }
                }
                catch (System.Exception e)
                {
                    dd.DownloadBytes -= (uint)readSize;
                    LogMgr.Log("OLD_FTP下载失败:" + e.ToString());
                    if (retryCount >= MAX_RETRY_COUNT)
                    {
                        break;
                    }
                    else
                    {
                        ++retryCount;
                        Thread.Sleep(500);
                        continue;
                    }
                }
            }
        }
        dd.DownState = DownloadState.DS_DOWNLOADED_ERROR;
        if (dd.Type != DownloadType.DOWNLOAD_DEFAULT)
        {
            m_CompletionList.AddItem(dd);
        }
    }
Пример #7
0
    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);
        }
    }