recovery for get_cryp

This commit is contained in:
ntr 2019-02-22 16:00:39 +11:00
parent 96f31346c5
commit 967b316e37
3 changed files with 21 additions and 22 deletions

View File

@ -61,7 +61,6 @@ function renderCryps() {
window.addEventListener('resize', () => {
game.scale.displaySize.maxWidth = window.innerHeight * 1.6;
game.scale.displaySize.maxHeight = window.innerHeight;
// game.scale.resize();
});

View File

@ -9,7 +9,7 @@ use postgres::transaction::Transaction;
use rpc::{AccountCreateParams, AccountLoginParams};
use cryp::{Cryp, CrypRecover, cryp_write};
use cryp::{Cryp, CrypRecover, cryp_write, cryp_recover};
use game::Game;
use zone::{Zone, zone_delete};
use skill::{Skill};
@ -149,23 +149,6 @@ pub fn account_login(params: AccountLoginParams, tx: &mut Transaction) -> Result
return Ok(account);
}
fn recover_cryp(cryp_bytes: Vec<u8>, tx: &mut Transaction) -> Result<Cryp, Error> {
let c = from_slice::<CrypRecover>(&cryp_bytes)?;
let mut cryp = Cryp::new()
.named(&c.name)
.level(c.lvl)
.learn(Skill::Attack)
.set_account(c.account)
.create();
cryp.id = c.id;
println!("recovered cryp {:?}", c.name);
return cryp_write(cryp, tx);
}
pub fn account_cryps(tx: &mut Transaction, account: &Account) -> Result<Vec<Cryp>, Error> {
let query = "
SELECT data
@ -181,7 +164,7 @@ pub fn account_cryps(tx: &mut Transaction, account: &Account) -> Result<Vec<Cryp
let cryp_bytes: Vec<u8> = row.get(0);
match from_slice::<Cryp>(&cryp_bytes) {
Ok(c) => Ok(c),
Err(_e) => recover_cryp(cryp_bytes, tx),
Err(_e) => cryp_recover(cryp_bytes, tx),
}
})
.collect();

View File

@ -7,7 +7,7 @@ use postgres::transaction::Transaction;
use failure::Error;
use failure::err_msg;
use account::Account;
use account::{Account};
use rpc::{CrypSpawnParams, CrypLearnParams, CrypForgetParams, CrypUnspecParams};
use skill::{Skill, Cooldown, Effect, Cast, Category, Immunity, Disable, ResolutionResult};
use spec::{Spec, SpecLevel};
@ -682,7 +682,7 @@ pub fn cryp_get(tx: &mut Transaction, id: Uuid, account_id: Uuid) -> Result<Cryp
let result = result.iter().next().ok_or(format_err!("cryp {:} not found", id))?;
let cryp_bytes: Vec<u8> = result.get(0);
let cryp = from_slice::<Cryp>(&cryp_bytes)?;
let cryp = from_slice::<Cryp>(&cryp_bytes).or_else(|_| cryp_recover(cryp_bytes, tx))?;
return Ok(cryp);
}
@ -758,6 +758,23 @@ pub fn cryp_write(cryp: Cryp, tx: &mut Transaction) -> Result<Cryp, Error> {
return Ok(cryp);
}
pub fn cryp_recover(cryp_bytes: Vec<u8>, tx: &mut Transaction) -> Result<Cryp, Error> {
let c = from_slice::<CrypRecover>(&cryp_bytes)?;
let mut cryp = Cryp::new()
.named(&c.name)
.level(c.lvl)
.learn(Skill::Attack)
.set_account(c.account)
.create();
cryp.id = c.id;
println!("recovered cryp {:?}", c.name);
return cryp_write(cryp, tx);
}
#[cfg(test)]
mod tests {
use cryp::*;