Ejemplo n.º 1
0
        private async Task <(SteamSessionCreateService.Status status, SteamSession session)> GetSessionStatus()
        {
            (SteamSessionCreateService.Status status, SteamSession session)createSessionResponse = await _sessionService.TryCreateSession();

            _steamSession = createSessionResponse.session;
            return(createSessionResponse);
        }
Ejemplo n.º 2
0
        private (Status, SteamSession) EvaluateLoginResponse(LoginResponse loginResponse, CookieContainer cookieContainer)
        {
            if (loginResponse.Message != null && loginResponse.Message.ToLower().Contains("password") && loginResponse.Message.ToLower().Contains("incorrect"))
            {
                return(Status.BadCredentials, null);
            }

            if (loginResponse.CaptchaNeeded)
            {
                requiresCaptcha = true;
                CaptchaID       = loginResponse.CaptchaGID;
                return(Status.NeedCaptcha, null);
            }

            if (loginResponse.EmailAuthNeeded)
            {
                requiresEmail = true;
                steamID       = loginResponse.EmailSteamID;
                return(Status.NeedEmail, null);
            }

            if (loginResponse.TwoFactorNeeded && !loginResponse.Success)
            {
                requires2FA = true;
                return(Status.Need2FA, null);
            }

            if (loginResponse.Message != null && loginResponse.Message.Contains("too many login failures"))
            {
                return(Status.TooManyFailedLogins, null);
            }

            if (loginResponse.OAuthData == null || loginResponse.OAuthData.OAuthToken == null || loginResponse.OAuthData.OAuthToken.Length == 0)
            {
                return(Status.GeneralFailure, null);
            }

            if (!loginResponse.LoginComplete)
            {
                return(Status.BadCredentials, null);
            }
            else
            {
                var readableCookies = cookieContainer.GetCookies(new Uri("https://steamcommunity.com"));
                var oAuthData       = loginResponse.OAuthData;

                SteamSession session = new SteamSession();
                session.OAuthToken       = oAuthData.OAuthToken;
                session.SteamID          = oAuthData.SteamID;
                session.SteamLogin       = session.SteamID + "%7C%7C" + oAuthData.SteamLogin;
                session.SteamLoginSecure = session.SteamID + "%7C%7C" + oAuthData.SteamLoginSecure;
                session.WebCookie        = oAuthData.Webcookie;
                session.SessionID        = readableCookies["sessionid"].Value;
                return(Status.Okay, session);
            }
        }
Ejemplo n.º 3
0
		/// <summary>
		/// Create a new SteamClient
		/// </summary>
		public SteamClient(SteamAuthenticator auth, string session = null)
		{
			this.Authenticator = auth;
			this.Session = new SteamSession(session);

			if (this.Session.Confirmations != null)
			{
				if (this.IsLoggedIn() == false)
				{
					this.Session.Confirmations = null;
				}
				else
				{
					Task.Factory.StartNew(() =>
					{
						Refresh();
						PollConfirmations(this.Session.Confirmations);
					});
				}
			}
		}
