优化 输出格式

This commit is contained in:
Suwings 2020-07-21 16:59:48 +08:00
parent 38dce2a93c
commit 4d219b16c4
6 changed files with 35 additions and 21 deletions

4
app.js
View File

@ -95,6 +95,7 @@ MCSERVER.dataCenter = {};
//装载log记录器
require('./core/log');
MCSERVER.info('控制面板正在启动中...');
//全局登陆记录器
MCSERVER.login = {};
@ -199,8 +200,7 @@ process.on("uncaughtException", function (err) {
});
process.on('unhandledRejection', (reason, p) => {
MCSERVER.infoLog('错误报告:');
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
MCSERVER.error('错误报告:', reason);
});
//初始化目录结构环境

View File

@ -23,15 +23,17 @@ log4js.configure({
const logger = log4js.getLogger("default");
MCSERVER.log = function () {
let str = "";
for (let i = 0; i < arguments.length; i++) {
str += arguments[i] + ' ';
// 多参数输出,但仅限于输出 INFO 级别
MCSERVER.log = function (...p) {
let msg = '';
for (const v of p) {
if (v) msg += v + ' ';
}
MCSERVER.infoLog('INFO', str);
logger.info(msg);
}
MCSERVER.infoLog = (info = "", value = "", colors = false) => {
// INFO 级别输出
MCSERVER.infoLog = (info = "", value = "") => {
let msg = value;
if (info.toUpperCase() != 'INFO') {
msg = [info, '-', value].join(' ');
@ -39,13 +41,24 @@ MCSERVER.infoLog = (info = "", value = "", colors = false) => {
logger.info(msg);
}
//error 报告器
// INFO 级别输出
MCSERVER.info = (...p) => {
let msg = '';
for (const v of p) {
if (v) msg += v + ' ';
}
logger.info(msg);
}
// ERROR 级别输出
MCSERVER.error = (msg, err) => {
logger.error(msg);
logger.error(err);
}
// WARN 级别输出
MCSERVER.warning = (title, msg = null) => {
logger.warn(msg);
}

View File

@ -7,14 +7,14 @@ let _endFlag = false;
process.on('SIGINT', function () {
if (_endFlag) return;
_endFlag = true;
MCSERVER.infoLog('PROCESS', '控制面板正在结束与回收资源,请稍等...'.red);
MCSERVER.infoLog('PROCESS', '控制面板正在结束与回收资源,请稍等...');
//保存
// 保存
counter.save();
serverModel.ServerManager().saveAllMinecraftServer();
userModel.userCenter().saveAllUser();
//关闭所有服务器
// 关闭所有服务器
let servers = serverModel.ServerManager().getServerObjects();
for (let k in servers) {
let server = servers[k];
@ -30,8 +30,7 @@ process.on('SIGINT', function () {
}
setTimeout(() => {
MCSERVER.infoLog('PROCESS', '进程结束流程逻辑执行完毕.'.red);
MCSERVER.infoLog('PROCESS', 'EXIT...'.red);
MCSERVER.infoLog('PROCESS', 'EXIT...');
process.exit(0);
}, 4000)
}, 3000)
});

View File

@ -16,12 +16,12 @@ const userManager = userCenter();
//用户退出事件
router.post('/loginout', function (req, res) {
if (!req.xhr) return;
MCSERVER.log('[loginout] 用户:' + req.session['username'] + '退出');
//删除一些辅助管理器的值
if (req.session['username'] && req.session['login'])
loginedContainer.delLogined(req.sessionID);
TokenManager.delToken(req.session['token']);
MCSERVER.log('[ loginout ] 用户:', req.session['username'], '退出,会话注销');
//退出后的 Session 并不会立刻反馈到所有 Session 上
req.session['login'] = false;
@ -86,8 +86,7 @@ router.post('/login', function (req, res) {
//登陆次数加一
counter.plus('login');
MCSERVER.log('[Login]'.green, '用户尝试登陆:', username, "密匙:", password);
MCSERVER.log('用户', username, '正在尝试登录...');
loginUser(username, password, (loginUser) => {
//只有这里 唯一的地方设置 login = true
@ -99,7 +98,7 @@ router.post('/login', function (req, res) {
delete MCSERVER.login[ip];
//添加到 login 容器 注意,全部代码只能有这一个地方使用这个函数
loginedContainer.addLogined(req.sessionID, username, loginUser.dataModel);
MCSERVER.log('[Login]'.green, '用户:', username, "密匙正确", "准许登录");
MCSERVER.log('[ Login ]', '用户:', username, "密匙正确", "准许登录");
response.returnMsg(res, 'login/check', true);
}, () => {
//密码错误记录
@ -115,7 +114,7 @@ router.post('/login', function (req, res) {
req.session.save();
//删除到 login 容器
if (req.session['username']) loginedContainer.delLogined(req.sessionID);
MCSERVER.log('[Login]'.green, '用户:', username, "密匙错误", "拒绝登录");
MCSERVER.log('[ Login ]', '用户:', username, "密匙错误", "拒绝登录");
response.returnMsg(res, 'login/check', false);
}, enkey);
});

View File

@ -32,6 +32,7 @@ WebSocketObserver().listener('server/get', (data) => {
response.wsSend(data.ws, 'server/get', serverData);
});
WebSocketObserver().listener('server/create', (data) => {
if (!permssion.isMaster(data.WsSession)) return;
@ -50,6 +51,7 @@ WebSocketObserver().listener('server/create', (data) => {
response.wsMsgWindow(data.ws, '创建完成√');
});
WebSocketObserver().listener('server/create_dir', (data) => {
if (!permssion.isMaster(data.WsSession)) return;
@ -64,7 +66,6 @@ WebSocketObserver().listener('server/create_dir', (data) => {
});
WebSocketObserver().listener('server/rebulider', (data) => {
if (!permssion.isMaster(data.WsSession)) return;

View File

@ -59,6 +59,7 @@ WebSocketObserver().listener('userset/create', (data) => {
userCenter().get(username).allowedServer(allowedServerList);
//其数据模型保存
userCenter().get(username).dataModel.save();
MCSERVER.info('用户', data.WsSession.username, '建立', username, '用户');
response.wsSend(data.ws, 'userset/create', true);
response.wsMsgWindow(data.ws, '用户建立完成√');
return;
@ -76,6 +77,7 @@ WebSocketObserver().listener('userset/delete', (data) => {
try {
let deleteObj = JSON.parse(data.body);
let username = deleteObj.username.trim();
MCSERVER.info('用户', data.WsSession.username, '删除', username, '用户');
deleteUser(username, () => {
userCenter().initUser();
response.wsSend(data.ws, 'userset/delete', true);