Update user money handling to prevent serialization errors: Adjusted the SQL query to cast money as numeric and modified the UserCharacterWorker to clamp and format the money value before executing the update. This change ensures valid numeric input and enhances error handling for user transactions.
This commit is contained in:
@@ -747,8 +747,17 @@ impl UserCharacterWorker {
|
||||
.get()
|
||||
.map_err(|e| DbError::new(format!("DB-Verbindung fehlgeschlagen: {e}")))?;
|
||||
|
||||
// Endliche Werte und gültiger Bereich für numeric(10,2), sonst Serialisierungsfehler
|
||||
let clamped = if !new_amount.is_finite() {
|
||||
1000.0
|
||||
} else {
|
||||
const MAX_ABS: f64 = 99_999_999.99;
|
||||
new_amount.clamp(-MAX_ABS, MAX_ABS)
|
||||
};
|
||||
let money_str = format!("{:.2}", clamped);
|
||||
|
||||
conn.prepare("update_user_money", QUERY_UPDATE_USER_MONEY)?;
|
||||
conn.execute("update_user_money", &[&new_amount, &falukant_user_id])?;
|
||||
conn.execute("update_user_money", &[&money_str, &falukant_user_id])?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user