From 95c463757df398b9895c9869ee3ed9c332a47b69 Mon Sep 17 00:00:00 2001 From: ntr Date: Sat, 27 Apr 2019 22:54:16 +1000 Subject: [PATCH 01/11] warden wip --- server/WORKLOG.md | 25 +++++++++++++----- server/src/game.rs | 47 ++++++++++++++++++++++++++++++++++ server/src/instance.rs | 18 ++----------- server/src/main.rs | 1 + server/src/net.rs | 7 +++++- server/src/player.rs | 3 ++- server/src/rpc.rs | 14 +---------- server/src/warden.rs | 57 ++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 135 insertions(+), 37 deletions(-) create mode 100644 server/src/warden.rs diff --git a/server/WORKLOG.md b/server/WORKLOG.md index 22cece8f..8cda1ec5 100644 --- a/server/WORKLOG.md +++ b/server/WORKLOG.md @@ -16,14 +16,22 @@ # WORK WORK ## NOW -*INSTANCES* +*WARDEN* + +* games +check updated timestamps + once a second? +add a timestamp to each team + after 30s issue warning (client) + after 1m automove + increment warnings + after 3 warnings forfeit + +* instances + add timestamp to each player + after 60s force ready -lobby opens - add player - add player - players ready - on start -> vbox *CLIENT* * general @@ -76,6 +84,11 @@ make strike *really* hit first / resolve at same time? ## LATER * redis for game events + +* store instances / games in redis? + * not sure hwo to get sets of player games + * set joined_games_$account [game_id] + * chat * notifications * elo + leaderboards diff --git a/server/src/game.rs b/server/src/game.rs index 3bfca93b..90e43348 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -681,6 +681,7 @@ pub fn game_get(tx: &mut Transaction, id: Uuid) -> Result { SELECT * FROM games WHERE id = $1 + FOR UPDATE; "; let result = tx @@ -698,6 +699,52 @@ pub fn game_get(tx: &mut Transaction, id: Uuid) -> Result { return Ok(game); } +pub fn games_afk(tx: &mut Transaction) -> Result, Error> { + let query = " + SELECT data, id + FROM games + WHERE updated_at < now() - interval '5 seconds'; + "; + + let result = tx + .query(query, &[])?; + + let mut list = vec![]; + + for row in result.into_iter() { + let bytes: Vec = row.get(0); + let id = row.get(1); + + match from_slice::(&bytes) { + Ok(i) => list.push(i), + Err(_e) => { + game_delete(tx, id)?; + } + }; + } + + return Ok(list); +} + +pub fn game_delete(tx: &mut Transaction, id: Uuid) -> Result<(), Error> { + let query = " + DELETE + FROM games + WHERE id = $1; + "; + + let result = tx + .execute(query, &[&id])?; + + if result != 1 { + return Err(format_err!("unable to delete player {:?}", id)); + } + + println!("game deleted {:?}", id); + + return Ok(()); +} + pub fn game_global_startup(tx: &mut Transaction) -> Result<(), Error> { if game_global_get(tx).is_ok() { println!("global mm game exists"); diff --git a/server/src/instance.rs b/server/src/instance.rs index 8c97d6a7..31189ceb 100644 --- a/server/src/instance.rs +++ b/server/src/instance.rs @@ -389,16 +389,6 @@ impl Instance { } } - fn scores(&self) -> Vec<(String, Score)> { - let mut scores = self.players.iter() - .map(|p| (p.name.clone(), p.score)) - .collect::>(); - scores.sort_unstable_by_key(|s| s.1.wins); - scores.reverse(); - - scores - } - // PLAYER ACTIONS fn account_player(&mut self, account: Uuid) -> Result<&mut Player, Error> { self.players @@ -485,7 +475,8 @@ pub fn instance_get(tx: &mut Transaction, instance_id: Uuid) -> Result Result, Error> { - let scores = instance_get(tx, params.instance_id)?.scores(); - Ok(scores) -} - pub fn instance_ready(params: InstanceReadyParams, tx: &mut Transaction, account: &Account) -> Result { let mut instance = instance_get(tx, params.instance_id)?; let player_id = instance.account_player(account.id)?.id; diff --git a/server/src/main.rs b/server/src/main.rs index 8fa4a8b1..ba798350 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -33,6 +33,7 @@ mod player; mod mob; mod util; mod vbox; +mod warden; use dotenv::dotenv; use net::{start}; diff --git a/server/src/net.rs b/server/src/net.rs index 862ab83d..7ca1cc94 100644 --- a/server/src/net.rs +++ b/server/src/net.rs @@ -19,6 +19,7 @@ pub type Db = PooledConnection; use rpc::{Rpc}; use util::{startup}; +use warden::{warden}; // struct Server { // client: WebSocket, @@ -69,9 +70,13 @@ pub fn start() { } let server = TcpListener::bind("0.0.0.0:40000").unwrap(); + + let warden_pool = pool.clone(); + spawn(move || warden(warden_pool)); + for stream in server.incoming() { let db = pool.clone(); - spawn (move || { + spawn(move || { let mut websocket = accept(stream.unwrap()).unwrap(); let rpc = Rpc {}; diff --git a/server/src/player.rs b/server/src/player.rs index c5edeefd..4e278e0a 100644 --- a/server/src/player.rs +++ b/server/src/player.rs @@ -266,7 +266,8 @@ pub fn player_get(tx: &mut Transaction, account_id: Uuid, instance_id: Uuid) -> SELECT * FROM players WHERE account = $1 - AND instance = $2; + AND instance = $2 + FOR UPDATE; "; let result = tx diff --git a/server/src/rpc.rs b/server/src/rpc.rs index 357a1cf3..d802c936 100644 --- a/server/src/rpc.rs +++ b/server/src/rpc.rs @@ -22,7 +22,7 @@ use skill::{Skill}; // use zone::{Zone, zone_create, zone_join, zone_close}; use spec::{Spec}; use player::{Score, player_mm_cryps_set, Player}; -use instance::{Instance, instance_state, instance_new, instance_ready, instance_join, instance_scores}; +use instance::{Instance, instance_state, instance_new, instance_ready, instance_join}; use vbox::{Var, vbox_accept, vbox_apply, vbox_discard, vbox_combine, vbox_reclaim, vbox_unequip}; pub struct Rpc; @@ -75,7 +75,6 @@ impl Rpc { "instance_join" => Rpc::instance_join(data, &mut tx, account.unwrap(), client), "instance_ready" => Rpc::instance_ready(data, &mut tx, account.unwrap(), client), "instance_new" => Rpc::instance_new(data, &mut tx, account.unwrap(), client), - "instance_scores" => Rpc::instance_scores(data, &mut tx, account.unwrap(), client), "instance_state" => Rpc::instance_state(data, &mut tx, account.unwrap(), client), "player_mm_cryps_set" => Rpc::player_mm_cryps_set(data, &mut tx, account.unwrap(), client), @@ -261,17 +260,6 @@ impl Rpc { // return Ok(response); // } - fn instance_scores(data: Vec, tx: &mut Transaction, account: Account, _client: &mut WebSocket) -> Result { - let msg = from_slice::(&data).or(Err(err_msg("invalid params")))?; - - let response = RpcResponse { - method: "instance_scores".to_string(), - params: RpcResult::InstanceScores(instance_scores(msg.params, tx, &account)?) - }; - - return Ok(response); - } - fn instance_state(data: Vec, tx: &mut Transaction, account: Account, _client: &mut WebSocket) -> Result { let msg = from_slice::(&data).or(Err(err_msg("invalid params")))?; match instance_state(msg.params, tx, &account)? { diff --git a/server/src/warden.rs b/server/src/warden.rs new file mode 100644 index 00000000..a77f8263 --- /dev/null +++ b/server/src/warden.rs @@ -0,0 +1,57 @@ +use std::time::{Duration}; +use std::thread::sleep; + +// Db Commons +use postgres::transaction::Transaction; +use failure::Error; +use failure::err_msg; + +use r2d2::{Pool}; +use r2d2_postgres::{PostgresConnectionManager}; + +use game::{Game, games_afk, game_write}; +use instance::{Instance, instances_afk, instance_write}; + +fn handle_afk_game(game: Game) -> Game { + game +} + +fn fetch_games(mut tx: Transaction) -> Result { + let games = games_afk(&mut tx)?; + + for mut game in games { + game = handle_afk_game(game); + game_write(&game, &mut tx)?; + } + + Ok(tx) +} + +fn handle_afk_instance(instance: Instance) -> Instance { + instance +} + +fn fetch_instances(mut tx: Transaction) -> Result { + let instances = instances_afk(&mut tx)?; + + for mut instance in instances { + instance = handle_afk_instance(instance); + instance_write(&instance, &mut tx)?; + } + + Ok(tx) +} + +pub fn warden(pool: Pool) -> Result<(), Error> { + loop { + let db_connection = pool.get().expect("unable to get db connection"); + + fetch_games(db_connection.transaction()?)? + .commit()?; + + fetch_instances(db_connection.transaction()?) + .commit()?; + + sleep(Duration::new(30, 0)); + } +} \ No newline at end of file From 0daa7967f4f11a4350c7c6998b3308cb3218668c Mon Sep 17 00:00:00 2001 From: ntr Date: Sat, 27 Apr 2019 23:27:44 +1000 Subject: [PATCH 02/11] fix scoreboard --- client/src/components/info.component.jsx | 2 +- client/src/keyboard.jsx | 1 + server/src/game.rs | 13 +++++++---- server/src/instance.rs | 29 +++++++++++++++++++++++- server/src/warden.rs | 16 +++---------- server/src/zone.rs | 2 +- 6 files changed, 43 insertions(+), 20 deletions(-) diff --git a/client/src/components/info.component.jsx b/client/src/components/info.component.jsx index ade31874..9d395a9c 100644 --- a/client/src/components/info.component.jsx +++ b/client/src/components/info.component.jsx @@ -180,7 +180,7 @@ function Info(args) { ? infoCrypElement(player.cryps.find(c => c.id === activeCryp.id)) : null; - const otherInfo = !info[0] + const otherInfo = info[0] ? infoVar(info) : null; diff --git a/client/src/keyboard.jsx b/client/src/keyboard.jsx index 14392540..73fadac8 100644 --- a/client/src/keyboard.jsx +++ b/client/src/keyboard.jsx @@ -8,6 +8,7 @@ function setupKeys(store) { key('esc', () => store.dispatch(actions.setReclaiming(false))); key('esc', () => store.dispatch(actions.setActiveSkill(null))); key('esc', () => store.dispatch(actions.setActiveCryp(null))); + key('esc', () => store.dispatch(actions.setInfo([null, null]))); } module.exports = setupKeys; diff --git a/server/src/game.rs b/server/src/game.rs index 90e43348..6293eaf2 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -587,6 +587,11 @@ impl Game { self } + + pub fn handle_afk(mut self) -> Game { + + self + } } pub fn game_skill(params: GameSkillParams, tx: &mut Transaction, account: &Account) -> Result { @@ -758,7 +763,7 @@ pub fn game_global_startup(tx: &mut Transaction) -> Result<(), Error> { .set_team_size(3) .set_mode(GameMode::Pvp); - game_write(&game, tx)?; + game_write(tx, &game)?; let query = " INSERT INTO matchmaking (id, game) @@ -830,7 +835,7 @@ pub fn game_global_get(tx: &mut Transaction) -> Result { } -pub fn game_update(game: &Game, tx: &mut Transaction) -> Result<(), Error> { +pub fn game_update(tx: &mut Transaction, game: &Game) -> Result<(), Error> { let game_bytes = to_vec(&game)?; let query = " @@ -902,7 +907,7 @@ pub fn game_update(game: &Game, tx: &mut Transaction) -> Result<(), Error> { // let game = game_pve_new(params.cryp_ids, GameMode::Normal, tx, account)?; // // persist -// game_write(&game, tx)?; +// game_write(tx, &game)?; // Ok(game) // } @@ -930,7 +935,7 @@ pub fn game_instance_new(tx: &mut Transaction, players: Vec, game_id: Uu } // persist - game_write(&game, tx)?; + game_write(tx, &game)?; Ok(game) } diff --git a/server/src/instance.rs b/server/src/instance.rs index 31189ceb..7e7c89b8 100644 --- a/server/src/instance.rs +++ b/server/src/instance.rs @@ -533,6 +533,33 @@ pub fn instance_get_open(tx: &mut Transaction) -> Result { return Ok(instance); } +pub fn instances_afk(tx: &mut Transaction) -> Result, Error> { + let query = " + SELECT data, id + FROM instances + WHERE updated_at < now() - interval '5 seconds'; + "; + + let result = tx + .query(query, &[])?; + + let mut list = vec![]; + + for row in result.into_iter() { + let bytes: Vec = row.get(0); + let id = row.get(1); + + match from_slice::(&bytes) { + Ok(i) => list.push(i), + Err(_e) => { + instance_delete(tx, id)?; + } + }; + } + + return Ok(list); +} + pub fn instance_new(params: InstanceLobbyParams, tx: &mut Transaction, account: &Account) -> Result { let mut instance = match params.players { 1 => Instance::new() @@ -601,7 +628,7 @@ pub fn instance_ready(params: InstanceReadyParams, tx: &mut Transaction, account Ok(g) => g, Err(_) => { let game = instance.bot_vs_player_game(player_id)?; - game_write(&game, tx)?; + game_write(tx, &game)?; game }, }, diff --git a/server/src/warden.rs b/server/src/warden.rs index a77f8263..12960d28 100644 --- a/server/src/warden.rs +++ b/server/src/warden.rs @@ -10,33 +10,23 @@ use r2d2::{Pool}; use r2d2_postgres::{PostgresConnectionManager}; use game::{Game, games_afk, game_write}; -use instance::{Instance, instances_afk, instance_write}; - -fn handle_afk_game(game: Game) -> Game { - game -} +use instance::{Instance, instances_afk, instance_update}; fn fetch_games(mut tx: Transaction) -> Result { let games = games_afk(&mut tx)?; for mut game in games { - game = handle_afk_game(game); - game_write(&game, &mut tx)?; + game_write(&game.handle_afk(), &mut tx)?; } Ok(tx) } -fn handle_afk_instance(instance: Instance) -> Instance { - instance -} - fn fetch_instances(mut tx: Transaction) -> Result { let instances = instances_afk(&mut tx)?; for mut instance in instances { - instance = handle_afk_instance(instance); - instance_write(&instance, &mut tx)?; + instance_update(&mut tx, instance.handle_afk())?; } Ok(tx) diff --git a/server/src/zone.rs b/server/src/zone.rs index b70eaab8..84fe4a9c 100644 --- a/server/src/zone.rs +++ b/server/src/zone.rs @@ -187,7 +187,7 @@ pub fn zone_join(params: ZoneJoinParams, tx: &mut Transaction, account: &Account } // persist - game_write(&game, tx)?; + game_write(tx, &game)?; zone_update(&zone, tx)?; return Ok(game); From 03aae7e3cd14716de40d2f39e01a24d430d1a535 Mon Sep 17 00:00:00 2001 From: ntr Date: Sat, 27 Apr 2019 23:32:15 +1000 Subject: [PATCH 03/11] warden init --- server/src/game.rs | 7 +++---- server/src/instance.rs | 4 ++++ server/src/warden.rs | 6 +++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/server/src/game.rs b/server/src/game.rs index 6293eaf2..6af74f45 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -589,7 +589,6 @@ impl Game { } pub fn handle_afk(mut self) -> Game { - self } } @@ -623,7 +622,7 @@ pub fn game_skill(params: GameSkillParams, tx: &mut Transaction, account: &Accou game = game.resolve_phase_start(); } - game_update(&game, tx)?; + game_update(tx, &game)?; Ok(game) } @@ -658,7 +657,7 @@ pub fn game_skill(params: GameSkillParams, tx: &mut Transaction, account: &Accou // Ok(game) // } -pub fn game_write(game: &Game, tx: &mut Transaction) -> Result<(), Error> { +pub fn game_write(tx: &mut Transaction, game: &Game) -> Result<(), Error> { let game_bytes = to_vec(&game)?; let query = " @@ -953,7 +952,7 @@ pub fn game_instance_join(tx: &mut Transaction, player: Player, game_id: Uuid) - println!("{:?} game joined", game.id); - game_update(&game, tx)?; + game_update(tx, &game)?; Ok(game) } diff --git a/server/src/instance.rs b/server/src/instance.rs index 7e7c89b8..7062ceda 100644 --- a/server/src/instance.rs +++ b/server/src/instance.rs @@ -72,6 +72,10 @@ impl Instance { } } + pub fn handle_afk(mut self) -> Instance { + self + } + fn set_max_players(mut self, max: usize) -> Result { if max > 16 || max % 2 != 0 { return Err(err_msg("max players must be divisible by 2 and less than 16")); diff --git a/server/src/warden.rs b/server/src/warden.rs index 12960d28..7d1b2947 100644 --- a/server/src/warden.rs +++ b/server/src/warden.rs @@ -9,14 +9,14 @@ use failure::err_msg; use r2d2::{Pool}; use r2d2_postgres::{PostgresConnectionManager}; -use game::{Game, games_afk, game_write}; +use game::{Game, games_afk, game_update}; use instance::{Instance, instances_afk, instance_update}; fn fetch_games(mut tx: Transaction) -> Result { let games = games_afk(&mut tx)?; for mut game in games { - game_write(&game.handle_afk(), &mut tx)?; + game_update(&mut tx, &game.handle_afk())?; } Ok(tx) @@ -39,7 +39,7 @@ pub fn warden(pool: Pool) -> Result<(), Error> { fetch_games(db_connection.transaction()?)? .commit()?; - fetch_instances(db_connection.transaction()?) + fetch_instances(db_connection.transaction()?)? .commit()?; sleep(Duration::new(30, 0)); From 618f3667967265dc28a9f834ebea4515def1b01e Mon Sep 17 00:00:00 2001 From: ntr Date: Mon, 29 Apr 2019 12:27:08 +1000 Subject: [PATCH 04/11] fix reclaimning --- client/src/components/vbox.component.jsx | 5 +++-- ops/migrations/20181020104420_games.js | 4 ++-- server/Cargo.toml | 3 ++- server/src/game.rs | 22 +++++++++++++++------- server/src/instance.rs | 4 ++-- server/src/main.rs | 9 ++------- server/src/warden.rs | 14 +++++++------- 7 files changed, 33 insertions(+), 28 deletions(-) diff --git a/client/src/components/vbox.component.jsx b/client/src/components/vbox.component.jsx index ba0de3f4..b354ca4a 100644 --- a/client/src/components/vbox.component.jsx +++ b/client/src/components/vbox.component.jsx @@ -110,7 +110,7 @@ function Vbox(args) { if (boundTimer) { clearTimeout(boundTimer); - if (reclaiming && i) sendVboxReclaim(i); + if (reclaiming && vbox.bound[i]) sendVboxReclaim(i); else if (vbox.bound[i]) { const insert = combiner.findIndex(j => j === null); if (insert === -1) return setCombiner([i, null, null]); @@ -128,7 +128,7 @@ function Vbox(args) { } function boundClick(e, i) { - if (reclaiming && i) sendVboxReclaim(i); + if (reclaiming && vbox.bound[i]) sendVboxReclaim(i); else if (vbox.bound[i]) { const insert = combiner.findIndex(j => j === null); if (insert === -1) return setCombiner([i, null, null]); @@ -210,6 +210,7 @@ function Vbox(args) { return setReclaiming(!reclaiming); } +console.log('reclaiminig', reclaiming) const classes = `vbox ${activeVar !== null || activeCryp ? 'hidden' : ''}`; const reclaimClass = `instance-btn instance-ui-btn vbox-btn ${reclaiming ? 'reclaiming' : ''}`; diff --git a/ops/migrations/20181020104420_games.js b/ops/migrations/20181020104420_games.js index 5f1b1531..ca62041e 100644 --- a/ops/migrations/20181020104420_games.js +++ b/ops/migrations/20181020104420_games.js @@ -14,8 +14,8 @@ exports.up = async knex => { table.timestamps(true, true); table.binary('data').notNullable(); - table.boolean('open') - .defaultTo(true) + table.boolean('finished') + .defaultTo(false) .notNullable() .index(); }); diff --git a/server/Cargo.toml b/server/Cargo.toml index a59216f9..d2e1c30d 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -10,9 +10,10 @@ serde = "1" serde_derive = "1" serde_cbor = "0.9" +chrono = { version = "0.4", features = ["serde"] } + tungstenite = "0.6" bcrypt = "0.2" -petgraph = { version = "0.4", features = ["serde-1"] } dotenv = "0.9.0" env_logger = "*" diff --git a/server/src/game.rs b/server/src/game.rs index 6af74f45..44e7fb38 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -1,6 +1,8 @@ use rand::prelude::*; use uuid::Uuid; +use std::time::Instant; + // Db Commons use serde_cbor::{from_slice, to_vec}; use postgres::transaction::Transaction; @@ -588,7 +590,7 @@ impl Game { self } - pub fn handle_afk(mut self) -> Game { + pub fn upkeep(mut self) -> Game { self } } @@ -703,13 +705,19 @@ pub fn game_get(tx: &mut Transaction, id: Uuid) -> Result { return Ok(game); } -pub fn games_afk(tx: &mut Transaction) -> Result, Error> { +pub fn games_need_upkeep(tx: &mut Transaction) -> Result, Error> { + // let query = " + // SELECT data, id + // FROM games + // WHERE updated_at < now() - interval '5 seconds' + // AND finished = false; + // "; + let query = " SELECT data, id FROM games - WHERE updated_at < now() - interval '5 seconds'; + WHERE finished = false; "; - let result = tx .query(query, &[])?; @@ -839,13 +847,13 @@ pub fn game_update(tx: &mut Transaction, game: &Game) -> Result<(), Error> { let query = " UPDATE games - SET data = $1, updated_at = now() - WHERE id = $2 + SET data = $1, complete = $2, updated_at = now() + WHERE id = $3 RETURNING id, data; "; let result = tx - .query(query, &[&game_bytes, &game.id])?; + .query(query, &[&game_bytes, &game.finished(), &game.id])?; result.iter().next().ok_or(format_err!("game {:?} could not be written", game))?; diff --git a/server/src/instance.rs b/server/src/instance.rs index 7062ceda..c043ae50 100644 --- a/server/src/instance.rs +++ b/server/src/instance.rs @@ -72,7 +72,7 @@ impl Instance { } } - pub fn handle_afk(mut self) -> Instance { + pub fn upkeep(mut self) -> Instance { self } @@ -537,7 +537,7 @@ pub fn instance_get_open(tx: &mut Transaction) -> Result { return Ok(instance); } -pub fn instances_afk(tx: &mut Transaction) -> Result, Error> { +pub fn instances_need_upkeep(tx: &mut Transaction) -> Result, Error> { let query = " SELECT data, id FROM instances diff --git a/server/src/main.rs b/server/src/main.rs index ba798350..084c8dc9 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -3,33 +3,28 @@ extern crate uuid; extern crate tungstenite; extern crate env_logger; extern crate bcrypt; +extern crate chrono; extern crate dotenv; -// extern crate petgraph; extern crate postgres; extern crate r2d2; extern crate r2d2_postgres; extern crate serde; extern crate serde_cbor; -#[macro_use] -extern crate serde_derive; - +#[macro_use] extern crate serde_derive; #[macro_use] extern crate failure; -// #[macro_use] extern crate failure_derive; mod cryp; mod game; mod net; mod skill; mod spec; -// mod passives; mod names; mod rpc; mod account; mod instance; mod player; -// mod zone; mod mob; mod util; mod vbox; diff --git a/server/src/warden.rs b/server/src/warden.rs index 7d1b2947..0187abb2 100644 --- a/server/src/warden.rs +++ b/server/src/warden.rs @@ -9,24 +9,24 @@ use failure::err_msg; use r2d2::{Pool}; use r2d2_postgres::{PostgresConnectionManager}; -use game::{Game, games_afk, game_update}; -use instance::{Instance, instances_afk, instance_update}; +use game::{Game, games_need_upkeep, game_update}; +use instance::{Instance, instances_need_upkeep, instance_update}; fn fetch_games(mut tx: Transaction) -> Result { - let games = games_afk(&mut tx)?; + let games = games_need_upkeep(&mut tx)?; for mut game in games { - game_update(&mut tx, &game.handle_afk())?; + game_update(&mut tx, &game.upkeep())?; } Ok(tx) } fn fetch_instances(mut tx: Transaction) -> Result { - let instances = instances_afk(&mut tx)?; + let instances = instances_need_upkeep(&mut tx)?; for mut instance in instances { - instance_update(&mut tx, instance.handle_afk())?; + instance_update(&mut tx, instance.upkeep())?; } Ok(tx) @@ -42,6 +42,6 @@ pub fn warden(pool: Pool) -> Result<(), Error> { fetch_instances(db_connection.transaction()?)? .commit()?; - sleep(Duration::new(30, 0)); + sleep(Duration::new(1, 0)); } } \ No newline at end of file From 15ae93e70f120cb999039eac6c668a7b2d0d860a Mon Sep 17 00:00:00 2001 From: ntr Date: Mon, 29 Apr 2019 15:31:12 +1000 Subject: [PATCH 05/11] about to change teams -> player --- .../src/components/instance.create.form.jsx | 3 +- ops/migrations/20181020104420_games.js | 6 +- server/WORKLOG.md | 2 + server/src/game.rs | 141 +++++++++--------- server/src/instance.rs | 27 +++- server/src/net.rs | 14 +- server/src/vbox.rs | 6 +- server/src/warden.rs | 19 ++- 8 files changed, 124 insertions(+), 94 deletions(-) diff --git a/client/src/components/instance.create.form.jsx b/client/src/components/instance.create.form.jsx index f8b5f8cb..4e52fbc9 100644 --- a/client/src/components/instance.create.form.jsx +++ b/client/src/components/instance.create.form.jsx @@ -67,10 +67,11 @@ class InstanceCreateForm extends Component {