From c3b5ab4ab2aea24a3f9d2869586fbc1fefacefd8 Mon Sep 17 00:00:00 2001 From: genteure Date: Sat, 21 May 2022 22:01:33 +0800 Subject: [PATCH] Core: Fix danmaku user id greater than int32.max causing overflow --- BililiveRecorder.Core/Api/Danmaku/DanmakuModel.cs | 10 +++++----- BililiveRecorder.Core/Danmaku/BasicDanmakuWriter.cs | 3 +++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/BililiveRecorder.Core/Api/Danmaku/DanmakuModel.cs b/BililiveRecorder.Core/Api/Danmaku/DanmakuModel.cs index ca36c89..567eb07 100644 --- a/BililiveRecorder.Core/Api/Danmaku/DanmakuModel.cs +++ b/BililiveRecorder.Core/Api/Danmaku/DanmakuModel.cs @@ -101,7 +101,7 @@ namespace BililiveRecorder.Core.Api.Danmaku /// /// /// - public int UserID { get; set; } + public long UserID { get; set; } /// /// 用户舰队等级 @@ -192,7 +192,7 @@ namespace BililiveRecorder.Core.Api.Danmaku case "DANMU_MSG": this.MsgType = DanmakuMsgType.Comment; this.CommentText = obj["info"]?[1]?.ToObject(); - this.UserID = obj["info"]?[2]?[0]?.ToObject() ?? 0; + this.UserID = obj["info"]?[2]?[0]?.ToObject() ?? 0; this.UserName = obj["info"]?[2]?[1]?.ToObject(); this.IsAdmin = obj["info"]?[2]?[2]?.ToObject() == "1"; this.IsVIP = obj["info"]?[2]?[3]?.ToObject() == "1"; @@ -202,13 +202,13 @@ namespace BililiveRecorder.Core.Api.Danmaku this.MsgType = DanmakuMsgType.GiftSend; this.GiftName = obj["data"]?["giftName"]?.ToObject(); this.UserName = obj["data"]?["uname"]?.ToObject(); - this.UserID = obj["data"]?["uid"]?.ToObject() ?? 0; + this.UserID = obj["data"]?["uid"]?.ToObject() ?? 0; this.GiftCount = obj["data"]?["num"]?.ToObject() ?? 0; break; case "GUARD_BUY": { this.MsgType = DanmakuMsgType.GuardBuy; - this.UserID = obj["data"]?["uid"]?.ToObject() ?? 0; + this.UserID = obj["data"]?["uid"]?.ToObject() ?? 0; this.UserName = obj["data"]?["username"]?.ToObject(); this.UserGuardLevel = obj["data"]?["guard_level"]?.ToObject() ?? 0; this.GiftName = this.UserGuardLevel == 3 ? "舰长" : this.UserGuardLevel == 2 ? "提督" : this.UserGuardLevel == 1 ? "总督" : ""; @@ -219,7 +219,7 @@ namespace BililiveRecorder.Core.Api.Danmaku { this.MsgType = DanmakuMsgType.SuperChat; this.CommentText = obj["data"]?["message"]?.ToString(); - this.UserID = obj["data"]?["uid"]?.ToObject() ?? 0; + this.UserID = obj["data"]?["uid"]?.ToObject() ?? 0; this.UserName = obj["data"]?["user_info"]?["uname"]?.ToString(); this.Price = obj["data"]?["price"]?.ToObject() ?? 0; this.SCKeepTime = obj["data"]?["time"]?.ToObject() ?? 0; diff --git a/BililiveRecorder.Core/Danmaku/BasicDanmakuWriter.cs b/BililiveRecorder.Core/Danmaku/BasicDanmakuWriter.cs index c28a006..9e093ed 100644 --- a/BililiveRecorder.Core/Danmaku/BasicDanmakuWriter.cs +++ b/BililiveRecorder.Core/Danmaku/BasicDanmakuWriter.cs @@ -155,6 +155,7 @@ namespace BililiveRecorder.Core.Danmaku var ts = Math.Max((DateTimeOffset.UtcNow - this.offset).TotalSeconds, 0d); await this.xmlWriter.WriteAttributeStringAsync(null, "ts", null, ts.ToString("F3")).ConfigureAwait(false); await this.xmlWriter.WriteAttributeStringAsync(null, "user", null, RemoveInvalidXMLChars(danmakuModel.UserName)).ConfigureAwait(false); + await this.xmlWriter.WriteAttributeStringAsync(null, "uid", null, danmakuModel.UserID.ToString()).ConfigureAwait(false); await this.xmlWriter.WriteAttributeStringAsync(null, "price", null, danmakuModel.Price.ToString()).ConfigureAwait(false); await this.xmlWriter.WriteAttributeStringAsync(null, "time", null, danmakuModel.SCKeepTime.ToString()).ConfigureAwait(false); if (recordDanmakuRaw) @@ -170,6 +171,7 @@ namespace BililiveRecorder.Core.Danmaku var ts = Math.Max((DateTimeOffset.UtcNow - this.offset).TotalSeconds, 0d); await this.xmlWriter.WriteAttributeStringAsync(null, "ts", null, ts.ToString("F3")).ConfigureAwait(false); await this.xmlWriter.WriteAttributeStringAsync(null, "user", null, RemoveInvalidXMLChars(danmakuModel.UserName)).ConfigureAwait(false); + await this.xmlWriter.WriteAttributeStringAsync(null, "uid", null, danmakuModel.UserID.ToString()).ConfigureAwait(false); await this.xmlWriter.WriteAttributeStringAsync(null, "giftname", null, RemoveInvalidXMLChars(danmakuModel.GiftName)).ConfigureAwait(false); await this.xmlWriter.WriteAttributeStringAsync(null, "giftcount", null, danmakuModel.GiftCount.ToString()).ConfigureAwait(false); if (recordDanmakuRaw) @@ -184,6 +186,7 @@ namespace BililiveRecorder.Core.Danmaku var ts = Math.Max((DateTimeOffset.UtcNow - this.offset).TotalSeconds, 0d); await this.xmlWriter.WriteAttributeStringAsync(null, "ts", null, ts.ToString("F3")).ConfigureAwait(false); await this.xmlWriter.WriteAttributeStringAsync(null, "user", null, RemoveInvalidXMLChars(danmakuModel.UserName)).ConfigureAwait(false); + await this.xmlWriter.WriteAttributeStringAsync(null, "uid", null, danmakuModel.UserID.ToString()).ConfigureAwait(false); await this.xmlWriter.WriteAttributeStringAsync(null, "level", null, danmakuModel.UserGuardLevel.ToString()).ConfigureAwait(false); ; await this.xmlWriter.WriteAttributeStringAsync(null, "count", null, danmakuModel.GiftCount.ToString()).ConfigureAwait(false); if (recordDanmakuRaw)