diff --git a/Auxiliary/DDcenter/DdcClient.cs b/Auxiliary/DDcenter/DdcClient.cs index c1cd29eb3..62d8f0ec8 100644 --- a/Auxiliary/DDcenter/DdcClient.cs +++ b/Auxiliary/DDcenter/DdcClient.cs @@ -19,7 +19,7 @@ public static void Connect() { try { - MMPU.DDC采集间隔 = int.Parse(MMPU.TcpSend(30001, "{}", true)); + MMPU.DDC采集间隔 = int.Parse(MMPU.TcpSend(30001, "{}", true,50)); } catch (Exception) { diff --git a/Auxiliary/MMPU.cs b/Auxiliary/MMPU.cs index 00cbfc4bc..cc2fc062b 100644 --- a/Auxiliary/MMPU.cs +++ b/Auxiliary/MMPU.cs @@ -31,7 +31,7 @@ public class MMPU public static int 直播更新时间 = 60; public static string 下载储存目录 = ""; public static string 版本号 = "2.0.4.5b"; - public static string[] 不检测的版本号 = {}; + public static string[] 不检测的版本号 = {"2.0.4.3b"}; public static bool 第一次打开播放窗口 = true; public static int 默认音量 = 0; public static int 缩小功能 = 1; @@ -97,7 +97,7 @@ public static bool 配置文件初始化(int 模式) { InfoLog.InfoInit("./DDTVLiveRecLog.out", new InfoLog.InfoClasslBool() { - Debug = false, + Debug = true, 下载必要提示 = true, 杂项提示 = false, 系统错误信息 = true, @@ -189,7 +189,7 @@ public static void DokiDoki(int 模式) { try { - MMPU.TcpSend(模式 == 0 ? Server.RequestCode.SET_DokiDoki_DDTV : Server.RequestCode.SET_DokiDoki_DDTVLiveRec, "{}", true); + MMPU.TcpSend(模式 == 0 ? Server.RequestCode.SET_DokiDoki_DDTV : Server.RequestCode.SET_DokiDoki_DDTVLiveRec, "{}", true,50); } catch (Exception) { } Thread.Sleep(3600 * 1000); @@ -1010,19 +1010,21 @@ public static bool setFiles(string key, string value) /// 消息内容 /// /// - public static string TcpSend(int code, string msg, bool 是否需要回复) + public static string TcpSend(int code, string msg, bool 是否需要回复,int 等待时间) { try { string 回复内容 = ""; Socket tcpClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + tcpClient.ReceiveBufferSize = 1024 * 1024 * 8; IPAddress ipaddress = Server.IP_ADDRESS; EndPoint point = new IPEndPoint(ipaddress, Server.PORT); tcpClient.Connect(point);//通过IP和端口号来定位一个所要连接的服务器端 tcpClient.Send(Encoding.UTF8.GetBytes(JSON发送拼接(code, msg))); if (是否需要回复) { - byte[] buffer = new byte[1024 * 1024]; + byte[] buffer = new byte[1024 * 1024 * 8]; + Thread.Sleep(等待时间); tcpClient.Receive(buffer); string 收到的数据 = Encoding.UTF8.GetString(buffer).Trim('\0'); 回复内容 = 收到的数据; @@ -1032,6 +1034,13 @@ public static string TcpSend(int code, string msg, bool 是否需要回复) 回复内容 = null; } tcpClient.Close(); + try + { + tcpClient.Dispose(); + } + catch (Exception) + { + } return 回复内容; } catch (Exception) diff --git a/Auxiliary/Server.cs b/Auxiliary/Server.cs index 05d225674..b83fbeed9 100644 --- a/Auxiliary/Server.cs +++ b/Auxiliary/Server.cs @@ -15,6 +15,8 @@ public static class Server public static readonly IPAddress IP_ADDRESS = MMPU.根据URL获取IP地址("api.ddtv.pro"); #elif false public static readonly IPAddress IP_ADDRESS = MMPU.根据URL获取IP地址("192.168.199.100"); +#elif false + public static readonly IPAddress IP_ADDRESS = MMPU.根据URL获取IP地址("127.0.0.1"); #endif public static readonly int PORT = 11433; public static readonly string PROJECT_ADDRESS = "https://github.com/CHKZL/DDTV2/releases/latest"; diff --git a/Auxiliary/bilibili.cs b/Auxiliary/bilibili.cs index 65a8a2e70..2ef5cc8ec 100644 --- a/Auxiliary/bilibili.cs +++ b/Auxiliary/bilibili.cs @@ -88,9 +88,15 @@ public static void 更新VTBS房间数据() { while (true) { + int 完整错误次数 = 0; try { - + if(完整错误次数>=5) + { + InfoLog.InfoPrintf($"----------【重要】----------\r\n多次尝试获取服务器RoomList缓存失败,切换为纯WSS连接模式,该模式下初始化连接速度较慢,大约20连接一个房间\r\n----------【重要】----------", InfoLog.InfoClass.下载必要提示); + wss连接初始化准备已完成 = true; + return; + } string vtbs房间数据 = string.Empty; try { @@ -98,10 +104,12 @@ public static void 更新VTBS房间数据() } catch (Exception) { - vtbs房间数据 = MMPU.TcpSend(Server.RequestCode.GET_VTBSROOMLIST, "{}", true); + InfoLog.InfoPrintf($"通过原始数据源更新VTBS房间数据失败,切换到备用DDTV服务器获取", InfoLog.InfoClass.Debug); + vtbs房间数据 = MMPU.TcpSend(Server.RequestCode.GET_VTBSROOMLIST, "{}", true, 1500); } JArray JO = (JArray)JsonConvert.DeserializeObject(vtbs房间数据); + InfoLog.InfoPrintf($"获取VTBS房间数据完成:{JO}", InfoLog.InfoClass.Debug); foreach (var item in JO) { if (int.Parse(item["roomid"].ToString()) != 0) @@ -109,11 +117,14 @@ public static void 更新VTBS房间数据() VtbsRoomList.Add(new VtbsRoom() { mid = int.Parse(item["mid"].ToString()), room = int.Parse(item["roomid"].ToString()), name = item["uname"].ToString() }); } } + InfoLog.InfoPrintf($"VTBS数据数据准备完成", InfoLog.InfoClass.Debug); wss连接初始化准备已完成 = true; break; } - catch (Exception) + catch (Exception ) { + 完整错误次数++; + InfoLog.InfoPrintf($"VTBS获取RoomList失败,再次重试,已重试次数{完整错误次数}/5", InfoLog.InfoClass.Debug); } Thread.Sleep(5000); @@ -215,7 +226,7 @@ public static void 使用vtbsAPI更新房间状态() InfoLog.InfoPrintf("Vtbs数据加载失败,使用备用数据源开始获取", InfoLog.InfoClass.Debug); try { - JArray JO = (JArray)JsonConvert.DeserializeObject(MMPU.TcpSend(Server.RequestCode.GET_LIVELSIT, "{}", true)); + JArray JO = (JArray)JsonConvert.DeserializeObject(MMPU.TcpSend(Server.RequestCode.GET_LIVELSIT, "{}", true,200)); foreach (var roomtask in RoomList) { if (!roomtask.名称.Contains("-NV")) @@ -354,15 +365,19 @@ public static void 初始化所有房间连接() }).Start(); while (!wss连接初始化准备已完成) { - Thread.Sleep(1000); + InfoLog.InfoPrintf("连接初始化准备未完成3秒后重试", InfoLog.InfoClass.Debug); + Thread.Sleep(3000); } + InfoLog.InfoPrintf("wss连接初始化准备已完成", InfoLog.InfoClass.Debug); List MTPlist = new List(); + InfoLog.InfoPrintf($"wss连接初始化准备已完成,列表长度:{VtbsRoomList.Count}", InfoLog.InfoClass.Debug); foreach (var item in VtbsRoomList) { MTPlist.Add(item.room); } List Vtbs存在的直播间 = new List(); List Vtbs不存在的直播间 = new List(); + InfoLog.InfoPrintf($"生成双边队列临时API房间列表数:{Vtbs存在的直播间.Count},优先连接组数:{Vtbs不存在的直播间.Count}", InfoLog.InfoClass.Debug); foreach (var item in RoomList) { if(MTPlist.Contains(int.Parse(item.房间号))) @@ -381,7 +396,7 @@ public static void 初始化所有房间连接() InfoLog.InfoPrintf("LiveChatListener开始连接非VTBS监控范围内房间:" + item.房间号, InfoLog.InfoClass.Debug); if (item.平台 == "bilibili") { - item.liveChatListener = new LiveChatListener(); + item.liveChatListener = new LiveChatListener(); item.liveChatListener.Connect(int.Parse(item.房间号)); item.liveChatListener.MessageReceived += 直播间状态WS变化事件; 已连接的直播间状态.Add(new 直播间状态() { 房间号 = int.Parse(item.房间号) }); @@ -834,11 +849,11 @@ public static string 获取真实房间号(string roomID) try { JObject result = JObject.Parse(roomHtml); - string live_status = result["data"]["live_status"].ToString(); - if (live_status != "1") - { - return "-1"; - } + //string live_status = result["data"]["live_status"].ToString(); + //if (live_status != "1") + //{ + // return "-1"; + //} string roomid = result["data"]["room_id"].ToString(); DataCache.写缓存(CacheStr + roomID, roomid); return roomid; diff --git "a/Auxiliary/\345\244\226\351\203\250API.cs" "b/Auxiliary/\345\244\226\351\203\250API.cs" index e13b5f1cc..d19acefad 100644 --- "a/Auxiliary/\345\244\226\351\203\250API.cs" +++ "b/Auxiliary/\345\244\226\351\203\250API.cs" @@ -35,7 +35,7 @@ public class 直播信息 public List<直播信息> 直播数据 = new List<直播信息>(); public void 更新正在直播数据() { - string UURL = MMPU.TcpSend(30002, "{}", true); + string UURL = MMPU.TcpSend(30002, "{}", true,50); string URL = string.IsNullOrEmpty(UURL)?"https://hiyoko.sonoj.net/dy-st/30s/6c6cb639-1d2f-4151-81c7-fd877700cf98.json": UURL; JArray jo = (JArray)JsonConvert.DeserializeObject(MMPU.返回网页内容(URL)); for(int i =0;i< jo.Count;i++) diff --git a/DDTVLiveRec/App.config b/DDTVLiveRec/App.config index cb2015ebc..e992731c4 100644 --- a/DDTVLiveRec/App.config +++ b/DDTVLiveRec/App.config @@ -1,6 +1,7 @@  + @@ -29,6 +30,8 @@ + + diff --git a/DDTVLiveRec/DDTV.ico b/DDTVLiveRec/DDTV.ico new file mode 100644 index 000000000..75f97efe9 Binary files /dev/null and b/DDTVLiveRec/DDTV.ico differ diff --git a/DDTVLiveRec/DDTVLiveRec.csproj b/DDTVLiveRec/DDTVLiveRec.csproj index d912e7e34..f6dab02b1 100644 --- a/DDTVLiveRec/DDTVLiveRec.csproj +++ b/DDTVLiveRec/DDTVLiveRec.csproj @@ -3,6 +3,7 @@ Exe net5.0 + DDTV.ico diff --git a/DDTVLiveRec/Program.cs b/DDTVLiveRec/Program.cs index 2be2cb15e..7024a9fa0 100644 --- a/DDTVLiveRec/Program.cs +++ b/DDTVLiveRec/Program.cs @@ -1,4 +1,6 @@ using Auxiliary; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using System; using System.Drawing; using System.IO; @@ -15,19 +17,19 @@ static void Main(string[] args) 下载("14275133"); #else - Auxiliary.VTBS.API.VTBS服务器CDN.根据CDN更新VTBS_Url(); + Auxiliary.VTBS.API.VTBS服务器CDN.根据CDN更新VTBS_Url(); MMPU.配置文件初始化(1); new Task(() => { DDTVLiveRecWebServer.Program.Main(new string[] { }); }).Start(); - - + + #endif - new Task(() => + new Task(() => { try { - string 服务器版本号 = MMPU.TcpSend(20013, "{}", true); + string 服务器版本号 = MMPU.TcpSend(20013, "{}", true,50); if (!string.IsNullOrEmpty(服务器版本号)) { bool 检测状态 = true; @@ -41,7 +43,7 @@ static void Main(string[] args) if (MMPU.版本号 != 服务器版本号 && 检测状态) { MMPU.是否有新版本 = true; - InfoLog.InfoPrintf("检测到版本更新,更新公告:\n" + MMPU.TcpSend(20014, "{}", true) + "\n\n", InfoLog.InfoClass.下载必要提示); + InfoLog.InfoPrintf("检测到版本更新,更新公告:\n" + MMPU.TcpSend(20014, "{}", true,100) + "\n\n", InfoLog.InfoClass.下载必要提示); //Console.ReadKey(); } } diff --git a/DDTV_New/AddMonitoringList.xaml.cs b/DDTV_New/AddMonitoringList.xaml.cs index ea56d8f7c..2584a8136 100644 --- a/DDTV_New/AddMonitoringList.xaml.cs +++ b/DDTV_New/AddMonitoringList.xaml.cs @@ -142,7 +142,7 @@ private void BT1_Click(object sender, RoutedEventArgs e) NewThreadTask.Run(() => { MMPU.TcpSend(Server.RequestCode.GET_NEW_MEMBER_LIST_CONTENT, - JsonConvert.SerializeObject(NEWV), true); + JsonConvert.SerializeObject(NEWV), true,50); }); RoomBox rlc = JsonConvert.DeserializeObject(ReadConfigFile(RoomConfigFile)); @@ -183,7 +183,7 @@ private void BT1_Click(object sender, RoutedEventArgs e) NewThreadTask.Run(() => { MMPU.TcpSend(Server.RequestCode.GET_NEW_MEMBER_LIST_CONTENT, - JsonConvert.SerializeObject(NEWV), true); + JsonConvert.SerializeObject(NEWV), true,50); }); RoomBox rlc = JsonConvert.DeserializeObject(ReadConfigFile(RoomConfigFile)); diff --git a/DDTV_New/App.config b/DDTV_New/App.config index 7a6c63fba..8b7bb3b07 100644 --- a/DDTV_New/App.config +++ b/DDTV_New/App.config @@ -1,5 +1,6 @@  + diff --git a/DDTV_New/MainWindow.xaml.cs b/DDTV_New/MainWindow.xaml.cs index f6ca0421e..53c95a6ed 100644 --- a/DDTV_New/MainWindow.xaml.cs +++ b/DDTV_New/MainWindow.xaml.cs @@ -57,7 +57,7 @@ public MainWindow() InitializeComponent(); this.Title = "DDTV2.0主窗口"; - + ViewModel = new MainViewModel(); this.WhenActivated(disposable => @@ -515,13 +515,13 @@ public void 公告项目启动() NewThreadTask.Loop(runOnLocalThread => { bool 动态推送1开关 = MMPU.TcpSend( - Server.RequestCode.GET_TOGGLE_DYNAMIC_NOTIFICATION, "{}", true) + Server.RequestCode.GET_TOGGLE_DYNAMIC_NOTIFICATION, "{}", true,50) == "1" ? true : false; if (动态推送1开关) { string 动态推送内容 = MMPU.TcpSend( - Server.RequestCode.GET_DYNAMIC_NOTIFICATION, "{}", true); + Server.RequestCode.GET_DYNAMIC_NOTIFICATION, "{}", true, 50); runOnLocalThread(() => ViewModel.PushNotification = 动态推送内容); } }, this, 3600 * 1000); @@ -536,7 +536,7 @@ public void 公告项目启动() NewThreadTask.Run(() => { string 服务器版本号 = MMPU.TcpSend( - Server.RequestCode.GET_LATEST_VERSION_NUMBER, "{}", true); + Server.RequestCode.GET_LATEST_VERSION_NUMBER, "{}", true, 50); if (!string.IsNullOrEmpty(服务器版本号)) { @@ -552,7 +552,7 @@ public void 公告项目启动() { MessageBoxResult dr = MessageBox.Show( "检测到版本更新,更新公告:\n" - + MMPU.TcpSend(Server.RequestCode.GET_UPDATE_ANNOUNCEMENT, "{}", true) + + MMPU.TcpSend(Server.RequestCode.GET_UPDATE_ANNOUNCEMENT, "{}", true, 100) + "\n\n点击确定启动自动更新,点击取消忽略", "有新版本", MessageBoxButton.OKCancel, @@ -590,7 +590,7 @@ public void 公告项目启动() NewThreadTask.Run(runOnLocalThread => { string 推送内容1text = MMPU.TcpSend( - Server.RequestCode.GET_PUSH_NOTIFICATION_1, "{}", true); + Server.RequestCode.GET_PUSH_NOTIFICATION_1, "{}", true, 100); if (推送内容1text.Length > 0) { runOnLocalThread(() => ViewModel.Announcement = 推送内容1text); diff --git "a/DDTV_New/window/\345\242\236\345\212\240\347\233\221\346\216\247\345\210\227\350\241\250.xaml.cs" "b/DDTV_New/window/\345\242\236\345\212\240\347\233\221\346\216\247\345\210\227\350\241\250.xaml.cs" index 1caa8950b..5687ce36f 100644 --- "a/DDTV_New/window/\345\242\236\345\212\240\347\233\221\346\216\247\345\210\227\350\241\250.xaml.cs" +++ "b/DDTV_New/window/\345\242\236\345\212\240\347\233\221\346\216\247\345\210\227\350\241\250.xaml.cs" @@ -42,7 +42,7 @@ private void Button_Click(object sender, RoutedEventArgs e) try { roomId = int.Parse(唯一码.Text); - if (roomId < 10000) + if (roomId < 10001) { string roomDD = bilibili.根据房间号获取房间信息.获取真实房间号(roomId.ToString()); if(!string.IsNullOrEmpty(roomDD)) @@ -73,7 +73,7 @@ private void Button_Click(object sender, RoutedEventArgs e) RB.data.Add(item); } } - RB.data.Add(new RoomCadr() { Name = 名称.Text + "-NV", OfficialName = 名称.Text + "-NV", RoomNumber = 唯一码.Text }); + RB.data.Add(new RoomCadr() { Name = 名称.Text + "-NV", OfficialName = 名称.Text + "-NV", RoomNumber = roomId.ToString() }); string JOO = JsonConvert.SerializeObject(RB); MMPU.储存文本(JOO, RoomConfigFile); 提示.Content = 名称.Text + "-NV["+ 唯一码.Text + "]添加完成";