From 0daa7967f4f11a4350c7c6998b3308cb3218668c Mon Sep 17 00:00:00 2001 From: ntr Date: Sat, 27 Apr 2019 23:27:44 +1000 Subject: [PATCH] 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);