summaryrefslogtreecommitdiffstats
path: root/src/client/core.rs
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-11-01 16:17:19 +0100
committersalmonik <salmonik@tuta.io>2026-11-01 16:17:19 +0100
commitf07221b4e1d8aa464a44fe566884ccc0565406e9 (patch)
tree48020a68cee1c95521d594dc6803c1f7ec01c801 /src/client/core.rs
parentadd nginx + php-fpm deployment example (diff)
downloadzagan-bet-f07221b4e1d8aa464a44fe566884ccc0565406e9.tar.gz
zagan-bet-f07221b4e1d8aa464a44fe566884ccc0565406e9.zip
v3.2.0: straight and split bets anywhere on the felt; add history command
Diffstat (limited to 'src/client/core.rs')
-rw-r--r--src/client/core.rs34
1 files changed, 31 insertions, 3 deletions
diff --git a/src/client/core.rs b/src/client/core.rs
index 54a6434..0b2e683 100644
--- a/src/client/core.rs
+++ b/src/client/core.rs
@@ -1,13 +1,15 @@
1use crate::client::games::manager::GameManager; 1use crate::client::games::manager::GameManager;
2use crate::client::games::response::{ 2use 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_history_response,
4 parse_roulette_response, parse_spin_response,
4}; 5};
5use crate::client::games::roulette::Direction; 6use crate::client::games::roulette::Direction;
6use crate::client::ui::{ 7use crate::client::ui::{
7 command_names, completion_lines, display_width, help_lines, input_cursor_column, parse_bet_arg, 8 command_names, completion_lines, display_width, help_lines, history_lines,
8 record_history, 9 input_cursor_column, parse_bet_arg, record_history,
9}; 10};
10use crate::crash::{CrashState, multiplier_at}; 11use crate::crash::{CrashState, multiplier_at};
12use crate::history::MAX_HISTORY;
11use crate::roulette::Bets; 13use crate::roulette::Bets;
12use std::time::{Duration, Instant}; 14use std::time::{Duration, Instant};
13 15
@@ -74,6 +76,7 @@ enum Pending {
74 CrashStart, 76 CrashStart,
75 CrashCashout, 77 CrashCashout,
76 CrashForfeit, 78 CrashForfeit,
79 History,
77 Ping, 80 Ping,
78 Echo, 81 Echo,
79 Info, 82 Info,
@@ -290,6 +293,10 @@ impl ClientCore {
290 self.board_effects() 293 self.board_effects()
291 } 294 }
292 }, 295 },
296 Some(Pending::History) => match parse_history_response(reply) {
297 Ok(records) => vec![Effect::Print(history_lines(&records))],
298 Err(message) => print_line(message),
299 },
293 Some(Pending::Ping) => { 300 Some(Pending::Ping) => {
294 if reply.trim() == "PONG" { 301 if reply.trim() == "PONG" {
295 print_line("Pong") 302 print_line("Pong")
@@ -782,6 +789,7 @@ impl ClientCore {
782 } 789 }
783 } 790 }
784 "info" => self.cmd_info(), 791 "info" => self.cmd_info(),
792 "history" => self.cmd_history(&parts),
785 "hosts" => vec![Effect::ListHosts], 793 "hosts" => vec![Effect::ListHosts],
786 "forget-host" => { 794 "forget-host" => {
787 let target = parts 795 let target = parts
@@ -851,6 +859,26 @@ impl ClientCore {
851 vec![Effect::Print(lines)] 859 vec![Effect::Print(lines)]
852 } 860 }
853 861
862 fn cmd_history(&mut self, parts: &[&str]) -> Vec<Effect> {
863 if !self.connected {
864 return print_line("Not connected. Use 'connect <ip>:<port>' first.");
865 }
866 if self.logged_in.is_none() {
867 return print_line("Not logged in. Use 'login' first.");
868 }
869
870 let request = match parts.get(1) {
871 Some(raw) => match raw.parse::<u32>() {
872 Ok(count) if (1..=MAX_HISTORY).contains(&count) => format!("HISTORY {count}"),
873 _ => return print_line(format!("Usage: history [1-{MAX_HISTORY}]")),
874 },
875 None => "HISTORY".to_string(),
876 };
877
878 self.pending = Some(Pending::History);
879 vec![Effect::SendLine(request)]
880 }
881
854 fn cmd_info(&mut self) -> Vec<Effect> { 882 fn cmd_info(&mut self) -> Vec<Effect> {
855 if !self.connected { 883 if !self.connected {
856 return print_line("Not connected to any host."); 884 return print_line("Not connected to any host.");