demo
This commit is contained in:
@@ -65,7 +65,9 @@ pub fn account_create(params: AccountCreateParams, tx: &mut Transaction) -> Resu
|
||||
if params.password.len() < PASSWORD_MIN_LEN {
|
||||
return Err(err_msg("password must be at least 12 characters"));
|
||||
}
|
||||
let password = hash(¶ms.password, 4)?;
|
||||
|
||||
let rounds = 8;
|
||||
let password = hash(¶ms.password, rounds)?;
|
||||
|
||||
let mut rng = thread_rng();
|
||||
let token: String = iter::repeat(())
|
||||
|
||||
@@ -4,6 +4,11 @@ use tungstenite::Message::Binary;
|
||||
use postgres::transaction::Transaction;
|
||||
use std::net::{TcpStream};
|
||||
|
||||
// demo
|
||||
use std::iter;
|
||||
use rand::{thread_rng, Rng};
|
||||
use rand::distributions::Alphanumeric;
|
||||
|
||||
use serde_cbor::{from_slice, to_vec};
|
||||
use uuid::Uuid;
|
||||
use failure::Error;
|
||||
@@ -38,6 +43,7 @@ impl Rpc {
|
||||
match v.method.as_ref() {
|
||||
"account_create" => (),
|
||||
"account_login" => (),
|
||||
"account_demo" => (),
|
||||
_ => match account {
|
||||
Some(_) => (),
|
||||
None => return Err(err_msg("auth required")),
|
||||
@@ -50,6 +56,7 @@ impl Rpc {
|
||||
// no auth methods
|
||||
"account_create" => Rpc::account_create(data, &mut tx, client),
|
||||
"account_login" => Rpc::account_login(data, &mut tx, client),
|
||||
"account_demo" => Rpc::account_demo(data, &mut tx, client),
|
||||
|
||||
// auth methods
|
||||
"cryp_spawn" => Rpc::cryp_spawn(data, &mut tx, account.unwrap(), client),
|
||||
@@ -251,6 +258,43 @@ impl Rpc {
|
||||
}
|
||||
}
|
||||
|
||||
fn account_demo(_data: Vec<u8>, tx: &mut Transaction, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let mut rng = thread_rng();
|
||||
|
||||
let acc_name: String = iter::repeat(())
|
||||
.map(|()| rng.sample(Alphanumeric))
|
||||
.take(8)
|
||||
.collect();
|
||||
|
||||
let account = account_create(AccountCreateParams { name: acc_name, password: "grepgrepgrep".to_string() }, tx)?;
|
||||
|
||||
let name: String = iter::repeat(()).map(|()| rng.sample(Alphanumeric)).take(8).collect();
|
||||
let cryp = cryp_spawn(CrypSpawnParams { name }, tx, &account)?;
|
||||
cryp_learn(CrypLearnParams { id: cryp.id, skill: Skill::Block }, tx, &account)?;
|
||||
cryp_learn(CrypLearnParams { id: cryp.id, skill: Skill::Stun }, tx, &account)?;
|
||||
cryp_learn(CrypLearnParams { id: cryp.id, skill: Skill::Throw }, tx, &account)?;
|
||||
|
||||
let name: String = iter::repeat(()).map(|()| rng.sample(Alphanumeric)).take(8).collect();
|
||||
let cryp = cryp_spawn(CrypSpawnParams { name }, tx, &account)?;
|
||||
cryp_learn(CrypLearnParams { id: cryp.id, skill: Skill::Decay }, tx, &account)?;
|
||||
cryp_learn(CrypLearnParams { id: cryp.id, skill: Skill::Blast }, tx, &account)?;
|
||||
cryp_learn(CrypLearnParams { id: cryp.id, skill: Skill::Drain }, tx, &account)?;
|
||||
|
||||
let name: String = iter::repeat(()).map(|()| rng.sample(Alphanumeric)).take(8).collect();
|
||||
let cryp = cryp_spawn(CrypSpawnParams { name }, tx, &account)?;
|
||||
cryp_learn(CrypLearnParams { id: cryp.id, skill: Skill::Triage }, tx, &account)?;
|
||||
cryp_learn(CrypLearnParams { id: cryp.id, skill: Skill::Heal }, tx, &account)?;
|
||||
cryp_learn(CrypLearnParams { id: cryp.id, skill: Skill::Purify }, tx, &account)?;
|
||||
|
||||
let res = RpcResponse {
|
||||
method: "account_create".to_string(),
|
||||
params: RpcResult::Account(account),
|
||||
};
|
||||
|
||||
return Ok(res);
|
||||
}
|
||||
|
||||
|
||||
fn account_cryps(_data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
Ok(RpcResponse {
|
||||
method: "account_cryps".to_string(),
|
||||
|
||||
Reference in New Issue
Block a user