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:
@@ -7,6 +7,9 @@ pub struct CliArgs {
|
||||
/// Robocraft user data root
|
||||
#[arg(long, default_value_t = {"../data/robocraft".to_string()})]
|
||||
pub data_robocraft: String,
|
||||
/// Robocraft asset data root
|
||||
#[arg(long, default_value_t = {"../assets/robocraft".to_string()})]
|
||||
pub assets_robocraft: String,
|
||||
}
|
||||
|
||||
impl CliArgs {
|
||||
@@ -14,10 +17,10 @@ impl CliArgs {
|
||||
Self::parse()
|
||||
}
|
||||
|
||||
pub fn preloaded(self) -> Config {
|
||||
pub async fn preloaded(self) -> Config {
|
||||
Config {
|
||||
#[cfg(feature = "robocraft")]
|
||||
robocraft: crate::robocraft::RcConfig::from_args(&self),
|
||||
robocraft: crate::robocraft::RcConfig::from_args(&self).await,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,12 +17,12 @@ fn index() -> String {
|
||||
}
|
||||
|
||||
#[rocket::launch]
|
||||
fn rocket() -> _ {
|
||||
async fn rocket() -> _ {
|
||||
env_logger::init();
|
||||
let args = common::cli::CliArgs::get();
|
||||
#[allow(unused_mut)]
|
||||
let mut builder = rocket::build().mount("/", rocket::routes![index])
|
||||
.manage(args.preloaded());
|
||||
.manage(args.preloaded().await);
|
||||
|
||||
#[cfg(feature = "cardlife")]
|
||||
{builder = builder.attach(cardlife::stage());}
|
||||
|
||||
@@ -2,7 +2,7 @@ use rc_core::UserAuthenticator;
|
||||
use rocket::{post, routes, serde::json::Json, http::Status, State};
|
||||
|
||||
#[post("/authenticate/robocraft/game", data = "<body>")]
|
||||
pub fn email_password_auth(body: Json<libfj::robocraft::EmailUserAuthenticationPayload>, config: &State<crate::common::cli::Config>) -> Result<Json<libfj::robocraft::AuthenticationResponseInfo>, Status> {
|
||||
pub async fn email_password_auth(body: Json<libfj::robocraft::EmailUserAuthenticationPayload>, config: &State<crate::common::cli::Config>) -> Result<Json<libfj::robocraft::AuthenticationResponseInfo>, Status> {
|
||||
log::info!("Authenticating {} user {}", body.target, body.display_name);
|
||||
let payload = libfj::robocraft::TokenPayload {
|
||||
public_id: body.display_name.clone(),
|
||||
@@ -16,7 +16,7 @@ pub fn email_password_auth(body: Json<libfj::robocraft::EmailUserAuthenticationP
|
||||
payload,
|
||||
extra: rc_core::persist::user::ExtraUserInfo::Standalone { password: body.password.clone() },
|
||||
};
|
||||
let response = config.robocraft.account_provider.login(user_info)
|
||||
let response = config.robocraft.account_provider.login(user_info).await
|
||||
.map_err(|e| {
|
||||
log::error!("Failed to authenticate {} user {}: {}", body.target, body.display_name, e);
|
||||
Status { code: 401 }
|
||||
|
||||
@@ -18,9 +18,10 @@ pub struct RcConfig {
|
||||
}
|
||||
|
||||
impl RcConfig {
|
||||
pub fn from_args(args: &crate::common::cli::CliArgs) -> Self {
|
||||
pub async fn from_args(args: &crate::common::cli::CliArgs) -> Self {
|
||||
let conf = rc_core::persist::config::ConfigImpl::load(&args.assets_robocraft).expect("Bad config data");
|
||||
Self {
|
||||
account_provider: rc_core::UserImpl::load_for_auth(&args.data_robocraft).expect("Invalid Robocraft user data"),
|
||||
account_provider: rc_core::UserImpl::load(&args.data_robocraft, &conf).await.expect("Invalid Robocraft user data"),
|
||||
root: args.data_robocraft.clone().into(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ use rc_core::UserAuthenticator;
|
||||
use rocket::{http::Status, post, routes, serde::json::Json, State};
|
||||
|
||||
#[post("/authenticate/steam/game", data = "<body>")]
|
||||
pub fn steam_auth(body: Json<libfj::robocraft::SteamAuthenticationPayload>, config: &State<crate::common::cli::Config>) -> Result<Json<libfj::robocraft::AuthenticationResponseInfo>, Status> {
|
||||
pub async fn steam_auth(body: Json<libfj::robocraft::SteamAuthenticationPayload>, config: &State<crate::common::cli::Config>) -> Result<Json<libfj::robocraft::AuthenticationResponseInfo>, Status> {
|
||||
let steam_id = crate::common::steam_utils::authenticate_steam_ticket(&body.steam_ticket)
|
||||
.map_err(|_| Status { code: 401 })?;
|
||||
log::info!("Authenticating {} steam user {}", body.target, steam_id);
|
||||
@@ -18,7 +18,7 @@ pub fn steam_auth(body: Json<libfj::robocraft::SteamAuthenticationPayload>, conf
|
||||
payload,
|
||||
extra: rc_core::persist::user::ExtraUserInfo::Steam { id: steam_id },
|
||||
};
|
||||
let response = config.robocraft.account_provider.login(user_info)
|
||||
let response = config.robocraft.account_provider.login(user_info).await
|
||||
.map_err(|e| {
|
||||
log::error!("Failed to authenticate {} steam user {}: {}", body.target, steam_id, e);
|
||||
Status { code: 401 }
|
||||
|
||||
Reference in New Issue
Block a user