public static void Main() { WriteLine("Misuzu Authentication Tester"); using ManualResetEvent mre = new ManualResetEvent(false); string cfgPath = Path.GetDirectoryName(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); string buildMode = Path.GetFileName(cfgPath); cfgPath = Path.Combine( Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(cfgPath))), @"SharpChat", @"bin", buildMode, @"net5.0", @"sharpchat.cfg" ); WriteLine($@"Reading config from {cfgPath}"); using IConfig config = new StreamConfig(cfgPath); WriteLine($@"Enter token found on {config.ReadValue(@"dp:misuzu:endpoint")}/login:"******"SharpChat/1.0"; IDataProvider dataProvider = new MisuzuDataProvider(config.ScopeTo(@"dp:misuzu"), HttpClient.Instance); long userId = long.Parse(token[0]); IPAddress remoteAddr = IPAddress.Parse(@"1.2.4.8"); IUserAuthResponse authRes = null; mre.Reset(); dataProvider.UserAuthClient.AttemptAuth( new UserAuthRequest(userId, token[1], remoteAddr), onSuccess: res => { authRes = res; WriteLine(@"Auth success!"); WriteLine($@" User ID: {authRes.UserId}"); WriteLine($@" Username: {authRes.UserName}"); WriteLine($@" Colour: {authRes.Colour.Raw:X8}"); WriteLine($@" Hierarchy: {authRes.Rank}"); WriteLine($@" Silenced: {authRes.SilencedUntil}"); WriteLine($@" Perms: {authRes.Permissions}"); mre.Set(); }, onFailure: ex => { WriteLine($@"Auth failed: {ex.Message}"); mre.Set(); } ); mre.WaitOne(); if (authRes == null) { return; } #if F****D WriteLine(@"Bumping last seen..."); mre.Reset(); dataProvider.UserBumpClient.SubmitBumpUsers( new[] { new User(authRes) }, onSuccess: () => mre.Set(), onFailure: ex => { WriteLine($@"Bump failed: {ex.Message}"); mre.Set(); } ); mre.WaitOne(); #endif WriteLine(@"Fetching ban list..."); IEnumerable <IBanRecord> bans = Enumerable.Empty <IBanRecord>(); mre.Reset(); dataProvider.BanClient.GetBanList(x => { bans = x; mre.Set(); }, e => { WriteLine(e); mre.Set(); }); mre.WaitOne(); WriteLine($@"{bans.Count()} BANS"); foreach (IBanRecord ban in bans) { WriteLine($@"BAN INFO"); WriteLine($@" User ID: {ban.UserId}"); WriteLine($@" Username: {ban.Username}"); WriteLine($@" IP Address: {ban.UserIP}"); WriteLine($@" Expires: {ban.Expires}"); } }
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 string configFile = GetFlagArgument(args, @"--cfg") ?? CONFIG; // If the config file doesn't exist and we're using the default path, run the converter if (!File.Exists(configFile) && configFile == CONFIG) { ConvertConfiguration(); } using IConfig config = new StreamConfig(configFile); // Load database and data provider libraries ReflectionUtilities.LoadAssemblies(@"SharpChat.Database.*.dll"); ReflectionUtilities.LoadAssemblies(@"SharpChat.DataProvider.*.dll"); // Allow forcing a sqlite database through console flags string sqliteDbPath = GetFlagArgument(args, @"--dbpath"); string databaseBackendName; object databaseArgument; if (!string.IsNullOrEmpty(sqliteDbPath)) { Logger.Write($@"Forcing SQLite: {sqliteDbPath}"); databaseBackendName = @"sqlite"; databaseArgument = sqliteDbPath; } else { databaseBackendName = GetFlagArgument(args, @"--dbb") ?? config.ReadValue(@"db"); databaseArgument = config.ScopeTo($@"db:{databaseBackendName}"); } IDatabaseBackend databaseBackend = new ObjectConstructor <IDatabaseBackend, DatabaseBackendAttribute, NullDatabaseBackend>() .Construct(databaseBackendName, databaseArgument); using HttpClient httpClient = new HttpClient { DefaultUserAgent = @"SharpChat/1.0", }; string dataProviderName = GetFlagArgument(args, @"--dpn") ?? config.ReadValue(@"dp"); IDataProvider dataProvider = new ObjectConstructor <IDataProvider, DataProviderAttribute, NullDataProvider>() .Construct(dataProviderName, config.ScopeTo($@"dp:{dataProviderName}"), httpClient); string portArg = GetFlagArgument(args, @"--port") ?? config.ReadValue(@"chat:port"); if (string.IsNullOrEmpty(portArg) || !ushort.TryParse(portArg, out ushort port)) { port = DEFAULT_PORT; } using IServer wss = new FleckServer(new IPEndPoint(IPAddress.Any, port)); using ChatServer scs = new ChatServer(config, wss, dataProvider, databaseBackend); using ManualResetEvent mre = new ManualResetEvent(false); Console.CancelKeyPress += (s, e) => { e.Cancel = true; mre.Set(); }; mre.WaitOne(); if (dataProvider is IDisposable dpd) { dpd.Dispose(); } if (databaseBackend is IDisposable dbd) { dbd.Dispose(); } }
public static void Main(string[] args) { Console.WriteLine(@" _____ __ ________ __ "); Console.WriteLine(@" / ___// /_ ____ __________ / ____/ /_ ____ _/ /_"); Console.WriteLine(@" \__ \/ __ \/ __ `/ ___/ __ \/ / / __ \/ __ `/ __/"); Console.WriteLine(@" ___/ / / / / /_/ / / / /_/ / /___/ / / / /_/ / /_ "); Console.WriteLine(@"/____/_/ /_/\__,_/_/ / .___/\____/_/ /_/\__,_/\__/ "); /**/ Console.Write(@" / _/"); if (SharpInfo.IsDebugBuild) { Console.WriteLine(); Console.Write(@"== "); Console.Write(SharpInfo.VersionString); Console.WriteLine(@" == DBG =="); } else { Console.WriteLine(SharpInfo.VersionStringShort.PadLeft(28, ' ')); } string configFile = GetFlagArgument(args, @"--cfg") ?? CONFIG; // If the config file doesn't exist and we're using the default path, run the converter if (!File.Exists(configFile) && configFile == CONFIG) { ConvertConfiguration(); } using IConfig config = new StreamConfig(configFile); // Load database and data provider libraries ReflectionUtilities.LoadAssemblies(@"SharpChat.Database.*.dll"); ReflectionUtilities.LoadAssemblies(@"SharpChat.DataProvider.*.dll"); ReflectionUtilities.LoadAssemblies(@"SharpChat.Protocol.*.dll"); // Allow forcing a sqlite database through console flags string sqliteDbPath = GetFlagArgument(args, @"--dbpath"); string databaseBackendName; object databaseArgument; if (!string.IsNullOrEmpty(sqliteDbPath)) { Logger.Write($@"Forcing SQLite: {sqliteDbPath}"); databaseBackendName = @"sqlite"; databaseArgument = sqliteDbPath; } else { databaseBackendName = GetFlagArgument(args, @"--dbb") ?? config.ReadValue(@"db"); databaseArgument = config.ScopeTo($@"db:{databaseBackendName}"); } IDatabaseBackend databaseBackend = new ObjectConstructor <IDatabaseBackend, DatabaseBackendAttribute, NullDatabaseBackend>() .Construct(databaseBackendName, databaseArgument); using HttpClient httpClient = new HttpClient { DefaultUserAgent = @"SharpChat/1.0", }; string dataProviderName = GetFlagArgument(args, @"--dpn") ?? config.ReadValue(@"dp"); IDataProvider dataProvider = new ObjectConstructor <IDataProvider, DataProviderAttribute, NullDataProvider>() .Construct(dataProviderName, config.ScopeTo($@"dp:{dataProviderName}"), httpClient); string portArg = GetFlagArgument(args, @"--port") ?? config.ReadValue(@"chat:port"); if (string.IsNullOrEmpty(portArg) || !ushort.TryParse(portArg, out ushort port)) { port = DEFAULT_PORT; } ObjectConstructor <IServer, ServerAttribute, NullServer> serverConstructor = new ObjectConstructor <IServer, ServerAttribute, NullServer>(); Logger.Write(@"Creating context..."); using Context ctx = new Context(config.ScopeTo(@"chat"), databaseBackend, dataProvider); List <IServer> servers = new List <IServer>(); // Crusty temporary solution, just want to have the variable constructor arguments for servers in place already string[] serverNames = new[] { @"sockchat", #if DEBUG @"irc", #endif }; foreach (string serverName in serverNames) { Logger.Write($@"Starting {serverName} server..."); IServer server = serverConstructor.Construct(serverName, ctx, config.ScopeTo(serverName)); servers.Add(server); if (server is SockChatServer) { server.Listen(new IPEndPoint(IPAddress.Any, port)); } else if (server is IRCServer) { server.Listen(new IPEndPoint(IPAddress.Any, 6667)); } } using ManualResetEvent mre = new ManualResetEvent(false); Console.CancelKeyPress += (s, e) => { e.Cancel = true; mre.Set(); }; mre.WaitOne(); foreach (IServer server in servers) { server.Dispose(); } if (dataProvider is IDisposable dpd) { dpd.Dispose(); } if (databaseBackend is IDisposable dbd) { dbd.Dispose(); } }