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:
@@ -49,6 +49,7 @@ async fn main() -> std::io::Result<()> {
|
||||
let start_time = chrono::Utc::now();
|
||||
START_TIMESTAMP_S.store(start_time.timestamp(), std::sync::atomic::Ordering::Relaxed);
|
||||
|
||||
log::info!("services_room ready");
|
||||
if args.once {
|
||||
log::warn!("Handling first connection and then exiting");
|
||||
let (socket, address) = listener.accept().await?;
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +10,12 @@ pub(super) fn player_level_info_provider() -> SimpleFunc<3, crate::UserTy, impl
|
||||
key_ty: TypePrefix::Int, // int
|
||||
val_ty: TypePrefix::Int, // int
|
||||
items: vec![
|
||||
(Typed::Int(0), Typed::Int(99)),
|
||||
(Typed::Int(10_000), Typed::Int(99_000)),
|
||||
// FIXME load this from config
|
||||
// these are interpolated by the client
|
||||
(Typed::Int(0), Typed::Int(0)),
|
||||
// this should interpolate to display a level of 1337
|
||||
(Typed::Int(2674), Typed::Int(1)),
|
||||
(Typed::Int(10_000), Typed::Int(i32::MAX / 2)),
|
||||
] }));
|
||||
Ok(params.into())
|
||||
})
|
||||
|
||||
@@ -1,16 +1,34 @@
|
||||
use polariton_server::operations::SimpleFunc;
|
||||
use polariton::operation::{ParameterTable, Typed};
|
||||
use polariton_server::operations::{SimpleOpError, SimpleOperation, SimpleOpImpl};
|
||||
|
||||
const CURRENT_CODE: u8 = 187;
|
||||
const CURRENT_PARAM_KEY: u8 = 214;
|
||||
|
||||
pub(super) fn tech_points_provider() -> SimpleFunc<187, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result<ParameterTable, i16>) + Sync + Sync> {
|
||||
SimpleFunc::new(|params, _| {
|
||||
let mut params = params.to_dict();
|
||||
params.insert(CURRENT_PARAM_KEY, Typed::Int(1337));
|
||||
Ok(params.into())
|
||||
})
|
||||
pub(super) struct CurrentTechPointers;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl <C: Send + 'static> SimpleOperation<C> for CurrentTechPointers {
|
||||
type User = crate::UserTy;
|
||||
const CODE: u8 = CURRENT_CODE;
|
||||
|
||||
async fn handle(&self, _params: ParameterTable<C>, user: &Self::User) -> Result<ParameterTable<C>, SimpleOpError> {
|
||||
let mut table = ParameterTable::with_capacity(2);
|
||||
let user_info = user.user()?;
|
||||
let exp = user_info.currency(
|
||||
oj_rc_core::persist::user::CurrencyType::TechPoints,
|
||||
oj_rc_core::persist::user::CurrencyOp::Get,
|
||||
).await?;
|
||||
table.insert(CURRENT_PARAM_KEY, Typed::Int(exp as _));
|
||||
Ok(table)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn tech_points_provider<C: Send + 'static>() -> SimpleOpImpl<C, crate::UserTy, CurrentTechPointers> {
|
||||
SimpleOpImpl::new(CurrentTechPointers)
|
||||
}
|
||||
|
||||
|
||||
const UNCLAIMED_PARAM_KEY: u8 = 212;
|
||||
|
||||
pub(super) fn tech_points_awards_provider() -> SimpleFunc<185, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result<ParameterTable, i16>) + Sync + Sync> {
|
||||
|
||||
@@ -1,12 +1,29 @@
|
||||
use polariton_server::operations::SimpleFunc;
|
||||
use polariton_server::operations::{SimpleOpError, SimpleOperation, SimpleOpImpl};
|
||||
use polariton::operation::{ParameterTable, Typed};
|
||||
|
||||
const CODE: u8 = 83;
|
||||
|
||||
const PARAM_KEY: u8 = 8;
|
||||
|
||||
pub(super) fn get_user_xp_provider() -> SimpleFunc<83, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result<ParameterTable, i16>) + Sync + Sync> {
|
||||
SimpleFunc::new(|params, _| {
|
||||
let mut params = params.to_dict();
|
||||
params.insert(PARAM_KEY, Typed::Int(31337));
|
||||
Ok(params.into())
|
||||
})
|
||||
pub(super) struct UserTotalExperiencer;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl <C: Send + 'static> SimpleOperation<C> for UserTotalExperiencer {
|
||||
type User = crate::UserTy;
|
||||
const CODE: u8 = CODE;
|
||||
|
||||
async fn handle(&self, _params: ParameterTable<C>, user: &Self::User) -> Result<ParameterTable<C>, SimpleOpError> {
|
||||
let mut table = ParameterTable::with_capacity(2);
|
||||
let user_info = user.user()?;
|
||||
let exp = user_info.currency(
|
||||
oj_rc_core::persist::user::CurrencyType::Experience,
|
||||
oj_rc_core::persist::user::CurrencyOp::Get,
|
||||
).await?;
|
||||
table.insert(PARAM_KEY, Typed::Int(exp as _));
|
||||
Ok(table)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn get_user_xp_provider<C: Send + 'static>() -> SimpleOpImpl<C, crate::UserTy, UserTotalExperiencer> {
|
||||
SimpleOpImpl::new(UserTotalExperiencer)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user