/** * Focuses the League client, if it exists. */ public void Focus() { Console.WriteLine("Focusing league"); if (!connected) { return; } LeagueUtils.FocusWindow(processInfo.Item1); }
/** * Tries to connect to a currently running league process. Called * by the connection timer every 5 seconds. */ private void TryConnect(object sender, EventArgs args) { // We're already connected. if (connected) { return; } // Check league status, abort if league is not running. var status = LeagueUtils.GetLeagueStatus(); if (status == null) { return; } // Update local state. leaguePollTimer.Stop(); processInfo = status; connected = true; // Set the password and base address for our httpclient so we don't have to specify it every time. var byteArray = Encoding.ASCII.GetBytes("riot:" + status.Item2); HTTP_CLIENT.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray)); // Connect to our websocket. socketConnection = new WebSocket("wss://127.0.0.1:" + status.Item3 + "/", "wamp"); socketConnection.SetCredentials("riot", status.Item2, true); socketConnection.SslConfiguration.EnabledSslProtocols = SslProtocols.Tls12; socketConnection.SslConfiguration.ServerCertificateValidationCallback = (a, b, c, d) => true; socketConnection.OnMessage += HandleMessage; socketConnection.OnClose += HandleDisconnect; socketConnection.Connect(); // Subscribe to Json API events from the LCU. socketConnection.Send("[5,\"OnJsonApiEvent\"]"); // Emit our events. OnConnected?.Invoke(); }