-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: removed lockfile authentication
- Loading branch information
Showing
9 changed files
with
711 additions
and
292 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use lazy_static::lazy_static; | ||
|
||
const LCU_PORT_KEY: &str = "--app-port="; | ||
const LCU_TOKEN_KEY: &str = "--remoting-auth-token="; | ||
const LCU_DIR_KEY: &str = "--install-directory="; | ||
const LCU_COMMAND: &str = "Get-CimInstance Win32_Process -Filter \"name = 'LeagueClientUx.exe'\" | Select-Object -ExpandProperty CommandLine"; | ||
|
||
lazy_static! { | ||
static ref PORT_REGEXP: regex::Regex = regex::Regex::new(r"--app-port=\d+").unwrap(); | ||
static ref TOKEN_REGEXP: regex::Regex = regex::Regex::new(r"--remoting-auth-token=\S+").unwrap(); | ||
static ref DIR_REGEXP: regex::Regex = regex::Regex::new(r#"--install-directory=(.*?)""#).unwrap(); | ||
static ref MAC_DIR_REGEXP: regex::Regex = regex::Regex::new(r"--install-directory=([^\s]+).*?--").unwrap(); | ||
} | ||
|
||
#[derive(Default, Debug, Clone, Serialize, Deserialize)] | ||
pub struct CommandLineOutput { | ||
pub auth_url: String, | ||
pub token: String, | ||
pub port: String, | ||
pub dir: String, | ||
} | ||
|
||
#[cfg(target_os = "windows")] | ||
pub fn get_commandline() -> CommandLineOutput { | ||
use powershell_script::PsScriptBuilder; | ||
|
||
let ps = PsScriptBuilder::new() | ||
.no_profile(true) | ||
.non_interactive(true) | ||
.hidden(true) | ||
.print_commands(false) | ||
.build(); | ||
|
||
match ps.run(LCU_COMMAND) { | ||
Ok(out) => { | ||
let output = out.stdout(); | ||
|
||
if output.is_some() { | ||
return match_stdout(&String::from(output.unwrap())); | ||
} | ||
} | ||
Err(err) => println!("cmd error: {:?}", err), | ||
} | ||
|
||
CommandLineOutput { | ||
..Default::default() | ||
} | ||
} | ||
|
||
fn match_stdout(stdout: &str) -> CommandLineOutput { | ||
let port = if let Some(port_match) = PORT_REGEXP.find(stdout) { | ||
port_match.as_str().replace(LCU_PORT_KEY, "") | ||
} else { | ||
"0".to_string() | ||
}; | ||
|
||
let token = if let Some(token_match) = TOKEN_REGEXP.find(stdout) { | ||
token_match | ||
.as_str() | ||
.replace(LCU_TOKEN_KEY, "") | ||
.replace(['\\', '\"'], "") | ||
} else { | ||
"".to_string() | ||
}; | ||
|
||
let auth_url = make_auth_url(&token, &port); | ||
|
||
let raw_dir = if let Some(dir_match) = DIR_REGEXP.find(stdout) { | ||
dir_match.as_str().replace(LCU_DIR_KEY, "") | ||
} else { | ||
"".to_string() | ||
}; | ||
let output_dir = raw_dir.replace('\"', ""); | ||
let dir = format!("{output_dir}/"); | ||
|
||
CommandLineOutput { | ||
auth_url, | ||
token, | ||
port, | ||
dir, | ||
} | ||
} | ||
|
||
fn make_auth_url(token: &String, port: &String) -> String { | ||
format!("https://riot:{token}@127.0.0.1:{port}") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use std::time::Duration; | ||
use lazy_static::lazy_static; | ||
|
||
lazy_static! { | ||
static ref CLIENT: reqwest::blocking::Client = { | ||
reqwest::blocking::Client::builder() | ||
.use_rustls_tls() | ||
.danger_accept_invalid_certs(true) | ||
.timeout(Duration::from_secs(2)) | ||
.no_proxy() | ||
.build() | ||
.unwrap() | ||
}; | ||
} | ||
|
||
pub fn make_client() -> &'static reqwest::blocking::Client { | ||
&CLIENT | ||
} | ||
|
||
pub fn accept_match(endpoint: &str) { | ||
let client = make_client(); | ||
let url = format!("{endpoint}/lol-matchmaking/v1/ready-check/accept"); | ||
let _ = client | ||
.post(url) | ||
.version(reqwest::Version::HTTP_2) | ||
.header(reqwest::header::ACCEPT, "application/json") | ||
.send(); | ||
} | ||
|
||
pub fn get_phase(endpoint: &str) -> String { | ||
let mut phase = String::from("Unknown"); | ||
let url = format!("{endpoint}/lol-gameflow/v1/gameflow-phase"); | ||
let client = make_client(); | ||
let response = client | ||
.get(url) | ||
.version(reqwest::Version::HTTP_2) | ||
.header(reqwest::header::ACCEPT, "application/json") | ||
.send() | ||
.ok(); | ||
if let Some(response) = response { | ||
phase = response.text().unwrap_or(phase); | ||
phase = phase.trim_matches('"').to_string(); | ||
} | ||
phase | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,50 @@ | ||
#![windows_subsystem = "windows"] | ||
|
||
mod accept; | ||
mod cmd; | ||
mod lcu; | ||
mod tray; | ||
|
||
use accept::Acceptor; | ||
use tray::TrayApp; | ||
use std::sync::Arc; | ||
use std::sync::atomic::{AtomicBool, Ordering}; | ||
use std::thread; | ||
use std::time::Duration; | ||
|
||
use crate::tray::TrayApp; | ||
|
||
fn main() { | ||
let mut app = TrayApp::new(Acceptor::new()); | ||
app.run(); | ||
let pause = Arc::new(AtomicBool::new(false)); | ||
let pause_clone = Arc::clone(&pause); | ||
let terminate = Arc::new(AtomicBool::new(false)); | ||
let terminate_clone = Arc::clone(&terminate); | ||
|
||
// Start Acceptor | ||
let mut auth = cmd::get_commandline(); | ||
thread::spawn(move || { | ||
while !terminate.load(Ordering::SeqCst) { | ||
if !pause.load(Ordering::SeqCst) && !auth.auth_url.is_empty() { | ||
match lcu::get_phase(&auth.auth_url).as_str() { | ||
"Lobby" => { | ||
thread::sleep(Duration::from_millis(1000)); | ||
continue; | ||
} | ||
"Matchmaking" => { | ||
thread::sleep(Duration::from_millis(300)); | ||
continue; | ||
} | ||
"ReadyCheck" => { | ||
lcu::accept_match(&auth.auth_url); | ||
thread::sleep(Duration::from_millis(1000)); | ||
continue; | ||
} | ||
_ => {}, | ||
} | ||
} | ||
auth = cmd::get_commandline(); | ||
thread::sleep(Duration::from_millis(5000)); | ||
} | ||
}); | ||
|
||
// Start Tray Icon | ||
let mut icon = TrayApp::new(); | ||
icon.show(pause_clone, terminate_clone); | ||
} |
Oops, something went wrong.