Skip to content

Commit

Permalink
Fix: map downloader invalid login detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotrekol committed Nov 3, 2019
1 parent fd89139 commit 90b397f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace System.Net
public class CookieAwareWebClient : WebClient
{
public int ClientId = -1;
public string Login(string loginPageAddress, string loginData)
public bool Login(string loginPageAddress, string loginData)
{
var homePageRequest = (HttpWebRequest)WebRequest.Create("https://osu.ppy.sh/home");
homePageRequest.CookieContainer = CookieContainer;
Expand All @@ -31,15 +31,28 @@ public string Login(string loginPageAddress, string loginData)
var requestStream = request.GetRequestStream();
requestStream.Write(buffer, 0, buffer.Length);
requestStream.Close();

var response = request.GetResponse();
string ResponseText = "";
WebResponse response = null;
try
{
response = request.GetResponse();
}
catch (WebException e)
{
if (e.Response is HttpWebResponse resp && resp.StatusCode.GetHashCode() == 422)
{
return false;
}

throw;
}

string responseText;
using (StreamReader sr = new StreamReader(response.GetResponseStream()))
{
ResponseText = sr.ReadToEnd();
responseText = sr.ReadToEnd();
}
response.Close();
return ResponseText;
return !(responseText.IndexOf("Log me on automatically each visit", StringComparison.InvariantCultureIgnoreCase) > 0);
}

public CookieAwareWebClient(CookieContainer container)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public bool Login(LoginData loginData)
var client = this.Clients.Dequeue();
if (i == clientCount)
{
var response = client.Login(loginAddress, loginDataStr);
if (response.IndexOf("Log me on automatically each visit", StringComparison.InvariantCultureIgnoreCase) > 0)
if (!client.Login(loginAddress, loginDataStr))
return false;

cookies = client.CookieContainer;
}
else
Expand Down

0 comments on commit 90b397f

Please sign in to comment.