From f24b5afd5ca71f4098cad52f23e279def15dac13 Mon Sep 17 00:00:00 2001 From: ntr Date: Sun, 7 Jul 2019 15:42:29 +1000 Subject: [PATCH] default view games list --- WORKLOG.md | 2 +- client/.eslintrc.js | 3 --- client/src/components/account.status.jsx | 1 + client/src/components/main.jsx | 4 +--- client/src/components/nav.jsx | 7 +------ client/src/events.jsx | 7 ++++++- client/src/socket.jsx | 4 +--- server/src/account.rs | 11 ++++++++++- server/src/construct.rs | 7 +++---- server/src/names.rs | 6 ++++-- server/src/rpc.rs | 6 ++---- 11 files changed, 30 insertions(+), 28 deletions(-) diff --git a/WORKLOG.md b/WORKLOG.md index 75d3a926..2c7a7056 100644 --- a/WORKLOG.md +++ b/WORKLOG.md @@ -34,7 +34,7 @@ * invader set * start with 3 constructs w/ random names -* storing construct costs 5cr +* new construct costs 5cr * eth adapter diff --git a/client/.eslintrc.js b/client/.eslintrc.js index 3ec74b6b..2763e0b8 100644 --- a/client/.eslintrc.js +++ b/client/.eslintrc.js @@ -302,9 +302,6 @@ module.exports = { // disallow use of comma operator 'no-sequences': 'error', - // restrict what can be breakn as an exception - 'no-break-literal': 'error', - // disallow unmodified conditions of loops // https://eslint.org/docs/rules/no-unmodified-loop-condition 'no-unmodified-loop-condition': 'off', diff --git a/client/src/components/account.status.jsx b/client/src/components/account.status.jsx index 4ad082bb..e5f8dceb 100644 --- a/client/src/components/account.status.jsx +++ b/client/src/components/account.status.jsx @@ -3,6 +3,7 @@ const preact = require('preact'); const { Elements, injectStripe } = require('react-stripe-elements'); const { saw } = require('./shapes'); +const { postData } = require('./../utils'); function pingColour(ping) { if (ping < 100) return 'forestgreen'; diff --git a/client/src/components/main.jsx b/client/src/components/main.jsx index 235ecf4a..35782efb 100644 --- a/client/src/components/main.jsx +++ b/client/src/components/main.jsx @@ -21,8 +21,6 @@ function Main(props) { instance, account, nav, - team, - constructs, } = props; if (!account) { @@ -37,7 +35,7 @@ function Main(props) { return ; } - if (nav === 'team' || !team.some(t => t) || constructs.length < 3) return ; + if (nav === 'team') return ; if (nav === 'list') return ; return ( diff --git a/client/src/components/nav.jsx b/client/src/components/nav.jsx index b661e1a9..313ea2c7 100644 --- a/client/src/components/nav.jsx +++ b/client/src/components/nav.jsx @@ -3,6 +3,7 @@ const preact = require('preact'); const { Fragment } = require('preact'); const { postData } = require('../utils'); +console.log(postData); const actions = require('../actions'); const AccountStatus = require('./account.status'); @@ -33,10 +34,6 @@ const addState = connect( return ws.sendInstanceList(); } - function logout() { - postData('/logout').then(() => window.location.reload(true)); - } - return { account, instances, @@ -46,7 +43,6 @@ const addState = connect( sendInstanceState, sendAccountInstances, sendInstanceList, - logout, }; }, function receiveDispatch(dispatch) { @@ -142,7 +138,6 @@ function Nav(args) {

mnml.gg


-
{joined} diff --git a/client/src/events.jsx b/client/src/events.jsx index dbbbc76a..25d0e76c 100644 --- a/client/src/events.jsx +++ b/client/src/events.jsx @@ -33,7 +33,12 @@ function registerEvents(store) { // check team is in list const { team } = store.getState(); const ids = constructs.map(c => c.id); - if (!team.every(t => t && ids.includes(t))) store.dispatch(actions.setTeam([null, null, null])); + + // team is fucked up, or just registered + // reset to the first 3 constructs + if (!team.every(t => t && ids.includes(t))) { + store.dispatch(actions.setTeam([ids[0], ids[1], ids[2]])); + } store.dispatch(actions.setConstructs(constructs)); } diff --git a/client/src/socket.jsx b/client/src/socket.jsx index 18e2f1c3..3ca95f36 100644 --- a/client/src/socket.jsx +++ b/client/src/socket.jsx @@ -221,9 +221,7 @@ function createSocket(events) { }; function logout() { - localStorage.removeItem('account'); - account = null; - event.setAccount(null); + window.location.reload(true); } function errHandler(error) { diff --git a/server/src/account.rs b/server/src/account.rs index 9705fc4e..0873e175 100644 --- a/server/src/account.rs +++ b/server/src/account.rs @@ -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) diff --git a/server/src/construct.rs b/server/src/construct.rs index 2b7eb90e..e1b48d76 100644 --- a/server/src/construct.rs +++ b/server/src/construct.rs @@ -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 { +pub fn construct_spawn(tx: &mut Transaction, params: ConstructSpawnParams, account: Uuid) -> Result { let construct = Construct::new() .named(¶ms.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"))?; diff --git a/server/src/names.rs b/server/src/names.rs index 96280b92..b6b7d718 100644 --- a/server/src/names.rs +++ b/server/src/names.rs @@ -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 { diff --git a/server/src/rpc.rs b/server/src/rpc.rs index f45be3da..1f535c8d 100644 --- a/server/src/rpc.rs +++ b/server/src/rpc.rs @@ -117,11 +117,10 @@ fn handle_game_ready(data: Vec, tx: &mut Transaction, account: &Account) -> Ok(RpcResult::GameState(game_ready(msg.params, tx, &account)?)) } - fn handle_construct_spawn(data: Vec, tx: &mut Transaction, account: &Account) -> Result { let msg = from_slice::(&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, tx: &mut Transaction, account: &Account) -> Result { @@ -130,7 +129,6 @@ fn handle_construct_delete(data: Vec, tx: &mut Transaction, account: &Accoun Ok(RpcResult::AccountConstructs(account_constructs(tx, &account)?)) } - // fn handle_account_create(data: Vec, tx: &mut Transaction) -> Result { // let msg = from_slice::(&data).or(Err(err_msg("invalid params")))?; // let account = account_create(msg.params, tx)?;