Ejemplo n.º 1
0
 void StartDownload(UpdateVersion zipInfo)
 {
     UpdateClient = HttpManager.Instance.Alloc();
     StartCoroutine(UpdateProgress());
     UpdateClient.AddRequest(string.Format(strFile, strHost, Main.port, strProjectUrl, zipInfo.File.strFile), zipInfo.File.strLocalPath,
                             (ref HttpRequest req) =>
     {
         zipInfo.File.Loadbytes  = req.loadBytes;
         zipInfo.File.Totalbytes = req.totalBytes;
         if (req.loadBytes == req.totalBytes && CheckUpdateCompleted(zipInfo.File))
         {
             if (req.fs != null)
             {
                 req.fs.Close();
                 req.fs = null;
             }
             req.bDone  = true;
             req.Status = TaskStatus.Done;
             Complete   = zipInfo;
             HttpManager.Instance.Quit();
         }
         else if (req.error != null)
         {
             //中断连接、断网,服务器关闭,或者http 404 /或者 http1.1发 thunk 或者其他,直接进入游戏。
             HttpManager.Instance.Quit();
             LocalMsg msg = new LocalMsg();
             msg.Message  = (int)LocalMsgType.GameStart;
             ProtoHandler.PostMessage(msg);
         }
     }
                             , zipInfo.File.Loadbytes, zipInfo.File);
     UpdateClient.StartDownload();
 }
Ejemplo n.º 2
0
    static void UploadLog(object param)
    {
        int fileCount = 0;

        for (int i = 0; i < logFile.Count; i++)
        {
            if (!File.Exists(logFile[i]))
            {
                continue;
            }
            fileCount++;
            FileStream fs    = File.Open(logFile[i], FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            FileInfo   finfo = new FileInfo(logFile[i]);
            FtpUpload(fs, finfo.Name);
            if (fs != null)
            {
                fs.Close();
            }
            //File.Delete(logFile[i]);
        }
        LocalMsg msg = new LocalMsg();

        msg.Message = (int)LocalMsgType.SendFTPLogComplete;
        msg.Result  = 1;
        msg.Param   = fileCount;
        ProtoHandler.PostMessage(msg);
        uploadThread = null;
    }
Ejemplo n.º 3
0
    public void Update()
    {
        ProtoHandler.Update();
        if (!Started)
        {
            //if (OnUpdates != null)
            //    OnUpdates();
            return;
        }

        AccumilatedTime = AccumilatedTime + Convert.ToInt32((Time.deltaTime * 1000));
        while (AccumilatedTime > LogicFrameLength)
        {
            FrameReplay.deltaTime = delta;
            UdpClientProxy.Update();
            LogicFrame();
            AccumilatedTime = AccumilatedTime - LogicFrameLength;
            time           += (LogicFrameLength / 1000.0f);
        }

        if (Main.Ins.CombatData.Replay)
        {
            if (LogicTurnIndex == Main.Ins.CombatData.GRecord.frames.Count)
            {
                OnBattleFinished();
                U3D.PopupTip("回放结束");
            }
        }
    }
Ejemplo n.º 4
0
    public static void OnTcpConnect(IAsyncResult ret)
    {
        LocalMsg result = new LocalMsg();

        try
        {
            if (sProxy != null)
            {
                sProxy.EndConnect(ret);
            }
            if (tConn != null)
            {
                tConn.Change(Timeout.Infinite, Timeout.Infinite);
            }
        }
        catch (Exception exp)
        {
            Debug.LogError(exp.Message);
            result.Message = (int)LocalMsgType.Connect;
            result.message = exp.Message;
            result.Result  = 0;
            ProtoHandler.PostMessage(result);
            if (tConn != null)
            {
                tConn.Change(delay, delay);
            }
            return;
        }

        //被关闭了的.
        if (sProxy == null)
        {
            return;
        }

        result.Message = (int)LocalMsgType.Connect;
        result.Result  = 1;
        ProtoHandler.PostMessage(result);
        try
        {
            sProxy.BeginReceive(proxy.GetBuffer(), 0, PacketProxy.PacketSize, SocketFlags.None, OnReceivedData, sProxy);
        }
        catch
        {
            result.Message = (int)LocalMsgType.DisConnect;
            result.Result  = 0;
            ProtoHandler.PostMessage(result);
            sProxy.Close();
            proxy.Reset();
            if (tConn != null)
            {
                tConn.Change(5000, 5000);
            }
        }
    }
Ejemplo n.º 5
0
        public void DoWorkByFecha(int fechaDesde, int fechaHasta)
        {
            using (var proto = new ProtoHandler(bag))
            {
                startF.Input.Selector = (cmd == 1) ?
                                        DNLRF_Selector.CTD :
                                        (cmd == 2) ? DNLRF_Selector.DUPLI_A : DNLRF_Selector.RESUMEN;

                startF.Input.FechaDesde = fechaDesde;
                startF.Input.FechaHasta = (fechaHasta == 0)? fechaDesde: fechaHasta;
                startF.Input.Zipeado    = true;
                CommonDoWork(proto, startF, c => ((CMD_DNL_RangoFechas)c).Output.NomArchivo);
            }
        }
Ejemplo n.º 6
0
        public void DoWorkByZeta(int zetaDesde, int zetaHasta)
        {
            using (var proto = new ProtoHandler(bag))
            {
                startZ.Input.Selector = (cmd == 1) ?
                                        DNLRZ_Selector.CTD :
                                        (cmd == 2) ? DNLRZ_Selector.DUPLI_A : DNLRZ_Selector.RESUMEN;

                startZ.Input.ZetaDesde = zetaDesde;
                startZ.Input.ZetaHasta = (zetaHasta == 0)? zetaDesde: zetaHasta;
                startZ.Input.Zipeado   = true;
                CommonDoWork(proto, startZ, c => ((CMD_DNL_RangoZetas)c).Output.NomArchivo);
            }
        }
Ejemplo n.º 7
0
    public static void OnTcpConnect(IAsyncResult ret)
    {
        LocalMsg result = new LocalMsg();

        try
        {
            sProxy.EndConnect(ret);
            if (tConn != null)
            {
                tConn.Change(Timeout.Infinite, Timeout.Infinite);
            }
        }
        catch (Exception exp)
        {
            Log.LogInfo(exp.Message);
            result.Message = (int)LocalMsgType.Connect;
            result.Result  = 0;
            ProtoHandler.PostMessage(result);
            if (tConn != null)
            {
                tConn.Change(5000, 5000);
            }
            return;
        }

        result.Message = (int)LocalMsgType.Connect;
        result.Result  = 1;
        ProtoHandler.PostMessage(result);
        if (proxy == null)
        {
            proxy = new TcpProxy();
        }
        try
        {
            sProxy.BeginReceive(proxy.GetBuffer(), 0, TcpProxy.PacketSize, SocketFlags.None, OnReceivedData, sProxy);
        }
        catch
        {
            result.Message = (int)LocalMsgType.DisConnect;
            result.Result  = 0;
            ProtoHandler.PostMessage(result);
            sProxy.Close();
            sProxy = null;
            proxy  = null;
            if (tConn != null)
            {
                tConn.Change(5000, 5000);
            }
        }
    }
Ejemplo n.º 8
0
        public void DoStatus()
        {
            using (var proto = new ProtoHandler(bag))
            {
                var cmd = new CMD_DNL_Info();
                var mo  = proto.ExchangePacket(cmd);
                if (mo == null)
                {
                    return;
                }

                Console.WriteLine("<donwload>");
                Console.WriteLine($"  <ctd>{cmd.Output.DescargaCTDDesde}</ctd>");
                Console.WriteLine($"  <resu>{cmd.Output.DescargaRESUDesde}</resu>");
                Console.WriteLine($"  <dupliA>{cmd.Output.DescargaDUPLIDesde}</dupliA>");
                Console.WriteLine($"  <listo>{cmd.Output.ListasHasta}</listo>");
                Console.WriteLine($"  <borrado>{cmd.Output.BorradasHasta}</borrado>");
                Console.WriteLine("</donwload>");
            }
        }
Ejemplo n.º 9
0
 void CalcCore()
 {
     while (true)
     {
         waitEvent.WaitOne();
         lock (pathQueue)
         {
             while (pathQueue.Count != 0)
             {
                 PathPameter pameter = pathQueue[0];
                 pathQueue.RemoveAt(0);
                 PathMng.Ins.FindPath(pameter.context, pameter.start, pameter.end, pameter.ways);
                 LocalMsg msg = new LocalMsg();
                 msg.Message = (int)LocalMsgType.PathCalcFinished;
                 msg.context = pameter;
                 ProtoHandler.PostMessage(msg);
             }
         }
     }
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Establece un nuevo gestor de protocolo.
 /// </summary>
 ///
 /// <param name="nproto">El nuevo gestor</param>
 void SetProtoHandler(ProtoHandler nproto)
 {
     this.proto          = nproto;
     prevHook            = this.proto.LowPaper;
     labPort.Text        = nproto.Port.Name;
     this.proto.LowPaper = opened =>
     {
         if (!this.IsDisposed)
         {
             this.Invoke((MethodInvoker) delegate
             {
                 if (labPapel.Visible)
                 {
                     labPapel.Visible = opened;
                 }
             });
         }
         return;
     };
 }
Ejemplo n.º 11
0
    void WriteFileCore()
    {
        GameRecord record = new GameRecord();

        record.RecordVersion = version;
        record.guid          = Guid.NewGuid();
        record.Name          = GenerateRecordName(Main.Ins.CombatData.GLevelItem, Main.Ins.CombatData.GLevelMode, Main.Ins.CombatData.GGameMode);
        record.Mode          = (int)Main.Ins.CombatData.GLevelMode;
        record.Chapter       = (int)(Main.Ins.CombatData.Chapter == null ? 0 : Main.Ins.CombatData.Chapter.ChapterId);
        record.Id            = (int)(Main.Ins.CombatData.GLevelItem.ID);
        record.RandomSeed    = Main.Ins.CombatData.RandSeed;
        record.frames        = Main.Ins.FrameSync.Frames;

        try
        {
            System.IO.FileStream fs = System.IO.File.Create(recordPath + record.Name + ".mrc");
            ProtoBuf.Serializer.Serialize(fs, record);
            fs.Close();
        }
        catch (Exception exp)
        {
            LocalMsg resultFailed = new LocalMsg();
            resultFailed.Message = (int)LocalMsgType.SaveRecord;
            resultFailed.message = exp.Message;
            resultFailed.Result  = 0;
            ProtoHandler.PostMessage(resultFailed);
            WriteThread = null;
            return;
        }
        //do sth
        LocalMsg result = new LocalMsg();

        result.Message = (int)LocalMsgType.SaveRecord;
        result.Result  = 1;
        ProtoHandler.PostMessage(result);
        WriteThread = null;
    }
Ejemplo n.º 12
0
        private void CommonDoWork(ProtoHandler proto, CMD_Generic start, Func <CMD_Generic, string> getFileName)
        {
            StringBuilder data = new StringBuilder();

            try
            {
                // Lanza la descarga.
                var mo = proto.ExchangePacket(start);
                if (mo == null || mo.ErrorCodeInt != 0)
                {
                    string msg =
                        (start as CMD_DNL_RangoFechas)?.Output.ErrorCode ??
                        (start as CMD_DNL_RangoZetas)?.Output.ErrorCode ??
                        "<Error Desconocido>";

                    Console.WriteLine($"ERROR: '{msg}'");
                    return;
                }

                // Lazo de descarga
                int prog = 0;
                Console.Write("Descargando: ");
                while (true)
                {
                    mo = proto.ExchangePacket(gloop);
                    if (mo.ErrorCodeInt != 0)
                    {
                        throw new Exception(mo.Error);
                    }
                    data.Append(gloop.Output.Data);
                    if (!gloop.Output.Continua)
                    {
                        break;
                    }

                    if (prog++ == 5)
                    {
                        Console.Write("\b\b\b\b\b     \b\b\b\b\b");
                        prog = 0;
                    }
                    else
                    {
                        Console.Write(".");
                    }
                }

                // Finaliza
                proto.ExchangePacket(end);
                var fn = Path.Combine(carpeta, getFileName(start));
                Console.Write($"\r                         \r==> '{ShortPath(fn)}'\n");
                File.WriteAllText(fn, data.ToString());
                if (decrypt)
                {
                    var xml = Path.ChangeExtension(fn, "xml");
                    Console.WriteLine($" Decrypt  '{ShortPath(fn)}' => '{ShortPath(xml)}");
                    DecryptPEMFile(fn);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"ERROR - '{ex.Message}'");
                try
                {
                    proto.ExchangePacket(canc);
                }
                catch { }
            }
        }
Ejemplo n.º 13
0
 public static void Init()
 {
     ProtoHandler.RegisterPacket(Packet);
 }
Ejemplo n.º 14
0
 // Update is called once per frame
 void Update()
 {
     frameIdx++;
     ProtoHandler.Update();
 }
Ejemplo n.º 15
0
    static void OnReceivedData(IAsyncResult ar)
    {
        int len = 0;

        try
        {
            len = sProxy.EndReceive(ar);
        }
        catch
        {
        }
        if (len <= 0)
        {
            if (!quit)
            {
                LocalMsg msg = new LocalMsg();
                msg.Message = (int)LocalMsgType.DisConnect;
                msg.Result  = 1;
                ProtoHandler.PostMessage(msg);
                if (sProxy.Connected)
                {
                    sProxy.Close();
                }
                proxy.Reset();
                if (tConn != null)
                {
                    tConn.Change(5000, 5000);
                }
            }
            if (proxy != null)
            {
                proxy.Reset();
            }
            return;
        }

        lock (Packet)
        {
            if (!proxy.Analysis(len, Packet))
            {
                sProxy.Close();
                proxy.Reset();
                return;
            }
        }
        //logicEvent.Set();

        if (!quit)
        {
            try
            {
                sProxy.BeginReceive(proxy.GetBuffer(), 0, PacketProxy.PacketSize, SocketFlags.None, OnReceivedData, sProxy);
            }
            catch
            {
                LocalMsg msg = new LocalMsg();
                msg.Message = (int)LocalMsgType.DisConnect;
                msg.Result  = 1;
                ProtoHandler.PostMessage(msg);
                sProxy.Close();
                proxy.Reset();
                if (tConn != null)
                {
                    tConn.Change(5000, 5000);
                }
            }
        }
    }
Ejemplo n.º 16
0
 /// <summary>
 /// Constructor
 /// </summary>
 ///
 /// <param name="proto">
 /// El manejador del protocolo fiscal que se usará para enviar comandos al CF.
 /// </param>
 ///
 /// <param name="errorShow">
 /// Método que se invocará cuando9 se produzca un error.
 /// </param>
 public ERunner(ProtoHandler proto, Action <string> errorShow)
 {
     this.proto     = proto;
     this.errorShow = errorShow;
 }
Ejemplo n.º 17
0
 public static void Init()
 {
     Packet = new Dictionary <int, byte[]>();
     //注册解析udp数据包.
     ProtoHandler.RegisterPacket(Packet);
 }