fix stuff and add warden back

This commit is contained in:
ntr 2019-07-11 22:18:52 +10:00
parent 844fa6b54f
commit 1d84cf666f
3 changed files with 31 additions and 5 deletions

View File

@ -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) {

View File

@ -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
},

View File

@ -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);