Ejemplo n.º 4
0
		/// <summary>
		/// Load the trade confirmations
		/// </summary>
		/// <param name="state">current Steam session</param>
		/// <returns></returns>
		public string LoadTrades(SteamSession state)
		{
			// clear error
			state.Error = null;

			try
			{
				var data = new NameValueCollection();
				var cookies = state.Cookies = state.Cookies ?? new CookieContainer();
				string response;

				if (string.IsNullOrEmpty(state.OAuthToken) == true)
				{
					// get session
					if (cookies.Count == 0)
					{
						cookies.Add(new Cookie("mobileClientVersion", "3067969+%282.1.3%29", "/", ".steamcommunity.com"));
						cookies.Add(new Cookie("mobileClient", "android", "/", ".steamcommunity.com"));
						cookies.Add(new Cookie("steamid", "", "/", ".steamcommunity.com"));
						cookies.Add(new Cookie("steamLogin", "", "/", ".steamcommunity.com"));
						cookies.Add(new Cookie("Steam_Language", "english", "/", ".steamcommunity.com"));
						cookies.Add(new Cookie("dob", "", "/", ".steamcommunity.com"));

						NameValueCollection headers = new NameValueCollection();
						headers.Add("X-Requested-With", "com.valvesoftware.android.steam.community");

						response = Request("https://steamcommunity.com/login?oauth_client_id=DE45CD61&oauth_scope=read_profile%20write_profile%20read_client%20write_client", "GET", null, cookies, headers);
					}

					// get the user's RSA key
					data.Add("username", state.Username);
					response = Request(COMMUNITY_BASE + "/login/getrsakey", "POST", data, cookies);
					var rsaresponse = JObject.Parse(response);
					if (rsaresponse.SelectToken("success").Value<bool>() != true)
					{
						throw new InvalidTradesResponseException("Cannot get steam information for user: "******"publickey_exp").Value<string>());
						p.Modulus = Authenticator.StringToByteArray(rsaresponse.SelectToken("publickey_mod").Value<string>());
						rsa.ImportParameters(p);
						byte[] encryptedPassword = rsa.Encrypt(passwordBytes, false);
						encryptedPassword64 = Convert.ToBase64String(encryptedPassword);
					}

					// login request
					data = new NameValueCollection();
					data.Add("password", encryptedPassword64);
					data.Add("username", state.Username);
					data.Add("twofactorcode", state.AuthCode ?? string.Empty);
					data.Add("emailauth", (state.EmailAuthText != null ? state.EmailAuthText : string.Empty));
					data.Add("loginfriendlyname", "#login_emailauth_friendlyname_mobile");
					data.Add("captchagid", (state.CaptchaId != null ? state.CaptchaId : "-1"));
					data.Add("captcha_text", (state.CaptchaText != null ? state.CaptchaText : "enter above characters"));
					data.Add("emailsteamid", (state.EmailAuthText != null ? state.SteamId ?? string.Empty : string.Empty));
					data.Add("rsatimestamp", rsaresponse.SelectToken("timestamp").Value<string>());
					data.Add("remember_login", "false");
					data.Add("oauth_client_id", "DE45CD61");
					data.Add("oauth_scope", "read_profile write_profile read_client write_client");
					data.Add("donotache", new DateTime().ToUniversalTime().Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds.ToString());
					response = Request(COMMUNITY_BASE + "/login/dologin/", "POST", data, cookies);
					Dictionary<string, object> loginresponse = JsonConvert.DeserializeObject<Dictionary<string, object>>(response);

					if (loginresponse.ContainsKey("emailsteamid") == true)
					{
						state.SteamId = loginresponse["emailsteamid"] as string;
					}

					// require captcha
					if (loginresponse.ContainsKey("captcha_needed") == true && (bool)loginresponse["captcha_needed"] == true)
					{
						state.RequiresCaptcha = true;
						state.CaptchaId = (string)loginresponse["captcha_gid"];
						state.CaptchaUrl = COMMUNITY_BASE + "/public/captcha.php?gid=" + state.CaptchaId;
					}
					else
					{
						state.RequiresCaptcha = false;
						state.CaptchaId = null;
						state.CaptchaUrl = null;
						state.CaptchaText = null;
					}

					// require email auth
					if (loginresponse.ContainsKey("emailauth_needed") == true && (bool)loginresponse["emailauth_needed"] == true)
					{
						if (loginresponse.ContainsKey("emaildomain") == true)
						{
							var emaildomain = (string)loginresponse["emaildomain"];
							if (string.IsNullOrEmpty(emaildomain) == false)
							{
								state.EmailDomain = emaildomain;
							}
						}
						state.RequiresEmailAuth = true;
					}
					else
					{
						state.EmailDomain = null;
						state.RequiresEmailAuth = false;
					}

					// require email auth
					if (loginresponse.ContainsKey("requires_twofactor") == true && (bool)loginresponse["requires_twofactor"] == true)
					{
						state.Requires2FA = true;
					}
					else
					{
						state.Requires2FA = false;
					}

					// if we didn't login, return the result
					if (loginresponse.ContainsKey("login_complete") == false || (bool)loginresponse["login_complete"] == false || loginresponse.ContainsKey("oauth") == false)
					{
						if (loginresponse.ContainsKey("oauth") == false)
						{
							state.Error = "No OAuth token in response";
						}
						if (loginresponse.ContainsKey("message") == true)
						{
							state.Error = (string)loginresponse["message"];
						}

						return null;
					}

					// get the OAuth token
					string oauth = (string)loginresponse["oauth"];
					var oauthjson = JObject.Parse(oauth);
					state.OAuthToken = oauthjson.SelectToken("oauth_token").Value<string>();
					if (oauthjson.SelectToken("steamid") != null)
					{
						state.SteamId = oauthjson.SelectToken("steamid").Value<string>();

						// add the steamid into the data if missing
						var steamdata = JObject.Parse(this.SteamData);
						if (steamdata.SelectToken("steamid") == null)
						{
							steamdata.Add("steamid", state.SteamId);
							this.SteamData = steamdata.ToString(Newtonsoft.Json.Formatting.None);
						}
					}
				}

				// get servertime
				//var timeresponse = Request(SYNC_URL, "POST");
				//var timejson = JObject.Parse(timeresponse);
				//long servertime = timejson.SelectToken("response.server_time").Value<long>();
				long servertime = (CurrentTime + ServerTimeDiff) / 1000L;

				var jids = JObject.Parse(this.SteamData).SelectToken("identity_secret");
				string ids = (jids != null ? jids.Value<string>() : string.Empty);

				var timehash = CreateTimeHash(servertime, "conf", ids);

				data.Clear();
				data.Add("p", this.DeviceId);
				data.Add("a", state.SteamId);
				data.Add("k", timehash);
				data.Add("t", servertime.ToString());
				data.Add("m", "android");
				data.Add("tag", "conf");

				return Request(COMMUNITY_BASE + "/mobileconf/conf", "GET", data, state.Cookies);
			}
			catch (InvalidRequestException ex)
			{
				state.Error = ex.Message;
				throw new InvalidTradesResponseException("Error trading", ex);
			}
		}
