Skip to content

Commit

Permalink
修复了因为steamdb.ml api挂掉导致的程序启动崩溃
Browse files Browse the repository at this point in the history
  • Loading branch information
rmbadmin committed Jan 8, 2021
1 parent 42b11ce commit d38588d
Show file tree
Hide file tree
Showing 16 changed files with 233 additions and 145 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,10 @@
---

## 开发环境
> 程序使用C# WPF在 .NET Framework4.7.2 和 .NET5环境下开发。
如果无法运行请下载安装[.NET Framework 4.7.2](https://dotnet.microsoft.com/download/dotnet-framework/net472)[.NET 5](https://dotnet.microsoft.com/download/dotnet/5.0)

* [Titanium-Web-Proxy](https://github.com/rmbadmin/Titanium-Web-Proxy)
* [MetroRadiance](https://github.com/rmbadmin/MetroRadiance)

> 开发工具 [Visual Studio 2019](https://visualstudio.microsoft.com/)
> 开发语言 C# WPF
> .NET版本 .NET Framework4.7.2 和 .NET5
> 如果无法运行请下载安装[.NET Framework 4.7.2](https://dotnet.microsoft.com/download/dotnet-framework/net472)[.NET 5](https://dotnet.microsoft.com/download/dotnet/5.0)
---

## License
Expand Down
24 changes: 24 additions & 0 deletions resources/RewardRecord.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,29 @@
"PayType": 1,
"Remark": "平其心论天下之事,定其心应天下之变",
"PayTime": "2021-01-06 17:08:36"
},
{
"Name": "K",
"Amount": 10,
"OrderNumber": "",
"PayType": 2,
"Remark": "支持一下",
"PayTime": "2021-01-07 14:46:04"
},
{
"Name": "*鹏",
"Amount": 10,
"OrderNumber": "",
"PayType": 1,
"Remark": "加油💪",
"PayTime": "2021-01-07 11:42:38"
},
{
"Name": "*成",
"Amount": 6.66,
"OrderNumber": "",
"PayType": 1,
"Remark": "",
"PayTime": "2021-01-07 12:25:59"
}
]
67 changes: 36 additions & 31 deletions source/SteamTool.Authenticator/SteamClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ public class SteamClient : IDisposable
/// </summary>
private const string COMMUNITY_DOMAIN = "steamcommunity.com";
private const string COMMUNITY_BASE = "https://" + COMMUNITY_DOMAIN;
private static string WEBAPI_BASE = "https://api.steampowered.com";
private static string API_GETWGTOKEN = WEBAPI_BASE + "/IMobileAuthService/GetWGToken/v0001";
private static string API_LOGOFF = WEBAPI_BASE + "/ISteamWebUserPresenceOAuth/Logoff/v0001";
private static string API_LOGON = WEBAPI_BASE + "/ISteamWebUserPresenceOAuth/Logon/v0001";
private static string API_POLLSTATUS = WEBAPI_BASE + "/ISteamWebUserPresenceOAuth/PollStatus/v0001";
private const string WEBAPI_BASE = "https://api.steampowered.com";
private const string API_GETWGTOKEN = WEBAPI_BASE + "/IMobileAuthService/GetWGToken/v0001";
private const string API_LOGOFF = WEBAPI_BASE + "/ISteamWebUserPresenceOAuth/Logoff/v0001";
private const string API_LOGON = WEBAPI_BASE + "/ISteamWebUserPresenceOAuth/Logon/v0001";
private const string API_POLLSTATUS = WEBAPI_BASE + "/ISteamWebUserPresenceOAuth/PollStatus/v0001";

/// <summary>
/// Default mobile user agent
Expand All @@ -64,11 +64,11 @@ public class SteamClient : IDisposable
/// <summary>
/// Regular expressions for trade confirmations
/// </summary>
private static Regex _tradesRegex = new Regex("\"mobileconf_list_entry\"(.*?)>(.*?)\"mobileconf_list_entry_sep\"", RegexOptions.Singleline | RegexOptions.IgnoreCase);
private static Regex _tradeConfidRegex = new Regex(@"data-confid\s*=\s*""([^""]+)""", RegexOptions.Singleline | RegexOptions.IgnoreCase);
private static Regex _tradeKeyRegex = new Regex(@"data-key\s*=\s*""([^""]+)""", RegexOptions.Singleline | RegexOptions.IgnoreCase);
private static Regex _tradePlayerRegex = new Regex("\"mobileconf_list_entry_icon\"(.*?)src=\"([^\"]+)\"", RegexOptions.Singleline | RegexOptions.IgnoreCase);
private static Regex _tradeDetailsRegex = new Regex("\"mobileconf_list_entry_description\".*?<div>([^<]*)</div>[^<]*<div>([^<]*)</div>[^<]*<div>([^<]*)</div>[^<]*</div>", RegexOptions.Singleline | RegexOptions.IgnoreCase);
private static readonly Regex _tradesRegex = new Regex("\"mobileconf_list_entry\"(.*?)>(.*?)\"mobileconf_list_entry_sep\"", RegexOptions.Singleline | RegexOptions.IgnoreCase);
private static readonly Regex _tradeConfidRegex = new Regex(@"data-confid\s*=\s*""([^""]+)""", RegexOptions.Singleline | RegexOptions.IgnoreCase);
private static readonly Regex _tradeKeyRegex = new Regex(@"data-key\s*=\s*""([^""]+)""", RegexOptions.Singleline | RegexOptions.IgnoreCase);
private static readonly Regex _tradePlayerRegex = new Regex("\"mobileconf_list_entry_icon\"(.*?)src=\"([^\"]+)\"", RegexOptions.Singleline | RegexOptions.IgnoreCase);
private static readonly Regex _tradeDetailsRegex = new Regex("\"mobileconf_list_entry_description\".*?<div>([^<]*)</div>[^<]*<div>([^<]*)</div>[^<]*<div>([^<]*)</div>[^<]*</div>", RegexOptions.Singleline | RegexOptions.IgnoreCase);

/// <summary>
/// Number of Confirmation retries
Expand Down Expand Up @@ -130,10 +130,11 @@ public override string ToString()
}
else
{
List<string> props = new List<string>();

props.Add("\"duration\":" + this.Duration);
props.Add("\"action\":" + (int)this.Action);
List<string> props = new List<string>
{
"\"duration\":" + this.Duration,
"\"action\":" + (int)this.Action
};
if (this.Ids != null)
{
props.Add("\"ids\":[" + (this.Ids.Count != 0 ? "\"" + string.Join("\",\"", this.Ids.ToArray()) + "\"" : string.Empty) + "]");
Expand Down Expand Up @@ -533,20 +534,22 @@ public bool Login(string username, string password, string captchaId = null, str
}

// login request
data = new NameValueCollection();
data.Add("password", encryptedPassword64);
data.Add("username", username);
data.Add("twofactorcode", this.Authenticator.CurrentCode);
//data.Add("emailauth", string.Empty);
data.Add("loginfriendlyname", "#login_emailauth_friendlyname_mobile");
data.Add("captchagid", (string.IsNullOrEmpty(captchaId) == false ? captchaId : "-1"));
data.Add("captcha_text", (string.IsNullOrEmpty(captchaText) == false ? captchaText : "enter above characters"));
//data.Add("emailsteamid", (string.IsNullOrEmpty(emailcode) == false ? this.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());
data = new NameValueCollection
{
{ "password", encryptedPassword64 },
{ "username", username },
{ "twofactorcode", this.Authenticator.CurrentCode },
//data.Add("emailauth", string.Empty);
{ "loginfriendlyname", "#login_emailauth_friendlyname_mobile" },
{ "captchagid", (string.IsNullOrEmpty(captchaId) == false ? captchaId : "-1") },
{ "captcha_text", (string.IsNullOrEmpty(captchaText) == false ? captchaText : "enter above characters") },
//data.Add("emailsteamid", (string.IsNullOrEmpty(emailcode) == false ? this.SteamId ?? string.Empty : string.Empty));
{ "rsatimestamp", rsaresponse.SelectToken("timestamp").Value<string>() },
{ "remember_login", "false" },
{ "oauth_client_id", "DE45CD61" },
{ "oauth_scope", "read_profile write_profile read_client write_client" },
{ "donotache", new DateTime().ToUniversalTime().Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds.ToString() }
};
response = GetString(COMMUNITY_BASE + "/mobilelogin/dologin/", "POST", data);
Dictionary<string, object> loginresponse = JsonConvert.DeserializeObject<Dictionary<string, object>>(response);

Expand Down Expand Up @@ -641,9 +644,11 @@ public void Logout()

if (string.IsNullOrEmpty(this.Session.UmqId) == false)
{
var data = new NameValueCollection();
data.Add("access_token", this.Session.OAuthToken);
data.Add("umqid", this.Session.UmqId);
var data = new NameValueCollection
{
{ "access_token", this.Session.OAuthToken },
{ "umqid", this.Session.UmqId }
};
GetString(API_LOGOFF, "POST", data);
}
}
Expand Down
20 changes: 14 additions & 6 deletions source/SteamTool.Steam.Service/Web/SteamDbApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,34 @@ public class SteamDbApiService
public async Task<SteamUser> GetUserInfo(long steamId64)
{
var r = await httpServices.Get(string.Format(Const.STEAMDB_USERINFO_URL, steamId64));
var userInfo = JsonConvert.DeserializeObject<SteamUser>(r);
return userInfo;
if (!string.IsNullOrEmpty(r))
{
var userInfo = JsonConvert.DeserializeObject<SteamUser>(r);
return userInfo;
}
return new SteamUser() { SteamId64 = steamId64 };
}

public async Task<List<SteamUser>> GetUserInfo(long[] steamId64s)
{
var users = new List<SteamUser>();
foreach (var i in steamId64s)
foreach (var i in steamId64s)
{
users.Add(await GetUserInfo(i));
}
return users;
}


public async Task<SteamApp> GetAppInfo(long appId)
public async Task<SteamApp> GetAppInfo(int appId)
{
var r = await httpServices.Get(string.Format(Const.STEAMDB_APPINFO_URL, appId));
var steamApp = JsonConvert.DeserializeObject<SteamApp>(r);
return steamApp;
if (!string.IsNullOrEmpty(r))
{
var steamApp = JsonConvert.DeserializeObject<SteamApp>(r);
return steamApp;
}
return new SteamApp() { AppId = (uint)appId };
}

}
Expand Down
2 changes: 1 addition & 1 deletion source/SteamTools/Services/ResourceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void ChangeCulture(string name)

public string GetCurrentCultureSteamLanguageName()
{
return supportedCultureSteamNames[SteamTools.Properties.Resources.Culture.Name];
return Resources.Culture == null ? supportedCultureSteamNames.First().Value : supportedCultureSteamNames[Resources.Culture.Name];
}
}
}
2 changes: 1 addition & 1 deletion source/SteamTools/SteamTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

