rename things

This commit is contained in:
ntr 2018-09-15 14:36:34 +10:00
parent f2a6aa01c3
commit a68c2c31ab
4 changed files with 28 additions and 17 deletions

View File

@ -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,
};

View File

@ -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)

View File

@ -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::<GenerateMsg>(&data) {
"cryp_spawn" => {
match from_slice::<CrypSpawnMsg>(&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::<AccountCreateMsg>(&data) {
match from_slice::<UserCreateMsg>(&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 {

4
server/src/user.rs Normal file → Executable file
View File

@ -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<RpcResult, Error> {
pub fn create(params: UserCreateParams, db: Db) -> Result<RpcResult, Error> {
let id = Uuid::new_v4();
if params.password.len() < PASSWORD_MIN_LEN {