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; }
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(); }
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); } } }
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); } } }
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); } } } }
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; }
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); } } } }