warden init
This commit is contained in:
parent
0daa7967f4
commit
03aae7e3cd
@ -589,7 +589,6 @@ impl Game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_afk(mut self) -> Game {
|
pub fn handle_afk(mut self) -> Game {
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -623,7 +622,7 @@ pub fn game_skill(params: GameSkillParams, tx: &mut Transaction, account: &Accou
|
|||||||
game = game.resolve_phase_start();
|
game = game.resolve_phase_start();
|
||||||
}
|
}
|
||||||
|
|
||||||
game_update(&game, tx)?;
|
game_update(tx, &game)?;
|
||||||
|
|
||||||
Ok(game)
|
Ok(game)
|
||||||
}
|
}
|
||||||
@ -658,7 +657,7 @@ pub fn game_skill(params: GameSkillParams, tx: &mut Transaction, account: &Accou
|
|||||||
// Ok(game)
|
// 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 game_bytes = to_vec(&game)?;
|
||||||
|
|
||||||
let query = "
|
let query = "
|
||||||
@ -953,7 +952,7 @@ pub fn game_instance_join(tx: &mut Transaction, player: Player, game_id: Uuid) -
|
|||||||
|
|
||||||
println!("{:?} game joined", game.id);
|
println!("{:?} game joined", game.id);
|
||||||
|
|
||||||
game_update(&game, tx)?;
|
game_update(tx, &game)?;
|
||||||
|
|
||||||
Ok(game)
|
Ok(game)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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> {
|
fn set_max_players(mut self, max: usize) -> Result<Instance, Error> {
|
||||||
if max > 16 || max % 2 != 0 {
|
if max > 16 || max % 2 != 0 {
|
||||||
return Err(err_msg("max players must be divisible by 2 and less than 16"));
|
return Err(err_msg("max players must be divisible by 2 and less than 16"));
|
||||||
|
|||||||
@ -9,14 +9,14 @@ use failure::err_msg;
|
|||||||
use r2d2::{Pool};
|
use r2d2::{Pool};
|
||||||
use r2d2_postgres::{PostgresConnectionManager};
|
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};
|
use instance::{Instance, instances_afk, instance_update};
|
||||||
|
|
||||||
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_write(&game.handle_afk(), &mut tx)?;
|
game_update(&mut tx, &game.handle_afk())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(tx)
|
Ok(tx)
|
||||||
@ -39,7 +39,7 @@ pub fn warden(pool: Pool<PostgresConnectionManager>) -> Result<(), Error> {
|
|||||||
fetch_games(db_connection.transaction()?)?
|
fetch_games(db_connection.transaction()?)?
|
||||||
.commit()?;
|
.commit()?;
|
||||||
|
|
||||||
fetch_instances(db_connection.transaction()?)
|
fetch_instances(db_connection.transaction()?)?
|
||||||
.commit()?;
|
.commit()?;
|
||||||
|
|
||||||
sleep(Duration::new(30, 0));
|
sleep(Duration::new(30, 0));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user