forge/lib/models/src/bank.rs
Jacob Schmidt ebfe77a340 feat: implement complete Forge framework with Rust/Redis backend and Arma 3 integration
Implemented features:
- High-performance Rust extension with Redis persistence
- Actor/player management with loadout, position, and state tracking
- Banking system with deposit, withdraw, and transfer operations
- Physical and virtual garage/locker systems for vehicle and equipment storage
- Organization management with member tracking and permissions
- Client-side UI with React-like state management
- Server-side event-driven architecture with CBA Events
- Security: Self-transfer prevention at multiple layers
- Logging system with per-module log files
- ICOM module for inter-server communication

Co-Authored-By: Warp <agent@warp.dev>
2026-01-04 12:52:15 -06:00

74 lines
1.8 KiB
Rust

use arma_rs::{FromArma, IntoArma};
use forge_shared::BankValidationError;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Bank {
pub uid: String,
pub name: String,
pub bank: f64,
pub cash: f64,
pub earnings: f64,
pub pin: u64,
pub transactions: Vec<String>,
}
impl Bank {
pub fn new<S: Into<String>>(uid: S, name: S, pin: u64) -> Result<Self, BankValidationError> {
let bank = Self {
uid: uid.into(),
name: name.into(),
bank: 0.0,
cash: 0.0,
earnings: 0.0,
pin: pin,
transactions: Vec::new(),
};
bank.validate()?;
Ok(bank)
}
pub fn validate(&self) -> Result<(), BankValidationError> {
if self.uid.trim().is_empty() {
return Err(BankValidationError::UidEmpty);
}
if self.name.trim().is_empty() {
return Err(BankValidationError::NameEmpty);
}
if self.bank < 0.0 {
return Err(BankValidationError::BankNegative);
}
if self.cash < 0.0 {
return Err(BankValidationError::CashNegative);
}
if self.pin < 1000 || self.pin > 9999 {
return Err(BankValidationError::InvalidPin(self.pin));
}
Ok(())
}
pub fn uid(&self) -> &str {
&self.uid
}
}
impl FromArma for Bank {
fn from_arma(s: String) -> Result<Self, arma_rs::FromArmaError> {
serde_json::from_str(&s)
.map_err(|e| arma_rs::FromArmaError::InvalidPrimitive(format!("Invalid JSON: {}", e)))
}
}
impl IntoArma for Bank {
fn to_arma(&self) -> arma_rs::Value {
let json_str = serde_json::to_string(self).unwrap_or_default();
arma_rs::Value::String(json_str)
}
}