Merge branch 'master' of ssh://cryps.gg:40022/~/cryps
This commit is contained in:
commit
6d44a5de5e
@ -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();
|
||||
});
|
||||
|
||||
|
||||
|
||||
@ -13,6 +13,8 @@ cost system for items
|
||||
design / implement specs
|
||||
combo specs
|
||||
round system for games
|
||||
add cryps to player
|
||||
find opponent or do pve
|
||||
|
||||
## SOON
|
||||
* clean up categories
|
||||
|
||||
@ -9,9 +9,9 @@ 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 zone::{Zone, zone_delete};
|
||||
use skill::{Skill};
|
||||
|
||||
use failure::Error;
|
||||
@ -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();
|
||||
@ -222,33 +205,33 @@ pub fn account_game_history(tx: &mut Transaction, account: &Account) -> Result<V
|
||||
|
||||
}
|
||||
|
||||
pub fn account_zone(tx: &mut Transaction, account: &Account) -> Result<Zone, Error> {
|
||||
let query = "
|
||||
SELECT *
|
||||
FROM zones
|
||||
WHERE account = $1
|
||||
AND active = true;
|
||||
";
|
||||
// pub fn account_zone(tx: &mut Transaction, account: &Account) -> Result<Zone, Error> {
|
||||
// let query = "
|
||||
// SELECT *
|
||||
// FROM zones
|
||||
// WHERE account = $1
|
||||
// AND active = true;
|
||||
// ";
|
||||
|
||||
let result = tx
|
||||
.query(query, &[&account.id])?;
|
||||
// let result = tx
|
||||
// .query(query, &[&account.id])?;
|
||||
|
||||
let returned = match result.iter().next() {
|
||||
Some(row) => row,
|
||||
None => return Err(err_msg("no active zone")),
|
||||
};
|
||||
// let returned = match result.iter().next() {
|
||||
// Some(row) => row,
|
||||
// None => return Err(err_msg("no active zone")),
|
||||
// };
|
||||
|
||||
// tells from_slice to cast into a cryp
|
||||
let bytes: Vec<u8> = returned.get("data");
|
||||
let zone = match from_slice::<Zone>(&bytes) {
|
||||
Ok(z) => z,
|
||||
Err(_) => {
|
||||
zone_delete(tx, returned.get("id"))?;
|
||||
return Err(err_msg("invalid zone removed"))
|
||||
},
|
||||
};
|
||||
// // tells from_slice to cast into a cryp
|
||||
// let bytes: Vec<u8> = returned.get("data");
|
||||
// let zone = match from_slice::<Zone>(&bytes) {
|
||||
// Ok(z) => z,
|
||||
// Err(_) => {
|
||||
// zone_delete(tx, returned.get("id"))?;
|
||||
// return Err(err_msg("invalid zone removed"))
|
||||
// },
|
||||
// };
|
||||
|
||||
return Ok(zone);
|
||||
}
|
||||
// return Ok(zone);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
@ -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::*;
|
||||
|
||||
@ -11,7 +11,7 @@ use account::Account;
|
||||
use rpc::{GameStateParams, GameSkillParams, GamePveParams};
|
||||
use cryp::{Cryp, cryp_get};
|
||||
use skill::{Skill, Cast, ResolutionResult};
|
||||
use zone::{node_finish};
|
||||
// use zone::{node_finish};
|
||||
use mob::{generate_mob_team};
|
||||
|
||||
pub type Log = Vec<String>;
|
||||
@ -659,13 +659,13 @@ pub fn game_update(game: &Game, tx: &mut Transaction) -> Result<(), Error> {
|
||||
|
||||
result.iter().next().ok_or(format_err!("game {:?} could not be written", game))?;
|
||||
|
||||
if game.finished() {
|
||||
// check for zone update
|
||||
if let Some((z, i)) = game.zone {
|
||||
node_finish(game, z, i, tx)?;
|
||||
}
|
||||
// if game.finished() {
|
||||
// // check for zone update
|
||||
// if let Some((z, i)) = game.zone {
|
||||
// node_finish(game, z, i, tx)?;
|
||||
// }
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@ extern crate env_logger;
|
||||
extern crate bcrypt;
|
||||
|
||||
extern crate dotenv;
|
||||
extern crate petgraph;
|
||||
// extern crate petgraph;
|
||||
extern crate postgres;
|
||||
extern crate r2d2;
|
||||
extern crate r2d2_postgres;
|
||||
@ -28,7 +28,7 @@ mod rpc;
|
||||
mod account;
|
||||
mod instance;
|
||||
mod player;
|
||||
mod zone;
|
||||
// mod zone;
|
||||
mod mob;
|
||||
|
||||
mod vbox;
|
||||
|
||||
@ -17,9 +17,9 @@ use failure::err_msg;
|
||||
use net::Db;
|
||||
use cryp::{Cryp, cryp_spawn, cryp_learn};
|
||||
use game::{Game, game_state, game_pve, game_skill};
|
||||
use account::{Account, account_create, account_login, account_from_token, account_cryps, account_zone};
|
||||
use account::{Account, account_create, account_login, account_from_token, account_cryps};
|
||||
use skill::{Skill};
|
||||
use zone::{Zone, zone_create, zone_join, zone_close};
|
||||
// use zone::{Zone, zone_create, zone_join, zone_close};
|
||||
use spec::{Spec};
|
||||
use player::{player_state, player_create, player_cryps_set, Player};
|
||||
use instance::{instance_join};
|
||||
@ -64,7 +64,7 @@ impl Rpc {
|
||||
|
||||
// auth methods
|
||||
"account_cryps" => Rpc::account_cryps(data, &mut tx, account.unwrap(), client),
|
||||
"account_zone" => Rpc::account_zone(data, &mut tx, account.unwrap(), client),
|
||||
// "account_zone" => Rpc::account_zone(data, &mut tx, account.unwrap(), client),
|
||||
|
||||
"cryp_spawn" => Rpc::cryp_spawn(data, &mut tx, account.unwrap(), client),
|
||||
|
||||
@ -72,9 +72,9 @@ impl Rpc {
|
||||
"game_pve" => Rpc::game_pve(data, &mut tx, account.unwrap(), client),
|
||||
"game_skill" => Rpc::game_skill(data, &mut tx, account.unwrap(), client),
|
||||
|
||||
"zone_create" => Rpc::zone_create(data, &mut tx, account.unwrap(), client),
|
||||
"zone_join" => Rpc::zone_join(data, &mut tx, account.unwrap(), client),
|
||||
"zone_close" => Rpc::zone_close(data, &mut tx, account.unwrap(), client),
|
||||
// "zone_create" => Rpc::zone_create(data, &mut tx, account.unwrap(), client),
|
||||
// "zone_join" => Rpc::zone_join(data, &mut tx, account.unwrap(), client),
|
||||
// "zone_close" => Rpc::zone_close(data, &mut tx, account.unwrap(), client),
|
||||
|
||||
"instance_join" => Rpc::instance_join(data, &mut tx, account.unwrap(), client),
|
||||
"player_state" => Rpc::player_state(data, &mut tx, account.unwrap(), client),
|
||||
@ -220,45 +220,45 @@ impl Rpc {
|
||||
})
|
||||
}
|
||||
|
||||
fn account_zone(_data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
Ok(RpcResponse {
|
||||
method: "zone_state".to_string(),
|
||||
params: RpcResult::ZoneState(account_zone(tx, &account)?)
|
||||
})
|
||||
}
|
||||
// fn account_zone(_data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
// Ok(RpcResponse {
|
||||
// method: "zone_state".to_string(),
|
||||
// params: RpcResult::ZoneState(account_zone(tx, &account)?)
|
||||
// })
|
||||
// }
|
||||
|
||||
fn zone_create(_data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
// let _msg = from_slice::<ZoneCreateMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||
// fn zone_create(_data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
// // let _msg = from_slice::<ZoneCreateMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||
|
||||
let response = RpcResponse {
|
||||
method: "zone_state".to_string(),
|
||||
params: RpcResult::ZoneState(zone_create(tx, &account)?)
|
||||
};
|
||||
// let response = RpcResponse {
|
||||
// method: "zone_state".to_string(),
|
||||
// params: RpcResult::ZoneState(zone_create(tx, &account)?)
|
||||
// };
|
||||
|
||||
return Ok(response);
|
||||
}
|
||||
// return Ok(response);
|
||||
// }
|
||||
|
||||
fn zone_join(data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let msg = from_slice::<ZoneJoinMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||
// fn zone_join(data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
// let msg = from_slice::<ZoneJoinMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||
|
||||
let response = RpcResponse {
|
||||
method: "game_state".to_string(),
|
||||
params: RpcResult::GameState(zone_join(msg.params, tx, &account)?)
|
||||
};
|
||||
// let response = RpcResponse {
|
||||
// method: "game_state".to_string(),
|
||||
// params: RpcResult::GameState(zone_join(msg.params, tx, &account)?)
|
||||
// };
|
||||
|
||||
return Ok(response);
|
||||
}
|
||||
// return Ok(response);
|
||||
// }
|
||||
|
||||
fn zone_close(data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let msg = from_slice::<ZoneCloseMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||
// fn zone_close(data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
// let msg = from_slice::<ZoneCloseMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||
|
||||
let response = RpcResponse {
|
||||
method: "zone_close".to_string(),
|
||||
params: RpcResult::ZoneClose(zone_close(msg.params, tx, &account)?)
|
||||
};
|
||||
// let response = RpcResponse {
|
||||
// method: "zone_close".to_string(),
|
||||
// params: RpcResult::ZoneClose(zone_close(msg.params, tx, &account)?)
|
||||
// };
|
||||
|
||||
return Ok(response);
|
||||
}
|
||||
// return Ok(response);
|
||||
// }
|
||||
|
||||
fn instance_join(data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let msg = from_slice::<InstanceJoinMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||
@ -371,8 +371,8 @@ pub enum RpcResult {
|
||||
Account(Account),
|
||||
CrypList(Vec<Cryp>),
|
||||
GameState(Game),
|
||||
ZoneState(Zone),
|
||||
ZoneClose(()),
|
||||
// ZoneState(Zone),
|
||||
// ZoneClose(()),
|
||||
|
||||
PlayerState(Player),
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user