filthy timeout

This commit is contained in:
ntr
2018-10-23 16:51:12 +11:00
parent af9f2c479d
commit cf7501b442
4 changed files with 45 additions and 2 deletions
+5 -1
View File
@@ -8,7 +8,7 @@ use failure::Error;
use failure::err_msg;
use account::Account;
use rpc::{GameSkillParams, GamePveParams, GamePvpParams, GameTargetParams, GameJoinParams};
use rpc::{GameStateParams, GameSkillParams, GamePveParams, GamePvpParams, GameTargetParams, GameJoinParams};
use cryp::{Cryp, cryp_get};
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
@@ -489,6 +489,10 @@ pub fn game_new(game: &Game, tx: &mut Transaction) -> Result<(), Error> {
return Ok(());
}
pub fn game_state(params: GameStateParams, tx: &mut Transaction, _account: &Account) -> Result<Game, Error> {
return game_get(tx, params.id)
}
pub fn game_get(tx: &mut Transaction, id: Uuid) -> Result<Game, Error> {
let query = "
SELECT *
+30 -1
View File
@@ -11,7 +11,7 @@ use failure::err_msg;
use net::Db;
use cryp::{Cryp, cryp_spawn};
use game::{Game, Skill, game_pve, game_pvp, game_join, game_skill, game_target};
use game::{Game, Skill, game_state, game_pve, game_pvp, game_join, game_skill, game_target};
use account::{Account, account_create, account_login, account_from_token, account_cryps};
use item::{Item, items_list, item_use};
@@ -38,6 +38,7 @@ impl Rpc {
// match on that to determine what fn to call
let response = match v.method.as_ref() {
"cryp_spawn" => Rpc::cryp_spawn(data, &mut tx, account, client),
"game_state" => Rpc::game_state(data, &mut tx, account, client),
"game_pve" => Rpc::game_pve(data, &mut tx, account, client),
"game_pvp" => Rpc::game_pvp(data, &mut tx, account, client),
"game_join" => Rpc::game_join(data, &mut tx, account, client),
@@ -68,6 +69,23 @@ impl Rpc {
}
}
fn game_state(data: Vec<u8>, tx: &mut Transaction, account: Option<Account>, client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
let a = match account {
Some(a) => a,
None => return Err(err_msg("auth required")),
};
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_state(msg.params, tx, &a)?)
};
return Ok(game_response);
}
fn game_pve(data: Vec<u8>, tx: &mut Transaction, account: Option<Account>, client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
let a = match account {
Some(a) => a,
@@ -275,6 +293,17 @@ pub struct CrypSpawnParams {
pub name: String,
}
#[derive(Debug,Clone,Serialize,Deserialize)]
struct GameStateMsg {
method: String,
params: GameStateParams,
}
#[derive(Debug,Clone,Serialize,Deserialize)]
pub struct GameStateParams {
pub id: Uuid,
}
#[derive(Debug,Clone,Serialize,Deserialize)]
struct GamePveMsg {
method: String,