@@ -51,16 +51,22 @@ function CrypPanel({ cryp, sendCombatPve }) {
- );
+ ));
// map is a function that is called on every element of an array
// so in this ^^ case it calls Icon('Mashy') which returns some jsx
// that gets put into the dom
+
+ return (
+
+ );
}
module.exports = CrypPanel;
diff --git a/client/src/main.jsx b/client/src/main.jsx
index 15c676a4..de52979f 100644
--- a/client/src/main.jsx
+++ b/client/src/main.jsx
@@ -9,17 +9,17 @@ const actions = require('./actions');
const fizzyText = require('../lib/fizzy-text');
const createSocket = require('./socket');
-const CrypContainer = require('./components/cryp.container');
+const CrypsContainer = require('./components/cryps.container');
const LoginContainer = require('./components/login.container');
-const Navbar = require('./components/navbar');
+// const Navbar = require('./components/navbar');
// Redux Store
const store = createStore(
combineReducers({
account: reducers.accountReducer,
- cryp: reducers.crypReducer,
+ cryps: reducers.crypsReducer,
ws: reducers.wsReducer,
- }),
+ })
);
store.subscribe(() => console.log(store.getState()));
@@ -36,10 +36,9 @@ jdenticon.config = {
const Cryps = () => (
);
diff --git a/client/src/reducers.jsx b/client/src/reducers.jsx
index 1aab82ad..94ddfaa7 100644
--- a/client/src/reducers.jsx
+++ b/client/src/reducers.jsx
@@ -10,10 +10,10 @@ function accountReducer(state = defaultAccount, action) {
}
}
-const defaultCryp = null;
-function crypReducer(state = defaultCryp, action) {
+const defaultCryps = null;
+function crypsReducer(state = defaultCryps, action) {
switch (action.type) {
- case actions.SET_CRYP:
+ case actions.SET_CRYPS:
return action.value;
default:
return state;
@@ -32,6 +32,6 @@ function wsReducer(state = defaultWs, action) {
module.exports = {
accountReducer,
- crypReducer,
+ crypsReducer,
wsReducer,
};
diff --git a/client/src/socket.jsx b/client/src/socket.jsx
index 2f14975b..dd407f48 100644
--- a/client/src/socket.jsx
+++ b/client/src/socket.jsx
@@ -31,14 +31,19 @@ function createSocket(store) {
account = login;
store.dispatch(actions.setAccount(login));
+ send({ method: 'account_cryps', params: {} });
console.log(account);
- return send({ method: 'cryp_spawn', params: { name: 'drake' } });
+ }
+
+ function accountCryps(response) {
+ const [structName, cryps] = response;
+ store.dispatch(actions.setCryps(cryps));
+ console.log('got my cryps', cryps);
}
function crypSpawn(response) {
const [structName, cryp] = response;
console.log('got a new cryp', cryp);
- return store.dispatch(actions.setCryp(cryp));
}
function combatPve(response) {
@@ -74,6 +79,7 @@ function createSocket(store) {
combat_pve: combatPve,
account_login: accountLogin,
account_create: accountLogin,
+ account_cryps: accountCryps,
};
// decodes the cbor and
@@ -93,8 +99,7 @@ function createSocket(store) {
// Connection opened
ws.addEventListener('open', function wsOpen(event) {
- // send({ method: 'account_create', params: { name: 'ntr', password: 'grepgrepgrep' }});
- // send({ method: 'account_login', params: { name: 'ntr', password: 'grepgrepgrep' } });
+ send({ method: 'account_login', params: { name: 'ntr', password: 'grepgrepgrep' } });
});
// Listen for messages
diff --git a/server/WORKLOG.md b/server/WORKLOG.md
index c633109d..9a4dc796 100755
--- a/server/WORKLOG.md
+++ b/server/WORKLOG.md
@@ -34,5 +34,17 @@ items give skills
gem td style attr combinations
stoney + spikey = jagged
+ plants
+ animals
+ viruses
+ fungus
+ artificial
+ elementals
+
+
+ first strike
+
+ techno artists for the soundtrack
+
slimey
ghostly
\ No newline at end of file
diff --git a/server/src/account.rs b/server/src/account.rs
index b18217c4..7d8c47c7 100755
--- a/server/src/account.rs
+++ b/server/src/account.rs
@@ -3,12 +3,16 @@ use bcrypt::{hash, verify};
use rand::{thread_rng, Rng};
use rand::distributions::Alphanumeric;
use std::iter;
+use serde_cbor::{from_slice, to_vec};
+
use std::str;
use net::Db;
use rpc::{AccountCreateParams, AccountLoginParams, RpcResult};
+use cryp::Cryp;
+
use failure::Error;
use failure::err_msg;
@@ -55,7 +59,7 @@ pub fn from_token(token: String, db: &Db) -> Result
{
return Ok(entry);
}
-pub fn create(params: AccountCreateParams, db: Db) -> Result {
+pub fn create(params: AccountCreateParams, db: Db) -> Result {
let id = Uuid::new_v4();
if params.password.len() < PASSWORD_MIN_LEN {
@@ -99,10 +103,10 @@ pub fn create(params: AccountCreateParams, db: Db) -> Result {
tx.commit()?;
- return Ok(RpcResult::Account(entry));
+ return Ok(entry);
}
-pub fn login(params: AccountLoginParams, db: Db) -> Result {
+pub fn login(params: AccountLoginParams, db: Db) -> Result {
let query = "
SELECT id, name, token, password
FROM accounts
@@ -142,5 +146,31 @@ pub fn login(params: AccountLoginParams, db: Db) -> Result {
token: entry.token,
};
- return Ok(RpcResult::Account(account));
-}
\ No newline at end of file
+ return Ok(account);
+}
+
+pub fn fetch_cryps(db: Db, account: Account) -> Result, Error> {
+ let query = "
+ SELECT data
+ FROM cryps
+ WHERE account = $1;
+ ";
+
+ let result = db
+ .query(query, &[&account.id])?;
+
+ let cryps: Result, _> = result.iter().map(|row| {
+ let cryp_bytes: Vec = row.get(0);
+ from_slice::(&cryp_bytes)
+ }).collect();
+
+ // catch any errors
+ if cryps.is_err() {
+ return Err(err_msg("could not deserialize a cryp"));
+ }
+
+ // now unwrap is safe
+ return Ok(cryps.unwrap());
+}
+
+
diff --git a/server/src/combat.rs b/server/src/combat.rs
index 03c0ccf6..e0f3ddc0 100755
--- a/server/src/combat.rs
+++ b/server/src/combat.rs
@@ -121,10 +121,7 @@ where F: Fn(&Battle) -> Result<(), Error>
loop {
battle.next();
- match send(&battle) {
- Err(e) => break Err(err_msg("could not reply")),
- _ => (),
- };
+ send(&battle)?;
if battle.finished() {
break Ok(battle)
diff --git a/server/src/cryp.rs b/server/src/cryp.rs
index d4cad64b..109ec70a 100755
--- a/server/src/cryp.rs
+++ b/server/src/cryp.rs
@@ -1,7 +1,7 @@
use uuid::Uuid;
use rand::prelude::*;
use serde_cbor::*;
-use serde_cbor::{to_vec};
+use serde_cbor::{from_slice, to_vec};
use failure::Error;
use failure::err_msg;
@@ -217,7 +217,6 @@ pub fn spawn(params: CrypSpawnParams, db: Db, account: Account) -> Result(&data) {
Ok(v) => Ok(RpcResponse {
method: v.method,
- params: create(v.params, db)?
+ params: RpcResult::Account(create(v.params, db)?)
}),
Err(_e) => Err(err_msg("invalid params")),
}
@@ -84,12 +84,20 @@ impl Rpc {
match from_slice::(&data) {
Ok(v) => Ok(RpcResponse {
method: v.method,
- params: login(v.params, db)?
+ params: RpcResult::Account(login(v.params, db)?)
}),
Err(_e) => Err(err_msg("invalid params")),
}
},
-
+ "account_cryps" => {
+ match account {
+ Some(u) => Ok(RpcResponse {
+ method: v.method,
+ params: RpcResult::CrypList(fetch_cryps(db, u)?)
+ }),
+ None => Err(err_msg("auth required")),
+ }
+ },
_ => Err(err_msg("unknown method")),
}
},
@@ -108,6 +116,7 @@ pub struct RpcResponse {
pub enum RpcResult {
SpawnCryp(Cryp),
Account(Account),
+ CrypList(Vec),
Pve(Battle),
}
@@ -163,6 +172,12 @@ pub struct AccountLoginParams {
pub password: String,
}
+#[derive(Debug,Clone,Serialize,Deserialize)]
+struct AccountCrypsMsg {
+ method: String,
+ params: (),
+}
+
// #[cfg(test)]
// mod tests {
// use super::*;