From 1d84cf666f2f311697b8ed2c5c58de4af33fefa1 Mon Sep 17 00:00:00 2001 From: ntr Date: Thu, 11 Jul 2019 22:18:52 +1000 Subject: [PATCH] fix stuff and add warden back --- client/src/socket.jsx | 6 +++--- server/src/instance.rs | 2 ++ server/src/main.rs | 28 ++++++++++++++++++++++++++-- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/client/src/socket.jsx b/client/src/socket.jsx index b3295625..71230f83 100644 --- a/client/src/socket.jsx +++ b/client/src/socket.jsx @@ -108,15 +108,15 @@ function createSocket(events) { } function sendInstanceJoin(instanceId, constructs) { - send(['Instancejoin', { instance_id: instanceId, construct_ids: constructs }]); + send(['InstanceJoin', { instance_id: instanceId, construct_ids: constructs }]); } function sendInstanceNew(constructs, name, pve) { - send(['Instancenew', { construct_ids: constructs, name, pve }]); + send(['InstanceLobby', { construct_ids: constructs, name, pve }]); } function sendInstanceReady(instanceId) { - send(['instance_ready', { instance_id: instanceId }]); + send(['InstanceReady', { instance_id: instanceId }]); } function sendMtxApply(constructId, mtx) { diff --git a/server/src/instance.rs b/server/src/instance.rs index ba729358..e20ddcf3 100644 --- a/server/src/instance.rs +++ b/server/src/instance.rs @@ -702,6 +702,7 @@ pub fn instance_new(tx: &mut Transaction, account: &Account, construct_ids: Vec< let mut instance = match pve { true => { let bot = bot_player(); + let bot_id = bot.id; // generate bot imgs only in the real world for c in bot.constructs.iter() { @@ -714,6 +715,7 @@ pub fn instance_new(tx: &mut Transaction, account: &Account, construct_ids: Vec< .set_name(name)?; instance.add_player(bot)?; + instance.player_ready(bot_id)?; instance }, diff --git a/server/src/main.rs b/server/src/main.rs index cef9548b..47d2f8d1 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -50,9 +50,13 @@ mod vbox; mod warden; mod ws; -use std::thread::spawn; +use std::thread::{sleep, spawn}; +use std::time::{Duration}; use dotenv::dotenv; +use pubsub::pg_listen; +use warden::warden; + fn setup_logger() -> Result<(), fern::InitError> { fern::Dispatch::new() .format(|out, message, record| { @@ -65,7 +69,7 @@ fn setup_logger() -> Result<(), fern::InitError> { )) }) .level_for("postgres", log::LevelFilter::Info) - .level_for("actix_web", log::LevelFilter::Info) + .level_for("iron", log::LevelFilter::Info) .level(log::LevelFilter::Info) .chain(std::io::stdout()) .chain(fern::log_file("/var/log/mnml/mnml.log")?) @@ -81,6 +85,26 @@ fn main() { let ws_pool = pool.clone(); let http_pool = pool.clone(); + let warden_pool = pool.clone(); + let pubsub_pool = pool.clone(); + + spawn(move || { + loop { + let db_connection = warden_pool.get().expect("unable to get db connection"); + if let Err(e) = warden(db_connection) { + info!("{:?}", e); + } + sleep(Duration::new(1, 0)); + } + }); + + spawn(move || loop { + let pubsub_conn = pubsub_pool.get().expect("could not get pubsub pg connection"); + match pg_listen(pubsub_conn) { + Ok(_) => warn!("pg listen closed"), + Err(e) => warn!("pg_listen error {:?}", e), + } + }); spawn(move || net::start(http_pool)); ws::start(ws_pool);