CI / core (pull_request) Successful in 1m50s
- The core reads the champion played in the client's gameflow session (champion selections, else the teams, by the summoner's client PUUID) and follows the Live Match from one read to the next: it starts with an Arena game in progress and lasts through that game's end-of-game screen. - The follower tells the page the Live Match on each change, before the champ select's end, so the end of a champ select that launched a game shows « En partie » instead of « Défi », without computing the statistics again. - « En partie »: the banner with the champion's splash, the Season and the count, its tick of the ring lit and the stake (« Un top 1 validerait X : 88 / 172 », or the day it was validated); « Champion en cours d’identification » until the client says it. Under it, the card's sheet and the champion's 5 latest Matches of the Season, read at low priority. - A Live Match is a phase like the champ select: the signed-in Account and the current Season, the Account selector greyed, « Paramètres » closed, and a minimised or hidden window shown again without the focus, never raised. - Its end-of-game block ends it and #129 decides the screen; without a block, the lobby shows « Défi ». A screen gone with its tab falls back to « Défi ». - Tests with the simulated client: launch from the champ select, a client met in a game, the champion identified late, the end with and without a block, a game outside Arena. docs/interface.md and the guide are updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0192He3BEKJ9v922udzup4Qn
290 lines
10 KiB
Rust
290 lines
10 KiB
Rust
use super::*;
|
|
|
|
/// The id of the Arena game in the recorded in-game session of the client.
|
|
pub fn recorded_game_id() -> u64 {
|
|
let session: Value = serde_json::from_str(include_str!(
|
|
"../fixtures/client/gameflow_session_in_game.json"
|
|
))
|
|
.unwrap();
|
|
session["gameData"]["gameId"].as_u64().unwrap()
|
|
}
|
|
|
|
/// The game client, driven by the test between rounds.
|
|
#[derive(Clone, Default)]
|
|
pub struct FakeClient {
|
|
state: Arc<Mutex<ClientState>>,
|
|
/// Session and champion-list bodies the fake's champ select reader asked for.
|
|
session_reads: Arc<AtomicUsize>,
|
|
list_reads: Arc<AtomicUsize>,
|
|
}
|
|
|
|
#[derive(Default)]
|
|
struct ClientState {
|
|
signed_in: Option<(String, String)>,
|
|
gameflow: Gameflow,
|
|
tracks: HashMap<String, u32>,
|
|
waits: Vec<Duration>,
|
|
/// The raw bodies the client answers for the current champ select.
|
|
champ_select: Option<RawChampSelect>,
|
|
/// Reads the champ select the one way the live client does.
|
|
champ_select_reader: ChampSelectReader,
|
|
/// Session bodies the client reports as events, applied before `wait_for_event` returns.
|
|
events: VecDeque<Value>,
|
|
/// A raw gameflow body, replayed through the same parser as the live client.
|
|
raw_gameflow: Option<String>,
|
|
gameflow_error: Option<ClientError>,
|
|
champ_select_error: Option<ClientError>,
|
|
/// The client's PUUID of the signed-in summoner.
|
|
summoner_puuid: Option<String>,
|
|
/// The end-of-game block an event delivered, until a round takes it.
|
|
end_of_game_event: Option<EndOfGameBlock>,
|
|
/// What the end-of-game block route answers; `None` is a 404.
|
|
end_of_game_route: Option<String>,
|
|
end_of_game_reads: usize,
|
|
}
|
|
|
|
/// The raw client responses of a champ select, replayed through the same reader as the live
|
|
/// client.
|
|
#[derive(Clone)]
|
|
pub struct RawChampSelect {
|
|
pub pickable: String,
|
|
pub disabled: String,
|
|
/// `None` when the client's anvil list request fails.
|
|
pub anvil: Option<String>,
|
|
pub session: String,
|
|
}
|
|
|
|
impl ClientState {
|
|
/// A block with who is signed in now.
|
|
fn owned_block(&self, content: String) -> EndOfGameBlock {
|
|
EndOfGameBlock {
|
|
content,
|
|
client_puuid: self.summoner_puuid.clone(),
|
|
signed_in_riot_id: (self.signed_in.as_ref())
|
|
.map(|(name, tag)| arena_tracker_core::riot_id(name, tag)),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl FakeClient {
|
|
/// A client that is not running.
|
|
pub fn absent() -> FakeClient {
|
|
FakeClient::default()
|
|
}
|
|
|
|
/// Signed in as the recorded Account, with what the real client answered.
|
|
pub fn recorded() -> FakeClient {
|
|
let client = FakeClient::default();
|
|
let summoner: Value =
|
|
serde_json::from_str(include_str!("../fixtures/client/current_summoner.json")).unwrap();
|
|
client.sign_in(
|
|
summoner["gameName"].as_str().unwrap(),
|
|
summoner["tagLine"].as_str().unwrap(),
|
|
);
|
|
client.set_summoner_puuid(summoner["puuid"].as_str());
|
|
let phase: String =
|
|
serde_json::from_str(include_str!("../fixtures/client/gameflow_phase_none.json"))
|
|
.unwrap();
|
|
client.set_phase(&phase, false);
|
|
let groups: Vec<Value> = serde_json::from_str(include_str!(
|
|
"../fixtures/client/progression_groups_configuration.json"
|
|
))
|
|
.unwrap();
|
|
let instance: Value = serde_json::from_str(include_str!(
|
|
"../fixtures/client/progression_instance_data.json"
|
|
))
|
|
.unwrap();
|
|
let group = groups
|
|
.iter()
|
|
.find(|g| g["id"] == instance["groupId"])
|
|
.unwrap();
|
|
client.set_track(
|
|
group["name"].as_str().unwrap(),
|
|
instance["counters"][0]["counterValue"].as_u64().unwrap() as u32,
|
|
);
|
|
client
|
|
}
|
|
|
|
pub fn sign_in(&self, game_name: &str, tag_line: &str) {
|
|
self.state.lock().unwrap().signed_in = Some((game_name.into(), tag_line.into()));
|
|
}
|
|
|
|
/// The client closes.
|
|
pub fn sign_out(&self) {
|
|
self.state.lock().unwrap().signed_in = None;
|
|
}
|
|
|
|
/// `phase` is the client's own name for it, e.g. "InProgress".
|
|
pub fn set_phase(&self, phase: &str, arena: bool) {
|
|
let mut state = self.state.lock().unwrap();
|
|
state.raw_gameflow = None;
|
|
state.gameflow = Gameflow {
|
|
phase: GamePhase::from_client(phase),
|
|
arena,
|
|
..state.gameflow.clone()
|
|
};
|
|
}
|
|
|
|
/// Replays a captured gameflow body through the live client's parser.
|
|
pub fn set_gameflow(&self, body: &str) {
|
|
self.state.lock().unwrap().raw_gameflow = Some(body.into());
|
|
}
|
|
|
|
/// The client's id of the game being played (kept across phases until changed).
|
|
pub fn set_game_id(&self, game_id: Option<u64>) {
|
|
self.state.lock().unwrap().gameflow.game_id = game_id;
|
|
}
|
|
|
|
/// The champion the signed-in summoner plays in the game (kept across phases until
|
|
/// changed); `None` while the client does not say it.
|
|
pub fn set_champion(&self, champion_id: Option<u32>) {
|
|
self.state.lock().unwrap().gameflow.champion_id = champion_id;
|
|
}
|
|
|
|
pub fn set_champ_select(&self, raw: RawChampSelect) {
|
|
self.state.lock().unwrap().champ_select = Some(raw);
|
|
}
|
|
|
|
/// Reports one of the captured session bodies as the client's champ select event.
|
|
pub fn send_champ_select_event(&self, session: &str) {
|
|
let session = serde_json::from_str(session).unwrap_or(Value::Null);
|
|
self.state.lock().unwrap().events.push_back(session);
|
|
}
|
|
|
|
/// How many session and champion-list bodies the champ select reader asked the client for.
|
|
pub fn champ_select_reads(&self) -> (usize, usize) {
|
|
(
|
|
self.session_reads.load(Ordering::SeqCst),
|
|
self.list_reads.load(Ordering::SeqCst),
|
|
)
|
|
}
|
|
|
|
/// The next gameflow or champ select read fails with this, until cleared.
|
|
pub fn fail_gameflow(&self, error: Option<ClientError>) {
|
|
self.state.lock().unwrap().gameflow_error = error;
|
|
}
|
|
|
|
pub fn fail_champ_select(&self, error: Option<ClientError>) {
|
|
self.state.lock().unwrap().champ_select_error = error;
|
|
}
|
|
|
|
pub fn set_track(&self, name: &str, value: u32) {
|
|
self.state.lock().unwrap().tracks.insert(name.into(), value);
|
|
}
|
|
|
|
pub fn remove_track(&self, name: &str) {
|
|
self.state.lock().unwrap().tracks.remove(name);
|
|
}
|
|
|
|
/// The client's PUUID of the signed-in summoner (the Riot API's may differ).
|
|
pub fn set_summoner_puuid(&self, puuid: Option<&str>) {
|
|
self.state.lock().unwrap().summoner_puuid = puuid.map(Into::into);
|
|
}
|
|
|
|
/// The client creates its end-of-game block: the event delivers it, and the route answers
|
|
/// it until `return_to_lobby`.
|
|
pub fn create_end_of_game_block(&self, content: &str) {
|
|
let mut state = self.state.lock().unwrap();
|
|
// Given who is signed in when it arrives, as the real client's event is.
|
|
state.end_of_game_event = Some(state.owned_block(content.into()));
|
|
state.end_of_game_route = Some(content.into());
|
|
}
|
|
|
|
/// The route answers this block, but its event was missed.
|
|
pub fn set_end_of_game_route(&self, content: Option<&str>) {
|
|
self.state.lock().unwrap().end_of_game_route = content.map(Into::into);
|
|
}
|
|
|
|
/// The client deletes its end-of-game block: the route answers 404.
|
|
pub fn return_to_lobby(&self) {
|
|
self.set_end_of_game_route(None);
|
|
self.set_phase("Lobby", false);
|
|
}
|
|
|
|
/// Reads of the end-of-game block route.
|
|
pub fn end_of_game_reads(&self) -> usize {
|
|
self.state.lock().unwrap().end_of_game_reads
|
|
}
|
|
|
|
/// The timeouts the tracker asked to wait for.
|
|
pub fn waits(&self) -> Vec<Duration> {
|
|
self.state.lock().unwrap().waits.clone()
|
|
}
|
|
}
|
|
|
|
impl GameClientSource for FakeClient {
|
|
fn signed_in(&self) -> Result<(String, String), ClientError> {
|
|
let state = self.state.lock().unwrap();
|
|
state.signed_in.clone().ok_or(ClientError::Absent)
|
|
}
|
|
|
|
fn gameflow(&self) -> Result<Gameflow, ClientError> {
|
|
let state = self.state.lock().unwrap();
|
|
state.signed_in.as_ref().ok_or(ClientError::Absent)?;
|
|
if let Some(error) = &state.gameflow_error {
|
|
return Err(error.clone());
|
|
}
|
|
let flow = match &state.raw_gameflow {
|
|
Some(body) => decode_gameflow(200, body, state.summoner_puuid.as_deref())?,
|
|
None => state.gameflow.clone(),
|
|
};
|
|
state
|
|
.champ_select_reader
|
|
.reset_unless_arena_champ_select(&flow);
|
|
Ok(flow)
|
|
}
|
|
|
|
fn champ_select(&self) -> Result<ChampSelect, ClientError> {
|
|
let state = self.state.lock().unwrap();
|
|
if let Some(error) = &state.champ_select_error {
|
|
return Err(error.clone());
|
|
}
|
|
let raw = state.champ_select.as_ref().ok_or(ClientError::Absent)?;
|
|
let sessions = self.session_reads.clone();
|
|
let lists = self.list_reads.clone();
|
|
state.champ_select_reader.read(
|
|
|| {
|
|
sessions.fetch_add(1, Ordering::SeqCst);
|
|
Ok(raw.session.clone())
|
|
},
|
|
|| {
|
|
lists.fetch_add(1, Ordering::SeqCst);
|
|
Ok((
|
|
raw.pickable.clone(),
|
|
raw.disabled.clone(),
|
|
raw.anvil.clone(),
|
|
))
|
|
},
|
|
)
|
|
}
|
|
|
|
fn official_progress(&self, track_name: &str) -> Result<Option<u32>, ClientError> {
|
|
let state = self.state.lock().unwrap();
|
|
state.signed_in.as_ref().ok_or(ClientError::Absent)?;
|
|
Ok(state.tracks.get(track_name).copied())
|
|
}
|
|
|
|
fn take_end_of_game_block(&self) -> Option<EndOfGameBlock> {
|
|
self.state.lock().unwrap().end_of_game_event.take()
|
|
}
|
|
|
|
fn read_end_of_game_block(&self) -> Option<EndOfGameBlock> {
|
|
let mut state = self.state.lock().unwrap();
|
|
state.end_of_game_reads += 1;
|
|
let content = state.end_of_game_route.clone()?;
|
|
Some(state.owned_block(content))
|
|
}
|
|
|
|
fn wait_for_event(&self, timeout: Duration) -> ClientEvent {
|
|
let mut state = self.state.lock().unwrap();
|
|
state.waits.push(timeout);
|
|
match state.events.pop_front() {
|
|
Some(session) => {
|
|
state.champ_select_reader.set_session(session);
|
|
ClientEvent::ChampSelect
|
|
}
|
|
None => ClientEvent::Other,
|
|
}
|
|
}
|
|
}
|