default view games list

This commit is contained in:
ntr
2019-07-07 15:42:29 +10:00
parent ec4252d5c9
commit f24b5afd5c
11 changed files with 30 additions and 28 deletions
+10 -1
View File
@@ -8,7 +8,9 @@ use serde_cbor::{from_slice};
use postgres::transaction::Transaction;
use construct::{Construct, construct_recover};
use names::{name as generate_name};
use rpc::{ConstructSpawnParams};
use construct::{Construct, construct_recover, construct_spawn};
use instance::{Instance, instance_delete};
use failure::Error;
@@ -228,6 +230,13 @@ pub fn account_create(name: &String, password: &String, code: &String, tx: &mut
None => return Err(err_msg("account not created")),
};
// slow but neat
let account = Account::select(tx, id)?;
for _i in 0..3 {
construct_spawn(tx, ConstructSpawnParams { name: generate_name() }, account.id)?;
}
info!("registration account={:?}", name);
Ok(token)
+3 -4
View File
@@ -7,7 +7,6 @@ use postgres::transaction::Transaction;
use failure::Error;
use failure::err_msg;
use account::{Account};
use rpc::{ConstructSpawnParams};
use skill::{Skill, Cast, Immunity, Disable, Event};
use effect::{Cooldown, Effect, Colour};
@@ -838,10 +837,10 @@ pub fn construct_get(tx: &mut Transaction, id: Uuid, account_id: Uuid) -> Result
return Ok(construct);
}
pub fn construct_spawn(params: ConstructSpawnParams, tx: &mut Transaction, account: &Account) -> Result<Construct, Error> {
pub fn construct_spawn(tx: &mut Transaction, params: ConstructSpawnParams, account: Uuid) -> Result<Construct, Error> {
let construct = Construct::new()
.named(&params.name)
.set_account(account.id);
.set_account(account);
let construct_bytes = to_vec(&construct)?;
@@ -852,7 +851,7 @@ pub fn construct_spawn(params: ConstructSpawnParams, tx: &mut Transaction, accou
";
let result = tx
.query(query, &[&construct.id, &account.id, &construct_bytes])?;
.query(query, &[&construct.id, &account, &construct_bytes])?;
let _returned = result.iter().next().ok_or(err_msg("no row returned"))?;
+4 -2
View File
@@ -1,7 +1,7 @@
use rand::prelude::*;
use rand::{thread_rng};
const FIRSTS: [&'static str; 22] = [
const FIRSTS: [&'static str; 23] = [
"fierce",
"obscure",
"mighty",
@@ -24,9 +24,10 @@ const FIRSTS: [&'static str; 22] = [
"purified",
"organic",
"distorted",
"weary",
];
const LASTS: [&'static str; 29] = [
const LASTS: [&'static str; 30] = [
"kaffe",
"foilage",
"wildlife",
@@ -56,6 +57,7 @@ const LASTS: [&'static str; 29] = [
"warning",
"information",
"witness",
"traveller",
];
pub fn name() -> String {
+2 -4
View File
@@ -117,11 +117,10 @@ fn handle_game_ready(data: Vec<u8>, tx: &mut Transaction, account: &Account) ->
Ok(RpcResult::GameState(game_ready(msg.params, tx, &account)?))
}
fn handle_construct_spawn(data: Vec<u8>, tx: &mut Transaction, account: &Account) -> Result<RpcResult, Error> {
let msg = from_slice::<ConstructSpawnMsg>(&data).or(Err(err_msg("invalid params")))?;
construct_spawn(msg.params, tx, &account)?;
Ok(RpcResult::AccountConstructs(account_constructs(tx, &account)?))
construct_spawn(tx, msg.params, account.id)?;
Ok(RpcResult::AccountConstructs(account_constructs(tx, account)?))
}
fn handle_construct_delete(data: Vec<u8>, tx: &mut Transaction, account: &Account) -> Result<RpcResult, Error> {
@@ -130,7 +129,6 @@ fn handle_construct_delete(data: Vec<u8>, tx: &mut Transaction, account: &Accoun
Ok(RpcResult::AccountConstructs(account_constructs(tx, &account)?))
}
// fn handle_account_create(data: Vec<u8>, tx: &mut Transaction) -> Result<RpcResult, Error> {
// let msg = from_slice::<AccountCreateMsg>(&data).or(Err(err_msg("invalid params")))?;
// let account = account_create(msg.params, tx)?;