nginx changes and invader init
This commit is contained in:
parent
1d84cf666f
commit
4f3912a020
@ -55,6 +55,9 @@ do not allow vbox actions for finished instances
|
|||||||
*SERVER*
|
*SERVER*
|
||||||
|
|
||||||
* push events
|
* push events
|
||||||
|
* test rust-ws w/ hyper upgrade
|
||||||
|
* tx middleware
|
||||||
|
|
||||||
|
|
||||||
## SOON
|
## SOON
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
const anime = require('animejs').default;
|
const anime = require('animejs').default;
|
||||||
|
|
||||||
function idle(id) {
|
function idle(id) {
|
||||||
|
return false;
|
||||||
const duration = anime.random(2000, 18000);
|
const duration = anime.random(2000, 18000);
|
||||||
const target = document.getElementById(id);
|
const target = document.getElementById(id);
|
||||||
return anime({
|
return anime({
|
||||||
|
|||||||
@ -31,7 +31,7 @@ class ConstructAvatar extends Component {
|
|||||||
<div
|
<div
|
||||||
class="avatar"
|
class="avatar"
|
||||||
id={this.props.construct.id}
|
id={this.props.construct.id}
|
||||||
style={{ 'background-image': `url(/imgs/${this.props.construct.img}.svg)` }}
|
style={{ 'background-image': `url(/imgs/32809d3b-60e6-4d37-a183-e5d33374613b.svg)` }}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,14 @@
|
|||||||
error_log /var/log/nginx/mnml.nginx.log debug;
|
error_log /var/log/mnml/nginx.log debug;
|
||||||
|
|
||||||
upstream mnml {
|
upstream mnml_http {
|
||||||
server 127.0.0.1:40000;
|
server 127.0.0.1:40000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
upstream mnml_ws {
|
||||||
|
server 127.0.0.1:40055;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
map $http_upgrade $connection_upgrade {
|
map $http_upgrade $connection_upgrade {
|
||||||
default upgrade;
|
default upgrade;
|
||||||
'' close;
|
'' close;
|
||||||
@ -14,7 +19,7 @@ server {
|
|||||||
location / {
|
location / {
|
||||||
root /var/lib/mnml/public/dist;
|
root /var/lib/mnml/public/dist;
|
||||||
index index.html;
|
index index.html;
|
||||||
try_files $uri $uri/ =404;
|
try_files $uri $uri/ index.html;
|
||||||
}
|
}
|
||||||
|
|
||||||
location /imgs/ {
|
location /imgs/ {
|
||||||
@ -23,7 +28,7 @@ server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
location /api/ws {
|
location /api/ws {
|
||||||
proxy_pass http://mnml;
|
proxy_pass http://mnml_ws;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
proxy_set_header Connection $connection_upgrade;
|
proxy_set_header Connection $connection_upgrade;
|
||||||
@ -31,7 +36,7 @@ server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
location /api/ {
|
location /api/ {
|
||||||
proxy_pass http://mnml;
|
proxy_pass http://mnml_http;
|
||||||
proxy_read_timeout 600s;
|
proxy_read_timeout 600s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
use std::fs::copy;
|
use std::fs::copy;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::prelude::*;
|
||||||
|
|
||||||
use failure::Error;
|
use failure::Error;
|
||||||
use failure::err_msg;
|
use failure::err_msg;
|
||||||
@ -22,3 +24,103 @@ pub fn img_molecular_write(id: Uuid) -> Result<Uuid, Error> {
|
|||||||
|
|
||||||
return Err(err_msg("too many missing molecules. wrong directory?"))
|
return Err(err_msg("too many missing molecules. wrong directory?"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
fn invader_img_write(id: Uuid) -> Result<Uuid, Error> {
|
||||||
|
let mut rng = thread_rng();
|
||||||
|
let mut svg = Vec::new();
|
||||||
|
|
||||||
|
write!(&mut svg, "<svg xmlns='http://www.w3.org/2000/svg' version='1.1' viewBox='-250 -250 1000 1000' width='500' height='500'><g>")?;
|
||||||
|
for i in 0..50 {
|
||||||
|
let x = (i % 5) * 50;
|
||||||
|
let y = (i / 5) * 50;
|
||||||
|
|
||||||
|
let colour = match rng.gen_bool(0.5) {
|
||||||
|
true => "whitesmoke",
|
||||||
|
false => "none",
|
||||||
|
};
|
||||||
|
write!(&mut svg, "<rect fill=\"{}\" x=\"{}\" y=\"{}\" width=\"50\" height=\"50\" />", colour, x, y)?;
|
||||||
|
write!(&mut svg, "<rect fill=\"{}\" x=\"{}\" y=\"{}\" width=\"50\" height=\"50\" />", colour, 450 - x, y)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
write!(&mut svg, "</g></svg>")?;
|
||||||
|
|
||||||
|
// println!("{:?}", String::from_utf8(svg.clone())?);
|
||||||
|
|
||||||
|
let dest = format!("/var/lib/mnml/public/imgs/{}.svg", id);
|
||||||
|
println!("molecule dest={:?}", dest);
|
||||||
|
|
||||||
|
let mut file = File::create(dest)?;
|
||||||
|
file.write_all(&svg)?;
|
||||||
|
|
||||||
|
Ok(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn invader_img_test() {
|
||||||
|
invader_img_write(Uuid::new_v4()).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// function createColor() {
|
||||||
|
// //saturation is the whole color spectrum
|
||||||
|
// var h = Math.floor(rand() * 360);
|
||||||
|
// //saturation goes from 40 to 100, it avoids greyish colors
|
||||||
|
// var s = ((rand() * 60) + 40) + '%';
|
||||||
|
// //lightness can be anything from 0 to 100, but probabilities are a bell curve around 50%
|
||||||
|
// var l = ((rand()+rand()+rand()+rand()) * 25) + '%';
|
||||||
|
|
||||||
|
// var color = 'hsl(' + h + ',' + s + ',' + l + ')';
|
||||||
|
// return color;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// function createImageData(size) {
|
||||||
|
// var width = size; // Only support square icons for now
|
||||||
|
// var height = size;
|
||||||
|
|
||||||
|
// var dataWidth = Math.ceil(width / 2);
|
||||||
|
// var mirrorWidth = width - dataWidth;
|
||||||
|
|
||||||
|
// var data = [];
|
||||||
|
// for(var y = 0; y < height; y++) {
|
||||||
|
// var row = [];
|
||||||
|
// for(var x = 0; x < dataWidth; x++) {
|
||||||
|
// // this makes foreground and background color to have a 43% (1/2.3) probability
|
||||||
|
// // spot color has 13% chance
|
||||||
|
// row[x] = Math.floor(rand()*2.3);
|
||||||
|
// }
|
||||||
|
// var r = row.slice(0, mirrorWidth);
|
||||||
|
// r.reverse();
|
||||||
|
// row = row.concat(r);
|
||||||
|
|
||||||
|
// for(var i = 0; i < row.length; i++) {
|
||||||
|
// data.push(row[i]);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return data;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// function buildOpts(opts) {
|
||||||
|
// var newOpts = {};
|
||||||
|
|
||||||
|
// newOpts.seed = opts.seed || Math.floor((Math.random()*Math.pow(10,16))).toString(16);
|
||||||
|
|
||||||
|
// seedrand(newOpts.seed);
|
||||||
|
|
||||||
|
// newOpts.size = opts.size || 8;
|
||||||
|
// newOpts.scale = opts.scale || 4;
|
||||||
|
// newOpts.color = opts.color || createColor();
|
||||||
|
// newOpts.bgcolor = opts.bgcolor || createColor();
|
||||||
|
// newOpts.spotcolor = opts.spotcolor || createColor();
|
||||||
|
|
||||||
|
// return newOpts;
|
||||||
|
// }
|
||||||
@ -27,86 +27,86 @@ extern crate cookie;
|
|||||||
extern crate tungstenite;
|
extern crate tungstenite;
|
||||||
extern crate crossbeam_channel;
|
extern crate crossbeam_channel;
|
||||||
|
|
||||||
mod account;
|
// mod account;
|
||||||
mod construct;
|
// mod construct;
|
||||||
mod effect;
|
// mod effect;
|
||||||
mod game;
|
// mod game;
|
||||||
mod instance;
|
// mod instance;
|
||||||
mod item;
|
// mod item;
|
||||||
mod img;
|
mod img;
|
||||||
mod mob;
|
// mod mob;
|
||||||
mod mtx;
|
// mod mtx;
|
||||||
mod names;
|
// mod names;
|
||||||
mod net;
|
// mod net;
|
||||||
mod payments;
|
// mod payments;
|
||||||
mod pg;
|
// mod pg;
|
||||||
mod player;
|
// mod player;
|
||||||
mod pubsub;
|
// mod pubsub;
|
||||||
mod rpc;
|
// mod rpc;
|
||||||
mod skill;
|
// mod skill;
|
||||||
mod spec;
|
// mod spec;
|
||||||
mod util;
|
// mod util;
|
||||||
mod vbox;
|
// mod vbox;
|
||||||
mod warden;
|
// mod warden;
|
||||||
mod ws;
|
// mod ws;
|
||||||
|
|
||||||
use std::thread::{sleep, spawn};
|
// use std::thread::{sleep, spawn};
|
||||||
use std::time::{Duration};
|
// use std::time::{Duration};
|
||||||
use dotenv::dotenv;
|
// use dotenv::dotenv;
|
||||||
|
|
||||||
use pubsub::pg_listen;
|
// use pubsub::pg_listen;
|
||||||
use warden::warden;
|
// use warden::warden;
|
||||||
|
|
||||||
fn setup_logger() -> Result<(), fern::InitError> {
|
// fn setup_logger() -> Result<(), fern::InitError> {
|
||||||
fern::Dispatch::new()
|
// fern::Dispatch::new()
|
||||||
.format(|out, message, record| {
|
// .format(|out, message, record| {
|
||||||
out.finish(format_args!(
|
// out.finish(format_args!(
|
||||||
"{}[{}][{}] {}",
|
// "{}[{}][{}] {}",
|
||||||
chrono::Local::now().format("[%Y-%m-%d][%H:%M:%S]"),
|
// chrono::Local::now().format("[%Y-%m-%d][%H:%M:%S]"),
|
||||||
record.target(),
|
// record.target(),
|
||||||
record.level(),
|
// record.level(),
|
||||||
message
|
// message
|
||||||
))
|
// ))
|
||||||
})
|
// })
|
||||||
.level_for("postgres", log::LevelFilter::Info)
|
// .level_for("postgres", log::LevelFilter::Info)
|
||||||
.level_for("iron", log::LevelFilter::Info)
|
// .level_for("iron", log::LevelFilter::Info)
|
||||||
.level(log::LevelFilter::Info)
|
// .level(log::LevelFilter::Info)
|
||||||
.chain(std::io::stdout())
|
// .chain(std::io::stdout())
|
||||||
.chain(fern::log_file("/var/log/mnml/mnml.log")?)
|
// .chain(fern::log_file("/var/log/mnml/mnml.log")?)
|
||||||
.apply()?;
|
// .apply()?;
|
||||||
Ok(())
|
// Ok(())
|
||||||
}
|
// }
|
||||||
|
|
||||||
fn main() {
|
// fn main() {
|
||||||
dotenv().ok();
|
// dotenv().ok();
|
||||||
setup_logger().unwrap();
|
// setup_logger().unwrap();
|
||||||
|
|
||||||
let pool = pg::create_pool();
|
// let pool = pg::create_pool();
|
||||||
|
|
||||||
let ws_pool = pool.clone();
|
// let ws_pool = pool.clone();
|
||||||
let http_pool = pool.clone();
|
// let http_pool = pool.clone();
|
||||||
let warden_pool = pool.clone();
|
// let warden_pool = pool.clone();
|
||||||
let pubsub_pool = pool.clone();
|
// let pubsub_pool = pool.clone();
|
||||||
|
|
||||||
spawn(move || {
|
// spawn(move || {
|
||||||
loop {
|
// loop {
|
||||||
let db_connection = warden_pool.get().expect("unable to get db connection");
|
// let db_connection = warden_pool.get().expect("unable to get db connection");
|
||||||
if let Err(e) = warden(db_connection) {
|
// if let Err(e) = warden(db_connection) {
|
||||||
info!("{:?}", e);
|
// info!("{:?}", e);
|
||||||
}
|
// }
|
||||||
sleep(Duration::new(1, 0));
|
// sleep(Duration::new(1, 0));
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
|
||||||
spawn(move || loop {
|
// spawn(move || loop {
|
||||||
let pubsub_conn = pubsub_pool.get().expect("could not get pubsub pg connection");
|
// let pubsub_conn = pubsub_pool.get().expect("could not get pubsub pg connection");
|
||||||
match pg_listen(pubsub_conn) {
|
// match pg_listen(pubsub_conn) {
|
||||||
Ok(_) => warn!("pg listen closed"),
|
// Ok(_) => warn!("pg listen closed"),
|
||||||
Err(e) => warn!("pg_listen error {:?}", e),
|
// Err(e) => warn!("pg_listen error {:?}", e),
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
|
||||||
spawn(move || net::start(http_pool));
|
// spawn(move || net::start(http_pool));
|
||||||
ws::start(ws_pool);
|
// ws::start(ws_pool);
|
||||||
info!("server started");
|
// info!("server started");
|
||||||
}
|
// }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user