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:
@@ -16,3 +16,4 @@ polariton.workspace = true
|
||||
polariton_auth = { version = "*", path = "../polariton_auth" }
|
||||
polariton_server.workspace = true
|
||||
rc_core = { version = "*", path = "../rc_core" }
|
||||
async-trait.workspace = true
|
||||
|
||||
@@ -19,7 +19,7 @@ async fn main() -> std::io::Result<()> {
|
||||
log::debug!("Got cli args {:?}", args);
|
||||
|
||||
let cubes = rc_core::persist::config::ConfigImpl::load(&args.assets).expect("Bad config data");
|
||||
let users = std::sync::Arc::new(rc_core::persist::user::UserImpl::load(&args.data, &cubes).expect("Bad user data"));
|
||||
let users = std::sync::Arc::new(rc_core::persist::user::UserImpl::load(&args.data, &cubes).await.expect("Bad user data"));
|
||||
|
||||
let server = std::sync::Arc::new(polariton_server::Server::new(operations::handler(), polariton_server::events::EventsHandler::new()));
|
||||
|
||||
|
||||
@@ -1,38 +1,58 @@
|
||||
use polariton_server::operations::SimpleFunc;
|
||||
use polariton::operation::{ParameterTable, Typed};
|
||||
use polariton::operation::{ParameterTable, Typed, OperationResponse};
|
||||
|
||||
const CODE: u8 = 1;
|
||||
|
||||
const PARAM_KEY: u8 = 8;
|
||||
|
||||
pub(super) fn tdm_machines_provider() -> SimpleFunc<1, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result<ParameterTable, i16>) + Sync + Sync> {
|
||||
SimpleFunc::new(|params, user: &crate::UserTy| {
|
||||
let ulock = user.user()?;
|
||||
let mut params = params.to_dict();
|
||||
params.insert(PARAM_KEY, ulock.singleplayer_robots()?);
|
||||
let event_tx = user.event_sender();
|
||||
let user_bot_data = ulock.slot_by_id(ulock.selected_garage_slot() as _)?;
|
||||
tokio::spawn(async move {
|
||||
tokio::time::sleep(std::time::Duration::from_secs(20)).await;
|
||||
log::debug!("Sending singleplayer event");
|
||||
let mut spawn_params = std::collections::HashMap::with_capacity(4);
|
||||
spawn_params.insert(2 /* robot GUID */, Typed::Str("1337_1337".into()));
|
||||
spawn_params.insert(3 /* machine model */, user_bot_data.data);
|
||||
spawn_params.insert(4 /* robot name */, Typed::Str("RE_robot_spawn_name0".into())); // FIXME
|
||||
spawn_params.insert(7 /* color model */, user_bot_data.colour_data);
|
||||
event_tx.send(polariton_server::ToSend::Data {
|
||||
data: polariton::packet::Data::Event(polariton::operation::Event { code: 3, params: spawn_params.into() }),
|
||||
encrypt: true,
|
||||
channel: 0,
|
||||
reliable: true,
|
||||
}).unwrap();
|
||||
/*let mut update_params = std::collections::HashMap::with_capacity(1);
|
||||
update_params.insert(6 /* ??? */, Typed::Int(5));
|
||||
event_tx.send(polariton_server::ToSend::Data {
|
||||
data: polariton::packet::Data::Event(polariton::operation::Event { code: 5, params: update_params.into() }),
|
||||
encrypt: true,
|
||||
channel: 0,
|
||||
reliable: true,
|
||||
}).unwrap();*/
|
||||
});
|
||||
Ok(params.into())
|
||||
})
|
||||
pub(super) fn tdm_machines_provider() -> AiRobots {
|
||||
AiRobots
|
||||
}
|
||||
|
||||
async fn do_handling(params: ParameterTable<()>, user: &crate::UserTy) -> Result<ParameterTable<()>, i16> {
|
||||
let ulock = user.user()?;
|
||||
let mut params = params.to_dict();
|
||||
params.insert(PARAM_KEY, ulock.singleplayer_robots().await?);
|
||||
let event_tx = user.event_sender();
|
||||
let user_bot_data = ulock.slot_by_id(ulock.selected_garage().await.1 as _).await?;
|
||||
tokio::spawn(async move {
|
||||
tokio::time::sleep(std::time::Duration::from_secs(20)).await;
|
||||
log::debug!("Sending singleplayer event");
|
||||
let mut spawn_params = std::collections::HashMap::with_capacity(4);
|
||||
spawn_params.insert(2 /* robot GUID */, Typed::Str("1337_1337".into()));
|
||||
spawn_params.insert(3 /* machine model */, user_bot_data.data);
|
||||
spawn_params.insert(4 /* robot name */, Typed::Str("RE_robot_spawn_name0".into())); // FIXME
|
||||
spawn_params.insert(7 /* color model */, user_bot_data.colour_data);
|
||||
event_tx.send(polariton_server::ToSend::Data {
|
||||
data: polariton::packet::Data::Event(polariton::operation::Event { code: 3, params: spawn_params.into() }),
|
||||
encrypt: true,
|
||||
channel: 0,
|
||||
reliable: true,
|
||||
}).unwrap();
|
||||
/*let mut update_params = std::collections::HashMap::with_capacity(1);
|
||||
update_params.insert(6 /* ??? */, Typed::Int(5));
|
||||
event_tx.send(polariton_server::ToSend::Data {
|
||||
data: polariton::packet::Data::Event(polariton::operation::Event { code: 5, params: update_params.into() }),
|
||||
encrypt: true,
|
||||
channel: 0,
|
||||
reliable: true,
|
||||
}).unwrap();*/
|
||||
});
|
||||
Ok(params.into())
|
||||
}
|
||||
|
||||
pub struct AiRobots;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl polariton_server::operations::Operation<()> for AiRobots {
|
||||
type User = crate::UserTy;
|
||||
|
||||
async fn handle_async(&self, params: ParameterTable<()>, user: &Self::User) -> OperationResponse<()> {
|
||||
polariton_server::operations::result_to_op_resp::<CODE, ()>(do_handling(params, user).await)
|
||||
}
|
||||
}
|
||||
|
||||
impl polariton_server::operations::OperationCode for AiRobots {
|
||||
fn op_code() -> u8 {
|
||||
CODE
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,18 +7,19 @@ impl MoreLobbyAuth {
|
||||
const AUTH_PAYLOAD_KEY: u8 = 245;
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl <C: Send + 'static> Operation<C> for MoreLobbyAuth {
|
||||
type User = crate::UserTy;
|
||||
|
||||
fn handle(&self, params: polariton::operation::ParameterTable<C>, user: &Self::User) -> polariton::operation::OperationResponse<C> {
|
||||
async fn handle_async(&self, params: polariton::operation::ParameterTable<C>, user: &Self::User) -> polariton::operation::OperationResponse<C> {
|
||||
let params_dict = params.to_dict();
|
||||
if let Some(Typed::Str(auth_payload)) = params_dict.get(&Self::AUTH_PAYLOAD_KEY) {
|
||||
//let mut write_lock = user.write().unwrap();
|
||||
if user.update_with_auth(&auth_payload.string) {
|
||||
if user.update_with_auth(&auth_payload.string).await {
|
||||
let mut resp_params = std::collections::HashMap::new();
|
||||
resp_params.insert(Self::AUTH_PAYLOAD_KEY, polariton::operation::Typed::Byte(0));
|
||||
return polariton::operation::OperationResponse {
|
||||
code: 230,
|
||||
code: Self::op_code(),
|
||||
return_code: 0,
|
||||
message: polariton::operation::Typed::Null,
|
||||
params: resp_params.into(),
|
||||
@@ -26,7 +27,7 @@ impl <C: Send + 'static> Operation<C> for MoreLobbyAuth {
|
||||
}
|
||||
}
|
||||
polariton::operation::OperationResponse {
|
||||
code: 230,
|
||||
code: Self::op_code(),
|
||||
return_code: 120,
|
||||
message: polariton::operation::Typed::Null,
|
||||
params: std::collections::HashMap::new().into(),
|
||||
|
||||
Reference in New Issue
Block a user