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

20
Makefile Normal file
View File

@ -0,0 +1,20 @@
SHELL:=/bin/bash
all: mnml
deps:
./bin/deps.sh
package:
./bin/package.sh
mnml:
./bin/build.sh
# test: test-unit test-integration
# test-unit:
# ./test/test-unit.sh
# test-integration:
# ./test/test-integration.sh

1
VERSION Normal file
View File

@ -0,0 +1 @@
0.1.0

48
bin/build.sh Executable file
View File

@ -0,0 +1,48 @@
#!/bin/bash
# bless you chris and andy <3
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
MNML_PATH=$(realpath "$DIR/../")
if [ ! -f $MNML_PATH/etc/mnml.env ]; then
echo "create an env file in $MNML_PATH/etc/mnml.env"
echo "see $MNML_PATH/etc/mnml.SAMPLE.env for details"
exit 1;
fi
source $MNML_PATH/etc/mnml.env
# DIRECTORY SETUP
sudo mkdir -p /opt/mnml
sudo chown $MNML_USER: /opt/mnml
sudo mkdir -p /var/lib/mnml
sudo chown $MNML_USER: /var/lib/mnml
mkdir -p /var/lib/mnml/public
sudo mkdir -p /var/log/mnml
sudo chown $MNML_USER: /var/log/mnml
sudo ln -nfs $MNML_PATH/current /opt/mnml
# SERVICES
sudo cp $MNML_PATH/etc/systemd/system/mnml.service /etc/systemd/system
# POSTGRES SETUP
sudo -u postgres dropdb mnml
sudo -u postgres createdb mnml
sudo -u postgres createuser --encrypted mnml
echo "DATABASE_URL=postgres://mnml:$MNML_PG_PASSWORD@$MNML_PG_HOST/mnml" > $MNML_PATH/server/.env
sudo -u postgres psql -c "alter user mnml with encrypted password '$MNML_PG_PASSWORD';"
cd $MNML_PATH/ops && npm run migrate
# RUST SETUP
# cargo build
# cp -r $MNML_PATH/server/target/release /opt/mnml/bin
# NGINX
cp $MNML_PATH/etc/nginx/sites-available/mnml.gg.nginx.conf /etc/nginx/sites-available
cd $MNML_PATH/client && npm run build

5
bin/deps.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
sudo apt-get install -y postgresql postgresql-contrib
sudo apt-get install -y nginx
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

27
bin/package.sh Executable file
View File

@ -0,0 +1,27 @@
# bless you chris and andy <3
# DOES NOT WORK AT MOMENT
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
MNML_PATH=$(realpath "$DIR/../")
VERSION=$(<"$MNML_PATH/VERSION")
# copy this dir to the tmp build directory and build it
[[ -n "$BUILD_DIR" ]] || BUILD_DIR="/tmp/mnml/$VERSION"
[[ -n "$BUILD_PREFIX" ]] || BUILD_PREFIX="/opt/mnml"
[[ -n "$REPO_DIR" ]] || REPO_DIR="$HOME/mnml"
rm -rf "$BUILD_DIR" && mkdir -p "$BUILD_DIR/$BUILD_PREFIX" && cd "$BUILD_DIR/$BUILD_PREFIX"
(
rsync -a --delete --delete-excluded \
--exclude=".git/" \
--exclude=".gitignore" \
--exclude="packaging" \
"$REPO_DIR/" "$BUILD_DIR/$BUILD_PREFIX/"
rsync -a --delete --delete-excluded "$DIR/postinstall" "$BUILD_DIR/$BUILD_PREFIX/"
cd "$BUILD_DIR/$BUILD_PREFIX" &&
make
)

View File

@ -539,6 +539,8 @@ header {
grid-area: create;
flex: 1;
justify-self: flex-end;
display: flex;
flex-flow: row wrap;
margin-bottom: 1.5em;

View File

@ -4,9 +4,9 @@
"description": "",
"main": "index.js",
"scripts": {
"start": "parcel index.html --host 0.0.0.0 --port 40080 --no-source-maps",
"start": "parcel watch index.html --out-dir /var/lib/mnml/public",
"anims": "parcel animations.html --host 0.0.0.0 --port 40080 --no-source-maps",
"build": "rm -rf dist && parcel build index.html && cp -r assets/molecules/ dist/",
"build": "parcel build index.html --out-dir /var/lib/mnml/public",
"scss": "node-sass --watch assets/scss -o assets/styles",
"lint": "eslint --fix --ext .jsx src/",
"test": "echo \"Error: no test specified\" && exit 1"

2
etc/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
mnml.env
nginx/sites-available/mnml.gg.nginx.conf

6
etc/mnml.SAMPLE.env Normal file
View File

@ -0,0 +1,6 @@
#!/bin/bash
export MNML_USER=$(whoami)
export MNML_PG_PASSWORD=$(openssl rand -base64 16)
export MNML_PG_HOST="localhost"

View File

@ -0,0 +1,31 @@
upstream mnml {
server 127.0.0.1:40000;
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
# DEV
server {
root /var/lib/mnml/public/;
index index.html;
location / {
try_files $uri $uri/ =404;
}
location /api/ws {
proxy_pass http://mnml;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 600s;
}
location /api/ {
proxy_pass http://mnml;
proxy_read_timeout 600s;
}
}

View File

@ -9,7 +9,7 @@ map $http_upgrade $connection_upgrade {
# PRODUCTION
server {
root /home/git/mnml/client/dist/;
root /var/lib/mnml/public/;
index index.html;
server_name mnml.gg; # managed by Certbot

View File

@ -9,7 +9,7 @@ map $http_upgrade $connection_upgrade {
# DEV
server {
root /home/git/mnml/client/dist/;
root /var/lib/mnml/public/;
index index.html;
server_name dev.mnml.gg; # managed by Certbot

View File

@ -0,0 +1,14 @@
[Unit]
Description=OpenBSD Secure Shell server
After=network.target auditd.service
ConditionPathExists=!/etc/ssh/sshd_not_to_be_run
[Service]
ExecStart=/opt/mnml/bin/mnml
KillMode=process
Restart=on-failure
RestartPreventExitStatus=255
Type=notify
[Install]
WantedBy=multi-user.target

View File

@ -5,7 +5,7 @@ const local = {
connection: {
database: 'mnml',
user: 'mnml',
password: 'craftbeer'
password: process.env.MNML_PG_PASSWORD,
},
pool: {
min: 2,

View File

@ -1,5 +1,5 @@
{
"name": "constructs-ops",
"name": "mnml-ops",
"version": "1.0.0",
"description": "",
"main": "index.js",
@ -7,7 +7,8 @@
"split:molecules": "cd molecules; csplit -f mol bulk.sdf /\\$\\$\\$\\$/ {*} --suppress-matched -z",
"migrate": "knex migrate:latest",
"migrate:make": "knex migrate:make --",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"nginx:dev": "sudo cp mnml.gg.DEV.SAMPLE.nginx.conf /etc/nginx/sites-available/mnml.gg.DEV.nginx.conf && sudo ln -nfs /etc/nginx/sites-available/mnml.gg.DEV.nginx.conf /etc/nginx/sites-enabled"
},
"author": "",
"license": "UNLICENSED",

View File

@ -1 +1 @@
DATABASE_URL=postgres://mnml:craftbeer@localhost/mnml
DATABASE_URL=postgres://mnml:ECfcIvPdsGDMg+E3Wbwdig==@localhost/mnml

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);

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 },

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(())
}

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

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 |