private void RecordDanmu(string msgDanmu) { var dict = DyMsg.GetDict(msgDanmu); string msg = string.Format("{0}:{1}", dict["nn"], dict["txt"]); if (ShowDanmu) { DanmuPrint(msg + Environment.NewLine, true); } }
private static void StartDanmuRecord(object obj) { Operator op = (Operator)obj; DySocket s = new DySocket(); s.login(op.RoomID); op.StartDanmu = true; //打开弹幕文件 FileStream fs = new FileStream(op.RecordFilePath + ".danmu", FileMode.OpenOrCreate ); long LastTime = CommonTime.GetTimeStamp(); while (true) { s.keeplive(); if (op.StartDanmu == false) { break; } byte[] resraw = s.recv(4); if (resraw == null) { op.LogError("Recv Timeout"); break; } int len = BitConverter.ToInt32(resraw, 0); if (len <= 0) { continue; } resraw = s.recv(8); short type = BitConverter.ToInt16(resraw, 4); if (type != 690) { continue; } // 正式获取消息 resraw = s.recv(len - 8); string resstr = System.Text.Encoding.UTF8.GetString(resraw); // 弹幕 if (resstr.Contains("type@=chatmsg") && resstr.Contains("txt@=") && resstr.Contains("nn@=") ) { long timeCount = CommonTime.GetTimeStamp() - LastTime; var dict = DyMsg.GetDict(resstr); string outDanmu = null; if (dict.ContainsKey("col")) { outDanmu = string.Format("TimeCount={0},user={1},text={2},col={3}", timeCount, dict["nn"], dict["txt"], dict["col"]) + Environment.NewLine; } else { outDanmu = string.Format("TimeCount={0},user={1},text={2}", timeCount, dict["nn"], dict["txt"]) + Environment.NewLine; } byte[] bDanmu = Encoding.UTF8.GetBytes(outDanmu); try { fs.Write(bDanmu, 0, bDanmu.Length); } catch (Exception e) { op.LogError("Danmu:" + e.Message, true); } op.RecordDanmu(resstr); } } fs.Close(); s.logout(); s.release(); op.RecordDanmuClosing(); }