diff options
Diffstat (limited to '')
| -rw-r--r-- | src/server/core.rs | 7 | ||||
| -rw-r--r-- | src/server/database.rs | 28 |
2 files changed, 18 insertions, 17 deletions
diff --git a/src/server/core.rs b/src/server/core.rs index 350fe18..7231577 100644 --- a/src/server/core.rs +++ b/src/server/core.rs | |||
| @@ -259,16 +259,17 @@ impl ServerCore { | |||
| 259 | .get("win_cells") | 259 | .get("win_cells") |
| 260 | .cloned() | 260 | .cloned() |
| 261 | .unwrap_or_else(|| "-".to_string()); | 261 | .unwrap_or_else(|| "-".to_string()); |
| 262 | let details = | ||
| 263 | serde_json::to_string(&result.result_data).unwrap_or_else(|_| "{}".to_string()); | ||
| 262 | 264 | ||
| 263 | match database::apply_spin( | 265 | match database::apply_play( |
| 264 | &mut self.conn, | 266 | &mut self.conn, |
| 265 | &session_id, | 267 | &session_id, |
| 266 | user, | 268 | user, |
| 267 | game_type, | 269 | game_type, |
| 268 | bet_amount, | 270 | bet_amount, |
| 269 | winnings, | 271 | winnings, |
| 270 | &reels, | 272 | &details, |
| 271 | &win_type, | ||
| 272 | ) { | 273 | ) { |
| 273 | Ok(new_balance) => { | 274 | Ok(new_balance) => { |
| 274 | let _ = self.sessions.remove_session(&session_id); | 275 | let _ = self.sessions.remove_session(&session_id); |
diff --git a/src/server/database.rs b/src/server/database.rs index f6c8872..2a1fc40 100644 --- a/src/server/database.rs +++ b/src/server/database.rs | |||
| @@ -24,9 +24,8 @@ pub fn init_db(conn: &Connection) { | |||
| 24 | game_type TEXT NOT NULL, | 24 | game_type TEXT NOT NULL, |
| 25 | bet_amount INTEGER NOT NULL, | 25 | bet_amount INTEGER NOT NULL, |
| 26 | winnings INTEGER NOT NULL, | 26 | winnings INTEGER NOT NULL, |
| 27 | reels TEXT NOT NULL DEFAULT '', | ||
| 28 | win_type TEXT NOT NULL DEFAULT '', | ||
| 29 | balance_after INTEGER NOT NULL, | 27 | balance_after INTEGER NOT NULL, |
| 28 | details TEXT NOT NULL DEFAULT '{}', | ||
| 30 | created_at DATETIME DEFAULT CURRENT_TIMESTAMP | 29 | created_at DATETIME DEFAULT CURRENT_TIMESTAMP |
| 31 | )", | 30 | )", |
| 32 | [], | 31 | [], |
| @@ -111,20 +110,22 @@ pub fn get_balance(conn: &Connection, username: &str) -> Option<i64> { | |||
| 111 | } | 110 | } |
| 112 | } | 111 | } |
| 113 | 112 | ||
| 114 | /// Settle one spin and record its audit row in a single transaction. | 113 | /// Settle one play and record its audit row in a single transaction. |
| 115 | /// | 114 | /// |
| 116 | /// Returns the balance after the spin. All SQL is parameterized: usernames | 115 | /// `details` is a JSON object with game-specific fields (reels, cards, |
| 117 | /// are data, never part of the statement text. | 116 | /// winning number, crash point, ...). All SQL is parameterized: usernames are |
| 117 | /// data, never part of the statement text. | ||
| 118 | /// | ||
| 119 | /// Returns the balance after the play. | ||
| 118 | #[allow(clippy::too_many_arguments)] | 120 | #[allow(clippy::too_many_arguments)] |
| 119 | pub fn apply_spin( | 121 | pub fn apply_play( |
| 120 | conn: &mut Connection, | 122 | conn: &mut Connection, |
| 121 | session_id: &str, | 123 | session_id: &str, |
| 122 | username: &str, | 124 | username: &str, |
| 123 | game_type: &str, | 125 | game_type: &str, |
| 124 | bet_amount: i64, | 126 | bet_amount: i64, |
| 125 | winnings: i64, | 127 | winnings: i64, |
| 126 | reels: &str, | 128 | details: &str, |
| 127 | win_type: &str, | ||
| 128 | ) -> rusqlite::Result<i64> { | 129 | ) -> rusqlite::Result<i64> { |
| 129 | let tx = conn.transaction()?; | 130 | let tx = conn.transaction()?; |
| 130 | 131 | ||
| @@ -150,18 +151,17 @@ pub fn apply_spin( | |||
| 150 | 151 | ||
| 151 | tx.execute( | 152 | tx.execute( |
| 152 | "INSERT INTO plays | 153 | "INSERT INTO plays |
| 153 | (session_id, username, game_type, bet_amount, winnings, reels, | 154 | (session_id, username, game_type, bet_amount, winnings, |
| 154 | win_type, balance_after) | 155 | balance_after, details) |
| 155 | VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)", | 156 | VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)", |
| 156 | params![ | 157 | params![ |
| 157 | session_id, | 158 | session_id, |
| 158 | username, | 159 | username, |
| 159 | game_type, | 160 | game_type, |
| 160 | bet_amount, | 161 | bet_amount, |
| 161 | winnings, | 162 | winnings, |
| 162 | reels, | 163 | balance_after, |
| 163 | win_type, | 164 | details |
| 164 | balance_after | ||
| 165 | ], | 165 | ], |
| 166 | )?; | 166 | )?; |
| 167 | 167 | ||
