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 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("usernamepassfail", ErrorType.Password); Disconnect(); } else { Error("Unable to get Auth Key \n" + e, ErrorType.AuthKey); Disconnect(); } return false; } }