diff --git a/server/src/game.rs b/server/src/game.rs index 5fe399da..fb774527 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -12,13 +12,14 @@ use rpc::{GameStateParams, GameSkillParams}; use cryp::{Cryp}; use skill::{Skill, Cast, ResolutionResult}; use player::{Player}; -use instance::{instance_game_finished}; +use instance::{instance_game_finished, global_game_finished}; pub type Log = Vec; #[derive(Debug,Clone,Serialize,Deserialize)] pub struct Team { pub id: Uuid, + pub player: Option, pub bot: bool, cryps: Vec, } @@ -27,6 +28,7 @@ impl Team { pub fn new(account: Uuid) -> Team { return Team { id: account, + player: None, cryps: vec![], bot: false, }; @@ -741,7 +743,10 @@ pub fn game_update(game: &Game, tx: &mut Transaction) -> Result<(), Error> { if game.finished() { if let Some(i) = game.instance { - instance_game_finished(tx, &game, i)?; + match i == Uuid::nil() { + true => instance_game_finished(tx, &game, i)?, + false => global_game_finished(tx, &game)?, + } } } diff --git a/server/src/instance.rs b/server/src/instance.rs index c62b616d..8a757cdf 100644 --- a/server/src/instance.rs +++ b/server/src/instance.rs @@ -476,6 +476,22 @@ pub fn instance_ready(params: InstanceReadyParams, tx: &mut Transaction, account return Ok(game); } +pub fn global_game_finished(tx: &mut Transaction, game: &Game) -> Result<(), Error> { + let winner = game.winner().ok_or(err_msg("game not finished"))?; + + for team in game.teams.iter() { + let mut player = player_get(tx, team.id, Uuid::nil())?; + match team.id == winner.id { + true => player.add_win(), + false => player.add_loss(), + }; + player.vbox.fill(); + player_update(tx, player, true)?; + } + + Ok(()) +} + pub fn instance_game_finished(tx: &mut Transaction, game: &Game, instance_id: Uuid) -> Result<(), Error> { // update scores let winner = game.winner().ok_or(err_msg("game not finished"))?;