ready rpc
This commit is contained in:
parent
59a22b6122
commit
d3c301a3ac
@ -19,6 +19,7 @@ function GamePanel(props) {
|
||||
setActiveCryp,
|
||||
selectSkillTarget,
|
||||
sendInstanceState,
|
||||
sendGameReady,
|
||||
activeCryp,
|
||||
account,
|
||||
showLog,
|
||||
@ -69,6 +70,11 @@ function GamePanel(props) {
|
||||
onClick={() => toggleLog(!showLog)}>
|
||||
Log
|
||||
</button>
|
||||
<button
|
||||
className="game-back-btn instance-btn instance-ui-btn right"
|
||||
onClick={() => sendGameReady()}>
|
||||
Ready
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
|
||||
|
||||
@ -23,6 +23,10 @@ const addState = connect(
|
||||
return false;
|
||||
}
|
||||
|
||||
function sendGameReady() {
|
||||
ws.sendGameReady(game.id);
|
||||
}
|
||||
|
||||
function sendInstanceState(instanceId) {
|
||||
if (!instanceId) return false;
|
||||
return ws.sendInstanceState(instanceId);
|
||||
@ -42,6 +46,7 @@ const addState = connect(
|
||||
activeCryp,
|
||||
selectSkillTarget,
|
||||
sendInstanceState,
|
||||
sendGameReady,
|
||||
};
|
||||
},
|
||||
|
||||
|
||||
@ -74,8 +74,8 @@ function createSocket(events) {
|
||||
send({ method: 'game_state', params: { id } });
|
||||
}
|
||||
|
||||
function sendGameJoin(gameId, crypIds) {
|
||||
send({ method: 'game_join', params: { game_id: gameId, cryp_ids: crypIds } });
|
||||
function sendGameReady(id) {
|
||||
send({ method: 'game_ready', params: { id } });
|
||||
}
|
||||
|
||||
function sendSpecForget(id, spec) {
|
||||
@ -331,7 +331,7 @@ function createSocket(events) {
|
||||
sendAccountInstances,
|
||||
sendAccountZone,
|
||||
sendGameState,
|
||||
sendGameJoin,
|
||||
sendGameReady,
|
||||
sendGameSkill,
|
||||
sendGameTarget,
|
||||
sendCrypSpawn,
|
||||
|
||||
@ -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)?;
|
||||
|
||||
|
||||
@ -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")))?;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user