record-daemon: refactor and cleanup
This commit is contained in:
@@ -13,18 +13,10 @@ use crate::error::{LqpError, Result};
|
||||
/// League Client lockfile location (relative to League Client install).
|
||||
pub const LOCKFILE_NAME: &str = "lockfile";
|
||||
|
||||
/// Default League Client paths on Linux (via Lutris/Wine).
|
||||
pub const LINUX_CLIENT_PATHS: &[&str] = &[
|
||||
// Lutris default path
|
||||
"$HOME/Games/League of Legends/LeagueClient",
|
||||
// Wine prefix
|
||||
"$HOME/.wine/drive_c/Riot Games/League of Legends/LeagueClient",
|
||||
];
|
||||
|
||||
/// Default League Client paths on Windows.
|
||||
pub const WINDOWS_CLIENT_PATHS: &[&str] = &[
|
||||
"C:\\Riot Games\\League of Legends\\lockfile",
|
||||
"D:\\Riot Games\\League of Legends\\lockfile",
|
||||
"C:\\Riot Games\\League of Legends",
|
||||
"D:\\Riot Games\\League of Legends",
|
||||
];
|
||||
|
||||
/// Credentials extracted from the League Client lockfile.
|
||||
@@ -126,63 +118,16 @@ impl LockfileWatcher {
|
||||
|
||||
/// Discover possible lockfile paths based on OS.
|
||||
fn discover_lockfile_paths() -> Vec<PathBuf> {
|
||||
let mut paths = Vec::new();
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
// Check for Wine/Lutris installations
|
||||
if let Some(home) = std::env::var_os("HOME") {
|
||||
let home_path = PathBuf::from(&home);
|
||||
|
||||
// Lutris default
|
||||
let lutris_path = home_path
|
||||
.join("Games")
|
||||
.join("League of Legends")
|
||||
.join("lockfile");
|
||||
paths.push(lutris_path);
|
||||
|
||||
// Wine prefix
|
||||
let wine_path = home_path
|
||||
.join(".wine")
|
||||
.join("drive_c")
|
||||
.join("Riot Games")
|
||||
.join("League of Legends")
|
||||
.join("lockfile");
|
||||
paths.push(wine_path);
|
||||
|
||||
// Proton (Steam)
|
||||
let proton_path = home_path
|
||||
.join(".local")
|
||||
.join("share")
|
||||
.join("Steam")
|
||||
.join("steamapps")
|
||||
.join("compatdata")
|
||||
.join("League of Legends")
|
||||
.join("pfx")
|
||||
.join("drive_c")
|
||||
.join("Riot Games")
|
||||
.join("League of Legends")
|
||||
.join("lockfile");
|
||||
paths.push(proton_path);
|
||||
}
|
||||
// For now, League of Legends is not available on Linux.
|
||||
// There is no point in trying to locate the client.
|
||||
if cfg!(target_os = "windows") {
|
||||
WINDOWS_CLIENT_PATHS
|
||||
.iter()
|
||||
.map(|s| PathBuf::from(s).join(LOCKFILE_NAME))
|
||||
.collect()
|
||||
} else {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
// Default Windows paths
|
||||
paths.push(PathBuf::from("C:\\Riot Games\\League of Legends\\lockfile"));
|
||||
paths.push(PathBuf::from("D:\\Riot Games\\League of Legends\\lockfile"));
|
||||
|
||||
// Check Program Files
|
||||
paths.push(PathBuf::from(
|
||||
"C:\\Program Files\\Riot Games\\League of Legends\\lockfile",
|
||||
));
|
||||
paths.push(PathBuf::from(
|
||||
"C:\\Program Files (x86)\\Riot Games\\League of Legends\\lockfile",
|
||||
));
|
||||
}
|
||||
|
||||
paths
|
||||
}
|
||||
|
||||
/// Check if the League Client is currently running.
|
||||
|
||||
@@ -10,7 +10,7 @@ use tokio_tungstenite::{connect_async_tls_with_config, tungstenite::protocol::Me
|
||||
use tracing::{debug, error, info, trace, warn};
|
||||
|
||||
use super::auth::LockfileCredentials;
|
||||
use super::events::GameEvent;
|
||||
use super::events::{GameEvent, RawEvent};
|
||||
use crate::error::{LqpError, Result};
|
||||
|
||||
/// Custom certificate verifier that accepts any certificate.
|
||||
@@ -385,7 +385,22 @@ impl LqpClient {
|
||||
let event_data = arr.get(2)?;
|
||||
|
||||
if callback == "OnJsonApiEvent" {
|
||||
// Extract the actual URI and data from the event
|
||||
// Try to parse as RawEvent for type-safe access
|
||||
if let Ok(raw_event) =
|
||||
serde_json::from_value::<RawEvent>(event_data.clone())
|
||||
{
|
||||
let event_type = event_data
|
||||
.get("eventType")
|
||||
.and_then(|t| t.as_str())
|
||||
.unwrap_or("Update");
|
||||
return Self::parse_event_from_uri(
|
||||
&raw_event.uri,
|
||||
event_type,
|
||||
&serde_json::to_value(raw_event.data).unwrap_or_default(),
|
||||
);
|
||||
}
|
||||
|
||||
// Fallback to manual extraction
|
||||
let uri = event_data.get("uri")?.as_str()?;
|
||||
let data = event_data.get("data")?;
|
||||
let event_type = event_data
|
||||
@@ -582,6 +597,16 @@ impl LqpClient {
|
||||
pub async fn get_summoner(&self) -> Result<serde_json::Value> {
|
||||
self.request("GET", endpoints::SUMMONER).await
|
||||
}
|
||||
|
||||
/// Get champion select session info.
|
||||
pub async fn get_champion_select(&self) -> Result<serde_json::Value> {
|
||||
self.request("GET", endpoints::CHAMPION_SELECT).await
|
||||
}
|
||||
|
||||
/// Get end-of-game stats.
|
||||
pub async fn get_game_stats(&self) -> Result<serde_json::Value> {
|
||||
self.request("GET", endpoints::GAME_STATS).await
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for LqpClient {
|
||||
|
||||
Reference in New Issue
Block a user