recovery for get_cryp
This commit is contained in:
parent
96f31346c5
commit
967b316e37
@ -61,7 +61,6 @@ function renderCryps() {
|
|||||||
window.addEventListener('resize', () => {
|
window.addEventListener('resize', () => {
|
||||||
game.scale.displaySize.maxWidth = window.innerHeight * 1.6;
|
game.scale.displaySize.maxWidth = window.innerHeight * 1.6;
|
||||||
game.scale.displaySize.maxHeight = window.innerHeight;
|
game.scale.displaySize.maxHeight = window.innerHeight;
|
||||||
// game.scale.resize();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,7 @@ use postgres::transaction::Transaction;
|
|||||||
|
|
||||||
use rpc::{AccountCreateParams, AccountLoginParams};
|
use rpc::{AccountCreateParams, AccountLoginParams};
|
||||||
|
|
||||||
use cryp::{Cryp, CrypRecover, cryp_write};
|
use cryp::{Cryp, CrypRecover, cryp_write, cryp_recover};
|
||||||
use game::Game;
|
use game::Game;
|
||||||
use zone::{Zone, zone_delete};
|
use zone::{Zone, zone_delete};
|
||||||
use skill::{Skill};
|
use skill::{Skill};
|
||||||
@ -149,23 +149,6 @@ pub fn account_login(params: AccountLoginParams, tx: &mut Transaction) -> Result
|
|||||||
return Ok(account);
|
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> {
|
pub fn account_cryps(tx: &mut Transaction, account: &Account) -> Result<Vec<Cryp>, Error> {
|
||||||
let query = "
|
let query = "
|
||||||
SELECT data
|
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);
|
let cryp_bytes: Vec<u8> = row.get(0);
|
||||||
match from_slice::<Cryp>(&cryp_bytes) {
|
match from_slice::<Cryp>(&cryp_bytes) {
|
||||||
Ok(c) => Ok(c),
|
Ok(c) => Ok(c),
|
||||||
Err(_e) => recover_cryp(cryp_bytes, tx),
|
Err(_e) => cryp_recover(cryp_bytes, tx),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|||||||
@ -7,7 +7,7 @@ use postgres::transaction::Transaction;
|
|||||||
use failure::Error;
|
use failure::Error;
|
||||||
use failure::err_msg;
|
use failure::err_msg;
|
||||||
|
|
||||||
use account::Account;
|
use account::{Account};
|
||||||
use rpc::{CrypSpawnParams, CrypLearnParams, CrypForgetParams, CrypUnspecParams};
|
use rpc::{CrypSpawnParams, CrypLearnParams, CrypForgetParams, CrypUnspecParams};
|
||||||
use skill::{Skill, Cooldown, Effect, Cast, Category, Immunity, Disable, ResolutionResult};
|
use skill::{Skill, Cooldown, Effect, Cast, Category, Immunity, Disable, ResolutionResult};
|
||||||
use spec::{Spec, SpecLevel};
|
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 result = result.iter().next().ok_or(format_err!("cryp {:} not found", id))?;
|
||||||
let cryp_bytes: Vec<u8> = result.get(0);
|
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);
|
return Ok(cryp);
|
||||||
}
|
}
|
||||||
@ -758,6 +758,23 @@ pub fn cryp_write(cryp: Cryp, tx: &mut Transaction) -> Result<Cryp, Error> {
|
|||||||
return Ok(cryp);
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use cryp::*;
|
use cryp::*;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user