fix scoreboard

This commit is contained in:
ntr 2019-04-27 23:27:44 +10:00
parent 95c463757d
commit 0daa7967f4
6 changed files with 43 additions and 20 deletions

View File

@ -180,7 +180,7 @@ function Info(args) {
? infoCrypElement(player.cryps.find(c => c.id === activeCryp.id)) ? infoCrypElement(player.cryps.find(c => c.id === activeCryp.id))
: null; : null;
const otherInfo = !info[0] const otherInfo = info[0]
? infoVar(info) ? infoVar(info)
: null; : null;

View File

@ -8,6 +8,7 @@ function setupKeys(store) {
key('esc', () => store.dispatch(actions.setReclaiming(false))); key('esc', () => store.dispatch(actions.setReclaiming(false)));
key('esc', () => store.dispatch(actions.setActiveSkill(null))); key('esc', () => store.dispatch(actions.setActiveSkill(null)));
key('esc', () => store.dispatch(actions.setActiveCryp(null))); key('esc', () => store.dispatch(actions.setActiveCryp(null)));
key('esc', () => store.dispatch(actions.setInfo([null, null])));
} }
module.exports = setupKeys; module.exports = setupKeys;

View File

@ -587,6 +587,11 @@ impl Game {
self self
} }
pub fn handle_afk(mut self) -> Game {
self
}
} }
pub fn game_skill(params: GameSkillParams, tx: &mut Transaction, account: &Account) -> Result<Game, Error> { pub fn game_skill(params: GameSkillParams, tx: &mut Transaction, account: &Account) -> Result<Game, Error> {
@ -758,7 +763,7 @@ pub fn game_global_startup(tx: &mut Transaction) -> Result<(), Error> {
.set_team_size(3) .set_team_size(3)
.set_mode(GameMode::Pvp); .set_mode(GameMode::Pvp);
game_write(&game, tx)?; game_write(tx, &game)?;
let query = " let query = "
INSERT INTO matchmaking (id, game) INSERT INTO matchmaking (id, game)
@ -830,7 +835,7 @@ pub fn game_global_get(tx: &mut Transaction) -> Result<Game, Error> {
} }
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 game_bytes = to_vec(&game)?;
let query = " 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)?; // let game = game_pve_new(params.cryp_ids, GameMode::Normal, tx, account)?;
// // persist // // persist
// game_write(&game, tx)?; // game_write(tx, &game)?;
// Ok(game) // Ok(game)
// } // }
@ -930,7 +935,7 @@ pub fn game_instance_new(tx: &mut Transaction, players: Vec<Player>, game_id: Uu
} }
// persist // persist
game_write(&game, tx)?; game_write(tx, &game)?;
Ok(game) Ok(game)
} }

View File

@ -533,6 +533,33 @@ pub fn instance_get_open(tx: &mut Transaction) -> Result<Instance, Error> {
return Ok(instance); return Ok(instance);
} }
pub fn instances_afk(tx: &mut Transaction) -> Result<Vec<Instance>, 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<u8> = row.get(0);
let id = row.get(1);
match from_slice::<Instance>(&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<Instance, Error> { pub fn instance_new(params: InstanceLobbyParams, tx: &mut Transaction, account: &Account) -> Result<Instance, Error> {
let mut instance = match params.players { let mut instance = match params.players {
1 => Instance::new() 1 => Instance::new()
@ -601,7 +628,7 @@ pub fn instance_ready(params: InstanceReadyParams, tx: &mut Transaction, account
Ok(g) => g, Ok(g) => g,
Err(_) => { Err(_) => {
let game = instance.bot_vs_player_game(player_id)?; let game = instance.bot_vs_player_game(player_id)?;
game_write(&game, tx)?; game_write(tx, &game)?;
game game
}, },
}, },

View File

@ -10,33 +10,23 @@ use r2d2::{Pool};
use r2d2_postgres::{PostgresConnectionManager}; use r2d2_postgres::{PostgresConnectionManager};
use game::{Game, games_afk, game_write}; use game::{Game, games_afk, game_write};
use instance::{Instance, instances_afk, instance_write}; use instance::{Instance, instances_afk, instance_update};
fn handle_afk_game(game: Game) -> Game {
game
}
fn fetch_games(mut tx: Transaction) -> Result<Transaction, Error> { fn fetch_games(mut tx: Transaction) -> Result<Transaction, Error> {
let games = games_afk(&mut tx)?; let games = games_afk(&mut tx)?;
for mut game in games { for mut game in games {
game = handle_afk_game(game); game_write(&game.handle_afk(), &mut tx)?;
game_write(&game, &mut tx)?;
} }
Ok(tx) Ok(tx)
} }
fn handle_afk_instance(instance: Instance) -> Instance {
instance
}
fn fetch_instances(mut tx: Transaction) -> Result<Transaction, Error> { fn fetch_instances(mut tx: Transaction) -> Result<Transaction, Error> {
let instances = instances_afk(&mut tx)?; let instances = instances_afk(&mut tx)?;
for mut instance in instances { for mut instance in instances {
instance = handle_afk_instance(instance); instance_update(&mut tx, instance.handle_afk())?;
instance_write(&instance, &mut tx)?;
} }
Ok(tx) Ok(tx)

View File

@ -187,7 +187,7 @@ pub fn zone_join(params: ZoneJoinParams, tx: &mut Transaction, account: &Account
} }
// persist // persist
game_write(&game, tx)?; game_write(tx, &game)?;
zone_update(&zone, tx)?; zone_update(&zone, tx)?;
return Ok(game); return Ok(game);