1
0
mirror of https://git.ngram.ca/OpenJam/rc-servers synced 2026-08-23 23:08:52 +00:00

Add basic currency support and plumb multiplayer rewards screen #70

This commit is contained in:
NG (Graham)
2025-12-28 18:13:14 -05:00
parent 5e05cbdb59
commit 4ec64a9cd9
26 changed files with 802 additions and 48 deletions

View File

@@ -1,14 +1,36 @@
use polariton_server::operations::SimpleFunc;
use polariton_server::operations::{SimpleOpError, SimpleOperation, SimpleOpImpl};
use polariton::operation::{ParameterTable, Typed};
const FREE_BALANCE_PARAM_KEY: u8 = 74;
const PAID_BALANCE_PARAM_KEY: u8 = 87;
pub(super) fn balance_wallet_provider() -> SimpleFunc<66, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result<ParameterTable, i16>) + Sync + Sync> {
SimpleFunc::new(|params, _| {
let mut params = params.to_dict();
params.insert(FREE_BALANCE_PARAM_KEY, Typed::Long(31_337_000));
params.insert(PAID_BALANCE_PARAM_KEY, Typed::Long(1));
Ok(params.into())
})
const CODE: u8 = 66;
pub(super) struct WalletBallancer;
#[async_trait::async_trait]
impl <C: Send + 'static> SimpleOperation<C> for WalletBallancer {
type User = crate::UserTy;
const CODE: u8 = CODE;
async fn handle(&self, _params: ParameterTable<C>, user: &Self::User) -> Result<ParameterTable<C>, SimpleOpError> {
let mut params = ParameterTable::with_capacity(3);
let user_info = user.user()?;
let free = user_info.currency(
oj_rc_core::persist::user::CurrencyType::Free,
oj_rc_core::persist::user::CurrencyOp::Get,
).await?;
let paid = user_info.currency(
oj_rc_core::persist::user::CurrencyType::Paid,
oj_rc_core::persist::user::CurrencyOp::Get,
).await?;
params.insert(FREE_BALANCE_PARAM_KEY, Typed::Long(free as _));
params.insert(PAID_BALANCE_PARAM_KEY, Typed::Long(paid as _));
Ok(params)
}
}
pub(super) fn balance_wallet_provider<C: Send + 'static>() -> SimpleOpImpl<C, crate::UserTy, WalletBallancer> {
SimpleOpImpl::new(WalletBallancer)
}