account apply
This commit is contained in:
parent
8151c37f96
commit
c4a291e890
@ -4,11 +4,20 @@ const { connect } = require('preact-redux');
|
|||||||
const addState = connect(
|
const addState = connect(
|
||||||
function receiveState(state) {
|
function receiveState(state) {
|
||||||
const {
|
const {
|
||||||
|
ws,
|
||||||
account,
|
account,
|
||||||
|
mtxActive,
|
||||||
} = state;
|
} = state;
|
||||||
|
|
||||||
|
function sendMtxAccountApply() {
|
||||||
|
return ws.sendMtxAccountApply(mtxActive);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
account,
|
account,
|
||||||
|
mtxActive,
|
||||||
|
|
||||||
|
sendMtxAccountApply,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -17,10 +26,13 @@ const addState = connect(
|
|||||||
function AccountBox(args) {
|
function AccountBox(args) {
|
||||||
const {
|
const {
|
||||||
account,
|
account,
|
||||||
|
mtxActive,
|
||||||
|
|
||||||
|
sendMtxAccountApply,
|
||||||
} = args;
|
} = args;
|
||||||
|
|
||||||
const imgStyle = account.img
|
const imgStyle = account.img
|
||||||
? { 'background-image': `url(/imgs/${account.img}.svg)` }
|
? { 'background-image': `url(/imgs/${account.img}.svg)`, cursor: mtxActive ? 'pointer' : '' }
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
// if (!isTop) {
|
// if (!isTop) {
|
||||||
@ -33,10 +45,20 @@ function AccountBox(args) {
|
|||||||
// );
|
// );
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
const onClick = () => {
|
||||||
|
if (!mtxActive) return false;
|
||||||
|
return sendMtxAccountApply();
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class='player-box bottom'>
|
<div class='player-box bottom'>
|
||||||
<div class="msg"> </div>
|
<div class="msg"> </div>
|
||||||
<div class="img avatar" id={account.img} style={imgStyle}></div>
|
<div
|
||||||
|
class="img avatar"
|
||||||
|
id={account.img}
|
||||||
|
onClick={onClick}
|
||||||
|
style={imgStyle}>
|
||||||
|
</div>
|
||||||
<div class="name">{account.name}</div>
|
<div class="name">{account.name}</div>
|
||||||
<div class="score">0 MMR</div>
|
<div class="score">0 MMR</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -150,6 +150,10 @@ function createSocket(events) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sendMtxAccountApply(mtx) {
|
||||||
|
send(['MtxAccountApply', { mtx }]);
|
||||||
|
}
|
||||||
|
|
||||||
function sendMtxBuy(mtx) {
|
function sendMtxBuy(mtx) {
|
||||||
send(['MtxBuy', { mtx }]);
|
send(['MtxBuy', { mtx }]);
|
||||||
}
|
}
|
||||||
@ -368,6 +372,7 @@ function createSocket(events) {
|
|||||||
sendSubscriptionState,
|
sendSubscriptionState,
|
||||||
sendSubscriptionEnding,
|
sendSubscriptionEnding,
|
||||||
|
|
||||||
|
sendMtxAccountApply,
|
||||||
sendMtxApply,
|
sendMtxApply,
|
||||||
sendMtxBuy,
|
sendMtxBuy,
|
||||||
sendMtxConstructSpawn,
|
sendMtxConstructSpawn,
|
||||||
|
|||||||
@ -158,6 +158,23 @@ pub fn new_token(tx: &mut Transaction, id: Uuid) -> Result<String, MnmlHttpError
|
|||||||
Ok(token)
|
Ok(token)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn new_img(tx: &mut Transaction, id: Uuid) -> Result<Account, Error> {
|
||||||
|
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<String, MnmlHttpError> {
|
pub fn set_password(tx: &mut Transaction, id: Uuid, current: &String, password: &String) -> Result<String, MnmlHttpError> {
|
||||||
if password.len() < PASSWORD_MIN_LEN {
|
if password.len() < PASSWORD_MIN_LEN {
|
||||||
return Err(MnmlHttpError::PasswordUnacceptable);
|
return Err(MnmlHttpError::PasswordUnacceptable);
|
||||||
|
|||||||
@ -167,6 +167,26 @@ pub fn apply(tx: &mut Transaction, account: &Account, variant: MtxVariant, const
|
|||||||
account::team(tx, account)
|
account::team(tx, account)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn account_apply(tx: &mut Transaction, account: &Account, variant: MtxVariant) -> Result<Account, Error> {
|
||||||
|
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<Mtx, Error> {
|
pub fn select(tx: &mut Transaction, variant: MtxVariant, account: Uuid) -> Result<Mtx, Error> {
|
||||||
let query = "
|
let query = "
|
||||||
SELECT id, account, variant
|
SELECT id, account, variant
|
||||||
|
|||||||
@ -230,6 +230,9 @@ impl Connection {
|
|||||||
RpcRequest::MtxConstructApply { mtx, construct_id, name } =>
|
RpcRequest::MtxConstructApply { mtx, construct_id, name } =>
|
||||||
Ok(RpcMessage::AccountTeam(mtx::apply(&mut tx, account, 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 } =>
|
RpcRequest::MtxBuy { mtx } =>
|
||||||
Ok(RpcMessage::AccountShop(mtx::buy(&mut tx, account, mtx)?)),
|
Ok(RpcMessage::AccountShop(mtx::buy(&mut tx, account, mtx)?)),
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user