v2.7.2 更新
This commit is contained in:
@@ -7,7 +7,6 @@ using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BarrageGrab.Modles;
|
||||
using ColorConsole;
|
||||
|
||||
namespace BarrageGrab
|
||||
{
|
||||
@@ -163,6 +162,17 @@ namespace BarrageGrab
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据webRoomid从缓存获取房间信息
|
||||
/// </summary>
|
||||
/// <param name="webrid"></param>
|
||||
/// <returns></returns>
|
||||
public RoomInfo GetByWebRoomid(string webrid)
|
||||
{
|
||||
var find = RoomInfoCache.FirstOrDefault(p => p.Value.WebRoomId == webrid);
|
||||
return find.Value;
|
||||
}
|
||||
|
||||
|
||||
public class RoomCacheEventArgs : EventArgs
|
||||
{
|
||||
|
||||
@@ -6,7 +6,6 @@ using System.Net.WebSockets;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
using ColorConsole;
|
||||
using Fleck;
|
||||
using Newtonsoft.Json;
|
||||
using BarrageGrab.Modles;
|
||||
@@ -17,6 +16,7 @@ using System.IO;
|
||||
using BarrageGrab.Modles.JsonEntity;
|
||||
using BarrageGrab.Modles.ProtoEntity;
|
||||
using System.Drawing;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace BarrageGrab
|
||||
{
|
||||
@@ -28,10 +28,9 @@ namespace BarrageGrab
|
||||
WebSocketServer socketServer;
|
||||
Dictionary<string, UserState> socketList = new Dictionary<string, UserState>();
|
||||
//礼物计数缓存
|
||||
Dictionary<string, Tuple<int, DateTime>> giftCountCache = new Dictionary<string, Tuple<int, DateTime>>();
|
||||
ConcurrentDictionary<string, Tuple<int, DateTime>> giftCountCache = new ConcurrentDictionary<string, Tuple<int, DateTime>>();
|
||||
Timer dieout = new Timer(10000);
|
||||
Timer giftCountTimer = new Timer(10000);
|
||||
ConsoleWriter console = new ConsoleWriter();
|
||||
WssBarrageGrab grab = new WssBarrageGrab();
|
||||
Appsetting Appsetting = Appsetting.Current;
|
||||
bool debug = false;
|
||||
@@ -92,7 +91,7 @@ namespace BarrageGrab
|
||||
{
|
||||
timeOutKeys.ForEach(key =>
|
||||
{
|
||||
giftCountCache.Remove(key);
|
||||
giftCountCache.TryRemove(key, out _);
|
||||
|
||||
});
|
||||
}
|
||||
@@ -100,8 +99,12 @@ namespace BarrageGrab
|
||||
|
||||
private bool CheckRoomId(long roomid)
|
||||
{
|
||||
if (Appsetting.RoomIds.Length == 0) return true;
|
||||
return Appsetting.RoomIds.Any(a => a == roomid);
|
||||
if (!Appsetting.Current.WebRoomIds.Any()) return true;
|
||||
|
||||
var webrid = AppRuntime.RoomCaches.GetCachedWebRoomid(roomid.ToString());
|
||||
if (webrid <= 0) return true;
|
||||
|
||||
return Appsetting.Current.WebRoomIds.Contains(webrid);
|
||||
}
|
||||
|
||||
//解析用户
|
||||
@@ -179,10 +182,10 @@ namespace BarrageGrab
|
||||
if (++count > 10000)
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine("控制台已清理");
|
||||
Logger.PrintColor("控制台已清理");
|
||||
count = 0;
|
||||
}
|
||||
console.WriteLine(text + "\n", color);
|
||||
Logger.PrintColor(text + "\n", color);
|
||||
}
|
||||
|
||||
//粉丝团
|
||||
@@ -238,50 +241,46 @@ namespace BarrageGrab
|
||||
|
||||
var key = msg.Common.roomId + "-" + msg.giftId + "-" + msg.groupId.ToString();
|
||||
|
||||
//判断礼物重复
|
||||
if (msg.repeatEnd == 1)
|
||||
{
|
||||
//清除缓存中的key
|
||||
if (msg.groupId > 0 && giftCountCache.ContainsKey(key))
|
||||
{
|
||||
lock (giftCountCache)
|
||||
{
|
||||
giftCountCache.Remove(key);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int lastCount = 0;
|
||||
int currCount = (int)msg.repeatCount;
|
||||
var backward = currCount <= lastCount;
|
||||
if (currCount <= 0) currCount = 1;
|
||||
|
||||
if (giftCountCache.ContainsKey(key))
|
||||
int lastCount = 0;
|
||||
//Combo 为1时,表示为可连击礼物
|
||||
if (msg.Gift.Combo)
|
||||
{
|
||||
lastCount = giftCountCache[key].Item1;
|
||||
backward = currCount <= lastCount;
|
||||
if (!backward)
|
||||
//判断礼物重复
|
||||
if (msg.repeatEnd == 1)
|
||||
{
|
||||
lock (giftCountCache)
|
||||
//清除缓存中的key
|
||||
if (msg.groupId > 0 && giftCountCache.ContainsKey(key))
|
||||
{
|
||||
giftCountCache[key] = Tuple.Create(currCount, DateTime.Now);
|
||||
giftCountCache.TryRemove(key, out _);
|
||||
}
|
||||
return;
|
||||
}
|
||||
var backward = currCount <= lastCount;
|
||||
if (currCount <= 0) currCount = 1;
|
||||
|
||||
if (giftCountCache.ContainsKey(key))
|
||||
{
|
||||
lastCount = giftCountCache[key].Item1;
|
||||
backward = currCount <= lastCount;
|
||||
if (!backward)
|
||||
{
|
||||
lock (giftCountCache)
|
||||
{
|
||||
giftCountCache[key] = Tuple.Create(currCount, DateTime.Now);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (msg.groupId > 0 && !backward)
|
||||
else
|
||||
{
|
||||
lock (giftCountCache)
|
||||
if (msg.groupId > 0 && !backward)
|
||||
{
|
||||
giftCountCache.Add(key, Tuple.Create(currCount, DateTime.Now));
|
||||
giftCountCache.TryAdd(key, Tuple.Create(currCount, DateTime.Now));
|
||||
}
|
||||
}
|
||||
//比上次小,则说明先后顺序出了问题,直接丢掉,应为比它大的消息已经处理过了
|
||||
if (backward) return;
|
||||
}
|
||||
//比上次小,则说明先后顺序出了问题,直接丢掉,应为比它大的消息已经处理过了
|
||||
if (backward) return;
|
||||
|
||||
|
||||
var count = currCount - lastCount;
|
||||
|
||||
@@ -290,13 +289,15 @@ namespace BarrageGrab
|
||||
MsgId = msg.Common.msgId,
|
||||
RoomId = msg.Common.roomId,
|
||||
WebRoomId = AppRuntime.RoomCaches.GetCachedWebRoomid(msg.Common.roomId.ToString()),
|
||||
Content = $"{msg.User.Nickname} 送出 {msg.Gift.Name} x {currCount} 个,增量{count}个",
|
||||
Content = $"{msg.User.Nickname} 送出 {msg.Gift.Name}{(msg.Gift.Combo ? "(可连击)" : "")} x {msg.repeatCount}个,增量{count}个",
|
||||
DiamondCount = msg.Gift.diamondCount,
|
||||
RepeatCount = currCount,
|
||||
RepeatCount = msg.repeatCount,
|
||||
GiftCount = count,
|
||||
GroupId = msg.groupId,
|
||||
GiftId = msg.giftId,
|
||||
GiftName = msg.Gift.Name,
|
||||
Combo = msg.Gift.Combo,
|
||||
ImgUrl = msg.Gift.Image?.urlLists?.FirstOrDefault()??"",
|
||||
User = GetUser(msg.User),
|
||||
ToUser = GetUser(msg.toUser)
|
||||
};
|
||||
@@ -471,9 +472,9 @@ namespace BarrageGrab
|
||||
// if (++count > 1000)
|
||||
// {
|
||||
// Console.Clear();
|
||||
// Console.WriteLine("控制台已清理");
|
||||
// Logger.PrintColor("控制台已清理");
|
||||
// }
|
||||
// console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss")} [{bartype.ToString()}] " + msg + "\n", color);
|
||||
// Logger.PrintColor($"{DateTime.Now.ToString("HH:mm:ss")} [{bartype.ToString()}] " + msg + "\n", color);
|
||||
// count = 0;
|
||||
// }
|
||||
//}
|
||||
@@ -492,7 +493,7 @@ namespace BarrageGrab
|
||||
if (!socketList.ContainsKey(clientUrl))
|
||||
{
|
||||
socketList.Add(clientUrl, new UserState(socket));
|
||||
console.WriteLine($"{DateTime.Now.ToLongTimeString()} 已经建立与[{clientUrl}]的连接", ConsoleColor.Green);
|
||||
Logger.PrintColor($"{DateTime.Now.ToLongTimeString()} 已经建立与[{clientUrl}]的连接", ConsoleColor.Green);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -535,7 +536,7 @@ namespace BarrageGrab
|
||||
socket.OnClose = () =>
|
||||
{
|
||||
socketList.Remove(clientUrl);
|
||||
console.WriteLine($"{DateTime.Now.ToLongTimeString()} 已经关闭与[{clientUrl}]的连接", ConsoleColor.Red);
|
||||
Logger.PrintColor($"{DateTime.Now.ToLongTimeString()} 已经关闭与[{clientUrl}]的连接", ConsoleColor.Red);
|
||||
};
|
||||
|
||||
socket.OnPing = (data) =>
|
||||
|
||||
@@ -6,7 +6,6 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProtoBuf;
|
||||
using ColorConsole;
|
||||
using BarrageGrab.Proxy;
|
||||
using BarrageGrab.Proxy.ProxyEventArgs;
|
||||
using BarrageGrab.Modles.ProtoEntity;
|
||||
@@ -21,7 +20,6 @@ namespace BarrageGrab
|
||||
//ISystemProxy proxy = new FiddlerProxy();
|
||||
ISystemProxy proxy = new TitaniumProxy();
|
||||
Appsetting appsetting = Appsetting.Current;
|
||||
ConsoleWriter console = new ConsoleWriter();
|
||||
//解包成功的域名缓存
|
||||
List<string> succPackHostNames = new List<string>();
|
||||
|
||||
@@ -248,7 +246,7 @@ namespace BarrageGrab
|
||||
}
|
||||
else
|
||||
{
|
||||
console.WriteLine("未能识别的礼物ID:" + arg.giftId, ConsoleColor.Red);
|
||||
Logger.PrintColor("未能识别的礼物ID:" + arg.giftId, ConsoleColor.Red);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -312,7 +310,7 @@ namespace BarrageGrab
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("写入成功解包域名缓存失败:" + ex.Message, ConsoleColor.Red);
|
||||
Logger.PrintColor("写入成功解包域名缓存失败:" + ex.Message, ConsoleColor.Red);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -70,9 +70,6 @@
|
||||
<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>
|
||||
</Reference>
|
||||
<Reference Include="ColorConsole, Version=1.0.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\ColorConsole.1.0.1\lib\net40\ColorConsole.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Fleck, Version=1.2.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Fleck.1.2.0\lib\net45\Fleck.dll</HintPath>
|
||||
</Reference>
|
||||
@@ -139,15 +136,6 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="AppRuntime.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">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
@@ -207,12 +195,6 @@
|
||||
</BootstrapperPackage>
|
||||
</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">
|
||||
<DependentUpon>FormView.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
|
||||
Reference in New Issue
Block a user