mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Create RC database layer
This commit is contained in:
@@ -1,22 +1,40 @@
|
||||
use polariton_server::operations::SimpleFunc;
|
||||
use polariton::operation::{ParameterTable, Typed};
|
||||
use polariton::operation::{ParameterTable, Typed, OperationResponse};
|
||||
|
||||
const USERNAME_PARAM_KEY: u8 = 30; // in; str
|
||||
const RANK_PARAM_KEY: u8 = 84; // out; int
|
||||
const CPU_PARAM_KEY: u8 = 177; // out; int
|
||||
const COSMETIC_CPU_PARAM_KEY: u8 = 176; // out; int
|
||||
|
||||
pub(super) fn player_robot_rank_provider() -> SimpleFunc<79, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result<ParameterTable, i16>) + Sync + Sync> {
|
||||
SimpleFunc::new(|params, user: &crate::UserTy| {
|
||||
let user = user.user()?;
|
||||
let mut params = params.to_dict();
|
||||
if let Some(Typed::Str(username)) = params.get(&USERNAME_PARAM_KEY) {
|
||||
log::debug!("Get robot rank for user {}", username.string);
|
||||
}
|
||||
let robot = user.slot_by_id(user.selected_garage_slot() as i32)?;
|
||||
params.insert(RANK_PARAM_KEY, robot.robot_rank);
|
||||
params.insert(CPU_PARAM_KEY, robot.cpu);
|
||||
params.insert(COSMETIC_CPU_PARAM_KEY, robot.cosmetic_cpu);
|
||||
Ok(params.into())
|
||||
})
|
||||
pub(super) fn player_robot_rank_provider() -> PlayerRank {
|
||||
PlayerRank
|
||||
}
|
||||
|
||||
async fn do_handling(params: ParameterTable<()>, user: &crate::UserTy) -> Result<ParameterTable, i16> {
|
||||
let user = user.user()?;
|
||||
let mut params = params.to_dict();
|
||||
if let Some(Typed::Str(username)) = params.get(&USERNAME_PARAM_KEY) {
|
||||
log::debug!("Get robot rank for user {}", username.string);
|
||||
}
|
||||
let robot = user.slot_by_id(user.selected_garage().await.1 as i32).await?;
|
||||
params.insert(RANK_PARAM_KEY, robot.robot_rank);
|
||||
params.insert(CPU_PARAM_KEY, robot.cpu);
|
||||
params.insert(COSMETIC_CPU_PARAM_KEY, robot.cosmetic_cpu);
|
||||
Ok(params.into())
|
||||
}
|
||||
|
||||
pub struct PlayerRank;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl polariton_server::operations::Operation<()> for PlayerRank {
|
||||
type User = crate::UserTy;
|
||||
|
||||
async fn handle_async(&self, params: ParameterTable<()>, user: &Self::User) -> OperationResponse<()> {
|
||||
polariton_server::operations::result_to_op_resp::<79, ()>(do_handling(params, user).await)
|
||||
}
|
||||
}
|
||||
|
||||
impl polariton_server::operations::OperationCode for PlayerRank {
|
||||
fn op_code() -> u8 {
|
||||
79
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user