public void Connect(IUserAuthResponse uar, Action <IUser> callback) { if (uar == null) { throw new ArgumentNullException(nameof(uar)); } if (callback == null) { throw new ArgumentNullException(nameof(callback)); } lock (Sync) { GetUser(uar.UserId, user => { if (user == null) { Create(uar.UserId, uar.UserName, uar.Colour, uar.Rank, uar.Permissions, callback: callback); } else { Update(user, uar.UserName, uar.Colour, uar.Rank, uar.Permissions); callback(user); } }); } }
public void ApplyAuth(IUserAuthResponse auth) { UserName = auth.UserName; if (Status == UserStatus.Offline) { Status = UserStatus.Online; } Colour = auth.Colour; Rank = auth.Rank; Permissions = auth.Permissions; }
public IUser Connect(IUserAuthResponse uar) { lock (Sync) { IUser user = GetUser(uar.UserId); if (user == null) { return(Create(uar.UserId, uar.UserName, uar.Colour, uar.Rank, uar.Permissions)); } Update(user, uar.UserName, uar.Colour, uar.Rank, uar.Permissions); return(user); } }
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 User(IUserAuthResponse auth) { UserId = auth.UserId; ApplyAuth(auth); }