remove some unused fns
This commit is contained in:
+6
-10
@@ -185,10 +185,6 @@ impl Game {
|
||||
self
|
||||
}
|
||||
|
||||
fn joinable(&self) -> bool {
|
||||
self.phase == Phase::Start
|
||||
}
|
||||
|
||||
fn can_start(&self) -> bool {
|
||||
return self.teams.len() == self.team_num
|
||||
&& self.teams.iter().all(|t| t.cryps.len() == self.team_size)
|
||||
@@ -607,13 +603,13 @@ pub fn game_write(game: &Game, tx: &mut Transaction) -> Result<(), Error> {
|
||||
let game_bytes = to_vec(&game)?;
|
||||
|
||||
let query = "
|
||||
INSERT INTO games (id, joinable, data)
|
||||
VALUES ($1, $2, $3)
|
||||
INSERT INTO games (id, data)
|
||||
VALUES ($1, $2)
|
||||
RETURNING id;
|
||||
";
|
||||
|
||||
let result = tx
|
||||
.query(query, &[&game.id, &game.joinable(), &game_bytes])?;
|
||||
.query(query, &[&game.id, &game_bytes])?;
|
||||
|
||||
result.iter().next().ok_or(format_err!("no game written"))?;
|
||||
|
||||
@@ -653,13 +649,13 @@ pub fn game_update(game: &Game, tx: &mut Transaction) -> Result<(), Error> {
|
||||
|
||||
let query = "
|
||||
UPDATE games
|
||||
SET data = $1, joinable = $2
|
||||
WHERE id = $3
|
||||
SET data = $1
|
||||
WHERE id = $2
|
||||
RETURNING id, data;
|
||||
";
|
||||
|
||||
let result = tx
|
||||
.query(query, &[&game_bytes, &game.joinable(), &game.id])?;
|
||||
.query(query, &[&game_bytes, &game.id])?;
|
||||
|
||||
result.iter().next().ok_or(format_err!("game {:?} could not be written", game))?;
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -106,7 +106,7 @@ pub fn instance_get_open(tx: &mut Transaction) -> Result<Instance, Error> {
|
||||
let query = "
|
||||
SELECT *
|
||||
FROM instance
|
||||
AND open = true;
|
||||
WHERE open = true;
|
||||
";
|
||||
|
||||
let result = tx
|
||||
|
||||
+23
-3
@@ -8,10 +8,9 @@ use failure::Error;
|
||||
use failure::err_msg;
|
||||
|
||||
use account::Account;
|
||||
use instance::Instance;
|
||||
use cryp::{Cryp};
|
||||
use cryp::{Cryp, cryp_get};
|
||||
use vbox::{Vbox};
|
||||
use rpc::{PlayerStateParams};
|
||||
use rpc::{PlayerStateParams, PlayerCrypsSetParams};
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
pub struct Score {
|
||||
@@ -106,3 +105,24 @@ pub fn player_update(tx: &mut Transaction, player: Player) -> Result<Player, Err
|
||||
pub fn player_state(params: PlayerStateParams, tx: &mut Transaction, account: &Account) -> Result<Player, Error> {
|
||||
player_get(tx, account.id, params.instance_id)
|
||||
}
|
||||
|
||||
pub fn player_cryps_set(params: PlayerCrypsSetParams, tx: &mut Transaction, account: &Account) -> Result<Player, Error> {
|
||||
if params.instance_id != Uuid::nil() {
|
||||
return Err(err_msg("only the global team can be replaced"));
|
||||
}
|
||||
|
||||
if params.cryp_ids.len() != 3 {
|
||||
return Err(err_msg("team size is 3"));
|
||||
}
|
||||
|
||||
let mut player = player_get(tx, account.id, params.instance_id)?;
|
||||
|
||||
let cryps = params.cryp_ids
|
||||
.iter()
|
||||
.map(|id| cryp_get(tx, *id, account.id))
|
||||
.collect::<Result<Vec<Cryp>, Error>>()?;
|
||||
|
||||
player.cryps = cryps;
|
||||
|
||||
player_update(tx, player)
|
||||
}
|
||||
|
||||
+29
-10
@@ -21,7 +21,7 @@ use account::{Account, account_create, account_login, account_from_token, accoun
|
||||
use skill::{Skill};
|
||||
use zone::{Zone, zone_create, zone_join, zone_close};
|
||||
use spec::{Spec};
|
||||
use player::{player_state, player_create, Player};
|
||||
use player::{player_state, player_create, player_cryps_set, Player};
|
||||
use instance::{instance_join};
|
||||
use vbox::{vbox_accept, vbox_apply, vbox_discard, vbox_combine, vbox_drop};
|
||||
|
||||
@@ -91,7 +91,10 @@ impl Rpc {
|
||||
|
||||
return response;
|
||||
},
|
||||
Err(_e) => Err(err_msg("invalid message")),
|
||||
Err(e) => {
|
||||
println!("{:?}", e);
|
||||
Err(err_msg("invalid message"))
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +117,7 @@ impl Rpc {
|
||||
return Ok(game_response);
|
||||
}
|
||||
|
||||
fn game_pve(data: Vec<u8>, tx: &mut Transaction, account: Account, client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
fn game_pve(data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let msg = from_slice::<GamePveMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||
|
||||
let game_response = RpcResponse {
|
||||
@@ -122,11 +125,6 @@ impl Rpc {
|
||||
params: RpcResult::GameState(game_pve(msg.params, tx, &account)?)
|
||||
};
|
||||
|
||||
Rpc::send_msg(client, RpcResponse {
|
||||
method: "account_cryps".to_string(),
|
||||
params: RpcResult::CrypList(account_cryps(tx, &account)?)
|
||||
})?;
|
||||
|
||||
return Ok(game_response);
|
||||
}
|
||||
|
||||
@@ -272,7 +270,6 @@ impl Rpc {
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
|
||||
fn player_state(data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let msg = from_slice::<PlayerStateMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||
|
||||
@@ -284,6 +281,17 @@ impl Rpc {
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
fn player_cryps_set(data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let msg = from_slice::<PlayerStateMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||
|
||||
let response = RpcResponse {
|
||||
method: "player_state".to_string(),
|
||||
params: RpcResult::PlayerState(player_cryps_set(msg.params, tx, &account)?)
|
||||
};
|
||||
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
fn player_vbox_accept(data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let msg = from_slice::<VboxAcceptMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||
|
||||
@@ -362,7 +370,6 @@ pub enum RpcResult {
|
||||
Account(Account),
|
||||
CrypList(Vec<Cryp>),
|
||||
GameState(Game),
|
||||
GameJoinableList(Vec<Game>),
|
||||
ZoneState(Zone),
|
||||
ZoneClose(()),
|
||||
|
||||
@@ -540,6 +547,18 @@ pub struct PlayerStateParams {
|
||||
pub instance_id: Uuid,
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
struct PlayerCrypsSetMsg {
|
||||
method: String,
|
||||
params: PlayerCrypsSetParams,
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
pub struct PlayerCrypsSetParams {
|
||||
pub instance_id: Uuid,
|
||||
pub cryp_ids: Vec<Uuid>,
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
struct VboxAcceptMsg {
|
||||
method: String,
|
||||
|
||||
Reference in New Issue
Block a user