private bool GetIpAddress() { try { StringBuilder sb = new StringBuilder(); WebRequest con = WebRequest.Create("http://ll.leagueoflegends.com/services/connection_info"); WebResponse response = con.GetResponse(); int c; while ((c = response.GetResponseStream().ReadByte()) != -1) { sb.Append((char)c); } con.Abort(); TypedObject result = serializer.Deserialize <TypedObject>(sb.ToString()); ipAddress = result.GetString("ip_address"); return(true); } catch (Exception e) { Error("Unable to connect to Riot Games web server \n" + e.Message, ErrorType.General); Disconnect(); return(false); } }
private bool Login() { TypedObject result, body; // Login 1 body = new TypedObject("com.riotgames.platform.login.AuthenticationCredentials"); body.Add("password", password); body.Add("clientVersion", clientVersion); body.Add("ipAddress", ipAddress); body.Add("securityAnswer", null); body.Add("locale", locale); body.Add("domain", "lolclient.lol.riotgames.com"); body.Add("oldPassword", null); body.Add("authToken", authToken); if (useGarena) { body.Add("partnerCredentials", "8393 " + garenaToken); body.Add("username", userID); } else { body.Add("partnerCredentials", null); body.Add("username", user); } int id = Invoke("loginService", "login", new object[] { body }); result = GetResult(id); if (result["result"].Equals("_error")) { Error(GetErrorMessage(result), ErrorType.Login); Disconnect(); return false; } body = result.GetTO("data").GetTO("body"); sessionToken = body.GetString("token"); accountID = (int)body.GetTO("accountSummary").GetInt("accountId"); // Login 2 if (useGarena) body = WrapBody(Convert.ToBase64String(Encoding.UTF8.GetBytes(userID + ":" + sessionToken)), "auth", 8); else body = WrapBody(Convert.ToBase64String(Encoding.UTF8.GetBytes(user.ToLower() + ":" + sessionToken)), "auth", 8); body.type = "flex.messaging.messages.CommandMessage"; id = Invoke(body); result = GetResult(id); // Read result (and discard) isLoggedIn = true; if (OnLogin != null) OnLogin(this, user, ipAddress); return true; }
private bool GetAuthKey() { try { StringBuilder sb = new StringBuilder(); string payload = ""; string query = ""; if (useGarena) { payload = reToken(garenaToken); query = "payload=8393%20" + payload; } else { payload = "user="******",password="******"payload=" + payload; } WebRequest con = WebRequest.Create(loginQueue + "login-queue/rest/queue/authenticate"); con.Method = "POST"; Stream outputStream = con.GetRequestStream(); outputStream.Write(Encoding.ASCII.GetBytes(query), 0, Encoding.ASCII.GetByteCount(query)); WebResponse webresponse = con.GetResponse(); Stream inputStream = webresponse.GetResponseStream(); int c; while ((c = inputStream.ReadByte()) != -1) { sb.Append((char)c); } TypedObject result = serializer.Deserialize <TypedObject>(sb.ToString()); outputStream.Close(); inputStream.Close(); con.Abort(); /*if (!result.ContainsKey("token")) * { * int node = (int)result.GetInt("node"); * string champ = result.GetString("champ"); * int rate = (int)result.GetInt("rate"); * int delay = (int)result.GetInt("delay"); * * int id = 0; * int cur = 0; * * object[] tickers = result.GetArray("tickers"); * foreach (object o in tickers) * { * Dictionary<string, object> to = (Dictionary<string, object>)o; * * int tnode = (int)to["node"]; * if (tnode != node) * continue; * * id = (int)to["id"]; * cur = (int)to["current"]; * break; * } * * /* while (id - cur > rate) * { * sb.Clear(); * if (OnLoginQueueUpdate != null) * OnLoginQueueUpdate(this, id - cur); * * Thread.Sleep(delay); * con = WebRequest.Create(loginQueue + "login-queue/rest/queue/ticker/" + champ); * con.Method = "GET"; * webresponse = con.GetResponse(); * inputStream = webresponse.GetResponseStream(); * * int d; * while ((d = inputStream.ReadByte()) != -1) * sb.Append((char)d); * * result = serializer.Deserialize<TypedObject>(sb.ToString()); * * inputStream.Close(); * con.Abort(); * * if (result == null) * continue; * * cur = HexToInt(result.GetString(node.ToString())); * } */ /*while (sb.ToString() == null || !result.ContainsKey("token")) * { * try * { * sb.Clear(); * * if (id - cur < 0) * if (OnLoginQueueUpdate != null) * OnLoginQueueUpdate(this, 0); * else if (OnLoginQueueUpdate != null) * OnLoginQueueUpdate(this, id - cur); * * Thread.Sleep(delay / 10); * con = WebRequest.Create(loginQueue + "login-queue/rest/queue/authToken/" + user.ToLower()); * con.Method = "GET"; * webresponse = con.GetResponse(); * inputStream = webresponse.GetResponseStream(); * * int f; * while ((f = inputStream.ReadByte()) != -1) * sb.Append((char)f); * * result = serializer.Deserialize<TypedObject>(sb.ToString()); * * inputStream.Close(); * con.Abort(); * } * catch * { * } * } * }*/ if (OnLoginQueueUpdate != null) { OnLoginQueueUpdate(this, 0); } authToken = result.GetString("token"); userID = result.GetString("user"); Gas = sb.ToString(); return(true); } catch (Exception e) { if (e.Message == "The remote name could not be resolved: '" + loginQueue + "'") { Error("Please make sure you are connected the internet!", ErrorType.AuthKey); Disconnect(); } else if (e.Message == "The remote server returned an error: (403) Forbidden.") { Error("Your username or password is incorrect!", ErrorType.Password); Disconnect(); } else if (e.Message == "The given key was not present in the dictionary.") { Error("The given key was not present in the dictionary. Client version is wrong maybe?", ErrorType.AuthKey); Disconnect(); } else { Error("Unable to get Auth Key \n" + e, ErrorType.AuthKey); Disconnect(); } return(false); } }
private bool GetAuthKey() { try { StringBuilder sb = new StringBuilder(); string payload = "user="******",password="******"payload=" + payload; if (useGarena) { payload = reToken(garenaToken); query = "payload=8393%20" + payload; } WebRequest con = WebRequest.Create(loginQueue + "login-queue/rest/queue/authenticate"); con.Method = "POST"; Stream outputStream = con.GetRequestStream(); outputStream.Write(Encoding.ASCII.GetBytes(query), 0, Encoding.ASCII.GetByteCount(query)); WebResponse webresponse = con.GetResponse(); Stream inputStream = webresponse.GetResponseStream(); int c; while ((c = inputStream.ReadByte()) != -1) { sb.Append((char)c); } TypedObject result = serializer.Deserialize <TypedObject>(sb.ToString()); outputStream.Close(); inputStream.Close(); con.Abort(); if (!result.ContainsKey("token")) { int node = (int)result.GetInt("node"); string champ = result.GetString("champ"); int rate = (int)result.GetInt("rate"); int delay = (int)result.GetInt("delay"); int id = 0; int cur = 0; object[] tickers = result.GetArray("tickers"); foreach (object o in tickers) { Dictionary <string, object> to = (Dictionary <string, object>)o; int tnode = (int)to["node"]; if (tnode != node) { continue; } id = (int)to["id"]; cur = (int)to["current"]; break; } while (id - cur > rate) { sb.Clear(); if (OnLoginQueueUpdate != null) { OnLoginQueueUpdate(this, id - cur); } con = WebRequest.Create(loginQueue + "login-queue/rest/queue/ticker/" + champ); con.Method = "GET"; webresponse = con.GetResponse(); inputStream = webresponse.GetResponseStream(); int d; while ((d = inputStream.ReadByte()) != -1) { sb.Append((char)d); } result = serializer.Deserialize <TypedObject>(sb.ToString()); inputStream.Close(); con.Abort(); if (result == null) { continue; } cur = HexToInt(result.GetString(node.ToString())); } while (sb.ToString() == null || !result.ContainsKey("token")) { sb.Clear(); if (id - cur < 0) { if (OnLoginQueueUpdate != null) { OnLoginQueueUpdate(this, 0); } else if (OnLoginQueueUpdate != null) { OnLoginQueueUpdate(this, id - cur); } } con = WebRequest.Create(loginQueue + "login-queue/rest/queue/authToken/" + user.ToLower()); con.Method = "GET"; try { using (WebResponse nWebresponse = con.GetResponse()) { using (Stream nInputStream = nWebresponse.GetResponseStream()) { int f; while ((f = nInputStream.ReadByte()) != -1) { sb.Append((char)f); } result = serializer.Deserialize <TypedObject>(sb.ToString()); } } } catch (WebException e) { if (e.Status == WebExceptionStatus.ProtocolError && e.Response != null) { var response = (HttpWebResponse)e.Response; if (response.StatusCode == HttpStatusCode.NotFound) { Thread.Sleep(50); continue; } else { Debug.WriteLine(e.Message); } } } inputStream.Close(); con.Abort(); } } if (OnLoginQueueUpdate != null) { OnLoginQueueUpdate(this, 0); } authToken = result.GetString("token"); if (useGarena) { userID = result.GetString("token"); } return(true); } catch (Exception e) { if (e.Message == "The remote name could not be resolved: '" + loginQueue + "'") { Error("Please make sure you are connected the internet!", ErrorType.AuthKey); Disconnect(); } else if (e.Message == "The remote server returned an error: (403) Forbidden.") { Error("Your username or password is incorrect!", ErrorType.Password); Disconnect(); } else if (e.Message == "The given key was not present in the dictionary.") { Error("The given key was not present in the dictionary. Client version is wrong maybe?", ErrorType.AuthKey); Disconnect(); } else { Error("Unable to get Auth Key \n" + e, ErrorType.AuthKey); Disconnect(); } return(false); } }
private bool GetAuthKey() { try { StringBuilder sb = new StringBuilder(); string payload = "user="******",password="******"payload=" + payload; if (useGarena) payload = garenaToken; WebRequest con = WebRequest.Create(loginQueue + "login-queue/rest/queue/authenticate"); con.Method = "POST"; Stream outputStream = con.GetRequestStream(); outputStream.Write(Encoding.ASCII.GetBytes(query), 0, Encoding.ASCII.GetByteCount(query)); WebResponse webresponse = con.GetResponse(); Stream inputStream = webresponse.GetResponseStream(); int c; while ((c = inputStream.ReadByte()) != -1) sb.Append((char)c); TypedObject result = serializer.Deserialize<TypedObject>(sb.ToString()); outputStream.Close(); inputStream.Close(); con.Abort(); if (!result.ContainsKey("token")) { int node = (int)result.GetInt("node"); string champ = result.GetString("champ"); int rate = (int)result.GetInt("rate"); int delay = (int)result.GetInt("delay"); int id = 0; int cur = 0; object[] tickers = result.GetArray("tickers"); foreach (object o in tickers) { Dictionary<string, object> to = (Dictionary<string, object>)o; int tnode = (int)to["node"]; if (tnode != node) continue; id = (int)to["id"]; cur = (int)to["current"]; break; } while (id - cur > rate) { sb.Clear(); if (OnLoginQueueUpdate != null) OnLoginQueueUpdate(this, id - cur); Thread.Sleep(delay); con = WebRequest.Create(loginQueue + "login-queue/rest/queue/ticker/" + champ); con.Method = "GET"; webresponse = con.GetResponse(); inputStream = webresponse.GetResponseStream(); int d; while ((d = inputStream.ReadByte()) != -1) sb.Append((char)d); result = serializer.Deserialize<TypedObject>(sb.ToString()); inputStream.Close(); con.Abort(); if (result == null) continue; cur = HexToInt(result.GetString(node.ToString())); } while (sb.ToString() == null || !result.ContainsKey("token")) { try { sb.Clear(); if (id - cur < 0) if (OnLoginQueueUpdate != null) OnLoginQueueUpdate(this, 0); else if (OnLoginQueueUpdate != null) OnLoginQueueUpdate(this, id - cur); Thread.Sleep(delay / 10); con = WebRequest.Create(loginQueue + "login-queue/rest/queue/authToken/" + user.ToLower()); con.Method = "GET"; webresponse = con.GetResponse(); inputStream = webresponse.GetResponseStream(); int f; while ((f = inputStream.ReadByte()) != -1) sb.Append((char)f); result = serializer.Deserialize<TypedObject>(sb.ToString()); inputStream.Close(); con.Abort(); } catch { } } } if (OnLoginQueueUpdate != null) OnLoginQueueUpdate(this, 0); authToken = result.GetString("token"); return true; } catch (Exception e) { if (e.Message == "The remote name could not be resolved: '" + loginQueue + "'") { Error("Please make sure you are connected the internet!", ErrorType.AuthKey); Disconnect(); } else if (e.Message == "The remote server returned an error: (403) Forbidden.") { Error("Your username or password is incorrect!", ErrorType.Password); Disconnect(); } else { Error("Unable to get Auth Key", ErrorType.AuthKey); Disconnect(); } return false; } }