warden init

This commit is contained in:
ntr
2019-04-27 23:32:15 +10:00
parent 0daa7967f4
commit 03aae7e3cd
3 changed files with 10 additions and 7 deletions
+3 -4
View File
@@ -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)
}
+4
View File
@@ -72,6 +72,10 @@ impl Instance {
}
}
pub fn handle_afk(mut self) -> Instance {
self
}
fn set_max_players(mut self, max: usize) -> Result<Instance, Error> {
if max > 16 || max % 2 != 0 {
return Err(err_msg("max players must be divisible by 2 and less than 16"));
+3 -3
View File
@@ -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<Transaction, Error> {
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<PostgresConnectionManager>) -> Result<(), Error> {
fetch_games(db_connection.transaction()?)?
.commit()?;
fetch_instances(db_connection.transaction()?)
fetch_instances(db_connection.transaction()?)?
.commit()?;
sleep(Duration::new(30, 0));