diff --git a/server/src/net.rs b/server/src/net.rs index 07cb03fc..ace6beeb 100644 --- a/server/src/net.rs +++ b/server/src/net.rs @@ -44,6 +44,7 @@ impl Actor for MnmlSocket { impl StreamHandler for MnmlSocket { fn handle(&mut self, msg: ws::Message, ctx: &mut Self::Context) { // process websocket messages + let begin = Instant::now(); println!("msg: {:?}", msg); match msg { ws::Message::Ping(msg) => { @@ -60,7 +61,7 @@ impl StreamHandler for MnmlSocket { ws::Message::Nop => (), ws::Message::Binary(bin) => { let db_connection = self.pool.get().expect("unable to get db connection"); - match receive(bin.to_vec(), &db_connection, ctx) { + match receive(bin.to_vec(), &db_connection, ctx, begin) { Ok(reply) => { let response = to_vec(&reply) .expect("failed to serialize response"); diff --git a/server/src/rpc.rs b/server/src/rpc.rs index 210befe7..1633c5ea 100644 --- a/server/src/rpc.rs +++ b/server/src/rpc.rs @@ -1,7 +1,9 @@ +use std::time::{Instant}; + use actix_web_actors::ws; use postgres::transaction::Transaction; -use serde_cbor::{from_slice, to_vec}; +use serde_cbor::{from_slice}; use uuid::Uuid; use failure::Error; use failure::err_msg; @@ -18,7 +20,7 @@ use item::{Item, ItemInfoCtr, item_info}; type MnmlWs = ws::WebsocketContext; -pub fn receive(data: Vec, db: &Db, client: &mut MnmlWs) -> Result { +pub fn receive(data: Vec, db: &Db, client: &mut MnmlWs, begin: Instant) -> Result { // cast the data to this type to receive method name match from_slice::(&data) { Ok(v) => { @@ -87,6 +89,8 @@ pub fn receive(data: Vec, db: &Db, client: &mut MnmlWs) -> Result { @@ -144,6 +148,8 @@ fn handle_game_ready(data: Vec, tx: &mut Transaction, account: Account, _cli fn handle_construct_spawn(data: Vec, tx: &mut Transaction, account: Account, client: &mut MnmlWs) -> Result { let msg = from_slice::(&data).or(Err(err_msg("invalid params")))?; + construct_spawn(msg.params, tx, &account)?; + let construct_list = RpcResponse { method: "account_constructs".to_string(), params: RpcResult::ConstructList(account_constructs(tx, &account)?)