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


C# SteamClient.Disconnect方法代码示例

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


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

示例1: StartSteam

        public ECheckResult StartSteam()
        {
            _steamClient = new SteamClient();
            _manager = new CallbackManager(_steamClient);
            _steamUser = _steamClient.GetHandler<SteamUser>();

            _manager.Subscribe<SteamClient.ConnectedCallback>(OnConnected);
            _manager.Subscribe<SteamClient.DisconnectedCallback>(OnDisconnected);
            _manager.Subscribe<SteamUser.LoggedOnCallback>(OnLoggedOn);
            _manager.Subscribe<SteamUser.UpdateMachineAuthCallback>(OnMachineAuth);

            _isRunning = true;
            _steamClient.Connect();

            while (_isRunning)
                _manager.RunWaitCallbacks(TimeSpan.FromSeconds(1));

            if (_operation == EOperationType.CreateSentry)
                Thread.Sleep(500);

            _steamClient.Disconnect();
            return _checkResult;
        }
开发者ID:Shravan2x,项目名称:SteamSentryTool,代码行数:23,代码来源:SentryOperator.cs

示例2: Init

		internal async Task Init(SteamClient steamClient, string webAPIUserNonce, string vanityURL, string parentalPin) {
			if (steamClient == null || steamClient.SteamID == null || string.IsNullOrEmpty(webAPIUserNonce)) {
				return;
			}

			SteamID = steamClient.SteamID;
			VanityURL = vanityURL;

			string sessionID = Convert.ToBase64String(Encoding.UTF8.GetBytes(SteamID.ToString(CultureInfo.InvariantCulture)));

			// Generate an AES session key
			byte[] sessionKey = CryptoHelper.GenerateRandomBlock(32);

			// RSA encrypt it with the public key for the universe we're on
			byte[] cryptedSessionKey = null;
			using (RSACrypto rsa = new RSACrypto(KeyDictionary.GetPublicKey(steamClient.ConnectedUniverse))) {
				cryptedSessionKey = rsa.Encrypt(sessionKey);
			}

			// Copy our login key
			byte[] loginKey = new byte[20];
			Array.Copy(Encoding.ASCII.GetBytes(webAPIUserNonce), loginKey, webAPIUserNonce.Length);

			// AES encrypt the loginkey with our session key
			byte[] cryptedLoginKey = CryptoHelper.SymmetricEncrypt(loginKey, sessionKey);

			// Send the magic
			KeyValue authResult;
			Logging.LogGenericInfo(Bot.BotName, "Logging in to ISteamUserAuth...");
			using (dynamic iSteamUserAuth = WebAPI.GetInterface("ISteamUserAuth")) {
				iSteamUserAuth.Timeout = Timeout;

				try {
					authResult = iSteamUserAuth.AuthenticateUser(
						steamid: SteamID,
						sessionkey: Encoding.ASCII.GetString(WebUtility.UrlEncodeToBytes(cryptedSessionKey, 0, cryptedSessionKey.Length)),
						encrypted_loginkey: Encoding.ASCII.GetString(WebUtility.UrlEncodeToBytes(cryptedLoginKey, 0, cryptedLoginKey.Length)),
						method: WebRequestMethods.Http.Post,
						secure: true
					);
				} catch (Exception e) {
					Logging.LogGenericException(Bot.BotName, e);
					steamClient.Disconnect(); // We may get 403 if we use the same webAPIUserNonce twice
					return;
				}
			}

			if (authResult == null) {
				steamClient.Disconnect(); // Try again
				return;
			}

			Logging.LogGenericInfo(Bot.BotName, "Success!");

			string steamLogin = authResult["token"].AsString();
			string steamLoginSecure = authResult["tokensecure"].AsString();

			SteamCookieDictionary.Clear();
			SteamCookieDictionary.Add("sessionid", sessionID);
			SteamCookieDictionary.Add("steamLogin", steamLogin);
			SteamCookieDictionary.Add("steamLoginSecure", steamLoginSecure);
			SteamCookieDictionary.Add("birthtime", "-473356799"); // ( ͡° ͜ʖ ͡°)

			if (!string.IsNullOrEmpty(parentalPin) && !parentalPin.Equals("0")) {
				Logging.LogGenericInfo(Bot.BotName, "Unlocking parental account...");
				Dictionary<string, string> postData = new Dictionary<string, string>() {
					{"pin", parentalPin}
				};

				HttpResponseMessage response = await Utilities.UrlPostRequestWithResponse("https://steamcommunity.com/parental/ajaxunlock", postData, SteamCookieDictionary, "https://steamcommunity.com/").ConfigureAwait(false);
				if (response != null && response.IsSuccessStatusCode) {
					Logging.LogGenericInfo(Bot.BotName, "Success!");

					var setCookieValues = response.Headers.GetValues("Set-Cookie");
					foreach (string setCookieValue in setCookieValues) {
						if (setCookieValue.Contains("steamparental=")) {
							string setCookie = setCookieValue.Substring(setCookieValue.IndexOf("steamparental=") + 14);
							setCookie = setCookie.Substring(0, setCookie.IndexOf(';'));
							SteamCookieDictionary.Add("steamparental", setCookie);
							break;
						}
					}
				} else {
					Logging.LogGenericInfo(Bot.BotName, "Failed!");
				}
			}

			Bot.Trading.CheckTrades();
		}
开发者ID:xkomachi,项目名称:ArchiSteamFarm,代码行数:89,代码来源:ArchiWebHandler.cs


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