summaryrefslogtreecommitdiffstats
path: root/src/bin/client/repl.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/bin/client/repl.rs27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/bin/client/repl.rs b/src/bin/client/repl.rs
index 194860b..91fd10e 100644
--- a/src/bin/client/repl.rs
+++ b/src/bin/client/repl.rs
@@ -31,7 +31,11 @@ pub struct ClientState {
31 31
32impl ClientState { 32impl ClientState {
33 pub fn new() -> Self { 33 pub fn new() -> Self {
34 let conn = database::init_db(); 34 let conn = rusqlite::Connection::open(
35 std::env::var("CLIENT_DB").unwrap_or_else(|_| "client.db".to_string()),
36 )
37 .unwrap();
38 database::init_db(&conn);
35 let default_ip = "127.0.0.1".to_string(); 39 let default_ip = "127.0.0.1".to_string();
36 let default_port = 11525; 40 let default_port = 11525;
37 let last_host = database::get_last_host(&conn); 41 let last_host = database::get_last_host(&conn);
@@ -559,6 +563,25 @@ impl ClientState {
559 break 'outer; 563 break 'outer;
560 } 564 }
561 } 565 }
566 "forget-host" => {
567 let target = if parts.len() > 1 {
568 parts[1].to_string()
569 } else if let Some(addr) = &self.addr {
570 addr.clone()
571 } else {
572 println!(
573 "\nUsage: forget-host <ip>:<port> (or connect first)"
574 );
575 continue 'outer;
576 };
577 match database::forget_host(&self.conn, &target) {
578 Ok(_) => println!(
579 "\nCleared trust and stored credentials for {}.",
580 target
581 ),
582 Err(e) => println!("\nFailed to forget host: {}", e),
583 }
584 }
562 _ => help(), 585 _ => help(),
563 } 586 }
564 break; 587 break;
@@ -713,6 +736,7 @@ fn get_commands() -> Vec<String> {
713 "play".to_string(), 736 "play".to_string(),
714 "help".to_string(), 737 "help".to_string(),
715 "quit".to_string(), 738 "quit".to_string(),
739 "forget-host".to_string(),
716 ] 740 ]
717} 741}
718 742
@@ -730,6 +754,7 @@ fn help() {
730 info - show login info\r 754 info - show login info\r
731 play <game> [bet] - start a game (e.g., play slots 50)\r 755 play <game> [bet] - start a game (e.g., play slots 50)\r
732 help - show this message\r 756 help - show this message\r
757 forget-host [ip:port] - clear saved trust fingerprint and credentials\r
733 quit - quit the program" 758 quit - quit the program"
734 ); 759 );
735} 760}