优化 部分细节问题

This commit is contained in:
Suwings 2020-10-08 17:52:46 +08:00
parent 78990fc4e4
commit 5a566705ec
9 changed files with 8 additions and 38 deletions

View File

@ -2,17 +2,13 @@ const childProcess = require("child_process");
const iconv = require("iconv-lite");
const EventEmitter = require("events");
const DataModel = require("../DataModel");
const os = require("os");
const tools = require("../tools");
const permission = require("../../helper/Permission");
const path = require("path");
const properties = require("properties");
const fs = require("fs");
const Docker = require("dockerode");
const CODE_CONSOLE = MCSERVER.localProperty.console_encode;
class ServerProcess extends EventEmitter {
constructor(args) {

View File

@ -1,7 +1,5 @@
const ServerProcess = require("./BaseMcserver");
const DataModel = require("../DataModel");
const os = require("os");
const properties = require("properties");
const fs = require("fs");
const tools = require("../tools");
@ -71,7 +69,7 @@ class MinecraftServer extends ServerProcess {
//自定义参数
let tmpCommandeStart = args.highCommande || "";
//自定义参数去掉所有两个空格
tmpCommandeStart = tmpCommandeStart.replace(/ /gim, " ");
tmpCommandeStart = tmpCommandeStart.replace(/ {2}/gim, " ");
this.dataModel.highCommande = tmpCommandeStart;
this.propertiesLoad();
@ -110,7 +108,7 @@ class MinecraftServer extends ServerProcess {
//properties 库自动给等于两边加入了空格,现在去除
text = text.replace(/ = /gim, "=");
// 写入数据, 文件不存在会自动创建
fs.writeFile(this.dataModel.cwd + "/server.properties", text, (err) => {
fs.writeFile(this.dataModel.cwd + "/server.properties", text, () => {
this.propertiesLoad((properties, propertiesError) => {
callback && callback(properties, propertiesError);
});

View File

@ -4,25 +4,7 @@ const fs = require("fs");
const mcPingProtocol = require("../../helper/MCPingProtocol");
const BASE_SERVER_DIR = "./server/";
const BASE_SERVER_CORE_NAME = "server_core";
function deleteall(path) {
var files = [];
if (fs.existsSync(path)) {
files = fs.readdirSync(path);
files.forEach(function (file, index) {
var curPath = path + "/" + file;
if (fs.statSync(curPath).isDirectory()) {
// recurse
deleteall(curPath);
} else {
// delete file
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}
}
class ServerManager extends EventEmitter {
constructor(args) {
@ -31,6 +13,7 @@ class ServerManager extends EventEmitter {
}
newMinecraftServer(name) {
// eslint-disable-next-line no-prototype-builtins
if (!this.serverList.hasOwnProperty(name)) {
this.serverList[name] = new MinecraftServer(name);
this._bindEvent(name);
@ -113,6 +96,7 @@ class ServerManager extends EventEmitter {
}
isExist(name) {
// eslint-disable-next-line no-prototype-builtins
if (this.serverList.hasOwnProperty(name)) {
return true;
}

View File

@ -1,13 +1,7 @@
var fs = require("fs");
var path = require("path");
//因为这库在旧版本节点上有问题,所以从 github 获取最新版本
//npm i https://github.com/sstur/nodeftpd.git --save
var ftpdzz = require("ftpd");
var keyFile;
var certFile;
var options = null;
var FTPserver = null;
var rootCwdListener = () => {

View File

@ -17,7 +17,7 @@ ftpServerInterface.createFTPServer({
let serverName = arrName[1];
if (!realName || !serverName) return null;
let user = userModel.userCenter().get(realName);
// let user = userModel.userCenter().get(realName);
let dataModel = serverModel.ServerManager().getServer(serverName).dataModel || null;
if (dataModel) {

View File

@ -1,3 +1,4 @@
/* eslint-disable no-control-regex */
const net = require("net");
// Using SLT (Server List Ping) provided by Minecraft.

View File

@ -31,7 +31,7 @@ class RecordCommand {
else fs.writeFileSync(this.path, new Buffer(HISTORY_SIZE_LINE * 2).toString() + data);
}
readRecord(pstart = 0, length = 32, callback = (logStr) => {}) {
readRecord(pstart = 0, length = 32, callback = () => { }) {
if (!fs.existsSync(this.path)) return;
const fsstat = fs.statSync(this.path);
@ -54,7 +54,7 @@ class RecordCommand {
callback(resStr);
// 关闭文件
fs.close(fd, () => {});
fs.close(fd, () => { });
});
});
}

View File

@ -1,4 +1,3 @@
var querystring = require("querystring");
function send(res, info, value) {
let str = JSON.stringify({

View File

@ -1,6 +1,4 @@
const schedule = require("node-schedule");
const fs = require("fs");
const DataModel = require("../core/DataModel");
const serverModel = require("../model/ServerModel");