From a54ba2794b2f2b1fc19cc50dcf3f25b58246c930 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B0=8F=E7=99=BD=E7=8C=BF?= <1083092844@qq.com>
Date: Tue, 9 Jan 2024 22:39:08 +0800
Subject: [PATCH] =?UTF-8?q?=E5=BC=B9=E5=B9=95=E6=8A=93=E5=8C=85=E6=97=A5?=
=?UTF-8?q?=E5=BF=97?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
BarrageGrab/Logger.cs | 49 +++++++++++++++++++++++++--
BarrageGrab/Modles/ProtoEntity/Wss.cs | 1 -
BarrageGrab/WssBarrageGrab.cs | 1 +
BarrageGrab/WssBarrageService.csproj | 15 ++++++++
4 files changed, 63 insertions(+), 3 deletions(-)
diff --git a/BarrageGrab/Logger.cs b/BarrageGrab/Logger.cs
index 6147f33..aae19aa 100644
--- a/BarrageGrab/Logger.cs
+++ b/BarrageGrab/Logger.cs
@@ -56,6 +56,11 @@ namespace BarrageGrab
logger.Fatal(ex, message);
}
+ ///
+ /// 写入弹幕日志
+ ///
+ /// 弹幕类型
+ /// 弹幕内容
public static void LogBarrage(PackMsgType type, Msg msg)
{
if (!Appsetting.Current.BarrageLog) return;
@@ -86,10 +91,9 @@ namespace BarrageGrab
{
LogWarn("弹幕日志写入失败," + ex.Message);
return;
- }
+ }
}
-
private static string LogText(Msg msg, PackMsgType barType)
{
var rinfo = AppRuntime.RoomCaches.GetCachedWebRoomInfo(msg.RoomId.ToString());
@@ -112,5 +116,46 @@ namespace BarrageGrab
text += append;
return text;
}
+
+ ///
+ /// 写入弹幕抓包日志
+ ///
+ /// 分组名
+ /// 包名
+ /// 数据内容
+ /// 分组下最大存储包数量
+ public static void LogBarragePack(string group, string name, byte[] buff, int maxCount = 5)
+ {
+ if (buff.Length <= 10) return;
+ if (group.IsNullOrWhiteSpace()) return;
+ if (name.IsNullOrWhiteSpace()) return;
+ var filename = name + ".bin";
+ var dir = Path.Combine(AppContext.BaseDirectory, "logs", "弹幕包解析", group);
+ var fullPath = Path.Combine(dir, filename);
+
+ try
+ {
+ //获取该文件在该目录下的数量
+ var fiels = Directory.GetFiles(dir, filename);
+ var count = fiels.Length;
+ if (count > 0)
+ {
+ filename = $"{name}({count}).bin";
+ fullPath = Path.Combine(dir, filename);
+ }
+ File.WriteAllBytes(fullPath, buff);
+
+ if (++count > maxCount)
+ {
+ //删除最早的文件
+ var first = fiels.Select(s=>new FileInfo(s)).OrderBy(o=>o.CreationTime).FirstOrDefault();
+ File.Delete(first.FullName);
+ }
+ }
+ catch (Exception ex)
+ {
+ Logger.LogWarn("写入包日志时失败,错误信息:" + ex.Message);
+ }
+ }
}
}
diff --git a/BarrageGrab/Modles/ProtoEntity/Wss.cs b/BarrageGrab/Modles/ProtoEntity/Wss.cs
index e1cdcb6..016938d 100644
--- a/BarrageGrab/Modles/ProtoEntity/Wss.cs
+++ b/BarrageGrab/Modles/ProtoEntity/Wss.cs
@@ -46,6 +46,5 @@ namespace BarrageGrab.Modles.ProtoEntity
#pragma warning restore CS0612, CS0618, CS1591, CS3021, IDE0079, IDE1006, RCS1036, RCS1057, RCS1085, RCS1192
#endregion
-
}
diff --git a/BarrageGrab/WssBarrageGrab.cs b/BarrageGrab/WssBarrageGrab.cs
index 89631c1..f51833d 100644
--- a/BarrageGrab/WssBarrageGrab.cs
+++ b/BarrageGrab/WssBarrageGrab.cs
@@ -142,6 +142,7 @@ namespace BarrageGrab
private void Proxy_OnFetchResponse(object sender, HttpResponseEventArgs e)
{
var payload = e.HttpClient.Response.Body;
+
var response = Serializer.Deserialize(new ReadOnlyMemory(payload));
if (!succPackHostNames.Contains(e.HostName))
diff --git a/BarrageGrab/WssBarrageService.csproj b/BarrageGrab/WssBarrageService.csproj
index 7ca0c5b..1394cd0 100644
--- a/BarrageGrab/WssBarrageService.csproj
+++ b/BarrageGrab/WssBarrageService.csproj
@@ -139,6 +139,15 @@
+
+
+ FormView.cs
+
+
+
+
+ RoomDetail.cs
+
Form
@@ -198,6 +207,12 @@
+
+ FormView.cs
+
+
+ RoomDetail.cs
+
FormView.cs