Esempio n. 1
0
    public bool Handle(byte[] data, ushort offset, ushort length)
    {
        NetCmdBase cmd = NetCmdHelper.ByteToCmd(data, offset, length);

        if (cmd == null)
        {
            byte cmdType    = data[offset + 3];
            byte cmdSubType = data[offset + 2];
            LogMgr.Log(StringTable.GetString("cmd_error") + ":" + cmdType + ":" + cmdSubType);
            NativeInterface.ShowMsgAndExit("cmd_error", data[offset + 2]);
            return(false);
        }
        if (cmd.GetCmdType() == NetCmdType.CMD_HEARTBEAT)
        {
            //NetCmd nc = new NetCmd();
            //nc.SetCmdType(NetCmdType.CMD_HEARTBEAT);
            //Send<NetCmd>(nc);
        }
        else
        {
            NetCmdPack ncp = new NetCmdPack();
            ncp.cmd  = cmd;
            ncp.tick = Utility.GetTickCount();
            m_CmdList.AddItem(ncp);
        }
        return(true);
    }
Esempio n. 2
0
        public bool Handle(byte[] data, ushort offset, ushort length)
        {
            NetCmdBase cmd = NetCmdHelper.ByteToCmd(data, offset, length);

            if (cmd == null)
            {
                byte cmdType    = data[offset + 3];
                byte cmdSubType = data[offset + 2];
                Debug.LogError("错误类型:" + cmdType + "," + cmdSubType);
                return(false);
            }
            if (cmd.GetCmdType() == NetCmdType.CMD_HEARTBEAT)
            {
                Debug.Log("CMD_HEARTBEAT");
                //NetCmd nc = new NetCmd();
                //nc.SetCmdType(NetCmdType.CMD_HEARTBEAT);
                //Send<NetCmd>(nc);
            }
            else
            {
                NetCmdPack ncp = new NetCmdPack();
                ncp.cmd = cmd;
                Debug.Log("收到数据 = " + cmd.GetCmdTypeToString());
                ncp.tick = Utility.GetTickCount();
                cmdList.AddItem(ncp);
            }
            return(true);
        }
Esempio n. 3
0
        public void Send <T>(NetCmdBase ncb)
        {
            Debug.Log("TCP = " + typeof(T).ToString());
            SendCmdPack scp;

            scp.Cmd  = ncb;
            scp.Hash = Utility.GetHash(typeof(T).ToString());// TypeSize<T>.HASH;
            if (_mSendList.HasSpace())
            {
                _mSendList.AddItem(scp);
            }
            else
            {
                LogMgr.Log("发送命令队列已满");
            }

            byte[] sendData = NetCmdHelper.CmdToBytes(_mSendList.GetItem(), 0);
            if (sendData != null)
            {
                Send(sendData);
            }
            else
            {
                Debug.LogError("发送数据异常");
            }
        }
Esempio n. 4
0
    public void Send <T>(NetCmdBase ncb)
    {
        SendCmdPack scp;

        scp.Cmd  = ncb;
        scp.Hash = TypeSize <T> .HASH;
        if (m_SendList.HasSpace())
        {
            m_SendList.AddItem(scp);
        }
        else
        {
            LogMgr.Log("发送命令队列已满");
        }
    }
Esempio n. 5
0
        public void Send <T>(NetCmdBase ncb)
        {
            Debug.Log("UDP = " + typeof(T).ToString());
            SendCmdPack scp;

            scp.Cmd  = ncb;
            scp.Hash = TypeSize <T> .HASH;
            if (_mSendList.HasSpace())
            {
                _mSendList.AddItem(scp);
            }
            else
            {
                LogMgr.Log("发送命令队列已满");
            }
        }
Esempio n. 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);
        }
    }
Esempio n. 7
0
    //资源有带前缀"ftp://"
    public DownloadData AddMultiResDownload(DownloadType dt, List <ServerIPData> serverList, List <DownResData> resList, object obj = null)
    {
        if (m_DownList.HasSpace() == false)
        {
            return(null);
        }
        MultiFileDownData mfdd = new MultiFileDownData();

        mfdd.CompletionList   = new MultiFileOK[resList.Count];
        mfdd.FTPIPList        = new List <ServerIPData>();
        mfdd.FileList         = new List <DownResData>();
        mfdd.OutsideRecvIndex = 0;
        mfdd.RecvCount        = 0;
        mfdd.CurrentRecvSize  = 0;
        mfdd.ExtraData        = obj;
        mfdd.RecvFileList     = new RecvFileDataFlag[resList.Count];
        List <ServerIPData> ipList1 = new List <ServerIPData>();
        List <ServerIPData> ipList2 = new List <ServerIPData>();

        for (int i = 0; i < serverList.Count; ++i)
        {
            if (serverList[i].ISP == ISP_TYPE || serverList[i].ISP == (byte)ISPType.ISP_YD || ISP_TYPE == (byte)ISPType.ISP_YD)
            {
                ipList1.Add(serverList[i]);
            }
            //else
            //  ipList2.Add(sip);
        }
        if (ipList1.Count == 0)
        {
            for (int i = 0; i < serverList.Count; ++i)
            {
                ipList1.Add(serverList[i]);
            }
        }
        for (int i = 0; i < resList.Count; ++i)
        {
            mfdd.RecvFileList[i] = new RecvFileDataFlag();
            DownResData drd = resList[i];
            string      url = drd.ResUrl.ToLower();
            int         idx = url.IndexOf("fishpublish");
            if (idx == -1)
            {
                return(null);
            }
            drd.ResUrl = url.Substring(idx, url.Length - idx);
            mfdd.FileList.Add(drd);
        }
        //将FTP排队
        for (int i = 0; i < ipList1.Count;)
        {
            int idx = Utility.Range(0, ipList1.Count);
            if (idx >= ipList1.Count)
            {
                idx = ipList1.Count - 1;
            }
            mfdd.FTPIPList.Add(ipList1[idx]);
            ipList1.RemoveAt(idx);
        }
        for (int i = 0; i < ipList2.Count;)
        {
            int idx = Utility.Range(0, ipList2.Count);
            if (idx >= ipList2.Count)
            {
                idx = ipList2.Count - 1;
            }
            mfdd.FTPIPList.Add(ipList2[idx]);
            ipList2.RemoveAt(idx);
        }
        DownloadData dd = new DownloadData(null, mfdd, dt);

        dd.DownState = DownloadState.DS_DOWNLOADING;
        m_DownList.AddItem(dd);
        return(dd);
    }