Skip to content

Commit

Permalink
Do not hardcode account id, fixes #205
Browse files Browse the repository at this point in the history
  • Loading branch information
aknarts committed Jul 30, 2022
1 parent 34267ef commit 9a416c1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
34 changes: 30 additions & 4 deletions src/tools/epic_web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct RedirectResponse {
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EULAResponse {
pub errors: Option<Vec<Error>>,
pub data: Data,
}

Expand All @@ -34,7 +35,17 @@ pub struct Data {
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Eula {
pub has_account_accepted: HasAccountAccepted,
pub has_account_accepted: Option<HasAccountAccepted>,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Error {
pub message: String,
pub correlation_id: String,
pub service_response: String,
pub stack: Value,
pub path: Option<Vec<String>>,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -124,9 +135,11 @@ impl EpicWeb {
};
}

pub fn validate_eula(&self) -> bool {
pub fn validate_eula(&self, id: String) -> bool {
let mut map = HashMap::new();
map.insert("query", "{ Eula { hasAccountAccepted(id: \"unreal_engine\", locale: \"en\", accountId: \"8645b4947bbc4c0092a8b7236df169d1\"){ accepted key locale version } }}");
let query= vec!["{ Eula { hasAccountAccepted(id: \"unreal_engine\", locale: \"en\", accountId: \"", &id, "\"){ accepted key locale version } }}"];
map.insert("query", query.join(""));
println!("Params: {:?}", map);
match self
.client
.post("https://graphql.unrealengine.com/ue/graphql")
Expand All @@ -140,7 +153,20 @@ impl EpicWeb {
match r.text() {
Ok(t) => match serde_json::from_str::<EULAResponse>(&t) {
Ok(eula) => {
return eula.data.eula.has_account_accepted.accepted;
return match eula.data.eula.has_account_accepted {
None => {
match eula.errors {
None => {}
Some(errors) => {
for error in errors {
error!("Failed to query EULA status: {} with response: {}", error.message, error.service_response)
}
}
}
false
}
Some(accepted) => accepted.accepted,
};
}
Err(e) => {
error!("Failed to parse EULA json: {}", e);
Expand Down
11 changes: 10 additions & 1 deletion src/ui/widgets/logged_in/engines/epic_download.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::gio::glib::Sender;
use crate::tools::epic_web::EpicWeb;
use crate::ui::widgets::download_manager::epic_file::EpicFile;
use egs_api::api::types::account::AccountData;
use gtk4::glib::{clone, MainContext, PRIORITY_DEFAULT};
use gtk4::subclass::prelude::*;
use gtk4::{self, gio, prelude::*};
Expand All @@ -9,6 +10,7 @@ use gtk_macros::{action, get_action};
use regex::Regex;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::future::Future;
use std::thread;
use version_compare::Cmp;

Expand Down Expand Up @@ -366,14 +368,21 @@ impl EpicEngineDownload {
let win_ = window.imp();
let mut eg = win_.model.borrow().epic_games.borrow().clone();
let sender = self_.sender.clone();
let id = match eg.user_details().account_id {
None => {
sender.send(Msg::EULAValid(false)).unwrap();
return;
}
Some(i) => i,
};
thread::spawn(move || {
if let Some(token) = tokio::runtime::Runtime::new()
.unwrap()
.block_on(eg.game_token())
{
let mut web = EpicWeb::new();
web.start_session(token.code);
sender.send(Msg::EULAValid(web.validate_eula())).unwrap();
sender.send(Msg::EULAValid(web.validate_eula(id))).unwrap();
};
});
}
Expand Down

0 comments on commit 9a416c1

Please sign in to comment.