diff --git a/client/src/components/account.box.jsx b/client/src/components/account.box.jsx
index 1ad42023..9a3dcba9 100644
--- a/client/src/components/account.box.jsx
+++ b/client/src/components/account.box.jsx
@@ -4,11 +4,20 @@ const { connect } = require('preact-redux');
const addState = connect(
function receiveState(state) {
const {
+ ws,
account,
+ mtxActive,
} = state;
+ function sendMtxAccountApply() {
+ return ws.sendMtxAccountApply(mtxActive);
+ }
+
return {
account,
+ mtxActive,
+
+ sendMtxAccountApply,
};
}
);
@@ -17,10 +26,13 @@ const addState = connect(
function AccountBox(args) {
const {
account,
+ mtxActive,
+
+ sendMtxAccountApply,
} = args;
const imgStyle = account.img
- ? { 'background-image': `url(/imgs/${account.img}.svg)` }
+ ? { 'background-image': `url(/imgs/${account.img}.svg)`, cursor: mtxActive ? 'pointer' : '' }
: null;
// if (!isTop) {
@@ -33,10 +45,20 @@ function AccountBox(args) {
// );
// }
+ const onClick = () => {
+ if (!mtxActive) return false;
+ return sendMtxAccountApply();
+ };
+
return (
-
+
+
{account.name}
0 MMR
diff --git a/client/src/socket.jsx b/client/src/socket.jsx
index 1c6f6f37..ec174322 100644
--- a/client/src/socket.jsx
+++ b/client/src/socket.jsx
@@ -150,6 +150,10 @@ function createSocket(events) {
}
}
+ function sendMtxAccountApply(mtx) {
+ send(['MtxAccountApply', { mtx }]);
+ }
+
function sendMtxBuy(mtx) {
send(['MtxBuy', { mtx }]);
}
@@ -368,6 +372,7 @@ function createSocket(events) {
sendSubscriptionState,
sendSubscriptionEnding,
+ sendMtxAccountApply,
sendMtxApply,
sendMtxBuy,
sendMtxConstructSpawn,
diff --git a/server/src/account.rs b/server/src/account.rs
index ddbf01cf..10e0138f 100644
--- a/server/src/account.rs
+++ b/server/src/account.rs
@@ -158,6 +158,23 @@ pub fn new_token(tx: &mut Transaction, id: Uuid) -> Result Result {
+ let query = "
+ UPDATE accounts
+ SET img = $1, updated_at = now()
+ WHERE id = $2
+ RETURNING id, password, name, balance, subscribed, img
+ ";
+
+ let result = tx
+ .query(query, &[&Uuid::new_v4(), &id])?;
+
+ let row = result.iter().next()
+ .ok_or(format_err!("account not updated {:?}", id))?;
+
+ Account::try_from(row)
+}
+
pub fn set_password(tx: &mut Transaction, id: Uuid, current: &String, password: &String) -> Result {
if password.len() < PASSWORD_MIN_LEN {
return Err(MnmlHttpError::PasswordUnacceptable);
diff --git a/server/src/mtx.rs b/server/src/mtx.rs
index f32f9339..239e1fe7 100644
--- a/server/src/mtx.rs
+++ b/server/src/mtx.rs
@@ -167,6 +167,26 @@ pub fn apply(tx: &mut Transaction, account: &Account, variant: MtxVariant, const
account::team(tx, account)
}
+pub fn account_apply(tx: &mut Transaction, account: &Account, variant: MtxVariant) -> Result {
+ let mtx = select(tx, variant, account.id)?;
+ let cost = match mtx.variant {
+ MtxVariant::Rename => return Err(err_msg("rename not usable on account")),
+ _ => NEW_IMAGE_COST,
+ };
+
+ account::debit(tx, account.id, cost)?;
+ let account = account::new_img(tx, account.id)?;
+
+ match mtx.variant {
+ MtxVariant::Invader => img::invader_write(account.img)?,
+ MtxVariant::Molecular => img::molecular_write(account.img)?,
+ MtxVariant::Shapes => img::shapes_write(account.img)?,
+ _ => account.img,
+ };
+
+ Ok(account)
+}
+
pub fn select(tx: &mut Transaction, variant: MtxVariant, account: Uuid) -> Result {
let query = "
SELECT id, account, variant
diff --git a/server/src/rpc.rs b/server/src/rpc.rs
index 208cac07..141f6ee8 100644
--- a/server/src/rpc.rs
+++ b/server/src/rpc.rs
@@ -230,6 +230,9 @@ impl Connection {
RpcRequest::MtxConstructApply { mtx, construct_id, name } =>
Ok(RpcMessage::AccountTeam(mtx::apply(&mut tx, account, mtx, construct_id, name)?)),
+ RpcRequest::MtxAccountApply { mtx } =>
+ Ok(RpcMessage::AccountState(mtx::account_apply(&mut tx, account, mtx)?)),
+
RpcRequest::MtxBuy { mtx } =>
Ok(RpcMessage::AccountShop(mtx::buy(&mut tx, account, mtx)?)),