From a68c2c31ab672ec09e602661b17dec1b13e5eb23 Mon Sep 17 00:00:00 2001 From: ntr Date: Sat, 15 Sep 2018 14:36:34 +1000 Subject: [PATCH] rename things --- client/index.js | 4 ++-- server/src/cryp.rs | 4 ++-- server/src/rpc.rs | 33 ++++++++++++++++++++++----------- server/src/user.rs | 4 ++-- 4 files changed, 28 insertions(+), 17 deletions(-) mode change 100644 => 100755 server/src/user.rs diff --git a/client/index.js b/client/index.js index 7e866973..e00628f9 100755 --- a/client/index.js +++ b/client/index.js @@ -14,7 +14,7 @@ function user_login(res) { user = created; console.log(created); - return send({ method: 'cryp_generate', params: { level: 64 }}); + return send({ method: 'cryp_spawn', params: { level: 64 }}); } function new_cryp(cryp) { @@ -22,7 +22,7 @@ function new_cryp(cryp) { } const handlers = { - 'cryp_generate': new_cryp, + 'cryp_spawn': new_cryp, 'user_login': user_login, 'user_create': user_login, }; diff --git a/server/src/cryp.rs b/server/src/cryp.rs index ec57c1cc..bbb1645d 100755 --- a/server/src/cryp.rs +++ b/server/src/cryp.rs @@ -2,7 +2,7 @@ use uuid::Uuid; use rand::prelude::*; use serde_cbor::*; -use rpc::{GenerateParams}; +use rpc::{CrypSpawnParams}; use skill::{Skill}; #[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)] @@ -176,7 +176,7 @@ impl Cryp { } -pub fn generate(params: GenerateParams) -> Cryp { +pub fn spawn(params: CrypSpawnParams) -> Cryp { Cryp::new() .named("hatchling".to_string()) .level(params.level) diff --git a/server/src/rpc.rs b/server/src/rpc.rs index 8bffc0da..bc71b63e 100755 --- a/server/src/rpc.rs +++ b/server/src/rpc.rs @@ -4,7 +4,7 @@ use failure::Error; use failure::err_msg; use net::Db; -use cryp::{Cryp, generate}; +use cryp::{Cryp, spawn}; use user::{User, create}; pub struct Rpc; @@ -23,17 +23,17 @@ impl Rpc { // now we have the method name // match on that to determine what fn to call match v.method.as_ref() { - "cryp_generate" => { - match from_slice::(&data) { + "cryp_spawn" => { + match from_slice::(&data) { Ok(v) => Ok(RpcResponse { method: v.method, - params: RpcResult::Cryp(generate(v.params)) + params: RpcResult::Cryp(spawn(v.params)) }), Err(_e) => Err(err_msg("invalid params")), } }, "user_create" => { - match from_slice::(&data) { + match from_slice::(&data) { Ok(v) => Ok(RpcResponse { method: v.method, params: create(v.params, db)? @@ -69,28 +69,39 @@ pub struct RpcMessage { } #[derive(Debug,Clone,Serialize,Deserialize)] -struct GenerateMsg { +struct CrypSpawnMsg { method: String, - params: GenerateParams, + params: CrypSpawnParams, } #[derive(Debug,Clone,Serialize,Deserialize)] -pub struct GenerateParams { +pub struct CrypSpawnParams { pub level: u8, } #[derive(Debug,Clone,Serialize,Deserialize)] -struct AccountCreateMsg { +struct UserCreateMsg { method: String, - params: AccountCreateParams, + params: UserCreateParams, } #[derive(Debug,Clone,Serialize,Deserialize)] -pub struct AccountCreateParams { +pub struct UserCreateParams { pub name: String, pub password: String, } +#[derive(Debug,Clone,Serialize,Deserialize)] +struct UserLoginMsg { + method: String, + params: UserLoginParams, +} + +#[derive(Debug,Clone,Serialize,Deserialize)] +pub struct UserLoginParams { + pub name: String, + pub password: String, +} // #[cfg(test)] // mod tests { diff --git a/server/src/user.rs b/server/src/user.rs old mode 100644 new mode 100755 index 05937314..014b7f35 --- a/server/src/user.rs +++ b/server/src/user.rs @@ -7,7 +7,7 @@ use std::iter; use std::str; use net::Db; -use rpc::{AccountCreateParams, RpcResult}; +use rpc::{UserCreateParams, RpcResult}; use failure::Error; use failure::err_msg; @@ -28,7 +28,7 @@ struct UserEntry { static PASSWORD_MIN_LEN: usize = 12; -pub fn create(params: AccountCreateParams, db: Db) -> Result { +pub fn create(params: UserCreateParams, db: Db) -> Result { let id = Uuid::new_v4(); if params.password.len() < PASSWORD_MIN_LEN {