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
+9 -4
View File
@@ -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<Game, Error> {
@@ -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<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 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<Player>, game_id: Uu
}
// persist
game_write(&game, tx)?;
game_write(tx, &game)?;
Ok(game)
}
+28 -1
View File
@@ -533,6 +533,33 @@ pub fn instance_get_open(tx: &mut Transaction) -> Result<Instance, Error> {
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> {
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
},
},
+3 -13
View File
@@ -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<Transaction, Error> {
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<Transaction, Error> {
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)
+1 -1
View File
@@ -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);