礼物数量不再连续推送,改为取每次增量,去除GroupCount改为GiftCount即同一组礼物下本次相较上次的礼物的增量
This commit is contained in:
@@ -177,17 +177,16 @@
|
||||
/// </summary>
|
||||
public string GiftName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 本次(增量)礼物数量
|
||||
/// </summary>
|
||||
public long GiftCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 礼物数量(连续的)
|
||||
/// </summary>
|
||||
public long RepeatCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 礼物数量(本次)
|
||||
/// </summary>
|
||||
public long GroupCount { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 抖币价格
|
||||
/// </summary>
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace BarrageGrab
|
||||
private void GiftCountTimer_Elapsed(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
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)
|
||||
@@ -89,7 +89,7 @@ namespace BarrageGrab
|
||||
Id = data.Id,
|
||||
Level = data.Level,
|
||||
Nickname = data.Nickname,
|
||||
HeadImgUrl = data.avatarThumb.urlLists.FirstOrDefault()??"",
|
||||
HeadImgUrl = data.avatarThumb.urlLists.FirstOrDefault() ?? "",
|
||||
SecUid = data.sec_uid
|
||||
};
|
||||
user.FansClub = new FansClubInfo()
|
||||
@@ -98,7 +98,7 @@ namespace BarrageGrab
|
||||
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.Level = data.fansClub.Data.Level;
|
||||
@@ -151,13 +151,13 @@ namespace BarrageGrab
|
||||
{
|
||||
if (!CheckRoomId(e.Common.roomId)) return;
|
||||
|
||||
var key = e.giftId+"-"+e.groupId.ToString();
|
||||
var key = e.giftId + "-" + e.groupId.ToString();
|
||||
|
||||
//判断礼物重复
|
||||
if (e.repeatEnd == 1)
|
||||
{
|
||||
//清除缓存中的key
|
||||
if (e.groupId>0&& giftCountCache.ContainsKey(key))
|
||||
if (e.groupId > 0 && giftCountCache.ContainsKey(key))
|
||||
{
|
||||
lock (giftCountCache)
|
||||
{
|
||||
@@ -169,11 +169,14 @@ namespace BarrageGrab
|
||||
|
||||
int lastCount = 0;
|
||||
int currCount = (int)e.repeatCount;
|
||||
var backward = currCount <= lastCount;
|
||||
if (currCount <= 0) currCount = 1;
|
||||
|
||||
if (giftCountCache.ContainsKey(key))
|
||||
{
|
||||
lastCount = giftCountCache[key].Item1;
|
||||
if (currCount > lastCount)
|
||||
backward = currCount <= lastCount;
|
||||
if (!backward)
|
||||
{
|
||||
lock (giftCountCache)
|
||||
{
|
||||
@@ -183,7 +186,7 @@ namespace BarrageGrab
|
||||
}
|
||||
else
|
||||
{
|
||||
if (e.groupId > 0)
|
||||
if (e.groupId > 0 && !backward)
|
||||
{
|
||||
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+repeat,
|
||||
RoomId = e.Common.roomId,
|
||||
Content = $"{e.User.Nickname} 送出 {e.Gift.Name} x {repeat} 个",
|
||||
DiamondCount = e.Gift.diamondCount,
|
||||
RepeatCount = repeat,
|
||||
GroupCount = e.groupCount,
|
||||
GiftId = e.giftId,
|
||||
GiftName = e.Gift.Name,
|
||||
User = GetUser(e.User)
|
||||
};
|
||||
MsgId = e.Common.msgId,
|
||||
RoomId = e.Common.roomId,
|
||||
Content = $"{e.User.Nickname} 送出 {e.Gift.Name} x {currCount} 个,增量{count}个",
|
||||
DiamondCount = e.Gift.diamondCount,
|
||||
RepeatCount = currCount,
|
||||
GiftCount = count,
|
||||
GiftId = e.giftId,
|
||||
GiftName = e.Gift.Name,
|
||||
User = GetUser(e.User)
|
||||
};
|
||||
|
||||
Print($"{enty.User.GenderToString()} {enty.Content}", ConsoleColor.Red, BarrageMsgType.礼物消息);
|
||||
var pack = new BarrageMsgPack(JsonConvert.SerializeObject(enty), BarrageMsgType.礼物消息);
|
||||
var json = JsonConvert.SerializeObject(pack);
|
||||
this.Broadcast(json);
|
||||
}
|
||||
Print($"{enty.User.GenderToString()} {enty.Content}", ConsoleColor.Red, BarrageMsgType.礼物消息);
|
||||
var pack = new BarrageMsgPack(JsonConvert.SerializeObject(enty), BarrageMsgType.礼物消息);
|
||||
var json = JsonConvert.SerializeObject(pack);
|
||||
this.Broadcast(json);
|
||||
}
|
||||
|
||||
//关注
|
||||
@@ -337,7 +340,7 @@ namespace BarrageGrab
|
||||
pack = new BarrageMsgPack(JsonConvert.SerializeObject(enty), BarrageMsgType.下播);
|
||||
}
|
||||
|
||||
if(pack!=null)
|
||||
if (pack != null)
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(pack);
|
||||
this.Broadcast(json);
|
||||
|
||||
Reference in New Issue
Block a user