From e41bb0194e70d298bc18ca446c01d9e1dc5f9f10 Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Tue, 19 Mar 2019 12:28:07 -0400 Subject: [PATCH] separate node applications --- README.md | 3 ++- webapp/README.md | 16 ++++++++++++- webapp/masterserver.js | 32 +++++++++++++++++++++++++ webapp/minetestinfo.js | 29 +++++++++++++++++++++++ webapp/server.js | 53 ++++++++---------------------------------- 5 files changed, 88 insertions(+), 45 deletions(-) create mode 100644 webapp/masterserver.js create mode 100644 webapp/minetestinfo.js diff --git a/README.md b/README.md index 01758f0..18b2462 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # ENLIVEN ENLIVEN is a subgame for minetest with the goals of providing immersion and lessons for humanity. +(see also webapp/README.md) ## Primary Features of EnlivenMinetest Project * Server installer for ENLIVEN on linux server (Ubuntu so far) @@ -13,7 +14,7 @@ ENLIVEN is a subgame for minetest with the goals of providing immersion and less There are several improvements I may implement in new or existing mods. For more information and status, see my [Minetest Kanboard](https://poikilos.dyndns.org/kanboard/?controller=BoardViewController&action=readonly&token=f214530d2f1294d90279631ce66b2e8b8569c6f15faf3773086476158bc8). * maintain a table of short descriptions of mods * see also EnlivenMinetest/etc/game-install-enliven-testing.sh -* slimenodes fork: make glue replaceable with animal hide; disable jump or reduce bouncy value, otherwise bouncing gets higher indefinitely +* (resolved: glue can be made from saplings [from upstream]) slimenodes fork: make glue replaceable with animal hide; disable jump or reduce bouncy value, otherwise bouncing gets higher indefinitely * https://github.com/minetest-mods/tutor * https://github.com/minetest-mods/chat_anticurse * https://github.com/minetest-mods/cozy (sitting and laying down player animations)--compare with emote https://github.com/minetest-mods/emote.git diff --git a/webapp/README.md b/webapp/README.md index 0c2cfa5..ff79ab8 100755 --- a/webapp/README.md +++ b/webapp/README.md @@ -1,6 +1,10 @@ # EnlivenMinetest webapp EnlivenMinetest Node.js webapp for web management of minetest -* Must run as same user as minetestserver, and neither should be root! +* Before using this webapp, make sure you have installed minetest to + $HOME/minetest with the RUN_IN_PLACE option (this option is true by + default in Final Minetest builds). In the future, this webapp should + ask you which minetest to use. +* Must run as same user as minetestserver, and neither should be root. ## Install * Using Terminal, cd to your EnlivenMinetest/webapp diretory, then: @@ -17,11 +21,20 @@ npm install ## Planned Features +(~=optional) * Replace the "write" (stdout) method of the minetestserver process (see ) * parse Lua mods - show armor strengths * list mods (only additional ones vs basis such as Bucket_Game) +* store config file in ~/.config/EnlivenMinetest/webapp.json +* allow user to choose path of minetestserver on first run + * (~) detect location of minetestserver (based on running executable + maybe, or which is most recent in expected directories) +* choose minetest games directory separately from bin in case + not `RUN_IN_PLACE` +* choose minetest worlds directory separately from bin in case + not `RUN_IN_PLACE` ## Developer Notes @@ -53,6 +66,7 @@ return results; ``` ### Development Log +(for changelog, see CHANGELOG.md) ```bash #!/bin/sh sudo apt update diff --git a/webapp/masterserver.js b/webapp/masterserver.js new file mode 100644 index 0000000..b69f044 --- /dev/null +++ b/webapp/masterserver.js @@ -0,0 +1,32 @@ + +var express = require('express'); +var app = express(); + +app.get('/get-players', function (req, res) { + res.setHeader('Content-Type', 'application/json'); + res.send(JSON.stringify(players)); +}); + +var last_announce_string = "none"; + +app.get('/last-announce', function (req, res) { + res.setHeader('Content-Type', 'text/plain'); + res.send(last_announce_string); +}); + +app.get('/announce', function (req, res) { + last_announce_string = JSON.stringify(req.body); + console.log("announce got:"+last_announce_string); + res.setHeader('Content-Type', 'text/plain'); + res.send(); +}); + + +var server = app.listen(3000, function () { + //console.log('express-handlebars example server listening on: 3000'); + var host = server.address().address; + var port = server.address().port; + console.log("listserver address:"); + console.log(JSON.stringify(server.address())); + console.log("(experimental WIP) Minetest master server is listening at http://%s:%s", host, port); +}); diff --git a/webapp/minetestinfo.js b/webapp/minetestinfo.js new file mode 100644 index 0000000..0defd19 --- /dev/null +++ b/webapp/minetestinfo.js @@ -0,0 +1,29 @@ +var fs = require('fs'); + +const profilePath = require('os').homedir(); +exports.profilePath = profilePath; + +var minetestPath = profilePath + "/minetest"; // TODO: differs from .minetest if not RUN_IN_PLACE +exports.minetestPath = function() { + return minetestPath; +} + +const myName = "minetestinfo.js"; +var skinDir = ""; +exports.skinDir = function () { + return skinDir; +} + + +exports.regeneratePaths = function () { + exports.skinDir = exports.minetestPath + "/games/Bucket_Game/mods/codercore/coderskins/textures"; + if (fs.existsSync( minetestPath + "/games/ENLIVEN")) { + skinDir = minetestPath + "/games/ENLIVEN/mods/codercore/coderskins/textures"; + } + console.log("[" + myName + "] skinDir: \"" + skinDir + "\""); +} +var thisMinetest = "/tank/local/owner/minetest"; +if (fs.existsSync(thisMinetest)) { + minetestPath = thisMinetest; +} +exports.regeneratePaths(); diff --git a/webapp/server.js b/webapp/server.js index 3271bab..5701d9b 100644 --- a/webapp/server.js +++ b/webapp/server.js @@ -5,10 +5,6 @@ //return process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME']; //} - -const profilePath = require('os').homedir(); -var minetestPath = profilePath + "/minetest"; // TODO: differs from .minetest if not RUN_IN_PLACE -var skinDir = ""; var tz_offset = 240; //subtract this from server time to get local time; 4hrs is 240; 5hrs is 300 // TODO: handle tz_offset not divisible by 60 // var selected_date_s = null; @@ -26,6 +22,11 @@ const os = require('os'); var formidable = require('formidable') var querystring = require("querystring"); // built-in var mv = require('mv'); +// TODO: var config = require(storage_path + '/config.js') // config file contains all tokens and other private info +// var fun = require('./functions.js'); // functions file contains our non-app-specific functions including those for our Passport and database work +var mt = require('./minetestinfo.js'); // functions file contains our non-app-specific functions including those for our Passport and database work + + // var util = require('util') var app = express(); @@ -56,14 +57,6 @@ var unique_flags = [ ]; //#endregion derived from mtsenliven.py -function regeneratePaths() { - skinDir = minetestPath + "/games/Bucket_Game/mods/codercore/coderskins/textures"; - //doesn't work due to bug: - //if (fs.existsSync( minetestPath + "/games/ENLIVEN")) { - //skinDir = minetestPath + "/games/ENLIVEN/mods/codercore/coderskins/textures"; - //} - console.log("skinDir: \"" + skinDir + "\""); -} function process_logline(line, line_number) { //selected_date_s @@ -291,29 +284,6 @@ function read_log() { } } - - -app.get('/get-players', function (req, res) { - res.setHeader('Content-Type', 'application/json'); - res.send(JSON.stringify(players)); -}); - -var last_announce_string = "none"; - -app.get('/last-announce', function (req, res) { - res.setHeader('Content-Type', 'text/plain'); - res.send(last_announce_string); -}); - -app.get('/announce', function (req, res) { - last_announce_string = JSON.stringify(req.body); - console.log("announce got:"+last_announce_string); - res.setHeader('Content-Type', 'text/plain'); - res.send(); -}); - - - app.get('/skin-form', function (req, res) { var ret = ""; ret += ''+"\n"; @@ -351,8 +321,8 @@ app.post('/set-skin', function (req, res){ form.parse(req, function(err, fields, files) { if (err) next(err); destNameNoExt = destNameNoExt = "player_" + fields.userName; - directPath = skinDir + "/" + destNameNoExt + ".png"; - indirectPath = skinDir + "/" + destNameNoExt + ".skin"; + directPath = mt.skinDir() + "/" + destNameNoExt + ".png"; + indirectPath = mt.skinDir() + "/" + destNameNoExt + ".skin"; // TODO: make sure my_file and userName values are present if (files.hasOwnProperty('userFile')) { if (fields.hasOwnProperty('userName')) { @@ -474,13 +444,10 @@ Your browser does not support the canvas element. -var server = app.listen(3000, function () { +var server = app.listen(64638, function () { + // 8123 is default for Minecraft DynMap + // 64638 spells 'minet' on a telephone keypad, but 6463, 6472 is already Discord RPC server //console.log('express-handlebars example server listening on: 3000'); - var thisMinetest = "/tank/local/owner/minetest"; - if (fs.existsSync(thisMinetest)) { - minetestPath = thisMinetest; - } - regeneratePaths(); var host = server.address().address; var port = server.address().port; console.log("server address:");