mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Add avatar saving functionality (without CDN support)
This commit is contained in:
@@ -1,14 +1,36 @@
|
||||
use polariton_server::operations::SimpleFunc;
|
||||
use polariton::operation::{ParameterTable, Typed};
|
||||
use polariton::operation::{ParameterTable, OperationResponse};
|
||||
|
||||
const IS_CUSTOM_PARAM_KEY: u8 = 130;
|
||||
const AVATAR_ID_PARAM_KEY: u8 = 129;
|
||||
const CODE: u8 = 110;
|
||||
|
||||
pub(super) fn get_avatar_provider() -> SimpleFunc<110, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result<ParameterTable, i16>) + Sync + Sync> {
|
||||
SimpleFunc::new(|params, _| {
|
||||
let mut params = params.to_dict();
|
||||
params.insert(IS_CUSTOM_PARAM_KEY, Typed::Bool(false.into()));
|
||||
params.insert(AVATAR_ID_PARAM_KEY, Typed::Int(1));
|
||||
Ok(params.into())
|
||||
})
|
||||
const IS_CUSTOM_PARAM_KEY: u8 = 130; // bool
|
||||
const AVATAR_ID_PARAM_KEY: u8 = 129; // int
|
||||
|
||||
pub(super) fn avatar_get_provider() -> AvatarGetProvider {
|
||||
AvatarGetProvider
|
||||
}
|
||||
|
||||
async fn do_save(params: ParameterTable<()>, user: &crate::UserTy) -> Result<ParameterTable, i16> {
|
||||
let mut params = params.to_dict();
|
||||
let user_info = user.user()?;
|
||||
let info = user_info.get_avatar_info().await?;
|
||||
params.insert(IS_CUSTOM_PARAM_KEY, info.use_custom);
|
||||
params.insert(AVATAR_ID_PARAM_KEY, info.avatar_id);
|
||||
Ok(params.into())
|
||||
}
|
||||
|
||||
pub(super) struct AvatarGetProvider;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl polariton_server::operations::Operation<()> for AvatarGetProvider {
|
||||
type User = crate::UserTy;
|
||||
|
||||
async fn handle_async(&self, params: ParameterTable<()>, user: &Self::User) -> OperationResponse<()> {
|
||||
polariton_server::operations::result_to_op_resp::<CODE, ()>(do_save(params, user).await)
|
||||
}
|
||||
}
|
||||
|
||||
impl polariton_server::operations::OperationCode for AvatarGetProvider {
|
||||
fn op_code() -> u8 {
|
||||
CODE
|
||||
}
|
||||
}
|
||||
|
||||
42
rc_services_room/src/operations/avatar_set.rs
Normal file
42
rc_services_room/src/operations/avatar_set.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
use polariton::operation::{ParameterTable, Typed, OperationResponse};
|
||||
|
||||
const CODE: u8 = 111;
|
||||
|
||||
const IS_CUSTOM_PARAM_KEY: u8 = 130; // bool; in
|
||||
const AVATAR_ID_PARAM_KEY: u8 = 129; // int; in
|
||||
|
||||
pub(super) fn avatar_set_provider() -> AvatarSetProvider {
|
||||
AvatarSetProvider
|
||||
}
|
||||
|
||||
async fn do_save(params: ParameterTable<()>, user: &crate::UserTy) -> Result<ParameterTable, i16> {
|
||||
let mut params = params.to_dict();
|
||||
let user_info = user.user()?;
|
||||
if let Some(Typed::Int(avatar)) = params.remove(&AVATAR_ID_PARAM_KEY) {
|
||||
if let Some(Typed::Bool(is_custom)) = params.remove(&IS_CUSTOM_PARAM_KEY) {
|
||||
let info = rc_core::persist::user::AvatarInfo {
|
||||
avatar_id: avatar,
|
||||
use_custom: is_custom,
|
||||
};
|
||||
user_info.set_avatar_info(info).await?;
|
||||
}
|
||||
}
|
||||
Ok(params.into())
|
||||
}
|
||||
|
||||
pub(super) struct AvatarSetProvider;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl polariton_server::operations::Operation<()> for AvatarSetProvider {
|
||||
type User = crate::UserTy;
|
||||
|
||||
async fn handle_async(&self, params: ParameterTable<()>, user: &Self::User) -> OperationResponse<()> {
|
||||
polariton_server::operations::result_to_op_resp::<CODE, ()>(do_save(params, user).await)
|
||||
}
|
||||
}
|
||||
|
||||
impl polariton_server::operations::OperationCode for AvatarSetProvider {
|
||||
fn op_code() -> u8 {
|
||||
CODE
|
||||
}
|
||||
}
|
||||
44
rc_services_room/src/operations/avatar_set_custom.rs
Normal file
44
rc_services_room/src/operations/avatar_set_custom.rs
Normal file
@@ -0,0 +1,44 @@
|
||||
use polariton::operation::{ParameterTable, Typed, OperationResponse};
|
||||
|
||||
const CODE: u8 = 112;
|
||||
|
||||
const IMG_PARAM_KEY: u8 = 131; // int; in
|
||||
const FORMAT_PARAM_KEY: u8 = 132; // int enum; in
|
||||
|
||||
pub(super) fn custom_avatar_upload_handler() -> CustomAvatarHandler {
|
||||
CustomAvatarHandler
|
||||
}
|
||||
|
||||
async fn do_save(params: ParameterTable<()>, _user: &crate::UserTy) -> Result<ParameterTable, i16> {
|
||||
let mut params = params.to_dict();
|
||||
//let user_info = user.user()?;
|
||||
if let Some(Typed::Bytes(image)) = params.remove(&IMG_PARAM_KEY) {
|
||||
if let Some(Typed::Int(format)) = params.remove(&FORMAT_PARAM_KEY) {
|
||||
log::debug!("Got custom avatar ({}B) with format {}", image.vec.len(), format);
|
||||
// TODO actually save image
|
||||
/*let info = rc_core::persist::user::AvatarInfo {
|
||||
avatar_id: 0,
|
||||
use_custom: true,
|
||||
};
|
||||
user_info.set_avatar_info(info).await?;*/
|
||||
}
|
||||
}
|
||||
Ok(params.into())
|
||||
}
|
||||
|
||||
pub(super) struct CustomAvatarHandler;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl polariton_server::operations::Operation<()> for CustomAvatarHandler {
|
||||
type User = crate::UserTy;
|
||||
|
||||
async fn handle_async(&self, params: ParameterTable<()>, user: &Self::User) -> OperationResponse<()> {
|
||||
polariton_server::operations::result_to_op_resp::<CODE, ()>(do_save(params, user).await)
|
||||
}
|
||||
}
|
||||
|
||||
impl polariton_server::operations::OperationCode for CustomAvatarHandler {
|
||||
fn op_code() -> u8 {
|
||||
CODE
|
||||
}
|
||||
}
|
||||
@@ -91,6 +91,8 @@ mod crf_list_query;
|
||||
mod crf_vehicle_data;
|
||||
mod crf_purchase;
|
||||
mod crf_upload;
|
||||
mod avatar_set_custom;
|
||||
mod avatar_set;
|
||||
|
||||
use polariton_server::operations::OperationsHandler;
|
||||
|
||||
@@ -136,7 +138,7 @@ pub fn handler(init_ctx: &crate::InitConfig) -> OperationsHandler<crate::UserTy>
|
||||
.add(owned_cosmetics::selected_cosmetics_provider())
|
||||
.add(dev_message::dev_message_provider(&init_ctx.cubes))
|
||||
.add(custom_games_maps::allowed_maps_provider())
|
||||
.add(avatar_info::get_avatar_provider())
|
||||
.add(avatar_info::avatar_get_provider())
|
||||
.add(custom_game_session::get_custom_session_provider())
|
||||
.add(user_xp::get_user_xp_provider())
|
||||
.add(garage_upgrades::garage_upgrades_provider(&init_ctx.cubes))
|
||||
@@ -204,4 +206,6 @@ pub fn handler(init_ctx: &crate::InitConfig) -> OperationsHandler<crate::UserTy>
|
||||
.add(crf_vehicle_data::crf_item_data_provider(&init_ctx.factory))
|
||||
.add(crf_purchase::crf_copy_to_bay_provider(&init_ctx.factory, init_ctx.parsers.weapon_order()))
|
||||
.add(crf_upload::crf_upload_provider(&init_ctx.factory))
|
||||
.add(avatar_set_custom::custom_avatar_upload_handler())
|
||||
.add(avatar_set::avatar_set_provider())
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ pub(super) fn premium_remaining_provider() -> SimpleFunc<15, crate::UserTy, impl
|
||||
params.insert(HOURS_PARAM_KEY, Typed::Int(0));
|
||||
params.insert(MINUTES_PARAM_KEY, Typed::Int(0));
|
||||
params.insert(SECONDS_PARAM_KEY, Typed::Int(0));
|
||||
params.insert(LIFETIME_PARAM_KEY, Typed::Bool(false.into()));
|
||||
params.insert(LIFETIME_PARAM_KEY, Typed::Bool(false));
|
||||
Ok(params.into())
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user