This commit is contained in:
ntr
2019-07-09 12:40:18 +10:00
parent e224f57ea0
commit 1d6ab90fad
21 changed files with 192 additions and 25 deletions
+1 -1
View File
@@ -1 +1 @@
DATABASE_URL=postgres://mnml:craftbeer@localhost/mnml
DATABASE_URL=postgres://mnml:ECfcIvPdsGDMg+E3Wbwdig==@localhost/mnml
+7 -4
View File
@@ -12,6 +12,7 @@ use names::{name as generate_name};
use rpc::{ConstructSpawnParams};
use construct::{Construct, construct_recover, construct_spawn};
use instance::{Instance, instance_delete};
use mtx::{Mtx, FREE_MTX};
use failure::Error;
use failure::{err_msg, format_err};
@@ -230,11 +231,13 @@ pub fn account_create(name: &String, password: &String, code: &String, tx: &mut
None => return Err(err_msg("account not created")),
};
// slow but neat
let account = Account::select(tx, id)?;
for _i in 0..3 {
construct_spawn(tx, ConstructSpawnParams { name: generate_name() }, account.id)?;
construct_spawn(tx, ConstructSpawnParams { name: generate_name() }, id)?;
}
for mtx in FREE_MTX.iter() {
Mtx::new(*mtx, id)
.insert(tx)?;
}
info!("registration account={:?}", name);
+2
View File
@@ -197,6 +197,7 @@ pub struct ConstructRecover {
pub struct Construct {
pub id: Uuid,
pub account: Uuid,
pub img: Uuid,
pub red_power: ConstructStat,
pub red_life: ConstructStat,
pub blue_life: ConstructStat,
@@ -218,6 +219,7 @@ impl Construct {
return Construct {
id,
account: id,
img: Uuid::new_v4(),
red_power: ConstructStat { base: 256, value: 256, max: 256, stat: Stat::RedPower },
red_life: ConstructStat { base: 0, value: 0, max: 0, stat: Stat::RedLife },
blue_power: ConstructStat { base: 256, value: 256, max: 256, stat: Stat::BluePower },
+1 -1
View File
@@ -63,7 +63,7 @@ fn setup_logger() -> Result<(), fern::InitError> {
.level_for("actix_web", log::LevelFilter::Info)
.level(log::LevelFilter::Info)
.chain(std::io::stdout())
.chain(fern::log_file("log/mnml.log")?)
.chain(fern::log_file("/var/log/mnml/mnml.log")?)
.apply()?;
Ok(())
}
+16 -11
View File
@@ -7,21 +7,19 @@ use postgres::transaction::Transaction;
use failure::Error;
use failure::err_msg;
pub const FREE_MTX: [MtxVariant; 2] = [
MtxVariant::Rename,
MtxVariant::Reimage,
];
#[derive(Debug,Copy,Clone,Serialize,Deserialize)]
pub enum MtxVariant {
Rename,
Reimage,
ArchitectureMolecular,
ArchitectureInvader,
}
impl MtxVariant {
fn new(self, account: Uuid) -> Mtx {
match self {
MtxVariant::ArchitectureInvader => Mtx { id: Uuid::new_v4(), account, variant: self },
MtxVariant::ArchitectureMolecular => Mtx { id: Uuid::new_v4(), account, variant: self },
}
}
}
#[derive(Debug,Copy,Clone,Serialize,Deserialize)]
pub struct Mtx {
id: Uuid,
@@ -30,12 +28,19 @@ pub struct Mtx {
}
impl Mtx {
pub fn new(variant: MtxVariant, account: Uuid) -> Mtx {
match variant {
_ => Mtx { id: Uuid::new_v4(), account, variant },
// MtxVariant::ArchitectureInvader => Mtx { id: Uuid::new_v4(), account, variant: self },
// MtxVariant::ArchitectureMolecular => Mtx { id: Uuid::new_v4(), account, variant: self },
}
}
pub fn account_list(tx: &mut Transaction, account: Uuid) -> Result<Vec<Mtx>, Error> {
let query = "
SELECT data, id
FROM mtx
WHERE account = $1
FOR UPDATE;
WHERE account = $1;
";
let result = tx
+1 -1
View File
@@ -183,7 +183,7 @@ pub fn resolve(skill: Skill, source: &mut Construct, target: &mut Construct, mut
Skill::AbsorbI |
Skill::AbsorbII |
Skill::AbsorbIII => absorbtion(source, target, resolutions, skill),
Skill::AbsorbIII => absorb(source, target, resolutions, skill),
Skill::HybridI |
Skill::HybridII |