'use strict'; 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; //selected_date_s = "2018-05-08"; var express = require('express'), //var exphbs = require("express-handlebars"); // exphbs = require('../../'); // "express-handlebars" cookieParser = require('cookie-parser'), bodyParser = require('body-parser'), //session = require('express-session'), fs = require('fs'), readlines = require('n-readlines'); const os = require('os'); var app = express(); //app.engine('handlebars', exphbs({defaultLayout: 'main'})); //app.set('view engine', 'handlebars'); var players = []; var player_indices = {}; //see https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs/Introduction var prev_line = null; //#region derived from mtsenliven.py var msgprefix_flags = ["WARNING[Server]: ", "ACTION[Server]: "] var msgprefix_lists = {} // where flag is key var mf_len = msgprefix_flags.length; for (var mf_i=0; mf_i -1) { msgprefix_number = mf_i; msgprefix = msgprefix_flags[mf_i]; break; } } var skip_date_enable = false; for (var uf_i=0; uf_i -1) { verb_number = uf_i; verb = unique_flags[uf_i]; date_s = line.substring(0,10).trim(); if (selected_date_s==null || selected_date_s==date_s) { //console.log("(verbose message in process_logline) using '" + date_s + "' since selected '"+selected_date_s+"'"); time_s = line.substring(time_start_i, time_start_i+8); //console.log("using time "+time_s); if (msgprefix!=null) { player_name = line.substring(msgprefix_i+msgprefix.length, verb_i).trim(); var ip_flag = " ["; var ip_i = player_name.indexOf(ip_flag); if (ip_i > -1) { player_ip = player_name.substring(ip_i+ip_flag.length, player_name.length-1); player_name = player_name.substring(0,ip_i); } } else { player_name = "<missing msgprefix&rt;"; } } else { skip_date_enable = true; //console.log("WARNING in process_logline: skipping '" + date_s + "' since not '"+selected_date_s+"'"); } break; } } var index = -1; // player index if (player_name != null) { if (player_name.length > 0) { if (player_indices.hasOwnProperty(player_name)) { index = player_indices[player_name]; index_msg = "cached "; } else { index = players.length; //players.push({}); players[index] = {}; players[index].display_name = player_name; player_indices[player_name] = index; //console.log("created new index "+index); } } else { console.log("WARNING in process_logline: zero-length player name"); } } if (index<0 && !skip_date_enable) { //console.log("(verbose message in process_logline) "+index_msg+"index was '"+index+"' but date was good '" + date_s + "' for '"+line+"'"); } if (verb == "leaves game") { if (index > -1) { players[index].logout_time = time_s; } } else if (verb == "joins game") { if (index > -1) { //console.log("using index " + index); players[index].login_time = time_s; } } } function store_unique_log_data(output, line_number, err_flag=false) { var ret = ""; var output_strip = output.trim(); var u_prefix = "active block modifiers took "; var u_suffix = "ms (longer than 200ms)"; // (out_bytes is bytes) var show_enable = true; var found_flag = null; var f_i = null; var always_show_enable = false; var msg_msg = "previous message"; var uf_len = unique_flags.length; for (var uf_i=0; uf_i= 0) { found_flag = msgprefix_flags[mf_i]; break; } } if (found_flag!=null) { var sub_msg = output.substring(f_i+flag.length).trim(); var nuw_len = non_unique_wraps.length; for (var nuw_i=0; nuw_i -1) { show_enable = false; } else { msgprefix_lists[found_flag].push(sub_msg); } } } if (show_enable) { ret = output_strip; if (found_flag != null) { ret += "\n [ EnlivenMinetest ] " + msg_msg + " will be suppressed"; } } return ret; } var cached_date = null; app.get('/', function (req, res) { var ret = ""; ret += ''; // Whenever server starts the following is logged // (see also etc/example-input.txt): // //------------- // Separator //------------- // var selected_date_s = null; if (req.query.date) selected_date_s = req.query.date ret += "assuming minetestserver ran as: " + os.homedir() + "
\n"; ret += "timezone (tz_offset/60*-1): " + (Math.floor(tz_offset/60)*-1) + "
\n"; ret += "date (this YYYY-MM-DD filter limits all log processing): " + selected_date_s + "
\n"; if (selected_date_s==null) { ret += '2018-05-08'; } if (cached_date!=selected_date_s && selected_date_s!=null) { cached_date = selected_date_s; players = []; player_indices = []; var log_paths = [os.homedir() + "/.minetest/debug_archived/2018/05/08.txt", os.homedir() + "/.minetest/debug.txt"]; var lp_len = log_paths.length; for (var lp_i=0; lp_i Your browser does not support the canvas element.
loading...
`; ret += ''; res.send(ret); //res.render('home'); }); 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("EnlivenMinetest webapp listening at http://%s:%s", host, port); });