imgs folder
This commit is contained in:
@@ -12,6 +12,7 @@ use skill::{Skill, Cast, Immunity, Disable, Event};
|
||||
use effect::{Cooldown, Effect, Colour};
|
||||
use spec::{Spec};
|
||||
use item::{Item};
|
||||
use img::{img_molecular_create};
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
pub struct Colours {
|
||||
@@ -857,8 +858,9 @@ pub fn construct_spawn(tx: &mut Transaction, params: ConstructSpawnParams, accou
|
||||
|
||||
let _returned = result.iter().next().ok_or(err_msg("no row returned"))?;
|
||||
|
||||
// info!("{:?} spawned construct {:}", account.id, construct.id);
|
||||
img_molecular_create(construct.img)?;
|
||||
|
||||
info!("spawned construct account={:} construct={:?}", account, construct);
|
||||
return Ok(construct);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
use uuid::Uuid;
|
||||
use rand::prelude::*;
|
||||
use std::fs::copy;
|
||||
|
||||
use failure::Error;
|
||||
use failure::err_msg;
|
||||
|
||||
pub fn img_molecular_create(id: Uuid) -> Result<Uuid, Error> {
|
||||
let mut rng = thread_rng();
|
||||
|
||||
for _i in 0..100 {
|
||||
let mol: u32 = rng.gen_range(0, 10000);
|
||||
let src = format!("/var/lib/mnml/data/molecules/{}.svg", mol);
|
||||
println!("{:?}", src);
|
||||
let dest = format!("/var/lib/mnml/public/imgs/{}.svg", id);
|
||||
println!("{:?}", dest);
|
||||
if let Ok(_bytes) = copy(&src, &dest) {
|
||||
info!("new molecule avatar generated src={:?} dest={:?}", src, dest);
|
||||
return Ok(id);
|
||||
}
|
||||
}
|
||||
|
||||
return Err(err_msg("too many missing molecules. wrong directory?"))
|
||||
}
|
||||
@@ -30,6 +30,7 @@ mod effect;
|
||||
mod game;
|
||||
mod instance;
|
||||
mod item;
|
||||
mod img;
|
||||
mod mob;
|
||||
mod mtx;
|
||||
mod names;
|
||||
|
||||
+25
-5
@@ -12,7 +12,7 @@ use r2d2::{Pool};
|
||||
use r2d2::{PooledConnection};
|
||||
use r2d2_postgres::{TlsMode, PostgresConnectionManager};
|
||||
|
||||
use rpc::{RpcErrorResponse, AccountLoginParams, AccountCreateParams};
|
||||
use rpc::{AccountLoginParams, AccountCreateParams};
|
||||
use warden::{warden};
|
||||
use pubsub::{pg_listen};
|
||||
use ws::{connect};
|
||||
@@ -24,7 +24,12 @@ pub type PgPool = Pool<PostgresConnectionManager>;
|
||||
|
||||
const DB_POOL_SIZE: u32 = 20;
|
||||
|
||||
#[derive(Fail, Debug)]
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
pub struct JsonError {
|
||||
pub err: String
|
||||
}
|
||||
|
||||
#[derive(Fail, Debug, Serialize, Deserialize)]
|
||||
pub enum MnmlHttpError {
|
||||
// User Facing Errors
|
||||
#[fail(display="internal server error")]
|
||||
@@ -33,16 +38,22 @@ pub enum MnmlHttpError {
|
||||
Unauthorized,
|
||||
#[fail(display="bad request")]
|
||||
BadRequest,
|
||||
#[fail(display="account name taken or invalid")]
|
||||
AccountNameTaken,
|
||||
#[fail(display="password unacceptable. must be > 11 characters")]
|
||||
PasswordUnacceptable,
|
||||
#[fail(display="invalid code. https://discord.gg/YJJgurM")]
|
||||
InvalidCode,
|
||||
}
|
||||
|
||||
impl ResponseError for MnmlHttpError {
|
||||
fn error_response(&self) -> HttpResponse {
|
||||
match *self {
|
||||
MnmlHttpError::ServerError => HttpResponse::InternalServerError()
|
||||
.json(RpcErrorResponse { err: self.to_string() }),
|
||||
.json(JsonError { err: self.to_string() }),
|
||||
|
||||
MnmlHttpError::BadRequest => HttpResponse::BadRequest()
|
||||
.json(RpcErrorResponse { err: self.to_string() }),
|
||||
.json(JsonError { err: self.to_string() }),
|
||||
|
||||
MnmlHttpError::Unauthorized => HttpResponse::Unauthorized()
|
||||
.cookie(Cookie::build("x-auth-token", "")
|
||||
@@ -51,7 +62,16 @@ impl ResponseError for MnmlHttpError {
|
||||
.same_site(SameSite::Strict)
|
||||
.max_age(-1) // 1 week aligns with db set
|
||||
.finish())
|
||||
.json(RpcErrorResponse { err: self.to_string() }),
|
||||
.json(JsonError { err: self.to_string() }),
|
||||
|
||||
MnmlHttpError::AccountNameTaken => HttpResponse::BadRequest()
|
||||
.json(JsonError { err: self.to_string() }),
|
||||
|
||||
MnmlHttpError::PasswordUnacceptable => HttpResponse::BadRequest()
|
||||
.json(JsonError { err: self.to_string() }),
|
||||
|
||||
MnmlHttpError::InvalidCode => HttpResponse::BadRequest()
|
||||
.json(JsonError { err: self.to_string() }),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,11 +213,6 @@ fn handle_dev_resolve(data: Vec<u8>) -> Result<RpcResult, Error> {
|
||||
Ok(RpcResult::DevResolutions(dev_resolve(msg.params.a, msg.params.b, msg.params.skill)))
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
pub struct RpcErrorResponse {
|
||||
pub err: String
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
pub enum RpcResult {
|
||||
AccountState(Account),
|
||||
|
||||
+3
-3
@@ -6,9 +6,9 @@ use actix::prelude::*;
|
||||
|
||||
use account::{Account};
|
||||
use serde_cbor::{to_vec};
|
||||
use net::{PgPool, State, MnmlHttpError};
|
||||
use net::{PgPool, State, MnmlHttpError, JsonError};
|
||||
|
||||
use rpc::{receive, RpcResult, RpcErrorResponse};
|
||||
use rpc::{receive, RpcResult};
|
||||
|
||||
const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(5);
|
||||
const CLIENT_TIMEOUT: Duration = Duration::from_secs(10);
|
||||
@@ -73,7 +73,7 @@ impl StreamHandler<ws::Message, ws::ProtocolError> for MnmlSocket {
|
||||
ctx.binary(response);
|
||||
},
|
||||
Err(e) => {
|
||||
let response = to_vec(&RpcErrorResponse { err: e.to_string() })
|
||||
let response = to_vec(&JsonError { err: e.to_string() })
|
||||
.expect("failed to serialize error response");
|
||||
ctx.binary(response);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user