mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Add status reporting to auth server
This commit is contained in:
@@ -26,3 +26,5 @@ rand.workspace = true
|
||||
literustlib_server = { version = "0.2" }
|
||||
literustlib = { version = "0.2" }
|
||||
rlnl = { version = "0.1", path = "../../rlnl" }
|
||||
|
||||
oj_serdes.workspace = true
|
||||
|
||||
@@ -16,6 +16,8 @@ pub struct InitConfig {
|
||||
pub matches_chann: tokio::sync::mpsc::Sender<matches::GameMessage>,
|
||||
}
|
||||
|
||||
pub static START_TIMESTAMP_S: std::sync::atomic::AtomicI64 = std::sync::atomic::AtomicI64::new(0);
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
env_logger::init();
|
||||
@@ -41,5 +43,19 @@ async fn main() -> std::io::Result<()> {
|
||||
let event_handler = events::handler(&init_ctx).await;
|
||||
let server = literustlib_server::Server::new(event_handler, (args.ip, args.port), mtu).await.expect("Bad server");
|
||||
|
||||
let start_time = chrono::Utc::now();
|
||||
START_TIMESTAMP_S.store(start_time.timestamp(), std::sync::atomic::Ordering::Relaxed);
|
||||
|
||||
server.listen().await
|
||||
}
|
||||
|
||||
pub async fn update_status(user_info: &dyn oj_rc_core::persist::user::IntercomUser, player_count: u64) {
|
||||
user_info.update_status(
|
||||
env!("CARGO_PKG_NAME"),
|
||||
oj_serdes::ServerStatus {
|
||||
uptime_s: (chrono::Utc::now().timestamp() - crate::START_TIMESTAMP_S.load(std::sync::atomic::Ordering::Relaxed)).try_into().unwrap_or_default(),
|
||||
players: player_count,
|
||||
version: env!("CARGO_PKG_VERSION").to_owned(),
|
||||
},
|
||||
).await;
|
||||
}
|
||||
|
||||
@@ -220,17 +220,18 @@ impl GameMatches {
|
||||
if let Some(tx) = self.matches.get(&game_guid) {
|
||||
if tx.is_closed() {
|
||||
self.do_game_cleanup(&game_guid);
|
||||
self.create_new_game(user, game_guid, connection, response, sender).await;
|
||||
self.create_new_game(user.clone(), game_guid, connection, response, sender).await;
|
||||
} else {
|
||||
self.routing.insert(user.user_id(), game_guid.clone());
|
||||
if tx.send(super::GameMessage::NewConnection { user, game_guid, connection, response, sender }).await.is_err() {
|
||||
if tx.send(super::GameMessage::NewConnection { user: user.clone(), game_guid, connection, response, sender }).await.is_err() {
|
||||
log::error!("Failed to send NewConnection game message to existing match");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
self.create_new_game(user, game_guid, connection, response, sender).await;
|
||||
self.create_new_game(user.clone(), game_guid, connection, response, sender).await;
|
||||
}
|
||||
}
|
||||
crate::update_status(user.as_ref().as_ref(), self.routing.len() as u64).await;
|
||||
},
|
||||
msg => {
|
||||
let user_id = msg.user_id();
|
||||
let mut to_clean = None;
|
||||
|
||||
Reference in New Issue
Block a user