From 5d6b5049c2a34a3f8abe725d4a871ba84a0dd714 Mon Sep 17 00:00:00 2001 From: salmonik Date: Mon, 24 Aug 2026 14:48:12 +0200 Subject: TLS transport and games framework on client and server --- src/bin/client/database.rs | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'src/bin/client/database.rs') diff --git a/src/bin/client/database.rs b/src/bin/client/database.rs index da069a7..a274f31 100644 --- a/src/bin/client/database.rs +++ b/src/bin/client/database.rs @@ -8,7 +8,8 @@ pub fn init_db() -> Connection { last_used DATETIME DEFAULT CURRENT_TIMESTAMP )", [], - ).unwrap(); + ) + .unwrap(); conn.execute( "CREATE TABLE IF NOT EXISTS credentials ( host TEXT PRIMARY KEY, @@ -16,12 +17,15 @@ pub fn init_db() -> Connection { password TEXT NOT NULL )", [], - ).unwrap(); + ) + .unwrap(); conn } pub fn get_last_host(conn: &Connection) -> Option { - let mut stmt = conn.prepare("SELECT host FROM hosts ORDER BY last_used DESC LIMIT 1").unwrap(); + let mut stmt = conn + .prepare("SELECT host FROM hosts ORDER BY last_used DESC LIMIT 1") + .unwrap(); let mut rows = stmt.query([]).unwrap(); if let Ok(Some(row)) = rows.next() { row.get(0).ok() @@ -34,10 +38,16 @@ pub fn save_host(conn: &Connection, host: &str) { conn.execute( "INSERT OR REPLACE INTO hosts (host, last_used) VALUES (?1, CURRENT_TIMESTAMP)", [host], - ).unwrap(); + ) + .unwrap(); } -pub fn save_credentials(conn: &Connection, host: &str, username: &str, password: &str) -> Result<(), Box> { +pub fn save_credentials( + conn: &Connection, + host: &str, + username: &str, + password: &str, +) -> Result<(), Box> { conn.execute( "INSERT OR REPLACE INTO credentials (host, username, password) VALUES (?1, ?2, ?3)", (host, username, password), @@ -46,7 +56,9 @@ pub fn save_credentials(conn: &Connection, host: &str, username: &str, password: } pub fn get_credentials(conn: &Connection, host: &str) -> Option<(String, String)> { - let mut stmt = conn.prepare("SELECT username, password FROM credentials WHERE host = ?1").unwrap(); + let mut stmt = conn + .prepare("SELECT username, password FROM credentials WHERE host = ?1") + .unwrap(); let mut rows = stmt.query([host]).unwrap(); if let Ok(Some(row)) = rows.next() { let username: String = row.get(0).unwrap(); @@ -55,4 +67,4 @@ pub fn get_credentials(conn: &Connection, host: &str) -> Option<(String, String) } else { None } -} \ No newline at end of file +} -- cgit v1.2.3