<PackageId />

<Version>1.1.0</Version>
<Version>1.0.5</Version>

<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
</PropertyGroup>
Expand Down
40 changes: 39 additions & 1 deletion source/SteamTools/ViewModels/Page/SteamIdlePageViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using SteamTool.Model;
using SteamTools.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

Expand All @@ -15,5 +18,40 @@ public override string Name
protected set { throw new NotImplementedException(); }
}

public void ExtractSteamCookies()
{
var login_url = new Uri(Const.STEAM_LOGIN_URL);
var container = WinInet.GetUriCookieContainer(login_url);
var cookies = container.GetCookies(login_url);

foreach (Cookie cookie in cookies)
{
//if (cookie.Name == "sessionid")
//{
// steam.Session.Cookies.Add(login_url, cookie);
//}
//else if (cookie.Name == "steamLogin")
//{
// steam.Session.Cookies.Add(login_url, cookie);
// //Settings.Default.steamLogin = cookie.Value;
// //Settings.Default.myProfileURL = SteamProfile.GetSteamUrl();
//}
//else if (cookie.Name == "steamLoginSecure")
//{
// steam.Session.Cookies.Add(login_url, cookie);
// //Settings.Default.myProfileURL = SteamProfile.GetSteamUrl();
//}
//else if (cookie.Name == "steamparental")
//{
// //Settings.Default.steamparental = cookie.Value;
//}
//else if (cookie.Name == "steamRememberLogin")
//{
// //Settings.Default.steamRememberLogin = cookie.Value;
//}
}


}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public string Text
this._Text = value;
if (!string.IsNullOrEmpty(value))
{
this.Achievements = Achievements.Where(w => w.Name.IndexOf(Text, StringComparison.OrdinalIgnoreCase) > -1).ToList();
this.Achievements = Achievements.Where(w => w.Name.IndexOf(value, StringComparison.OrdinalIgnoreCase) > -1).ToList();
}
else
{
Expand Down Expand Up @@ -172,7 +172,6 @@ private bool LoadUserGameStatsSchema()
return false;
}

//var currentLanguage = SteamConnectService.Current.ApiService.GetCurrentGameLanguage();
var currentLanguage = ResourceService.Current.GetCurrentCultureSteamLanguageName(); ;
var stats = kv[this.AppId.ToString(CultureInfo.InvariantCulture)]["stats"];
if (stats.Valid == false ||
Expand Down
Loading

0 comments on commit d38588d

Please sign in to comment.