礼物数量不再连续推送,改为取每次增量,去除GroupCount改为GiftCount即同一组礼物下本次相较上次的礼物的增量

This commit is contained in:
小白猿
2023-04-10 20:39:49 +08:00
parent 2afca26477
commit f5c1241860
2 changed files with 53 additions and 51 deletions
+5 -6
View File
@@ -177,17 +177,16 @@
/// </summary> /// </summary>
public string GiftName { get; set; } public string GiftName { get; set; }
/// <summary>
/// 本次(增量)礼物数量
/// </summary>
public long GiftCount { get; set; }
/// <summary> /// <summary>
/// 礼物数量(连续的) /// 礼物数量(连续的)
/// </summary> /// </summary>
public long RepeatCount { get; set; } public long RepeatCount { get; set; }
/// <summary>
/// 礼物数量(本次)
/// </summary>
public long GroupCount { get; set; }
/// <summary> /// <summary>
/// 抖币价格 /// 抖币价格
/// </summary> /// </summary>
+31 -28
View File
@@ -61,7 +61,7 @@ namespace BarrageGrab
private void GiftCountTimer_Elapsed(object sender, ElapsedEventArgs e) private void GiftCountTimer_Elapsed(object sender, ElapsedEventArgs e)
{ {
var now = DateTime.Now; var now = DateTime.Now;
var timeOutKeys = giftCountCache.Where(w => w.Value.Item2 < now.AddSeconds(-10)||w.Value==null).Select(s => s.Key).ToList(); var timeOutKeys = giftCountCache.Where(w => w.Value.Item2 < now.AddSeconds(-10) || w.Value == null).Select(s => s.Key).ToList();
//淘汰过期的礼物计数缓存 //淘汰过期的礼物计数缓存
lock (giftCountCache) lock (giftCountCache)
@@ -89,7 +89,7 @@ namespace BarrageGrab
Id = data.Id, Id = data.Id,
Level = data.Level, Level = data.Level,
Nickname = data.Nickname, Nickname = data.Nickname,
HeadImgUrl = data.avatarThumb.urlLists.FirstOrDefault()??"", HeadImgUrl = data.avatarThumb.urlLists.FirstOrDefault() ?? "",
SecUid = data.sec_uid SecUid = data.sec_uid
}; };
user.FansClub = new FansClubInfo() user.FansClub = new FansClubInfo()
@@ -98,7 +98,7 @@ namespace BarrageGrab
Level = 0 Level = 0
}; };
if (data.fansClub!= null && data.fansClub.Data != null) if (data.fansClub != null && data.fansClub.Data != null)
{ {
user.FansClub.ClubName = data.fansClub.Data.clubName; user.FansClub.ClubName = data.fansClub.Data.clubName;
user.Level = data.fansClub.Data.Level; user.Level = data.fansClub.Data.Level;
@@ -151,13 +151,13 @@ namespace BarrageGrab
{ {
if (!CheckRoomId(e.Common.roomId)) return; if (!CheckRoomId(e.Common.roomId)) return;
var key = e.giftId+"-"+e.groupId.ToString(); var key = e.giftId + "-" + e.groupId.ToString();
//判断礼物重复 //判断礼物重复
if (e.repeatEnd == 1) if (e.repeatEnd == 1)
{ {
//清除缓存中的key //清除缓存中的key
if (e.groupId>0&& giftCountCache.ContainsKey(key)) if (e.groupId > 0 && giftCountCache.ContainsKey(key))
{ {
lock (giftCountCache) lock (giftCountCache)
{ {
@@ -169,11 +169,14 @@ namespace BarrageGrab
int lastCount = 0; int lastCount = 0;
int currCount = (int)e.repeatCount; int currCount = (int)e.repeatCount;
var backward = currCount <= lastCount;
if (currCount <= 0) currCount = 1;
if (giftCountCache.ContainsKey(key)) if (giftCountCache.ContainsKey(key))
{ {
lastCount = giftCountCache[key].Item1; lastCount = giftCountCache[key].Item1;
if (currCount > lastCount) backward = currCount <= lastCount;
if (!backward)
{ {
lock (giftCountCache) lock (giftCountCache)
{ {
@@ -183,7 +186,7 @@ namespace BarrageGrab
} }
else else
{ {
if (e.groupId > 0) if (e.groupId > 0 && !backward)
{ {
lock (giftCountCache) lock (giftCountCache)
{ {
@@ -191,29 +194,29 @@ namespace BarrageGrab
} }
} }
} }
//比上次小,则说明先后顺序出了问题,直接丢掉,因为上次已经填充发送过了 //比上次小,则说明先后顺序出了问题,直接丢掉,应为比它大的消息已经处理过了
if (currCount < lastCount) return; if (backward) return;
for (int repeat = lastCount+1; repeat <= currCount; repeat++)
var count = currCount - lastCount;
var enty = new GiftMsg()
{ {
var enty = new GiftMsg() MsgId = e.Common.msgId,
{ RoomId = e.Common.roomId,
MsgId = e.Common.msgId+repeat, Content = $"{e.User.Nickname} 送出 {e.Gift.Name} x {currCount} 个,增量{count}个",
RoomId = e.Common.roomId, DiamondCount = e.Gift.diamondCount,
Content = $"{e.User.Nickname} 送出 {e.Gift.Name} x {repeat} 个", RepeatCount = currCount,
DiamondCount = e.Gift.diamondCount, GiftCount = count,
RepeatCount = repeat, GiftId = e.giftId,
GroupCount = e.groupCount, GiftName = e.Gift.Name,
GiftId = e.giftId, User = GetUser(e.User)
GiftName = e.Gift.Name, };
User = GetUser(e.User)
};
Print($"{enty.User.GenderToString()} {enty.Content}", ConsoleColor.Red, BarrageMsgType.礼物消息); Print($"{enty.User.GenderToString()} {enty.Content}", ConsoleColor.Red, BarrageMsgType.礼物消息);
var pack = new BarrageMsgPack(JsonConvert.SerializeObject(enty), BarrageMsgType.礼物消息); var pack = new BarrageMsgPack(JsonConvert.SerializeObject(enty), BarrageMsgType.礼物消息);
var json = JsonConvert.SerializeObject(pack); var json = JsonConvert.SerializeObject(pack);
this.Broadcast(json); this.Broadcast(json);
}
} }
//关注 //关注
@@ -337,7 +340,7 @@ namespace BarrageGrab
pack = new BarrageMsgPack(JsonConvert.SerializeObject(enty), BarrageMsgType.下播); pack = new BarrageMsgPack(JsonConvert.SerializeObject(enty), BarrageMsgType.下播);
} }
if(pack!=null) if (pack != null)
{ {
var json = JsonConvert.SerializeObject(pack); var json = JsonConvert.SerializeObject(pack);
this.Broadcast(json); this.Broadcast(json);