项目结构优化

This commit is contained in:
小白猿
2023-08-17 20:37:22 +08:00
parent 22581018a3
commit e9c7c71aac
9 changed files with 439 additions and 128 deletions
+34
View File
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using BarrageGrab.Modles;
using ColorConsole;
namespace BarrageGrab
{
/// <summary>
/// 程序运行时信息
/// </summary>
public static class AppRuntime
{
/// <summary>
/// Ws弹幕服务示例
/// </summary>
public static WsBarrageService WssService { get; private set; } = new WsBarrageService();
/// <summary>
/// 程序进程信息
/// </summary>
public static Process CurrentProcess { get; private set; } = System.Diagnostics.Process.GetCurrentProcess();
static AppRuntime()
{
}
}
}
+175
View File
@@ -0,0 +1,175 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace BarrageGrab
{
/// <summary>
/// 扩展类
/// </summary>
public static class ObjectExtension
{
/// <summary>
/// 判断字符串是否为空或空白
/// </summary>
public static bool IsNullOrWhiteSpace(this string str) => string.IsNullOrWhiteSpace(str);
/// <summary>
/// 判断字符串是否为空
/// </summary>
public static bool IsNullOrEmpty(this string str) => string.IsNullOrEmpty(str);
/// <summary>
/// 转为Json
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public static string ToJson(this object obj)
{
if (obj is string)
{
return obj.ToString();
}
return JsonConvert.SerializeObject(obj);
}
/// <summary>
/// 转为对象
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="json"></param>
/// <returns></returns>
public static T AsObject<T>(this string json)
{
return JsonConvert.DeserializeObject<T>(json);
}
/// <summary>
/// 获取Value或其Value默认值
/// </summary>
public static TValue ValueOrDefault<Tkey, TValue>(this IDictionary<Tkey, TValue> dic, Tkey key)
{
if (dic.ContainsKey(key))
{
return dic[key];
}
return default;
}
/// <summary>
/// 获取Value或其Value默认值
/// </summary>
public static TValue ValueOrDefault<Tkey, TValue>(this IDictionary<Tkey, TValue> dic, Tkey key, TValue defaultValue)
{
if (dic.ContainsKey(key))
{
return dic[key];
}
return defaultValue;
}
/// <summary>
/// 遍历集合
/// </summary>
public static void Foreach<T>(this IEnumerable<T> list, Action<T> func)
{
foreach (var item in list) func(item);
}
/// <summary>
/// 遍历集合
/// </summary>
public static void Foreach<T>(this IEnumerable<T> list, Action<T, int> func)
{
int i = 0;
foreach (var item in list) func(item, i++);
}
public static CookieCollection ToCookies(this string cookieStr, string domain)
{
var cookies = new CookieCollection();
if (!string.IsNullOrEmpty(cookieStr))
{
var cookieArray = cookieStr.Split(';');
foreach (var cookie in cookieArray)
{
var cookieParts = cookie.Split('=');
if (cookieParts.Length == 2)
{
var cookieName = cookieParts[0].Trim();
var cookieValue = cookieParts[1].Trim();
var newCookie = new Cookie(cookieName, Uri.EscapeDataString(cookieValue));
newCookie.Path = "/";
newCookie.Domain = domain;
cookies.Add(newCookie);
}
}
}
return cookies;
}
/// <summary>
/// 追加另一个字典
/// </summary>
/// <param name="dic"></param>
/// <param name="other"></param>
/// <returns></returns>
public static IDictionary<string, string> Append(this IEnumerable<KeyValuePair<string, string>> dic, IEnumerable<KeyValuePair<string, string>> other)
{
var res = new Dictionary<string, string>();
foreach (var item in dic)
{
res.Add(item.Key, item.Value);
}
foreach (var item in other)
{
if (res.ContainsKey(item.Key))
{
res[item.Key] = item.Value;
}
else
{
res.Add(item.Key, item.Value);
}
}
return res;
}
/// <summary>
/// 转换为Cookie对象列表
/// </summary>
/// <param name="dic"></param>
/// <param name="domain"></param>
/// <returns></returns>
public static CookieCollection ToCookies(this IDictionary<string, string> dic, string domain)
{
var cookieCollection = new CookieCollection();
foreach (var item in dic)
{
cookieCollection.Add(new Cookie(item.Key, item.Value, "/", domain));
}
return cookieCollection;
}
/// <summary>
/// 添加Cookie
/// </summary>
/// <param name="cookies"></param>
/// <param name="dic"></param>
/// <param name="domain"></param>
public static void PushCookies(this CookieContainer cookies, string domain, IDictionary<string, string> dic)
{
if (cookies == null) return;
var cookieCollection = dic.ToCookies(domain);
cookies.Add(cookieCollection);
}
}
}
+26 -43
View File
@@ -1,27 +1,32 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net.Sockets;
using System.Net;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks;
namespace BarrageGrab namespace BarrageGrab
{ {
public class Program public class Program
{ {
private delegate bool ControlCtrlDelegate(int CtrlType);
static WsBarrageService server = null;
static void Main(string[] args) static void Main(string[] args)
{ {
SetConsoleCtrlHandler(cancelHandler, true);//捕获控制台关闭 if (CheckAlreadyRunning())
{
Console.WriteLine("已经有一个监听程序在运行,按任意键退出...");
Console.ReadKey();
return;
}
WinApi.SetConsoleCtrlHandler(cancelHandler, true);//捕获控制台关闭
WinApi.DisableQuickEditMode();//禁用控制台快速编辑模式
Console.Title = "抖音弹幕监听推送"; Console.Title = "抖音弹幕监听推送";
DisableQuickEditMode();
bool exited = false; bool exited = false;
server = new WsBarrageService(); AppRuntime.WssService.StartListen();
server.StartListen(); AppRuntime.WssService.OnClose += (s, e) =>
server.OnClose += (s, e) =>
{ {
//退出程序 //退出程序
exited = true; exited = true;
@@ -31,18 +36,14 @@ namespace BarrageGrab
{ {
Thread.Sleep(500); Thread.Sleep(500);
} }
Console.WriteLine("服务器已关闭..."); Console.WriteLine("服务器已关闭...");
//退出程序,不显示 按任意键退出 //退出程序,不显示 按任意键退出
Environment.Exit(0); Environment.Exit(0);
} }
private static WinApi.ControlCtrlDelegate cancelHandler = new WinApi.ControlCtrlDelegate((CtrlType) =>
[DllImport("kernel32.dll")]
private static extern bool SetConsoleCtrlHandler(ControlCtrlDelegate HandlerRoutine, bool Add);
private static ControlCtrlDelegate cancelHandler = new ControlCtrlDelegate(HandlerRoutine);
public static bool HandlerRoutine(int CtrlType)
{ {
switch (CtrlType) switch (CtrlType)
{ {
@@ -52,39 +53,21 @@ namespace BarrageGrab
break; break;
case 2: case 2:
Console.WriteLine("2工具被强制关闭");//按控制台关闭按钮关闭 Console.WriteLine("2工具被强制关闭");//按控制台关闭按钮关闭
server.Close(); AppRuntime.WssService.Close();
break; break;
} }
return false; return false;
} });
//检测程序是否多开
const int STD_INPUT_HANDLE = -10; private static bool CheckAlreadyRunning()
const uint ENABLE_QUICK_EDIT_MODE = 0x0040;
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern IntPtr GetStdHandle(int hConsoleHandle);
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint mode);
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint mode);
public static void EnableQuickEditMode()
{ {
IntPtr hStdin = GetStdHandle(STD_INPUT_HANDLE); const string mutexName = "DyBarrageGrab";
uint mode; // Try to create a new named mutex.
GetConsoleMode(hStdin, out mode); using (Mutex mutex = new Mutex(true, mutexName, out bool createdNew))
mode |= ENABLE_QUICK_EDIT_MODE; {
SetConsoleMode(hStdin, mode); return !createdNew;
}
} }
public static void DisableQuickEditMode()
{
IntPtr hStdin = GetStdHandle(STD_INPUT_HANDLE);
uint mode;
GetConsoleMode(hStdin, out mode);
mode &= ~ENABLE_QUICK_EDIT_MODE;
SetConsoleMode(hStdin, mode);
}
} }
} }
+6 -6
View File
@@ -5,11 +5,11 @@ using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下 // 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改 // 控制。更改这些特性值可修改
// 与程序集关联的信息。 // 与程序集关联的信息。
[assembly: AssemblyTitle("LiveCompanionBarrageGrab")] [assembly: AssemblyTitle("抖音弹幕监听")]
[assembly: AssemblyDescription("")] [assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")] [assembly: AssemblyCompany("小白不圆")]
[assembly: AssemblyProduct("LiveCompanionBarrageGrab")] [assembly: AssemblyProduct("抖音弹幕监听器")]
[assembly: AssemblyCopyright("Copyright © 2022")] [assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
@@ -20,7 +20,7 @@ using System.Runtime.InteropServices;
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("a07bb1da-d5c2-4eea-9f3f-e42aadb9c1d6")] [assembly: Guid("a07bb1da-d5c2-4bea-9f3f-e42aadb9c1d5")]
// 程序集的版本信息由下列四个值组成: // 程序集的版本信息由下列四个值组成:
// //
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示: //通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyVersion("2.6.8.0")]
[assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyFileVersion("2.6.8.0")]
+56
View File
@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace BarrageGrab
{
public static class WinApi
{
const int STD_INPUT_HANDLE = -10;
const uint ENABLE_QUICK_EDIT_MODE = 0x0040;
/// <summary>
/// 控制台系统操作回调委托
/// </summary>
public delegate bool ControlCtrlDelegate(int CtrlType);
/// <summary>
/// 设置控制台系统操作回调
/// </summary>
[DllImport("kernel32.dll")]
public static extern bool SetConsoleCtrlHandler(ControlCtrlDelegate HandlerRoutine, bool Add);
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern IntPtr GetStdHandle(int hConsoleHandle);
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint mode);
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint mode);
/// <summary>
/// 启用控制台快速编辑
/// </summary>
public static void EnableQuickEditMode()
{
IntPtr hStdin = GetStdHandle(STD_INPUT_HANDLE);
uint mode;
GetConsoleMode(hStdin, out mode);
mode |= ENABLE_QUICK_EDIT_MODE;
SetConsoleMode(hStdin, mode);
}
/// <summary>
/// 禁用控制台快速编辑
/// </summary>
public static void DisableQuickEditMode()
{
IntPtr hStdin = GetStdHandle(STD_INPUT_HANDLE);
uint mode;
GetConsoleMode(hStdin, out mode);
mode &= ~ENABLE_QUICK_EDIT_MODE;
SetConsoleMode(hStdin, mode);
}
}
}
+25 -19
View File
@@ -1,17 +1,22 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net;
using System.Net.WebSockets; using System.Net.WebSockets;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Timers; using System.Timers;
using BarrageGrab.JsonEntity;
using BarrageGrab.ProtoEntity;
using ColorConsole; using ColorConsole;
using Fleck; using Fleck;
using Newtonsoft.Json; using Newtonsoft.Json;
using BarrageGrab.Modles;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using static BarrageGrab.ProtoEntity.Image; using System.Net.Http;
using Org.BouncyCastle.Asn1.Crmf;
using System.IO.Compression;
using System.IO;
using BarrageGrab.Modles.JsonEntity;
using BarrageGrab.Modles.ProtoEntity;
namespace BarrageGrab namespace BarrageGrab
{ {
@@ -19,7 +24,7 @@ namespace BarrageGrab
/// <summary> /// <summary>
/// 弹幕服务 /// 弹幕服务
/// </summary> /// </summary>
internal class WsBarrageService public class WsBarrageService
{ {
WebSocketServer socketServer; WebSocketServer socketServer;
Dictionary<string, UserState> socketList = new Dictionary<string, UserState>(); Dictionary<string, UserState> socketList = new Dictionary<string, UserState>();
@@ -42,7 +47,7 @@ namespace BarrageGrab
#if DEBUG #if DEBUG
debug = true; debug = true;
#endif #endif
var socket = new WebSocketServer($"ws://127.0.0.1:{Appsetting.WsProt}"); var socket = new WebSocketServer($"ws://0.0.0.0:{Appsetting.WsProt}");
socket.RestartAfterListenError = true;//异常重启 socket.RestartAfterListenError = true;//异常重启
dieout.Elapsed += Dieout_Elapsed; dieout.Elapsed += Dieout_Elapsed;
@@ -81,11 +86,12 @@ namespace BarrageGrab
private bool CheckRoomId(long roomid) private bool CheckRoomId(long roomid)
{ {
return Appsetting.RoomIds.Length == 0 || Appsetting.RoomIds.Contains(roomid); if (Appsetting.RoomIds.Length == 0) return true;
return Appsetting.RoomIds.Any(a => a == roomid);
} }
//解析用户 //解析用户
private MsgUser GetUser(ProtoEntity.User data) private MsgUser GetUser(User data)
{ {
MsgUser user = new MsgUser() MsgUser user = new MsgUser()
{ {
@@ -94,7 +100,7 @@ namespace BarrageGrab
Gender = data.Gender, Gender = data.Gender,
Id = data.Id, Id = data.Id,
Level = data.Level, Level = data.Level,
PayLevel = (int)(data.payGrade?.Level??0), PayLevel = (int)(data.payGrade?.Level ?? 0),
Nickname = data.Nickname, Nickname = data.Nickname,
HeadImgUrl = data.avatarThumb.urlLists.FirstOrDefault() ?? "", HeadImgUrl = data.avatarThumb.urlLists.FirstOrDefault() ?? "",
SecUid = data.sec_uid, SecUid = data.sec_uid,
@@ -118,7 +124,7 @@ namespace BarrageGrab
} }
//粉丝团 //粉丝团
private void Grab_OnFansclubMessage(object sender, ProtoEntity.FansclubMessage e) private void Grab_OnFansclubMessage(object sender, FansclubMessage e)
{ {
if (!CheckRoomId(e.Common.roomId)) return; if (!CheckRoomId(e.Common.roomId)) return;
var enty = new FansclubMsg() var enty = new FansclubMsg()
@@ -137,7 +143,7 @@ namespace BarrageGrab
} }
//统计消息 //统计消息
private void Grab_OnRoomUserSeqMessage(object sender, ProtoEntity.RoomUserSeqMessage e) private void Grab_OnRoomUserSeqMessage(object sender, RoomUserSeqMessage e)
{ {
if (!CheckRoomId(e.Common.roomId)) return; if (!CheckRoomId(e.Common.roomId)) return;
var enty = new UserSeqMsg() var enty = new UserSeqMsg()
@@ -158,7 +164,7 @@ namespace BarrageGrab
} }
//礼物 //礼物
private void Grab_OnGiftMessage(object sender, ProtoEntity.GiftMessage e) private void Grab_OnGiftMessage(object sender, GiftMessage e)
{ {
if (!CheckRoomId(e.Common.roomId)) return; if (!CheckRoomId(e.Common.roomId)) return;
@@ -233,7 +239,7 @@ namespace BarrageGrab
} }
//关注 //关注
private void Grab_OnSocialMessage(object sender, ProtoEntity.SocialMessage e) private void Grab_OnSocialMessage(object sender, SocialMessage e)
{ {
if (!CheckRoomId(e.Common.roomId)) return; if (!CheckRoomId(e.Common.roomId)) return;
if (e.Action != 1) return; if (e.Action != 1) return;
@@ -252,7 +258,7 @@ namespace BarrageGrab
} }
//直播间分享 //直播间分享
private void Grab_OnShardMessage(object sender, ProtoEntity.SocialMessage e) private void Grab_OnShardMessage(object sender, SocialMessage e)
{ {
if (!CheckRoomId(e.Common.roomId)) return; if (!CheckRoomId(e.Common.roomId)) return;
if (e.Action != 3) return; if (e.Action != 3) return;
@@ -278,11 +284,11 @@ namespace BarrageGrab
} }
//来了 //来了
private void Grab_OnMemberMessage(object sender, ProtoEntity.MemberMessage e) private void Grab_OnMemberMessage(object sender, Modles.ProtoEntity.MemberMessage e)
{ {
if (!CheckRoomId(e.Common.roomId)) return; if (!CheckRoomId(e.Common.roomId)) return;
var enty = new JsonEntity.MemberMessage() var enty = new Modles.JsonEntity.MemberMessage()
{ {
MsgId = e.Common.msgId, MsgId = e.Common.msgId,
Content = $"{e.User.Nickname} 来了 直播间人数:{e.memberCount}", Content = $"{e.User.Nickname} 来了 直播间人数:{e.memberCount}",
@@ -297,7 +303,7 @@ namespace BarrageGrab
} }
//点赞 //点赞
private void Grab_OnLikeMessage(object sender, ProtoEntity.LikeMessage e) private void Grab_OnLikeMessage(object sender, LikeMessage e)
{ {
if (!CheckRoomId(e.Common.roomId)) return; if (!CheckRoomId(e.Common.roomId)) return;
@@ -317,7 +323,7 @@ namespace BarrageGrab
} }
//弹幕 //弹幕
private void Grab_OnChatMessage(object sender, ProtoEntity.ChatMessage e) private void Grab_OnChatMessage(object sender, ChatMessage e)
{ {
if (!CheckRoomId(e.Common.roomId)) return; if (!CheckRoomId(e.Common.roomId)) return;
@@ -417,7 +423,7 @@ namespace BarrageGrab
this.Close(); this.Close();
} }
} }
catch (Exception) {} catch (Exception) { }
}; };
socket.OnClose = () => socket.OnClose = () =>
@@ -445,7 +451,7 @@ namespace BarrageGrab
socket.Socket.Send(msg); socket.Socket.Send(msg);
} }
//删除掉线的套接字 //删除掉线的套接字
var offlines = socketList.Where(w=>!w.Value.Socket.IsAvailable).Select(s=>s.Key).ToList(); var offlines = socketList.Where(w => !w.Value.Socket.IsAvailable).Select(s => s.Key).ToList();
offlines.ForEach(key => socketList.Remove(key)); offlines.ForEach(key => socketList.Remove(key));
} }
+27 -23
View File
@@ -5,11 +5,11 @@ using System.IO.Compression;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using BarrageGrab.ProtoEntity;
using ProtoBuf; using ProtoBuf;
using ColorConsole; using ColorConsole;
using BarrageGrab.Proxy; using BarrageGrab.Proxy;
using BarrageGrab.Proxy.ProxyEventArgs; using BarrageGrab.Proxy.ProxyEventArgs;
using BarrageGrab.Modles.ProtoEntity;
namespace BarrageGrab namespace BarrageGrab
{ {
@@ -25,9 +25,6 @@ namespace BarrageGrab
//解包成功的域名缓存 //解包成功的域名缓存
List<string> succPackHostNames = new List<string>(); List<string> succPackHostNames = new List<string>();
//已知的弹幕域名服务器
string[] wsHostNames = Appsetting.Current.HostNameFilter;
/// <summary> /// <summary>
/// 进入直播间 /// 进入直播间
/// </summary> /// </summary>
@@ -71,7 +68,7 @@ namespace BarrageGrab
public WssBarrageGrab() public WssBarrageGrab()
{ {
proxy.OnWebSocketData += Proxy_OnWebSocketData; proxy.OnWebSocketData += Proxy_OnWebSocketData;
proxy.HostNameFilter = HostNameChecker; proxy.OnFetchResponse += Proxy_OnFetchResponse;
} }
public void Start() public void Start()
@@ -84,16 +81,6 @@ namespace BarrageGrab
proxy.Dispose(); proxy.Dispose();
} }
//域名过滤器
private bool HostNameChecker(string hostName)
{
if (!Appsetting.Current.FilterHostName) return true;
if (hostName.StartsWith("webcast")) return true;
if (wsHostNames.Any(a => a.ToLower() == hostName.ToLower())) return true;
return false;
}
//gzip解压缩 //gzip解压缩
private byte[] Decompress(byte[] zippedData) private byte[] Decompress(byte[] zippedData)
@@ -120,7 +107,8 @@ namespace BarrageGrab
if (!appsetting.ProcessFilter.Contains(e.ProcessName)) return; if (!appsetting.ProcessFilter.Contains(e.ProcessName)) return;
var buff = e.Payload; var buff = e.Payload;
if (buff.Length == 0) return; if (buff.Length == 0) return;
if (buff[0] != 0x08) return; //如果需要Gzip解压缩,但是开头字节不符合Gzip特征字节 则不处理
if (e.NeedDecompress && buff[0] != 0x08) return;
try try
{ {
@@ -130,11 +118,10 @@ namespace BarrageGrab
//检测包格式 //检测包格式
if (!enty.Headers.Any(a => a.Key == "compress_type" && a.Value == "gzip")) return; if (!enty.Headers.Any(a => a.Key == "compress_type" && a.Value == "gzip")) return;
byte[] allBuff;
//解压gzip //解压gzip
var odata = enty.Payload; allBuff = e.NeedDecompress ? Decompress(enty.Payload) : enty.Payload;
var decomp = Decompress(odata); var response = Serializer.Deserialize<Response>(new ReadOnlyMemory<byte>(allBuff));
var response = Serializer.Deserialize<Response>(new ReadOnlyMemory<byte>(decomp));
if (!succPackHostNames.Contains(e.HostName)) if (!succPackHostNames.Contains(e.HostName))
{ {
@@ -146,8 +133,25 @@ namespace BarrageGrab
catch (Exception) { } catch (Exception) { }
} }
//http 数据处理
private void Proxy_OnFetchResponse(object sender, HttpResponseEventArgs e)
{
var payload = e.HttpClient.Response.Body;
var response = Serializer.Deserialize<Response>(new ReadOnlyMemory<byte>(payload));
if (!succPackHostNames.Contains(e.HostName))
{
succPackHostNames.Add(e.HostName);
SaveHostNameCache();
}
response.Messages.ForEach(f =>
{
DoMessage(f);
});
}
//用于缓存接收过的消息ID,判断是否重复接收 //用于缓存接收过的消息ID,判断是否重复接收
Dictionary<string,List<long>> msgDic = new Dictionary<string,List<long>>(); Dictionary<string, List<long>> msgDic = new Dictionary<string, List<long>>();
//发送事件 //发送事件
private void DoMessage(Message msg) private void DoMessage(Message msg)
@@ -211,7 +215,7 @@ namespace BarrageGrab
{ {
if (arg.giftId == 685) if (arg.giftId == 685)
{ {
arg.Gift = new ProtoEntity.GiftStruct() arg.Gift = new GiftStruct()
{ {
Id = arg.giftId, Id = arg.giftId,
Name = "粉丝灯牌", Name = "粉丝灯牌",
@@ -292,7 +296,7 @@ namespace BarrageGrab
File.Create(fullPath); File.Create(fullPath);
} }
var text = File.ReadAllText(fullPath); var text = File.ReadAllText(fullPath);
var currentHosts = text.Split('\n').Where(w => !string.IsNullOrWhiteSpace(w)).Select(s=>s.Trim().Trim('\r')).ToList(); var currentHosts = text.Split('\n').Where(w => !string.IsNullOrWhiteSpace(w)).Select(s => s.Trim().Trim('\r')).ToList();
var newHosts = succPackHostNames.Except(currentHosts).ToList(); var newHosts = succPackHostNames.Except(currentHosts).ToList();
//保存 //保存
if (newHosts.Count > 0) if (newHosts.Count > 0)
+61 -11
View File
@@ -13,6 +13,21 @@
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion> <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic> <Deterministic>true</Deterministic>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
@@ -40,6 +55,7 @@
<PropertyGroup> <PropertyGroup>
<GenerateManifests>false</GenerateManifests> <GenerateManifests>false</GenerateManifests>
</PropertyGroup> </PropertyGroup>
<PropertyGroup />
<PropertyGroup> <PropertyGroup>
<ApplicationManifest>Properties\app.manifest</ApplicationManifest> <ApplicationManifest>Properties\app.manifest</ApplicationManifest>
</PropertyGroup> </PropertyGroup>
@@ -47,6 +63,9 @@
<Reference Include="BouncyCastle.Crypto, Version=1.8.8.0, Culture=neutral, PublicKeyToken=0e99375e54769942, processorArchitecture=MSIL"> <Reference Include="BouncyCastle.Crypto, Version=1.8.8.0, Culture=neutral, PublicKeyToken=0e99375e54769942, processorArchitecture=MSIL">
<HintPath>..\packages\Portable.BouncyCastle.1.8.8\lib\net40\BouncyCastle.Crypto.dll</HintPath> <HintPath>..\packages\Portable.BouncyCastle.1.8.8\lib\net40\BouncyCastle.Crypto.dll</HintPath>
</Reference> </Reference>
<Reference Include="BouncyCastle.Cryptography, Version=2.0.0.0, Culture=neutral, PublicKeyToken=072edcf4a5328938, processorArchitecture=MSIL">
<HintPath>..\packages\BouncyCastle.Cryptography.2.0.0\lib\net461\BouncyCastle.Cryptography.dll</HintPath>
</Reference>
<Reference Include="BrotliSharpLib, Version=0.3.2.0, Culture=neutral, PublicKeyToken=3f4e2a1cd615fcb7, processorArchitecture=MSIL"> <Reference Include="BrotliSharpLib, Version=0.3.2.0, Culture=neutral, PublicKeyToken=3f4e2a1cd615fcb7, processorArchitecture=MSIL">
<HintPath>..\packages\BrotliSharpLib.0.3.3\lib\net451\BrotliSharpLib.dll</HintPath> <HintPath>..\packages\BrotliSharpLib.0.3.3\lib\net451\BrotliSharpLib.dll</HintPath>
</Reference> </Reference>
@@ -56,12 +75,18 @@
<Reference Include="Fleck, Version=1.2.0.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Fleck, Version=1.2.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Fleck.1.2.0\lib\net45\Fleck.dll</HintPath> <HintPath>..\packages\Fleck.1.2.0\lib\net45\Fleck.dll</HintPath>
</Reference> </Reference>
<Reference Include="HtmlAgilityPack, Version=1.11.51.0, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a, processorArchitecture=MSIL">
<HintPath>..\packages\HtmlAgilityPack.1.11.51\lib\Net45\HtmlAgilityPack.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Win32.Registry, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <Reference Include="Microsoft.Win32.Registry, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Win32.Registry.5.0.0\lib\net461\Microsoft.Win32.Registry.dll</HintPath> <HintPath>..\packages\Microsoft.Win32.Registry.5.0.0\lib\net461\Microsoft.Win32.Registry.dll</HintPath>
</Reference> </Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath> <HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference> </Reference>
<Reference Include="NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.5.2.3\lib\net46\NLog.dll</HintPath>
</Reference>
<Reference Include="protobuf-net, Version=3.0.0.0, Culture=neutral, PublicKeyToken=257b51d87d2e4d67, processorArchitecture=MSIL"> <Reference Include="protobuf-net, Version=3.0.0.0, Culture=neutral, PublicKeyToken=257b51d87d2e4d67, processorArchitecture=MSIL">
<HintPath>..\packages\protobuf-net.3.1.22\lib\net462\protobuf-net.dll</HintPath> <HintPath>..\packages\protobuf-net.3.1.22\lib\net462\protobuf-net.dll</HintPath>
</Reference> </Reference>
@@ -77,8 +102,9 @@
</Reference> </Reference>
<Reference Include="System.Configuration" /> <Reference Include="System.Configuration" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> <Reference Include="System.IO.Compression" />
<HintPath>..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll</HintPath> <Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath>
</Reference> </Reference>
<Reference Include="System.Numerics" /> <Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
@@ -96,6 +122,7 @@
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> <Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath> <HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference> </Reference>
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
@@ -103,12 +130,20 @@
<Reference Include="System.Net.Http" /> <Reference Include="System.Net.Http" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="Titanium.Web.Proxy, Version=1.0.1.0, Culture=neutral, PublicKeyToken=8e41e1f1c790d7cf, processorArchitecture=MSIL"> <Reference Include="Titanium.Web.Proxy, Version=1.0.1.0, Culture=neutral, PublicKeyToken=8e41e1f1c790d7cf, processorArchitecture=MSIL">
<HintPath>..\packages\Titanium.Web.Proxy.3.2.0\lib\net461\Titanium.Web.Proxy.dll</HintPath> <HintPath>..\packages\Titanium.Web.Proxy.3.2.2-beta\lib\net461\Titanium.Web.Proxy.dll</HintPath>
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="AppRuntime.cs" />
<Compile Include="Appsetting.cs" /> <Compile Include="Appsetting.cs" />
<Compile Include="JsonEntity\Command.cs" /> <Compile Include="JsonEntity\Command.cs" />
<Compile Include="Logger.cs" />
<Compile Include="Modles\BusinessExecption.cs" />
<Compile Include="Modles\JsonEntity\BarrageMessages.cs" />
<Compile Include="Modles\JsonEntity\Command.cs" />
<Compile Include="Modles\ProtoEntity\Messages.cs" />
<Compile Include="Modles\ProtoEntity\Wss.cs" />
<Compile Include="ObjectExtension.cs" />
<Compile Include="Proxy\EventArgs\HttpResponseEventArgs.cs" /> <Compile Include="Proxy\EventArgs\HttpResponseEventArgs.cs" />
<Compile Include="Proxy\EventArgs\WsMessageEventArgs.cs" /> <Compile Include="Proxy\EventArgs\WsMessageEventArgs.cs" />
<Compile Include="Proxy\ISystemProxy.cs" /> <Compile Include="Proxy\ISystemProxy.cs" />
@@ -116,22 +151,37 @@
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Proxy\SystemProxy.cs" /> <Compile Include="Proxy\SystemProxy.cs" />
<Compile Include="Proxy\TitaniumProxy.cs" /> <Compile Include="Proxy\TitaniumProxy.cs" />
<Compile Include="WinApi.cs" />
<Compile Include="WssBarrageGrab.cs" /> <Compile Include="WssBarrageGrab.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ProtoEntity\Messages.cs" />
<Compile Include="ProtoEntity\Wss.cs" />
<Compile Include="WsBarrageService.cs" /> <Compile Include="WsBarrageService.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="App.config" /> <None Include="App.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="nlog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="packages.config" /> <None Include="packages.config" />
<None Include="Properties\app.manifest" /> <None Include="Properties\app.manifest" />
<None Include="proto\message.proto"> </ItemGroup>
<ItemGroup>
<Content Include="Scripts\inject\livePage.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None> </Content>
<None Include="proto\wss.proto"> </ItemGroup>
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <ItemGroup>
</None> <BootstrapperPackage Include=".NETFramework,Version=v4.8">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.8 %28x86 和 x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>
+5 -2
View File
@@ -1,20 +1,23 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="BouncyCastle.Cryptography" version="2.0.0" targetFramework="net48" />
<package id="BrotliSharpLib" version="0.3.3" targetFramework="net48" /> <package id="BrotliSharpLib" version="0.3.3" targetFramework="net48" />
<package id="ColorConsole" version="1.0.1" targetFramework="net48" /> <package id="ColorConsole" version="1.0.1" targetFramework="net48" />
<package id="Fleck" version="1.2.0" targetFramework="net48" /> <package id="Fleck" version="1.2.0" targetFramework="net48" />
<package id="HtmlAgilityPack" version="1.11.51" targetFramework="net48" />
<package id="Microsoft.Win32.Registry" version="5.0.0" targetFramework="net48" /> <package id="Microsoft.Win32.Registry" version="5.0.0" targetFramework="net48" />
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net48" /> <package id="Newtonsoft.Json" version="13.0.1" targetFramework="net48" />
<package id="NLog" version="5.2.3" targetFramework="net48" />
<package id="Portable.BouncyCastle" version="1.8.8" targetFramework="net48" /> <package id="Portable.BouncyCastle" version="1.8.8" targetFramework="net48" />
<package id="protobuf-net" version="3.1.22" targetFramework="net48" /> <package id="protobuf-net" version="3.1.22" targetFramework="net48" />
<package id="protobuf-net.Core" version="3.1.22" targetFramework="net48" /> <package id="protobuf-net.Core" version="3.1.22" targetFramework="net48" />
<package id="System.Buffers" version="4.5.1" targetFramework="net48" /> <package id="System.Buffers" version="4.5.1" targetFramework="net48" />
<package id="System.Collections.Immutable" version="1.7.1" targetFramework="net48" /> <package id="System.Collections.Immutable" version="1.7.1" targetFramework="net48" />
<package id="System.Memory" version="4.5.4" targetFramework="net48" /> <package id="System.Memory" version="4.5.5" targetFramework="net48" />
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net48" /> <package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net48" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.3" targetFramework="net48" /> <package id="System.Runtime.CompilerServices.Unsafe" version="4.5.3" targetFramework="net48" />
<package id="System.Security.AccessControl" version="5.0.0" targetFramework="net48" /> <package id="System.Security.AccessControl" version="5.0.0" targetFramework="net48" />
<package id="System.Security.Principal.Windows" version="5.0.0" targetFramework="net48" /> <package id="System.Security.Principal.Windows" version="5.0.0" targetFramework="net48" />
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net48" /> <package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net48" />
<package id="Titanium.Web.Proxy" version="3.2.0" targetFramework="net48" /> <package id="Titanium.Web.Proxy" version="3.2.2-beta" targetFramework="net48" />
</packages> </packages>