sharp-chat/SharpChat/Program.cs

47 lines
1.6 KiB
C#

using System;
using System.Net.Http;
using System.Threading;
namespace SharpChat {
public class Program {
public const ushort PORT = 6770;
public static void Main(string[] args) {
Console.WriteLine(@" _____ __ ________ __ ");
Console.WriteLine(@" / ___// /_ ____ __________ / ____/ /_ ____ _/ /_");
Console.WriteLine(@" \__ \/ __ \/ __ `/ ___/ __ \/ / / __ \/ __ `/ __/");
Console.WriteLine(@" ___/ / / / / /_/ / / / /_/ / /___/ / / / /_/ / /_ ");
Console.WriteLine(@"/____/_/ /_/\__,_/_/ / .___/\____/_/ /_/\__,_/\__/ ");
Console.WriteLine(@" / _/ Sock Chat Server");
#if DEBUG
Console.WriteLine(@"============================================ DEBUG ==");
#endif
Database.ReadConfig();
using ManualResetEvent mre = new(false);
bool hasCancelled = false;
void cancelKeyPressHandler(object sender, ConsoleCancelEventArgs ev) {
Console.CancelKeyPress -= cancelKeyPressHandler;
hasCancelled = true;
ev.Cancel = true;
mre.Set();
};
Console.CancelKeyPress += cancelKeyPressHandler;
if(hasCancelled) return;
using HttpClient httpClient = new();
httpClient.DefaultRequestHeaders.Add(@"User-Agent", @"SharpChat/20230206");
if(hasCancelled) return;
using SockChatServer scs = new(httpClient, PORT);
scs.Listen(mre);
mre.WaitOne();
}
}
}