private static ILoginResult TryLogin(SeededPrimitiveConnection seedConn, IAuthPromptResponse authPrompt) { var(seed, conn) = seedConn; var username = authPrompt.Username; var password = authPrompt.Password; var securedPassword = Md5Sum(string.Concat(seed, Md5Sum(password))); var loginCmd = new SystemCommand(SystemOp.Login); var loginMessage = new MessageBuilder(loginCmd).Add(username).Add(securedPassword); loginMessage.Send(conn); var(matched, authResult, description) = conn.ReceiveSystemStringCommand(SystemOp.LoginResult); if (!matched) { return(new InvalidProtocolLoginResult("login result listen")); } var authenticated = CommandUnpacking.Value(authResult) == 0; if (!authenticated) { return(new UserLoginException(description ?? "(no description)")); } return(new SuccessLoginResult()); }
public static (bool matched, ushort command, string?payload) ReceiveSystemStringCommand( this IPrimitiveSource src, SystemOp expectedOp) { // ArgumentNullException need a parameter name, but `src` isn't technically a parameter, and code analysis // fails if we try to pass `nameof(src)` in. Hmm. if (src is null) { throw new ArgumentException("Source on which this method was invoked is null."); } var cmd = src.ReceiveCommand(); _ = src.ReceiveUint(); // Discard length var isRightGroup = CommandUnpacking.Group(cmd) == CommandGroup.System; var isRightOp = CommandUnpacking.SystemOp(cmd) == expectedOp; var isRightCommand = isRightGroup && isRightOp; return(isRightCommand ? (true, cmd, src.ReceiveString()) : (false, default, null));
public void TestCommandGroup(CommandGroup expectedGroup) { Assert.Equal(expectedGroup, CommandUnpacking.Group(expectedGroup.ToWordBits())); }