新增本地配置修改

This commit is contained in:
suwings 2018-02-24 16:00:15 +08:00
parent d65ba4cb46
commit 21e80a8a88
7 changed files with 102 additions and 28 deletions

27
app.js
View File

@ -9,6 +9,15 @@ try {
//忽略任何版本检测导致的错误
}
//总全局变量
global.MCSERVER = {};
//全局仅限本地配置
MCSERVER.localProperty = {}
//加载配置
require('./property');
const express = require('express');
const fs = require('fs');
var session = require('express-session');
@ -51,8 +60,7 @@ const LOGO_FILE_PATH = './core/logo.txt';
let data = fs.readFileSync(LOGO_FILE_PATH, 'utf-8');
console.log(data);
//总全局变量
global.MCSERVER = {};
//全局数据中心 记录 CPU 内存
MCSERVER.dataCenter = {};
@ -126,7 +134,8 @@ app.use(session({
}));
//使用 gzip 静态文本压缩,但是如果你使用反向代理或某 HTTP 服务自带的gzip请关闭它
//app.use(compression());
if (MCSERVER.localProperty.is_gzip)
app.use(compression());
//初始化令牌管理器 已弃用 向下兼容
VarCenter.set('user_token', {});
@ -139,10 +148,12 @@ app.use('/public', express.static('./public'));
// console 中间件挂载
app.use((req, res, next) => {
console.log('[', req.protocol.green, req.httpVersion.green, req.method.cyan, ']', req.originalUrl);
// res.header("Access-Control-Allow-Origin", "*");
// res.header('Access-Control-Allow-Methods', 'GET, POST');
// res.header("Access-Control-Allow-Headers", "X-Requested-With");
// res.header('Access-Control-Allow-Headers', 'Content-Type');
if (MCSERVER.localProperty.is_allow_csrf) {
res.header("Access-Control-Allow-Origin", "*");
res.header('Access-Control-Allow-Methods', 'GET, POST');
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.header('Access-Control-Allow-Headers', 'Content-Type');
}
res.header('X-Soft', 'Mcserver Manager HTTP_SERVER');
res.header('X-Frame-Options', 'DENY');
next();
@ -154,7 +165,7 @@ app.get(['/login', '/l', '/', '/logined'], function (req, res) {
permission.needLogin(req, res, () => {
res.redirect('/public/#welcome');
}, () => {
res.redirect('/public/login/');
res.redirect(MCSERVER.localProperty.login_url);
});
});

View File

@ -5,12 +5,7 @@ const EventEmitter = require('events');
const DataModel = require('../DataModel');
const os = require('os');
var CODE_CONSOLE = 'GBK';
if (os.platform() == 'win32') {
CODE_CONSOLE = 'GBK';
} else {
CODE_CONSOLE = 'UTF-8';
}
var CODE_CONSOLE = MCSERVER.localProperty.console_encode;
//https://github.com/Gagle/Node-Properties
const properties = require("properties");

View File

@ -82,7 +82,7 @@ class MinecraftServer extends ServerProcess {
terminalLog(strLine) {
this.terminalQueue.push(strLine);
if (this.terminalQueue.length > 512) {
if (this.terminalQueue.length > MCSERVER.localProperty.terminalQueue_max_length) {
this.terminalQueue = this.terminalQueue.slice(400);
}
}

64
property.js Normal file
View File

@ -0,0 +1,64 @@
//仅限本地配置文件
//你可以根据这些说明进行一些相关的配置,修改。
/**
* ----------- 无计算机语言基础者请阅读 -----------
*
* 文本值双引号之间是文本描述字符串类似于 "UTF-8" "Hello" 等等
* 真假值, true 代表准许 false 代表禁止
* 数字值直接书写即可 列如 1,2,3,5.565,20000,5555,
* 注释纯属用来看的毫无作用 // 代表单行注释
*
* 请放心这不是要你书写计算机语言而是进行十分简单的编辑
* 当然你可以选择不改动此文件
*
*
* 绝大部分设置需要重启面板生效
*/
/* --------------- 功能代码区,请勿修改 ---------------*/
//控制台默认编码代码
const os = require("os");
let auto_console_coding;
if (os.platform() == "win32")
auto_console_coding = 'GBK';
else
auto_console_coding = 'UTF-8';
/* --------------- 功能代码区,请勿修改 ---------------*/
/*--------------- 配置开始,这与 Minecraft 服务器配置几乎差不多 --------------- */
//控制台实时刷新频率 单位毫秒 默认1100 毫秒
MCSERVER.localProperty.console_send_times = 1100;
//控制台默认编码,默认自动选择,你可以去除变量 auto_console_coding 自己写,如 "UFT-8" 或 "GBXXXX"
//如果控制台中文乱码,你可以尝试更改此选项
MCSERVER.localProperty.console_encode = auto_console_coding;
//是否开启 gzip 静态文件压缩,但是如果你使用反向代理或某 HTTP 服务自带的gzip请关闭它
MCSERVER.localProperty.is_gzip = true;
//是否准许跨域请求,如果准许,将失去一部分安全性,但是你二次开发可能需要
MCSERVER.localProperty.is_allow_csrf = false;
//登录页面 URL我们有两个登录页面你可以选择其一或自己选择
MCSERVER.localProperty.login_url = "/public/login/";
//控制台历史记录最大缓存长度
//缓存长度越高,能存下的日志越多,但是对服务器内存牺牲更大
//只建议调小,而不建议调大
MCSERVER.localProperty.terminalQueue_max_length = 512;
//控制数据中心 数据刷新频率 单位毫秒
//默认 2000 毫秒
MCSERVER.localProperty.data_center_times = 2000;

View File

@ -1,4 +1,6 @@
const { WebSocketObserver } = require('../../model/WebSocketModel');
const {
WebSocketObserver
} = require('../../model/WebSocketModel');
const counter = require('../../core/counter');
const tools = require('../../core/tools');
const response = require('../../helper/Response');
@ -40,12 +42,12 @@ let cacheSystemInfo = null;
let usage = process.memoryUsage();
//init 记录器
MCSERVER.logCenter.initLogData('CPU',16);
MCSERVER.logCenter.initLogData('RAM',16);
MCSERVER.logCenter.initLogData('CPU', 16);
MCSERVER.logCenter.initLogData('RAM', 16);
//实不相瞒,其实我是弄的缓存
setInterval(function() {
osUtils.cpuUsage(function(v) {
setInterval(function () {
osUtils.cpuUsage(function (v) {
// console.log('CPU Usage (%): ' + v * 100);
cacheCPU = (v * 100).toFixed(2);
MCSERVER.dataCenter.cacheCPU = cacheCPU;
@ -81,15 +83,15 @@ setInterval(function() {
}
let useMemBai = ((os.freemem() / 1024) / (os.totalmem() / 1024) * 100).toFixed(0);
let useMemBai = ((os.freemem() / 1024) / (os.totalmem() / 1024) * 100).toFixed(0);
//压入记录器
MCSERVER.logCenter.pushLogData('CPU',tools.getMineTime(),parseInt(cacheCPU));
MCSERVER.logCenter.pushLogData('RAM',tools.getMineTime(),100 - useMemBai);
MCSERVER.logCenter.pushLogData('CPU', tools.getMineTime(), parseInt(cacheCPU));
MCSERVER.logCenter.pushLogData('RAM', tools.getMineTime(), 100 - useMemBai);
// console.log(MCSERVER.logCenter.RAM)
setTimeout(() => counter.save(), 0); //让其异步的去保存
}, 2000);
}, MCSERVER.localProperty.data_center_times);
//数据中心

View File

@ -115,7 +115,7 @@ setInterval(() => {
delete consoleBuffer[serverName]
consoleBuffer[serverName] = "";
}
}, 1100);
}, MCSERVER.localProperty.console_send_times);
//控制台标准输出流
serverModel.ServerManager().on('console', (data) => {
let server = serverModel.ServerManager().getServer(data.serverName);

View File

@ -2,7 +2,9 @@ const response = require('../../../helper/Response');
var serverModel = require('../../../model/ServerModel');
var userModel = require('../../../model/UserModel');
const permssion = require('../../../helper/Permission');
const { WebSocketObserver } = require('../../../model/WebSocketModel');
const {
WebSocketObserver
} = require('../../../model/WebSocketModel');
//前端请求加载历史缓存
const HISTORY_SIZE = 64;
@ -22,7 +24,7 @@ WebSocketObserver().listener('server/console/history', (data) => {
stringHistory += dataHistory[i];
}
if (stringHistory == '' || stringHistory.length <= 2)
stringHistory = '------- 暂无历史记录 -------<br />';
stringHistory = '------- 暂无记录历史记录,更多历史记录请查看在线文件管理的 Log 文本文件 -------<br />';
response.wsSend(data.ws, 'server/console/history', 'terminalBack', stringHistory);
}