diff options
Diffstat (limited to '')
| -rw-r--r-- | src/client/core.rs | 43 | ||||
| -rw-r--r-- | src/client/database.rs | 7 | ||||
| -rw-r--r-- | src/client/games/blackjack.rs | 11 | ||||
| -rw-r--r-- | src/client/games/manager.rs | 8 | ||||
| -rw-r--r-- | src/client/games/response.rs | 4 | ||||
| -rw-r--r-- | src/client/games/roulette.rs | 12 | ||||
| -rw-r--r-- | src/client/games/slots.rs | 6 | ||||
| -rw-r--r-- | src/client/ui.rs | 13 |
8 files changed, 33 insertions, 71 deletions
diff --git a/src/client/core.rs b/src/client/core.rs index 5f8c513..06d9c42 100644 --- a/src/client/core.rs +++ b/src/client/core.rs | |||
| @@ -3,8 +3,8 @@ use crate::client::games::response::{ | |||
| 3 | parse_blackjack_response, parse_crash_response, parse_roulette_response, parse_spin_response, | 3 | parse_blackjack_response, parse_crash_response, parse_roulette_response, parse_spin_response, |
| 4 | }; | 4 | }; |
| 5 | use crate::client::ui::{ | 5 | use crate::client::ui::{ |
| 6 | command_names, completion_lines, display_width, help_lines, input_cursor_column, | 6 | command_names, completion_lines, display_width, help_lines, input_cursor_column, parse_bet_arg, |
| 7 | parse_bet_arg, record_history, | 7 | record_history, |
| 8 | }; | 8 | }; |
| 9 | use crate::crash::{multiplier_at, CrashState}; | 9 | use crate::crash::{multiplier_at, CrashState}; |
| 10 | use crate::roulette::{Bets, NumberBet}; | 10 | use crate::roulette::{Bets, NumberBet}; |
| @@ -225,10 +225,7 @@ impl ClientCore { | |||
| 225 | "Game exited. Active hand forfeited ({} PLN lost).", | 225 | "Game exited. Active hand forfeited ({} PLN lost).", |
| 226 | state.bet | 226 | state.bet |
| 227 | ); | 227 | ); |
| 228 | vec![ | 228 | vec![Effect::ClearRegion, Effect::Print(vec![message])] |
| 229 | Effect::ClearRegion, | ||
| 230 | Effect::Print(vec![message]), | ||
| 231 | ] | ||
| 232 | } | 229 | } |
| 233 | Err(message) => { | 230 | Err(message) => { |
| 234 | self.game.set_error(message); | 231 | self.game.set_error(message); |
| @@ -258,10 +255,7 @@ impl ClientCore { | |||
| 258 | Ok(state) => { | 255 | Ok(state) => { |
| 259 | self.crash_started = None; | 256 | self.crash_started = None; |
| 260 | self.game.end_game(); | 257 | self.game.end_game(); |
| 261 | let message = format!( | 258 | let message = format!("Game exited. Round forfeited ({} PLN lost).", state.bet); |
| 262 | "Game exited. Round forfeited ({} PLN lost).", | ||
| 263 | state.bet | ||
| 264 | ); | ||
| 265 | vec![Effect::ClearRegion, Effect::Print(vec![message])] | 259 | vec![Effect::ClearRegion, Effect::Print(vec![message])] |
| 266 | } | 260 | } |
| 267 | Err(_) if self.game.crash_status() != "running" => { | 261 | Err(_) if self.game.crash_status() != "running" => { |
| @@ -286,9 +280,7 @@ impl ClientCore { | |||
| 286 | self.logged_in = None; | 280 | self.logged_in = None; |
| 287 | vec![ | 281 | vec![ |
| 288 | Effect::Disconnect, | 282 | Effect::Disconnect, |
| 289 | Effect::Print(vec![ | 283 | Effect::Print(vec!["Connection lost".to_string()]), |
| 290 | "Connection lost".to_string(), | ||
| 291 | ]), | ||
| 292 | ] | 284 | ] |
| 293 | } | 285 | } |
| 294 | } | 286 | } |
| @@ -531,27 +523,20 @@ impl ClientCore { | |||
| 531 | } | 523 | } |
| 532 | } | 524 | } |
| 533 | Key::Char(' ') => self.start_blackjack(), | 525 | Key::Char(' ') => self.start_blackjack(), |
| 534 | Key::Char('h') | 526 | Key::Char('h') if hand.as_ref().is_some_and(|hand| hand.phase == "player") => { |
| 535 | if hand.as_ref().is_some_and(|hand| hand.phase == "player") => | ||
| 536 | { | ||
| 537 | self.blackjack_action("hit") | 527 | self.blackjack_action("hit") |
| 538 | } | 528 | } |
| 539 | Key::Char('s') | 529 | Key::Char('s') if hand.as_ref().is_some_and(|hand| hand.phase == "player") => { |
| 540 | if hand.as_ref().is_some_and(|hand| hand.phase == "player") => | ||
| 541 | { | ||
| 542 | self.blackjack_action("stand") | 530 | self.blackjack_action("stand") |
| 543 | } | 531 | } |
| 544 | Key::Char('d') | 532 | Key::Char('d') |
| 545 | if hand.as_ref().is_some_and(|hand| { | 533 | if hand.as_ref().is_some_and(|hand| { |
| 546 | hand.phase == "player" | 534 | hand.phase == "player" && hand.actions.iter().any(|action| action == "double") |
| 547 | && hand.actions.iter().any(|action| action == "double") | ||
| 548 | }) => | 535 | }) => |
| 549 | { | 536 | { |
| 550 | self.blackjack_action("double") | 537 | self.blackjack_action("double") |
| 551 | } | 538 | } |
| 552 | Key::Char('+') | Key::Char('=') | 539 | Key::Char('+') | Key::Char('=') if matches!(status.as_str(), "ready" | "done") => { |
| 553 | if matches!(status.as_str(), "ready" | "done") => | ||
| 554 | { | ||
| 555 | let _ = self.game.adjust_bet(10); | 540 | let _ = self.game.adjust_bet(10); |
| 556 | self.board_effects() | 541 | self.board_effects() |
| 557 | } | 542 | } |
| @@ -602,9 +587,7 @@ impl ClientCore { | |||
| 602 | if hand.phase != "player" { | 587 | if hand.phase != "player" { |
| 603 | return Vec::new(); | 588 | return Vec::new(); |
| 604 | } | 589 | } |
| 605 | if action == "double" | 590 | if action == "double" && !hand.actions.iter().any(|available| available == "double") { |
| 606 | && !hand.actions.iter().any(|available| available == "double") | ||
| 607 | { | ||
| 608 | return Vec::new(); | 591 | return Vec::new(); |
| 609 | } | 592 | } |
| 610 | self.pending = Some(Pending::BlackjackAction); | 593 | self.pending = Some(Pending::BlackjackAction); |
| @@ -914,9 +897,9 @@ impl ClientCore { | |||
| 914 | Some(fingerprint) => { | 897 | Some(fingerprint) => { |
| 915 | effects.push(Effect::Print(vec![format!("Fingerprint: {fingerprint}")])) | 898 | effects.push(Effect::Print(vec![format!("Fingerprint: {fingerprint}")])) |
| 916 | } | 899 | } |
| 917 | None => effects.push(Effect::Print(vec![ | 900 | None => effects.push(Effect::Print( |
| 918 | "Fingerprint: (not trusted)".to_string(), | 901 | vec!["Fingerprint: (not trusted)".to_string()], |
| 919 | ])), | 902 | )), |
| 920 | } | 903 | } |
| 921 | 904 | ||
| 922 | self.pending = Some(Pending::Info); | 905 | self.pending = Some(Pending::Info); |
diff --git a/src/client/database.rs b/src/client/database.rs index e1fa42d..e1cedaf 100644 --- a/src/client/database.rs +++ b/src/client/database.rs | |||
| @@ -110,9 +110,8 @@ pub fn get_all_hosts(conn: &Connection) -> Vec<(String, Option<String>)> { | |||
| 110 | let mut stmt = conn | 110 | let mut stmt = conn |
| 111 | .prepare("SELECT host, fingerprint FROM hosts ORDER BY last_used DESC") | 111 | .prepare("SELECT host, fingerprint FROM hosts ORDER BY last_used DESC") |
| 112 | .unwrap(); | 112 | .unwrap(); |
| 113 | let rows = stmt.query_map([], |row| { | 113 | let rows = stmt |
| 114 | Ok((row.get(0)?, row.get(1)?)) | 114 | .query_map([], |row| Ok((row.get(0)?, row.get(1)?))) |
| 115 | }) | 115 | .unwrap(); |
| 116 | .unwrap(); | ||
| 117 | rows.filter_map(|r| r.ok()).collect() | 116 | rows.filter_map(|r| r.ok()).collect() |
| 118 | } | 117 | } |
diff --git a/src/client/games/blackjack.rs b/src/client/games/blackjack.rs index bad1781..d5f45b3 100644 --- a/src/client/games/blackjack.rs +++ b/src/client/games/blackjack.rs | |||
| @@ -56,15 +56,14 @@ impl Game for BlackjackGame { | |||
| 56 | .get("status") | 56 | .get("status") |
| 57 | .map(String::as_str) | 57 | .map(String::as_str) |
| 58 | .unwrap_or("ready"); | 58 | .unwrap_or("ready"); |
| 59 | let balance = state | 59 | let balance = state.data.get("balance").map(String::as_str).unwrap_or("?"); |
| 60 | .data | ||
| 61 | .get("balance") | ||
| 62 | .map(String::as_str) | ||
| 63 | .unwrap_or("?"); | ||
| 64 | let hand = Self::state(state); | 60 | let hand = Self::state(state); |
| 65 | 61 | ||
| 66 | if let Some(error) = state.data.get("error") { | 62 | if let Some(error) = state.data.get("error") { |
| 67 | let bet = hand.as_ref().map(|hand| hand.bet).unwrap_or(state.bet_amount); | 63 | let bet = hand |
| 64 | .as_ref() | ||
| 65 | .map(|hand| hand.bet) | ||
| 66 | .unwrap_or(state.bet_amount); | ||
| 68 | return format!( | 67 | return format!( |
| 69 | "=== BLACKJACK ===\r\nBalance: {balance} PLN Bet: {bet} PLN\r\n\r\n\r\nERROR: {error}\r\n[Q] Quit" | 68 | "=== BLACKJACK ===\r\nBalance: {balance} PLN Bet: {bet} PLN\r\n\r\n\r\nERROR: {error}\r\n[Q] Quit" |
| 70 | ); | 69 | ); |
diff --git a/src/client/games/manager.rs b/src/client/games/manager.rs index 4d9e6a8..b20ff44 100644 --- a/src/client/games/manager.rs +++ b/src/client/games/manager.rs | |||
| @@ -138,9 +138,7 @@ impl GameManager { | |||
| 138 | session.bet_amount = result.bet_amount; | 138 | session.bet_amount = result.bet_amount; |
| 139 | session.data.remove("error"); | 139 | session.data.remove("error"); |
| 140 | session.data.insert("reels".to_string(), result.reels); | 140 | session.data.insert("reels".to_string(), result.reels); |
| 141 | session | 141 | session.data.insert("win_type".to_string(), result.win_type); |
| 142 | .data | ||
| 143 | .insert("win_type".to_string(), result.win_type); | ||
| 144 | session.data.insert( | 142 | session.data.insert( |
| 145 | "win_lines".to_string(), | 143 | "win_lines".to_string(), |
| 146 | result | 144 | result |
| @@ -339,7 +337,9 @@ impl GameManager { | |||
| 339 | for key in ["crash_point", "payout"] { | 337 | for key in ["crash_point", "payout"] { |
| 340 | session.data.remove(key); | 338 | session.data.remove(key); |
| 341 | } | 339 | } |
| 342 | session.data.insert("status".to_string(), state.phase.clone()); | 340 | session |
| 341 | .data | ||
| 342 | .insert("status".to_string(), state.phase.clone()); | ||
| 343 | session | 343 | session |
| 344 | .data | 344 | .data |
| 345 | .insert("session_id".to_string(), state.session_id); | 345 | .insert("session_id".to_string(), state.session_id); |
diff --git a/src/client/games/response.rs b/src/client/games/response.rs index 71e1fed..88df459 100644 --- a/src/client/games/response.rs +++ b/src/client/games/response.rs | |||
| @@ -128,8 +128,8 @@ pub fn parse_roulette_response(response: &str) -> Result<RouletteResult, String> | |||
| 128 | return Err(format!("Invalid roulette color: {color}")); | 128 | return Err(format!("Invalid roulette color: {color}")); |
| 129 | } | 129 | } |
| 130 | let bets = parts[7].to_string(); | 130 | let bets = parts[7].to_string(); |
| 131 | let _: crate::roulette::Bets = serde_json::from_str(&bets) | 131 | let _: crate::roulette::Bets = |
| 132 | .map_err(|error| format!("Invalid roulette bets: {error}"))?; | 132 | serde_json::from_str(&bets).map_err(|error| format!("Invalid roulette bets: {error}"))?; |
| 133 | 133 | ||
| 134 | Ok(RouletteResult { | 134 | Ok(RouletteResult { |
| 135 | session_id: parts[1].to_string(), | 135 | session_id: parts[1].to_string(), |
diff --git a/src/client/games/roulette.rs b/src/client/games/roulette.rs index 3379317..e80eca8 100644 --- a/src/client/games/roulette.rs +++ b/src/client/games/roulette.rs | |||
| @@ -53,11 +53,7 @@ impl RouletteGame { | |||
| 53 | 53 | ||
| 54 | match state.data.get("status").map(String::as_str) { | 54 | match state.data.get("status").map(String::as_str) { |
| 55 | Some("result") => { | 55 | Some("result") => { |
| 56 | let number = state | 56 | let number = state.data.get("number").map(String::as_str).unwrap_or("?"); |
| 57 | .data | ||
| 58 | .get("number") | ||
| 59 | .map(String::as_str) | ||
| 60 | .unwrap_or("?"); | ||
| 61 | let color = state | 57 | let color = state |
| 62 | .data | 58 | .data |
| 63 | .get("color") | 59 | .get("color") |
| @@ -102,11 +98,7 @@ impl Game for RouletteGame { | |||
| 102 | fn render(&self, state: &GameState) -> String { | 98 | fn render(&self, state: &GameState) -> String { |
| 103 | let bets = Self::bets(state); | 99 | let bets = Self::bets(state); |
| 104 | let chip = state.data.get("chip").map(String::as_str).unwrap_or("10"); | 100 | let chip = state.data.get("chip").map(String::as_str).unwrap_or("10"); |
| 105 | let balance = state | 101 | let balance = state.data.get("balance").map(String::as_str).unwrap_or("?"); |
| 106 | .data | ||
| 107 | .get("balance") | ||
| 108 | .map(String::as_str) | ||
| 109 | .unwrap_or("?"); | ||
| 110 | let input = state | 102 | let input = state |
| 111 | .data | 103 | .data |
| 112 | .get("number_input") | 104 | .get("number_input") |
diff --git a/src/client/games/slots.rs b/src/client/games/slots.rs index d34bf49..2ec354e 100644 --- a/src/client/games/slots.rs +++ b/src/client/games/slots.rs | |||
| @@ -109,11 +109,7 @@ impl Game for SlotsGame { | |||
| 109 | 109 | ||
| 110 | fn render(&self, state: &GameState) -> String { | 110 | fn render(&self, state: &GameState) -> String { |
| 111 | let reels = state.data.get("reels").cloned().unwrap_or_default(); | 111 | let reels = state.data.get("reels").cloned().unwrap_or_default(); |
| 112 | let balance = state | 112 | let balance = state.data.get("balance").map(String::as_str).unwrap_or("?"); |
| 113 | .data | ||
| 114 | .get("balance") | ||
| 115 | .map(String::as_str) | ||
| 116 | .unwrap_or("?"); | ||
| 117 | let winning = Self::highlighted_cells(state); | 113 | let winning = Self::highlighted_cells(state); |
| 118 | let grid = self.render_grid(&reels, &winning); | 114 | let grid = self.render_grid(&reels, &winning); |
| 119 | let paytable = paytable_lines(); | 115 | let paytable = paytable_lines(); |
diff --git a/src/client/ui.rs b/src/client/ui.rs index 0fe78ae..4ab0759 100644 --- a/src/client/ui.rs +++ b/src/client/ui.rs | |||
| @@ -94,10 +94,7 @@ pub fn command_names() -> Vec<&'static str> { | |||
| 94 | pub fn help_lines() -> Vec<String> { | 94 | pub fn help_lines() -> Vec<String> { |
| 95 | let mut lines = vec!["Available commands:".to_string()]; | 95 | let mut lines = vec!["Available commands:".to_string()]; |
| 96 | for command in COMMANDS { | 96 | for command in COMMANDS { |
| 97 | lines.push(format!( | 97 | lines.push(format!(" {:<28} - {}", command.usage, command.description)); |
| 98 | " {:<28} - {}", | ||
| 99 | command.usage, command.description | ||
| 100 | )); | ||
| 101 | } | 98 | } |
| 102 | lines | 99 | lines |
| 103 | } | 100 | } |
| @@ -291,16 +288,12 @@ pub fn host_lines(hosts: &[(String, Option<String>)]) -> Vec<String> { | |||
| 291 | /// on the current line. `render()` has no trailing newline, so a 7-line board | 288 | /// on the current line. `render()` has no trailing newline, so a 7-line board |
| 292 | /// needs `MoveUp(6)`. | 289 | /// needs `MoveUp(6)`. |
| 293 | pub fn lines_to_move_up(previous_lines: usize) -> u16 { | 290 | pub fn lines_to_move_up(previous_lines: usize) -> u16 { |
| 294 | previous_lines | 291 | previous_lines.saturating_sub(1).min(u16::MAX as usize) as u16 |
| 295 | .saturating_sub(1) | ||
| 296 | .min(u16::MAX as usize) as u16 | ||
| 297 | } | 292 | } |
| 298 | 293 | ||
| 299 | /// Column (0-based) to move to after the given prompt and input text. | 294 | /// Column (0-based) to move to after the given prompt and input text. |
| 300 | pub fn input_cursor_column(prompt_len: usize, input_len: usize) -> u16 { | 295 | pub fn input_cursor_column(prompt_len: usize, input_len: usize) -> u16 { |
| 301 | prompt_len | 296 | prompt_len.saturating_add(input_len).min(u16::MAX as usize) as u16 |
| 302 | .saturating_add(input_len) | ||
| 303 | .min(u16::MAX as usize) as u16 | ||
| 304 | } | 297 | } |
| 305 | 298 | ||
| 306 | /// Number of terminal rows a block of logical lines occupies after wrapping. | 299 | /// Number of terminal rows a block of logical lines occupies after wrapping. |
