2024-12-03 05:09:59 +00:00
|
|
|
mod nats_types;
|
2024-12-03 05:15:10 +00:00
|
|
|
mod validator;
|
2024-12-07 04:31:28 +00:00
|
|
|
mod publish_new;
|
|
|
|
mod publish_fix;
|
2024-11-26 01:30:55 +00:00
|
|
|
|
2024-12-03 06:09:01 +00:00
|
|
|
#[allow(dead_code)]
|
|
|
|
#[derive(Debug)]
|
|
|
|
enum StartupError{
|
2024-12-05 00:46:20 +00:00
|
|
|
API(api::ReqwestError),
|
2024-12-11 01:47:17 +00:00
|
|
|
NatsConnect(async_nats::ConnectError),
|
|
|
|
NatsSubscribe(async_nats::SubscribeError),
|
2024-12-12 01:43:01 +00:00
|
|
|
GRPCConnect(tonic::transport::Error),
|
2024-12-03 06:09:01 +00:00
|
|
|
}
|
2024-12-03 06:52:01 +00:00
|
|
|
impl std::fmt::Display for StartupError{
|
|
|
|
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
|
|
|
write!(f,"{self:?}")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl std::error::Error for StartupError{}
|
2024-12-03 06:09:01 +00:00
|
|
|
|
2024-12-07 05:00:19 +00:00
|
|
|
pub const GROUP_STRAFESNET:u64=6980477;
|
|
|
|
|
2024-12-12 01:43:01 +00:00
|
|
|
// annoying mile-long type
|
|
|
|
pub type MapsServiceClient=rust_grpc::maps::maps_service_client::MapsServiceClient<tonic::transport::channel::Channel>;
|
|
|
|
|
2024-12-03 05:15:10 +00:00
|
|
|
#[tokio::main]
|
2024-12-03 06:09:01 +00:00
|
|
|
async fn main()->Result<(),StartupError>{
|
2024-12-11 01:39:08 +00:00
|
|
|
// talk to roblox through STRAFESNET_CI2 account
|
|
|
|
let cookie=std::env::var("RBXCOOKIE").expect("RBXCOOKIE env required");
|
|
|
|
let cookie_context=rbx_asset::cookie::CookieContext::new(rbx_asset::cookie::Cookie::new(cookie));
|
2024-12-03 06:52:01 +00:00
|
|
|
|
2024-12-05 00:46:20 +00:00
|
|
|
// maps-service api
|
2024-12-11 01:39:08 +00:00
|
|
|
let api_host=std::env::var("API_HOST").expect("API_HOST env required");
|
|
|
|
let api=api::Context::new(api_host).map_err(StartupError::API)?;
|
2024-12-05 00:46:20 +00:00
|
|
|
|
2024-12-03 06:52:01 +00:00
|
|
|
// nats
|
2024-12-11 01:39:08 +00:00
|
|
|
let nats_host=std::env::var("NATS_HOST").expect("NATS_HOST env required");
|
2024-12-11 01:47:17 +00:00
|
|
|
let nasty=async_nats::connect(nats_host).await.map_err(StartupError::NatsConnect)?;
|
2024-12-03 06:52:01 +00:00
|
|
|
|
2024-12-12 01:43:01 +00:00
|
|
|
// data-service grpc for creating map entries
|
|
|
|
let data_host=std::env::var("DATA_HOST").expect("DATA_HOST env required");
|
|
|
|
let maps_grpc=MapsServiceClient::connect(data_host).await.map_err(StartupError::GRPCConnect)?;
|
|
|
|
|
2024-12-03 06:52:01 +00:00
|
|
|
// connect to nats
|
2024-12-07 04:31:28 +00:00
|
|
|
let (publish_new,publish_fix,validator)=tokio::try_join!(
|
2024-12-12 01:43:01 +00:00
|
|
|
publish_new::Publisher::new(nasty.clone(),cookie_context.clone(),api.clone(),maps_grpc),
|
2024-12-07 04:31:28 +00:00
|
|
|
publish_fix::Publisher::new(nasty.clone(),cookie_context.clone()),
|
2024-12-05 00:46:20 +00:00
|
|
|
// clone nats here because it's dropped within the function scope,
|
|
|
|
// meanining the last reference is dropped...
|
|
|
|
validator::Validator::new(nasty.clone(),cookie_context,api)
|
2024-12-11 01:47:17 +00:00
|
|
|
).map_err(StartupError::NatsSubscribe)?;
|
2024-12-03 06:52:01 +00:00
|
|
|
|
2024-12-07 04:31:28 +00:00
|
|
|
// publisher threads
|
|
|
|
tokio::spawn(publish_new.run());
|
|
|
|
tokio::spawn(publish_fix.run());
|
2024-12-03 06:52:01 +00:00
|
|
|
|
2024-12-03 06:09:01 +00:00
|
|
|
// run validator on the main thread indefinitely
|
|
|
|
validator.run().await;
|
2024-12-03 06:52:01 +00:00
|
|
|
|
2024-12-03 06:09:01 +00:00
|
|
|
Ok(())
|
2024-11-26 01:30:55 +00:00
|
|
|
}
|