Ejemplo n.º 5
0
		/// <summary>
		/// Confirm or reject a specific trade confirmation
		/// </summary>
		/// <param name="state">Steam state</param>
		/// <param name="id">id of trade</param>
		/// <param name="key">key for trade</param>
		/// <param name="accept">true to accept, false to reject</param>
		/// <returns>response data</returns>
		public string ConfirmTrade(SteamSession state, string id, string key, bool accept)
		{
			// clear error
			state.Error = null;

			try
			{
				// get servertime
				long servertime = (CurrentTime + ServerTimeDiff) / 1000L;

				var jids = JObject.Parse(this.SteamData).SelectToken("identity_secret");
				string ids = (jids != null ? jids.Value<string>() : string.Empty);
				var timehash = CreateTimeHash(servertime, "conf", ids);

				var data = new NameValueCollection();
				data.Add("op", accept ? "allow" : "cancel");
				data.Add("p", this.DeviceId);
				data.Add("a", state.SteamId);
				data.Add("k", timehash);
				data.Add("t", servertime.ToString());
				data.Add("m", "android");
				data.Add("tag", "conf");
				//
				data.Add("cid", id);
				data.Add("ck", key);
				return Request(COMMUNITY_BASE + "/mobileconf/ajaxop", "GET", data, state.Cookies);
			}
			catch (InvalidRequestException ex)
			{
				state.Error = ex.Message;
				throw new InvalidTradesResponseException("Error trading", ex);
			}
		}