当前位置: 首页>>代码示例>>C#>>正文


C# Connection.SendAsync方法代码示例

本文整理汇总了C#中Connection.SendAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Connection.SendAsync方法的具体用法?C# Connection.SendAsync怎么用?C# Connection.SendAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Connection的用法示例。


在下文中一共展示了Connection.SendAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Authenticate

		public static async Task<Account> Authenticate(Connection con)
		{
			await con.SendAsync("Please enter your username: (hit enter to register a new account)");
			var username = await con.ReadNextMsgAsync();

			Account account;
			if (username == "") {
				account = await Registrar.Register(con);;
			} else {
				var accounttask = Account.FromUsername(username);

				await con.SendAsync("Enter password: ");

				var pw = await con.ReadNextMsgAsync();

				account = await accounttask;
				var utf8 = new UTF8Encoding();
				if (account.GetPasswordHash() != PasswordSecurity.GenerateSaltedHash(utf8.GetBytes(pw), account.GetSalt())) {
					await con.SendAsync("Wrong password");
					return await Authenticate(con);
				}

			}
			return account;
		}
开发者ID:LennyPenny,项目名称:someWorld,代码行数:25,代码来源:Authenticator.cs

示例2: ReceiveValidUsername

		private static async Task<string> ReceiveValidUsername(Connection con)
		{
			await con.SendAsync("Please enter your desired username (a-Z, 0-9, _): ");
			var username = await con.ReadNextMsgAsync();

			if (await Account.IsUsernameTaken(username)) {
				await con.SendAsync("That name is already taken, please choose another one");
				return await ReceiveValidUsername(con);
			}

			return username;
		}
开发者ID:LennyPenny,项目名称:someWorld,代码行数:12,代码来源:Registrar.cs

示例3: ReceiveValidPassword

		private static async Task<string> ReceiveValidPassword(Connection con)
		{
			await con.SendAsync("Enter your desired password: ");
			var pw1 = await con.ReadNextMsgAsync();
			await con.SendAsync("Enter it again: ");
			var pw2 = await con.ReadNextMsgAsync();

			if (pw1 != pw2) {
				await con.SendAsync("Passwords don't match, try again ");
				return await ReceiveValidPassword(con);
			}

			return pw1;
		}
开发者ID:LennyPenny,项目名称:someWorld,代码行数:14,代码来源:Registrar.cs


注:本文中的Connection.SendAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。