ready rpc
This commit is contained in:
+4
-3
@@ -558,7 +558,7 @@ impl Game {
|
||||
{
|
||||
let winner = self.players.iter().find(|t| t.cryps.iter().any(|c| !c.is_ko()));
|
||||
match winner {
|
||||
Some(w) => self.log.push(format!("Winner: {:}", w.id)),
|
||||
Some(w) => self.log.push(format!("Winner: {:}", w.name)),
|
||||
None => self.log.push(format!("Game was drawn.")),
|
||||
};
|
||||
}
|
||||
@@ -585,6 +585,7 @@ impl Game {
|
||||
player.add_warning();
|
||||
if player.warnings >= 3 {
|
||||
player.forfeit();
|
||||
self.log.push(format!("{:?} forfeited.", player.name));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -818,8 +819,8 @@ pub fn game_skill(params: GameSkillParams, tx: &mut Transaction, account: &Accou
|
||||
Ok(game)
|
||||
}
|
||||
|
||||
pub fn game_ready(params: GameSkillParams, tx: &mut Transaction, account: &Account) -> Result<Game, Error> {
|
||||
let mut game = game_get(tx, params.game_id)?;
|
||||
pub fn game_ready(params: GameStateParams, tx: &mut Transaction, account: &Account) -> Result<Game, Error> {
|
||||
let mut game = game_get(tx, params.id)?;
|
||||
|
||||
game.player_ready(account.id)?;
|
||||
|
||||
|
||||
+14
-1
@@ -16,7 +16,7 @@ use failure::err_msg;
|
||||
|
||||
use net::Db;
|
||||
use cryp::{Cryp, cryp_spawn};
|
||||
use game::{Game, game_state, game_skill};
|
||||
use game::{Game, game_state, game_skill, game_ready};
|
||||
use account::{Account, account_create, account_login, account_from_token, account_cryps, account_instances};
|
||||
use skill::{Skill};
|
||||
// use zone::{Zone, zone_create, zone_join, zone_close};
|
||||
@@ -71,6 +71,7 @@ impl Rpc {
|
||||
|
||||
"game_state" => Rpc::game_state(data, &mut tx, account.unwrap(), client),
|
||||
"game_skill" => Rpc::game_skill(data, &mut tx, account.unwrap(), client),
|
||||
"game_ready" => Rpc::game_ready(data, &mut tx, account.unwrap(), client),
|
||||
|
||||
"instance_join" => Rpc::instance_join(data, &mut tx, account.unwrap(), client),
|
||||
"instance_ready" => Rpc::instance_ready(data, &mut tx, account.unwrap(), client),
|
||||
@@ -140,6 +141,18 @@ impl Rpc {
|
||||
return Ok(game_response);
|
||||
}
|
||||
|
||||
fn game_ready(data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let msg = from_slice::<GameStateMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||
|
||||
let game_response = RpcResponse {
|
||||
method: "game_state".to_string(),
|
||||
params: RpcResult::GameState(game_ready(msg.params, tx, &account)?)
|
||||
};
|
||||
|
||||
return Ok(game_response);
|
||||
}
|
||||
|
||||
|
||||
fn cryp_spawn(data: Vec<u8>, tx: &mut Transaction, account: Account, client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let msg = from_slice::<CrypSpawnMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user