imgs folder
This commit is contained in:
parent
fac62329e8
commit
b33ca86a58
@ -23,6 +23,8 @@ sudo chown $MNML_USER: /opt/mnml
|
|||||||
sudo mkdir -p /var/lib/mnml
|
sudo mkdir -p /var/lib/mnml
|
||||||
sudo chown $MNML_USER: /var/lib/mnml
|
sudo chown $MNML_USER: /var/lib/mnml
|
||||||
mkdir -p /var/lib/mnml/public
|
mkdir -p /var/lib/mnml/public
|
||||||
|
mkdir -p /var/lib/mnml/public/imgs
|
||||||
|
mkdir -p /var/lib/mnml/data
|
||||||
|
|
||||||
sudo mkdir -p /var/log/mnml
|
sudo mkdir -p /var/log/mnml
|
||||||
sudo chown $MNML_USER: /var/log/mnml
|
sudo chown $MNML_USER: /var/log/mnml
|
||||||
|
|||||||
@ -3,7 +3,7 @@ const preact = require('preact');
|
|||||||
const { Component } = require('preact')
|
const { Component } = require('preact')
|
||||||
const { connect } = require('preact-redux');
|
const { connect } = require('preact-redux');
|
||||||
|
|
||||||
const { postData } = require('../utils');
|
const { postData, errorToast } = require('../utils');
|
||||||
|
|
||||||
const addState = connect(
|
const addState = connect(
|
||||||
(state) => {
|
(state) => {
|
||||||
@ -12,14 +12,26 @@ const addState = connect(
|
|||||||
} = state;
|
} = state;
|
||||||
function submitLogin(name, password) {
|
function submitLogin(name, password) {
|
||||||
postData('/login', { name, password })
|
postData('/login', { name, password })
|
||||||
.then(data => ws.connect())
|
.then(res => {
|
||||||
.catch(error => console.error(error));
|
if (!res.ok) return errorToast(res);
|
||||||
|
res.text()
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
ws.connect();
|
||||||
|
})
|
||||||
|
.catch(error => errorToast(error));
|
||||||
}
|
}
|
||||||
|
|
||||||
function submitRegister(name, password, code) {
|
function submitRegister(name, password, code) {
|
||||||
postData('/register', { name, password, code })
|
postData('/register', { name, password, code })
|
||||||
.then(data => ws.connect())
|
.then(res => {
|
||||||
.catch(error => console.error(error));
|
if (!res.ok) return errorToast(res);
|
||||||
|
res.text()
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
ws.connect();
|
||||||
|
})
|
||||||
|
.catch(error => errorToast(error));
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -194,7 +194,7 @@ function registerEvents(store) {
|
|||||||
function errorPrompt(type) {
|
function errorPrompt(type) {
|
||||||
const message = errMessages[type];
|
const message = errMessages[type];
|
||||||
const OK_BUTTON = '<button type="submit">OK</button>';
|
const OK_BUTTON = '<button type="submit">OK</button>';
|
||||||
toast.info({
|
toast.error({
|
||||||
theme: 'dark',
|
theme: 'dark',
|
||||||
color: 'black',
|
color: 'black',
|
||||||
timeout: false,
|
timeout: false,
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
const preact = require('preact');
|
const preact = require('preact');
|
||||||
const get = require('lodash/get');
|
const get = require('lodash/get');
|
||||||
|
const toast = require('izitoast');
|
||||||
|
|
||||||
const shapes = require('./components/shapes');
|
const shapes = require('./components/shapes');
|
||||||
|
|
||||||
@ -369,6 +370,16 @@ function postData(url = '/', data = {}) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function errorToast(message) {
|
||||||
|
toast.error({
|
||||||
|
position: 'topRight',
|
||||||
|
drag: false,
|
||||||
|
close: false,
|
||||||
|
message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
stringSort,
|
stringSort,
|
||||||
convertItem,
|
convertItem,
|
||||||
@ -377,6 +388,7 @@ module.exports = {
|
|||||||
getCombatSequence,
|
getCombatSequence,
|
||||||
getCombatText,
|
getCombatText,
|
||||||
postData,
|
postData,
|
||||||
|
errorToast,
|
||||||
NULL_UUID,
|
NULL_UUID,
|
||||||
STATS,
|
STATS,
|
||||||
COLOURS,
|
COLOURS,
|
||||||
|
|||||||
@ -1,3 +1,6 @@
|
|||||||
|
error_log /var/log/mnml/nginx.error.log;
|
||||||
|
access_log /var/log/mnml/nginx.access.log;
|
||||||
|
|
||||||
upstream mnml {
|
upstream mnml {
|
||||||
server 127.0.0.1:40000;
|
server 127.0.0.1:40000;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,7 @@ use skill::{Skill, Cast, Immunity, Disable, Event};
|
|||||||
use effect::{Cooldown, Effect, Colour};
|
use effect::{Cooldown, Effect, Colour};
|
||||||
use spec::{Spec};
|
use spec::{Spec};
|
||||||
use item::{Item};
|
use item::{Item};
|
||||||
|
use img::{img_molecular_create};
|
||||||
|
|
||||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||||
pub struct Colours {
|
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"))?;
|
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);
|
return Ok(construct);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
24
server/src/img.rs
Normal file
24
server/src/img.rs
Normal file
@ -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 game;
|
||||||
mod instance;
|
mod instance;
|
||||||
mod item;
|
mod item;
|
||||||
|
mod img;
|
||||||
mod mob;
|
mod mob;
|
||||||
mod mtx;
|
mod mtx;
|
||||||
mod names;
|
mod names;
|
||||||
|
|||||||
@ -12,7 +12,7 @@ use r2d2::{Pool};
|
|||||||
use r2d2::{PooledConnection};
|
use r2d2::{PooledConnection};
|
||||||
use r2d2_postgres::{TlsMode, PostgresConnectionManager};
|
use r2d2_postgres::{TlsMode, PostgresConnectionManager};
|
||||||
|
|
||||||
use rpc::{RpcErrorResponse, AccountLoginParams, AccountCreateParams};
|
use rpc::{AccountLoginParams, AccountCreateParams};
|
||||||
use warden::{warden};
|
use warden::{warden};
|
||||||
use pubsub::{pg_listen};
|
use pubsub::{pg_listen};
|
||||||
use ws::{connect};
|
use ws::{connect};
|
||||||
@ -24,7 +24,12 @@ pub type PgPool = Pool<PostgresConnectionManager>;
|
|||||||
|
|
||||||
const DB_POOL_SIZE: u32 = 20;
|
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 {
|
pub enum MnmlHttpError {
|
||||||
// User Facing Errors
|
// User Facing Errors
|
||||||
#[fail(display="internal server error")]
|
#[fail(display="internal server error")]
|
||||||
@ -33,16 +38,22 @@ pub enum MnmlHttpError {
|
|||||||
Unauthorized,
|
Unauthorized,
|
||||||
#[fail(display="bad request")]
|
#[fail(display="bad request")]
|
||||||
BadRequest,
|
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 {
|
impl ResponseError for MnmlHttpError {
|
||||||
fn error_response(&self) -> HttpResponse {
|
fn error_response(&self) -> HttpResponse {
|
||||||
match *self {
|
match *self {
|
||||||
MnmlHttpError::ServerError => HttpResponse::InternalServerError()
|
MnmlHttpError::ServerError => HttpResponse::InternalServerError()
|
||||||
.json(RpcErrorResponse { err: self.to_string() }),
|
.json(JsonError { err: self.to_string() }),
|
||||||
|
|
||||||
MnmlHttpError::BadRequest => HttpResponse::BadRequest()
|
MnmlHttpError::BadRequest => HttpResponse::BadRequest()
|
||||||
.json(RpcErrorResponse { err: self.to_string() }),
|
.json(JsonError { err: self.to_string() }),
|
||||||
|
|
||||||
MnmlHttpError::Unauthorized => HttpResponse::Unauthorized()
|
MnmlHttpError::Unauthorized => HttpResponse::Unauthorized()
|
||||||
.cookie(Cookie::build("x-auth-token", "")
|
.cookie(Cookie::build("x-auth-token", "")
|
||||||
@ -51,7 +62,16 @@ impl ResponseError for MnmlHttpError {
|
|||||||
.same_site(SameSite::Strict)
|
.same_site(SameSite::Strict)
|
||||||
.max_age(-1) // 1 week aligns with db set
|
.max_age(-1) // 1 week aligns with db set
|
||||||
.finish())
|
.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)))
|
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)]
|
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||||
pub enum RpcResult {
|
pub enum RpcResult {
|
||||||
AccountState(Account),
|
AccountState(Account),
|
||||||
|
|||||||
@ -6,9 +6,9 @@ use actix::prelude::*;
|
|||||||
|
|
||||||
use account::{Account};
|
use account::{Account};
|
||||||
use serde_cbor::{to_vec};
|
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 HEARTBEAT_INTERVAL: Duration = Duration::from_secs(5);
|
||||||
const CLIENT_TIMEOUT: Duration = Duration::from_secs(10);
|
const CLIENT_TIMEOUT: Duration = Duration::from_secs(10);
|
||||||
@ -73,7 +73,7 @@ impl StreamHandler<ws::Message, ws::ProtocolError> for MnmlSocket {
|
|||||||
ctx.binary(response);
|
ctx.binary(response);
|
||||||
},
|
},
|
||||||
Err(e) => {
|
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");
|
.expect("failed to serialize error response");
|
||||||
ctx.binary(response);
|
ctx.binary(response);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user