2023-02-06 20:14:50 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Net.Http;
|
2022-08-30 15:00:58 +00:00
|
|
|
|
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
|
|
|
|
|
|
2022-08-30 15:28:46 +00:00
|
|
|
|
Database.ReadConfig();
|
2022-08-30 15:00:58 +00:00
|
|
|
|
|
2023-02-06 20:14:50 +00:00
|
|
|
|
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;
|
|
|
|
|
|
2023-02-08 00:01:55 +00:00
|
|
|
|
using HttpClient httpClient = new(new HttpClientHandler() {
|
|
|
|
|
UseProxy = false, // we will never and the initial resolving takes forever on linux
|
|
|
|
|
});
|
2023-02-06 20:14:50 +00:00
|
|
|
|
httpClient.DefaultRequestHeaders.Add(@"User-Agent", @"SharpChat/20230206");
|
|
|
|
|
|
|
|
|
|
if(hasCancelled) return;
|
|
|
|
|
|
|
|
|
|
using SockChatServer scs = new(httpClient, PORT);
|
|
|
|
|
scs.Listen(mre);
|
|
|
|
|
|
2022-08-30 15:00:58 +00:00
|
|
|
|
mre.WaitOne();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|