弹幕抓包日志
This commit is contained in:
+47
-2
@@ -56,6 +56,11 @@ namespace BarrageGrab
|
|||||||
logger.Fatal(ex, message);
|
logger.Fatal(ex, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 写入弹幕日志
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type">弹幕类型</param>
|
||||||
|
/// <param name="msg">弹幕内容</param>
|
||||||
public static void LogBarrage(PackMsgType type, Msg msg)
|
public static void LogBarrage(PackMsgType type, Msg msg)
|
||||||
{
|
{
|
||||||
if (!Appsetting.Current.BarrageLog) return;
|
if (!Appsetting.Current.BarrageLog) return;
|
||||||
@@ -86,10 +91,9 @@ namespace BarrageGrab
|
|||||||
{
|
{
|
||||||
LogWarn("弹幕日志写入失败," + ex.Message);
|
LogWarn("弹幕日志写入失败," + ex.Message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static string LogText(Msg msg, PackMsgType barType)
|
private static string LogText(Msg msg, PackMsgType barType)
|
||||||
{
|
{
|
||||||
var rinfo = AppRuntime.RoomCaches.GetCachedWebRoomInfo(msg.RoomId.ToString());
|
var rinfo = AppRuntime.RoomCaches.GetCachedWebRoomInfo(msg.RoomId.ToString());
|
||||||
@@ -112,5 +116,46 @@ namespace BarrageGrab
|
|||||||
text += append;
|
text += append;
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 写入弹幕抓包日志
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="group">分组名</param>
|
||||||
|
/// <param name="name">包名</param>
|
||||||
|
/// <param name="buff">数据内容</param>
|
||||||
|
/// <param name="maxCount">分组下最大存储包数量</param>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,5 @@ namespace BarrageGrab.Modles.ProtoEntity
|
|||||||
|
|
||||||
#pragma warning restore CS0612, CS0618, CS1591, CS3021, IDE0079, IDE1006, RCS1036, RCS1057, RCS1085, RCS1192
|
#pragma warning restore CS0612, CS0618, CS1591, CS3021, IDE0079, IDE1006, RCS1036, RCS1057, RCS1085, RCS1192
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -142,6 +142,7 @@ namespace BarrageGrab
|
|||||||
private void Proxy_OnFetchResponse(object sender, HttpResponseEventArgs e)
|
private void Proxy_OnFetchResponse(object sender, HttpResponseEventArgs e)
|
||||||
{
|
{
|
||||||
var payload = e.HttpClient.Response.Body;
|
var payload = e.HttpClient.Response.Body;
|
||||||
|
|
||||||
var response = Serializer.Deserialize<Response>(new ReadOnlyMemory<byte>(payload));
|
var response = Serializer.Deserialize<Response>(new ReadOnlyMemory<byte>(payload));
|
||||||
|
|
||||||
if (!succPackHostNames.Contains(e.HostName))
|
if (!succPackHostNames.Contains(e.HostName))
|
||||||
|
|||||||
@@ -139,6 +139,15 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="AppRuntime.cs" />
|
<Compile Include="AppRuntime.cs" />
|
||||||
<Compile Include="Appsetting.cs" />
|
<Compile Include="Appsetting.cs" />
|
||||||
|
<Compile Include="Forms - 复制\FormView.cs" />
|
||||||
|
<Compile Include="Forms - 复制\FormView.Designer.cs">
|
||||||
|
<DependentUpon>FormView.cs</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Forms - 复制\Models\RoomCacheItem.cs" />
|
||||||
|
<Compile Include="Forms - 复制\RoomDetail.cs" />
|
||||||
|
<Compile Include="Forms - 复制\RoomDetail.Designer.cs">
|
||||||
|
<DependentUpon>RoomDetail.cs</DependentUpon>
|
||||||
|
</Compile>
|
||||||
<Compile Include="Forms\FormView.cs">
|
<Compile Include="Forms\FormView.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
@@ -198,6 +207,12 @@
|
|||||||
</BootstrapperPackage>
|
</BootstrapperPackage>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Include="Forms - 复制\FormView.resx">
|
||||||
|
<DependentUpon>FormView.cs</DependentUpon>
|
||||||
|
</EmbeddedResource>
|
||||||
|
<EmbeddedResource Include="Forms - 复制\RoomDetail.resx">
|
||||||
|
<DependentUpon>RoomDetail.cs</DependentUpon>
|
||||||
|
</EmbeddedResource>
|
||||||
<EmbeddedResource Include="Forms\FormView.resx">
|
<EmbeddedResource Include="Forms\FormView.resx">
|
||||||
<DependentUpon>FormView.cs</DependentUpon>
|
<DependentUpon>FormView.cs</DependentUpon>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
|
|||||||
Reference in New Issue
Block a user