Unverified Commit 80b27623 authored by Suwings's avatar Suwings Committed by GitHub
Browse files

Merge pull request #28 from Suwings/develop

Develop
parents 658aab7e 50ea137d
Showing with 275 additions and 87 deletions
+275 -87
......@@ -13,7 +13,8 @@ server/*.json
public/*.json
McserverConfig.json
core/*.json
public/common/URL.js
property.js
# node
node_modules/
......
......@@ -21,8 +21,10 @@
运行环境
-----------
- 我们的部署简单至极,在`Master`分支下,我们的设计是下载即可运行,不需要编译与任何配置,除了安装一个环境。
- `Node.js` >= 8.0
- `镜像`: [https://npm.taobao.org/mirrors/node/v8.0.0/](https://npm.taobao.org/mirrors/node/v8.0.0/)
- `下载镜像站点`: [https://npm.taobao.org/mirrors/node/v8.0.0/](https://npm.taobao.org/mirrors/node/v8.0.0/)
<br />
......@@ -45,6 +47,7 @@
**方法二**
介于某些原因,您可能并不愿意安装这些运行环境,于是我们给予了一种绿色打包的运行环境,下载即可直接使用
下载直接双击运行: https://pan.baidu.com/s/1bpbB8Az (下载地址)
......@@ -75,9 +78,6 @@ node app.js #或 npm start
- 找不到模块 `ftpd`
> 请输入 `npm install ftpd` 进行再次手动安装,这个模块是直接 github 指定源
- 端口监听失败
> 请修改 `McserverConfig.json` 文件中的端口号
<br />
项目目录结构
......@@ -118,10 +118,27 @@ node app.js #或 npm start
<br />
配置文件
-----------
我们的配置文件是程序目录下的 `property.js` 文件,它会在你第一次运行的时候,自动生成。
> 注意!原旧版本的 McserverConfig.json 文件完全弃用。
> 现在,所有配置将全部归纳于此文件。
> 此文件不会与 github 版本冲突,更新时也不会自动覆盖
<br />
自定义设计
-----------
如果你是内部使用或学习用途,你可以对前端以及后端进行任何修改,包括版权声明。
> 注意!当你进行版本更新的时候,可能会覆盖掉你的自定义修改部分。
> 当然,并不是所有文件都需要覆盖一遍,也不一定非得使用新版本。
<br />
FTP 服务
......@@ -147,9 +164,9 @@ FTP 模块采用被动传输模式,传输命令默认使用 `10021`(可更改)
SSL
-----------
`public/common/URL.js` 中的 `'http://'` 改成 `'https://'`
打开前端 URL 定位文件 `public/common/URL.js`, 将 http 与 ws 改成 https 与 wss;
`public/common/js/websocket.js` 中的`'ws://'` 改成 `'wss://'`
> 此文件不会与 github 版本冲突,更新时也不会覆盖,请放心修改。
即可保证前端所有请求均为 Https 和 Wss
......@@ -190,7 +207,7 @@ SSL
<br />
开源协议与版权
协议与版权
-----------
程序是基于 [GNU Affero General Public License v3.0](./LICENSE "GNU Affero General Public License v3.0") 开放源代码的自由软件。
......
......@@ -9,17 +9,28 @@ try {
//忽略任何版本检测导致的错误
}
const fs = require('fs');
const fsex = require('fs-extra');
//总全局变量
global.MCSERVER = {};
//全局仅限本地配置
MCSERVER.localProperty = {};
const tools = require('./core/tools');
//生成第一次配置文件
const INIT_CONFIG_PATH = './model/init_config/';
const PRO_CONFIG = './property.js';
if (!fs.existsSync(PRO_CONFIG))
tools.mCopyFileSync(INIT_CONFIG_PATH + 'property.js', PRO_CONFIG);
//加载配置
require('./property');
const express = require('express');
const fs = require('fs');
const session = require('express-session');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
......@@ -40,6 +51,7 @@ const DataModel = require('./core/DataModel');
const ftpServerInterface = require('./ftpd/ftpserver');
const tokenManger = require('./helper/TokenManager');
//控制台颜色
const colors = require('colors');
colors.setTheme({
......@@ -60,26 +72,12 @@ const LOGO_FILE_PATH = './core/logo.txt';
let data = fs.readFileSync(LOGO_FILE_PATH, 'utf-8');
console.log(data);
//全局数据中心 记录 CPU 内存
MCSERVER.dataCenter = {};
//装载log记录器
require('./core/log');
//全局设置
MCSERVER.softConfig = new DataModel('McserverConfig');
if (fs.existsSync('./McserverConfig.json')) {
MCSERVER.softConfig.load();
} else {
//初始化
MCSERVER.softConfig.ip = '';
MCSERVER.softConfig.port = 23333;
MCSERVER.softConfig.FTP_port = 10021;
MCSERVER.softConfig.FTP_ip = '';
MCSERVER.softConfig.save();
}
//全局登陆记录器
MCSERVER.login = {};
//全局 在线用户监视器
......@@ -89,10 +87,6 @@ MCSERVER.allSockets = {};
//全局 数据内存记录器
MCSERVER.logCenter = {};
// 过期的数据对象
// MCSERVER.logCenter.CPU = [];
// MCSERVER.logCenter.RAM = [];
//init
MCSERVER.logCenter.initLogData = (objStr, len, def = null) => {
let tmp = [];
......@@ -185,19 +179,20 @@ process.on("uncaughtException", function (err) {
const SERVER_PATH = './server/';
const SERVER_PATH_CORE = './server/server_core/';
const CENTEN_LOG_JSON_PATH = './core/info.json';
const PUBLIC_URL_PATH = './public/common/URL.js';
try {
if (!fs.existsSync(USERS_PATH)) fs.mkdirSync(USERS_PATH);
if (!fs.existsSync(SERVER_PATH)) {
fs.mkdir(SERVER_PATH, () => fs.mkdirSync(SERVER_PATH_CORE));
}
if (!fs.existsSync(CENTEN_LOG_JSON_PATH)) {
let resetData = fs.readFileSync('./core/info_reset.json', {
encoding: 'UTF-8'
});
fs.writeFileSync('./core/info.json', resetData, {
encoding: 'UTF-8'
});
}
// 生成不 git 同步的文件
if (!fs.existsSync(CENTEN_LOG_JSON_PATH))
tools.mCopyFileSync(INIT_CONFIG_PATH + 'info_reset.json', CENTEN_LOG_JSON_PATH);
if (!fs.existsSync(PUBLIC_URL_PATH))
tools.mCopyFileSync(INIT_CONFIG_PATH + 'INIT_URL.js', PUBLIC_URL_PATH);
} catch (err) {
MCSERVER.error('初始化文件环境失败,建议重启,请检查以下报错:', err);
}
......@@ -230,26 +225,26 @@ app.use('/fs', require('./onlinefs/controller/function'));
ServerModel.ServerManager().loadALLMinecraftServer();
MCSERVER.infoLog('Module', '初始化 ServerManager Module ');
var host = MCSERVER.softConfig.ip;
var port = MCSERVER.softConfig.port;
var host = MCSERVER.localProperty.http_ip;
var port = MCSERVER.localProperty.http_port;
if (host == '::')
host = '127.0.0.1';
//App Http listen
app.listen(MCSERVER.softConfig.port, MCSERVER.softConfig.ip, () => {
app.listen(MCSERVER.localProperty.http_port, MCSERVER.localProperty.http_ip, () => {
MCSERVER.infoLog('HTTP', 'HTTP 模块监听: [ http://' + (host || '127.0.0.1'.yellow) + ':' + port + ' ]');
//现在执行 FTP 服务器启动过程
ftpServerInterface.initFTPdServerOptions({
host: MCSERVER.softConfig.FTP_ip || '127.0.0.1',
port: MCSERVER.softConfig.FTP_port,
host: MCSERVER.localProperty.ftp_ip || '127.0.0.1',
port: MCSERVER.localProperty.ftp_port,
tls: null
});
//执行ftp逻辑
require('./ftpd/index');
if (MCSERVER.localProperty.ftp_is_allow)
require('./ftpd/index'); //执行ftp逻辑
});
......
......@@ -42,4 +42,15 @@ module.exports.autoLoadModule = (proPath, minePath, callback) => {
throw err;
}
}
}
module.exports.mCopyFileSync = (oldpath, newpath) => {
let resetData = fs.readFileSync(oldpath, {
encoding: 'UTF-8'
});
fs.writeFileSync(newpath, resetData, {
encoding: 'UTF-8'
});
return true;
}
\ No newline at end of file
......@@ -72,6 +72,8 @@ module.exports.runFTPServer = () => {
].join(" "));
MCSERVER.infoLog('FTP'.green,
" FTP 模块监听: [ ftp://" + (MCSERVER.softConfig.FTP_ip || "127.0.0.1".yellow) + ":" + MCSERVER.softConfig.FTP_port + " ]");
" FTP 模块监听: [ ftp://" +
(options.host || "127.0.0.1".yellow) +
":" + options.port + " ]");
}
\ No newline at end of file
......@@ -94,4 +94,14 @@ module.exports.isCanServer = (userName, serverName) => {
}
}
return false;
}
module.exports.isOnline = (username) => {
let onlineusers = MCSERVER.onlineUser;
for (let k in onlineusers) {
if (k === username) {
return true;
}
}
return false;
}
\ No newline at end of file
const os = require("os");
//前端显示版本
//每次更新之后,修改此处,表明修改
//这样, 用户截图时, 可以知道具体的版本
const oversion = "Beta_8.3.0.0"; //前端
const tversion = "Beta_8.3.0.0"; //后端
//首页
// WebSocketObserver().listener('index/update', (data) => {
// if (!permssion.isMaster(data.WsSession)) return;
// response.wsSend(data.ws, 'index/update', {
// system: os.type() + " " + os.arch(),
// root: process.cwd(),
// oneversion: oversion,
// twoversion: tversion
// })
// });
let info = [os.type(), os.arch(), os.hostname(), os.release()].join(" ");
module.exports = {
system: info,
root: process.cwd(),
oneversion: oversion,
twoversion: tversion
}
\ No newline at end of file
//表实体
class Table {
constructor(tableName) {
this.tableName = tableName;
this._objs = {};
}
setItem(k, v = null) {
this._objs[k] = v;
}
addItem(k, v = null) {
if (this._objs[k])
throw new Error("ADD_ITEM_ERROR: This is not null!");
else
this._objs[k] = v;
}
delItem(k, v = null) {
delete this._objs[k];
}
toString() {
return JSON.stringify(this._objs);
}
}
//权限表实体
class PermissionTable extends Table {
constructor(tableName) {
super(tableName);
}
}
module.exports = {
PermissionTable,
Table
}
\ No newline at end of file
//标准的URL定位器
//如果你的程序不在根目录,可以考虑更改这里,或者你有什么其他姿势。
//保证 99% 的可用性,因为代码历史遗留问题,不能保证所有请求都能通过此 URL 定位器
//如果你需要反向代理加入SSL,请更改此处
//某些 login 页面没有 MCSERVER 全局变量,在此实例化
if (window.MCSERVER == undefined) window.MCSERVER = {};
//Ws 默认协议
MCSERVER.WS_PROTOCOL = 'ws://';
//HTTP 默认协议
MCSERVER.HTTP_PROTOCOL = 'http://';
//URL定位器
MCSERVER.URL = function (url, protocol) {
var _protocol = protocol || 'http://';
var _protocol = protocol || MCSERVER.HTTP_PROTOCOL;
var hostName = window.location.host;
var openURL = hostName + '/' + url;
return _protocol + openURL;
......
File moved
......@@ -15,7 +15,7 @@
* 当然你可以选择不改动此文件。
*
*
* 绝大部分设置,需要重启面板生效!
* 绝大部分设置,需要重启面板生效!
*/
......@@ -32,7 +32,26 @@ else
/*--------------- 配置开始,这与 Minecraft 服务器配置几乎差不多 --------------- */
/*--------------- 配置开始,这与 Minecraft 服务器配置基本一样 --------------- */
//HTTP 服务监听端口
MCSERVER.localProperty.http_port = 23333;
//HTTP 服务监听ip, 默认 0.0.0.0
MCSERVER.localProperty.http_ip = "";
//是否开启 FTP 服务
MCSERVER.localProperty.ftp_is_allow = true;
//FTP 服务监听端口
MCSERVER.localProperty.ftp_port = 10022;
//HTTP 服务监听ip, 默认 0.0.0.0
MCSERVER.localProperty.ftp_ip = "";
//FTP 被动模式端口范围
......
......@@ -78,4 +78,13 @@
100% {
opacity: 1;
}
}
@keyframes btnHover {
0% {
opacity: 1;
}
100% {
opacity: 0.4;
}
}
\ No newline at end of file
......@@ -172,6 +172,16 @@
background-color: #e6e6e6;
}
/* 专门用来覆盖 PanelItem 的特殊元素 */
.ItemTableList {
padding: 0px 8px;
width: 100%;
margin-bottom: 0px;
border-bottom: 1px solid #d8d8d8;
background-color: initial;
}
.input-group {
margin-bottom: 10px;
}
......
......@@ -24,6 +24,17 @@ input {
outline: none;
}
.btn {
border-radius: 0px;
}
.btn:hover {
opacity: 0.5;
/* action */
animation: btnHover 1s;
animation-fill-mode: forwards;
}
/*全局css定义结束*/
#Header {
......@@ -33,17 +44,19 @@ input {
top: 0px;
width: 100%;
z-index: 102;
box-shadow: 0 0 5px 0 rgba(0, 0, 0, .6);
}
#MasterLogo {
letter-spacing: 1.5px;
animation: ActionLogoA 1s;
animation-fill-mode: forwards;
/* background-color: rgb(255, 255, 255); */
/* letter-spacing: 1.5px; */
/* animation: ActionLogoA 1s; */
/* animation-fill-mode: forwards; */
}
#MasterLogo:hover {
animation: ActionLogoB 1s;
animation-fill-mode: forwards;
/* animation: ActionLogoB 1s; */
/* animation-fill-mode: forwards; */
}
#SideCol {
......@@ -65,12 +78,6 @@ input {
right: 0px;
}
@media (max-width:640px) {
#websocket {
display: none;
}
}
#MainContainer {
position: absolute;
width: 100%;
......@@ -81,13 +88,20 @@ input {
overflow-y: auto;
}
/* 右侧容器 */
#ConsoleMain {
max-width: 1360px;
margin: auto;
}
/*布局结束*/
/*标题*/
.HeaderItem {
color: #E5E5E5;
line-height: 49px;
line-height: 50px;
font-size: 14px;
margin: 0;
float: left;
......@@ -98,6 +112,18 @@ input {
/*标题的右侧菜单*/
.HeaderTitle {
display: inline-block;
*zoom: 1;
overflow: hidden;
text-align: center;
line-height: 50px;
color: rgb(252, 252, 252);
font-size: 12px;
padding: 0 16px;
font-weight: 400;
}
.HeaderR {
float: right;
}
......@@ -107,8 +133,8 @@ input {
*zoom: 1;
overflow: hidden;
text-align: center;
line-height: 49px;
color: white;
line-height: 50px;
color: rgb(250, 250, 250);
font-size: 12px;
padding: 0 12px;
cursor: pointer;
......@@ -296,4 +322,13 @@ input {
width: 100%;
overflow: hidden;
line-height: 3px;
}
@media (max-width:640px) {
#websocket {
display: none;
}
#HeaderInfo {
display: none;
}
}
\ No newline at end of file
......@@ -18,11 +18,6 @@
//管理员的
//注意,这些页面只能管理员访问,普通用户就算访问,也得不到任何数据
MCSERVER.meumObject.masterMeum = [{
class: 'glyphicon-home',
name: '控制面板情报',
link: './template/index.html',
api: 'index/update'
}, {
class: 'glyphicon-equalizer',
name: '监控数据中心',
link: './template/center.html',
......@@ -37,14 +32,9 @@
name: '用户权限设定',
link: './template/userset.html',
api: 'userset/update'
}, {
class: 'glyphicon-cog',
name: '控制面板设置',
link: './template/softset.html',
api: 'soft/view'
}, {
class: 'glyphicon-floppy-open',
name: '客户支持',
name: '服务与支持',
link: './template/feelback.html',
api: null
}]
......
......@@ -8,7 +8,7 @@
RES.TOKEN_NAME = TOKEN_NAME;
RES.TOKEN = null;
RES.getToken = function (callback) {
// 同源策略可以防止其他域对这里发送一个Ajax请求.
//同源策略可以防止其他域对这里发送一个Ajax请求.
var _url = MCSERVER.URL("./token?_LoveYouMaster_Time=" + Date.parse(new Date()));
$.get(_url, function (data, status) {
data = JSON.parse(data);
......@@ -101,7 +101,9 @@
});
RES.redirectPage = function (url, key, body, callback) {
var showUrl = url.replace(".", "");
var showKey = key || "Null"
TOOLS.setHeaderTitle(["正在加载...."].join(" "));
ToolsLoadingStart(function () {
MI.rOn('onend');
PageLoading();
......@@ -111,6 +113,7 @@
//触发页面切换事件
MI.on('RedirectPage', url);
RES.redirectHTML(url, key, body, function () {
TOOLS.setHeaderTitle(["当前", showUrl, " | ", "接口", showKey].join(" "));
MI.on('page/live');
//赋予的单页刷新
PAGE.refresh = function () {
......
......@@ -97,4 +97,14 @@
return reg.test(text);
}
var cacheHeaderTitleEle = $("#HeaderInfo");
//设置头上显示什么
TOOLS.setHeaderTitle = function (text) {
if (text) {
cacheHeaderTitleEle.html(TOOLS.encode(text));
} else {
cacheHeaderTitleEle.html("");
}
}
})();
\ No newline at end of file
......@@ -21,6 +21,7 @@
});
MI.listener('ws/close', function (ws) {
TOOLS.setHeaderTitle("离线 | 当前与服务器断开..");
var webscoketStatus = VIEW_MODEL['websocketStatus'];
webscoketStatus['status'] = '!!! 连接断开 !!!';
webscoketStatus['is'] = false;
......@@ -127,14 +128,20 @@
MI.routeListener('server/console/ws', function (data) {
var consoleSafe = terminalEncode(data.body);
var MinecraftConsole = document.getElementById('TerminalMinecraft');
if (MinecraftConsole == undefined) {
console.log('NULL')
if (MinecraftConsole == null) {
console.error('MinecraftConsole is null');
return;
}
MinecraftConsole.innerHTML += consoleSafe;
var flag = false;
//判断用户是否自己移动了滚轴
var BUFF_FONTIER_SIZE_DOWN = MinecraftConsole.scrollHeight - MinecraftConsole.clientHeight;
if (MinecraftConsole.scrollTop + 354 >= BUFF_FONTIER_SIZE_DOWN) {
flag = (MinecraftConsole.scrollTop + 354 >= BUFF_FONTIER_SIZE_DOWN);
//add
MinecraftConsole.innerHTML += consoleSafe;
//unblive bt ths is t
if (flag)
MinecraftConsole.scrollTop = MinecraftConsole.scrollHeight;
}
});
//获取控制台历史记录
......
......@@ -15,7 +15,7 @@
window.WS.init = function (openCallback) {
var wsURL = 'websocket/ws?' + RES.TOKEN_NAME + '=' + RES.TOKEN;
window.WS = new WebSocket(MCSERVER.URL(wsURL, 'ws://'));
window.WS = new WebSocket(MCSERVER.URL(wsURL, MCSERVER.WS_PROTOCOL));
var tmp_callback = null;
wsHeartBeatPackage(WS); //心跳包定时器开启
......
......@@ -54,6 +54,7 @@
<div id='MasterLogo' class="HeaderItem" onclick="MCSERVER.colmDo()" style="cursor: pointer;">
<img src="common/logo.png" width="160px" height="100%" />
</div>
<div id="HeaderInfo" class="HeaderTitle"></div>
<div class="HeaderR">
<div id='websocket' v-text="status" v-bind:style="{ color: tcolor}">
正在链接到服务器...
......@@ -199,18 +200,13 @@
//是否登陆
if (!MCSERVER.username) {
TOOLS.pushMsgWindow('[认证失败] 请登录您的账号,正在为您跳转....');
//重定向到登录页面
setTimeout(function () {
console.log("跳转");
window.location.href = MCSERVER.URL("login");
}, 4200);
window.location.href = MCSERVER.URL("login");
return;
}
//判断是否是#权限用户,请放心,后端也会给予判断并不只是前端
if (MCSERVER.username.substr(0, 1) == '#') {
RES.redirectPage('./template/index.html', 'index/update', '--- 更新页面 ---');
RES.redirectPage('./template/center.html', 'center/show', '--- 更新页面 ---');
} else {
RES.redirectPage('./template/gen_home.html', 'genuser/home', '--- 更新页面 ---');
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment