Exemplo n.º 1
0
    public void TryConn(object param)
    {
        if (sProxy != null && sProxy.Connected)
        {
            if (tConn != null)
            {
                tConn.Change(Timeout.Infinite, Timeout.Infinite);
            }
            return;
        }
        canceled = false;

        if (tConn != null)
        {
            tConn.Change(Timeout.Infinite, Timeout.Infinite);
        }
        IAsyncResult ar      = sProxy.BeginConnect(server, OnTcpConnect, sProxy);
        bool         success = ar.AsyncWaitHandle.WaitOne(2000);

        if (!success)
        {
            LocalMsg result = new LocalMsg();
            result.Message = (int)LocalMsgType.TimeOut;
            result.message = "服务器未响应";
            result.Result  = 0;
            TcpHandler.PostMessage(result);
            canceled = true;//超时连接取消重试.
            if (tConn != null)
            {
                tConn.Change(Timeout.Infinite, Timeout.Infinite);
            }
            return;
        }
    }
Exemplo 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;
    }
Exemplo n.º 3
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();
 }
Exemplo n.º 4
0
    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;
                TcpHandler.PostMessage(msg);
                if (sProxy.Connected)
                {
                    sProxy.Close();
                }
                proxy.Reset();
            }
            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;
                TcpHandler.PostMessage(msg);
                sProxy.Close();
                proxy.Reset();
            }
        }
    }
 static void OnPathCalcFinished(LocalMsg msg)
 {
     if (msg.context is PathPameter)
     {
         PathPameter pameter = msg.context as PathPameter;
         pameter.stateMachine.OnPathCalcFinished(pameter);
     }
 }
Exemplo n.º 6
0
    public void OnTcpConnect(IAsyncResult ret)
    {
        LocalMsg result = new LocalMsg();

        try
        {
            if (sProxy != null)
            {
                sProxy.EndConnect(ret);
            }
        }
        catch (Exception exp)
        {
            if (canceled)
            {
                return;
            }
            //Debug.LogError(exp.Message);
            result.Message = (int)LocalMsgType.Connect;
            result.message = exp.Message;
            result.Result  = 0;
            TcpHandler.PostMessage(result);
            return;
        }

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

        if (canceled)
        {
            sProxy.Close();
            sProxy = null;
            return;
        }
        result.Message = (int)LocalMsgType.Connect;
        result.Result  = 1;
        lock (Packet) {
            Packet.Clear();
        }
        TcpHandler.PostMessage(result);
        try
        {
            sProxy.BeginReceive(proxy.GetBuffer(), 0, PacketProxy.PacketSize, SocketFlags.None, OnReceivedData, sProxy);
        }
        catch
        {
            result.Message = (int)LocalMsgType.DisConnect;
            result.Result  = 0;
            TcpHandler.PostMessage(result);
            sProxy.Close();
            proxy.Reset();
        }
    }
Exemplo n.º 7
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);
            }
        }
    }
Exemplo n.º 8
0
    void WriteFileCore()
    {
        GameRecord record = new GameRecord();

        record.AppVersion          = version;
        record.MeteorVersion       = AppInfo.Ins.MeteorV1();
        record.EnableGodMode       = GameStateMgr.Ins.gameStatus.EnableGodMode =
            record.HidePlayer      = GameStateMgr.Ins.gameStatus.HidePlayer;
        record.EnableInfiniteAngry = GameStateMgr.Ins.gameStatus.EnableInfiniteAngry;
        record.Undead     = GameStateMgr.Ins.gameStatus.Undead;
        record.guid       = Guid.NewGuid();
        record.Name       = GenerateRecordName(CombatData.Ins.GLevelItem, CombatData.Ins.GLevelMode, CombatData.Ins.GGameMode);
        record.GameMode   = CombatData.Ins.GGameMode;
        record.LevelMode  = CombatData.Ins.GLevelMode;
        record.Chapter    = (int)(CombatData.Ins.Chapter == null ? 0 : CombatData.Ins.Chapter.ChapterId);
        record.Id         = (int)(CombatData.Ins.GLevelItem.Id);
        record.RandomSeed = CombatData.Ins.RandSeed;
        //record.frames = FrameSyncLocal.Ins.Frames;
        record.Level        = CombatData.Ins.GLevelItem;
        record.screenWidth  = (int)(UIHelper.CanvasWidth / 5);
        record.screenHeight = (int)(UIHelper.CanvasHeight / 5);
        record.screenPng    = recordPath + record.guid + ".png";
        Utility.SavePng(record.screenPng, screenShot);
        record.frameCount = frame;
        record.duration   = duration;
        record.deltaTime  = deltaTime;
        record.time       = DateTime.Now.ToFileTime();
        try
        {
            System.IO.FileStream fs = System.IO.File.Create(recordPath + record.Name + "_" + record.guid.ToString() + ".mrc");
            ProtoBuf.Serializer.Serialize(fs, record);
            fs.Close();
        }
        catch (Exception exp)
        {
            Debug.LogError(exp.Message + exp.StackTrace);
            LocalMsg resultFailed = new LocalMsg();
            resultFailed.Message = (int)LocalMsgType.SaveRecord;
            resultFailed.message = exp.Message;
            resultFailed.Result  = 0;
            TcpProtoHandler.Ins.PostMessage(resultFailed);
            WriteThread = null;
            return;
        }
        //do sth
        LocalMsg result = new LocalMsg();

        result.Message = (int)LocalMsgType.SaveRecord;
        result.Result  = 1;
        TcpProtoHandler.Ins.PostMessage(result);
        WriteThread = null;
    }
Exemplo n.º 9
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);
            }
        }
    }
Exemplo n.º 10
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);
             }
         }
     }
 }
Exemplo 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;
    }
Exemplo n.º 12
0
 //保存录像结束,把对应的Pending框关闭
 static void OnSaveRecord(LocalMsg msg)
 {
     DialogUtils.Ins.CloseWait();//关闭Pending框.
 }
Exemplo n.º 13
0
 public static void PostMessage(LocalMsg msg)
 {
     lock (messageQueue)
         messageQueue.Add(msg);
 }
Exemplo n.º 14
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);
                sProxy.Close();
                sProxy = null;
                proxy  = null;
                if (tConn != null)
                {
                    tConn.Change(5000, 5000);
                }
            }
            return;
        }

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

        if (!quit)
        {
            try
            {
                sProxy.BeginReceive(proxy.GetBuffer(), 0, TcpProxy.PacketSize, SocketFlags.None, OnReceivedData, sProxy);
            }
            catch
            {
                LocalMsg msg = new LocalMsg();
                msg.Message = (int)LocalMsgType.DisConnect;
                msg.Result  = 1;
                ProtoHandler.PostMessage(msg);
                sProxy.Close();
                sProxy = null;
                proxy  = null;
                if (tConn != null)
                {
                    tConn.Change(5000, 5000);
                }
            }
        }
    }
Exemplo n.º 15
0
 void OnSaveRecord(LocalMsg msg)
 {
     WaitDialogState.State.WaitExit(1.0f);//关闭Pending框.
 }