2022-10-06 17:44:08 +08:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace BarrageGrab
|
|
|
|
|
{
|
|
|
|
|
public class Program
|
|
|
|
|
{
|
|
|
|
|
private delegate bool ControlCtrlDelegate(int CtrlType);
|
|
|
|
|
|
2023-03-09 00:33:03 +08:00
|
|
|
static WsBarrageService server = null;
|
2022-10-06 17:44:08 +08:00
|
|
|
static void Main(string[] args)
|
|
|
|
|
{
|
|
|
|
|
SetConsoleCtrlHandler(cancelHandler, true);//捕获控制台关闭
|
2022-11-05 16:39:49 +08:00
|
|
|
Console.Title = "抖音弹幕监听推送";
|
2023-03-09 00:33:03 +08:00
|
|
|
server = new WsBarrageService();
|
2022-10-06 17:44:08 +08:00
|
|
|
server.StartListen();
|
|
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
var input = Console.ReadKey();
|
|
|
|
|
switch (input.Key)
|
|
|
|
|
{
|
2022-11-05 20:29:21 +08:00
|
|
|
case ConsoleKey.Escape: goto end; break;
|
2022-10-06 17:44:08 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
end:
|
2022-11-05 20:29:21 +08:00
|
|
|
server.Close();
|
2022-10-06 17:44:08 +08:00
|
|
|
Console.WriteLine("服务器已正常关闭,按任意键结束...");
|
|
|
|
|
Console.ReadKey();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[DllImport("kernel32.dll")]
|
|
|
|
|
private static extern bool SetConsoleCtrlHandler(ControlCtrlDelegate HandlerRoutine, bool Add);
|
|
|
|
|
private static ControlCtrlDelegate cancelHandler = new ControlCtrlDelegate(HandlerRoutine);
|
|
|
|
|
|
|
|
|
|
public static bool HandlerRoutine(int CtrlType)
|
|
|
|
|
{
|
|
|
|
|
switch (CtrlType)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
//Console.WriteLine("0工具被强制关闭"); //Ctrl+C关闭
|
|
|
|
|
//server.Close();
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
Console.WriteLine("2工具被强制关闭");//按控制台关闭按钮关闭
|
|
|
|
|
server.Close();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|