From a09307fc6fb1d7455b0d62055745e12f3a5f113f Mon Sep 17 00:00:00 2001 From: suwings Date: Tue, 13 Nov 2018 15:28:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20Docker=20Config=20?= =?UTF-8?q?=E5=AD=98=E5=82=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/Process/Mcserver.js | 10 ++++-- public/template/component/server.html | 7 ++-- public/template/dialog/docker_config.html | 40 +++++++++++++---------- route/websocket/docker.js | 30 ++++++++++++++++- 4 files changed, 63 insertions(+), 24 deletions(-) diff --git a/core/Process/Mcserver.js b/core/Process/Mcserver.js index 0d5a099..de416bb 100644 --- a/core/Process/Mcserver.js +++ b/core/Process/Mcserver.js @@ -32,9 +32,15 @@ class MinecraftServer extends ServerProcess { this.properties = undefined; //服务端配置表 //Docker 容器是否启用 - this.isDocker = false; + // this.isDocker = false; //Docker 配置项目 - this.dockerConfig = {}; + this.dataModel.dockerConfig = { + dockerCommand: 'docker run -i -m ${xmx} -v ${serverpath}:/mcsd/ ${ports} ${imagename} ${commande}', + dockerImageName: "mcsd", + dockerXmx: "", + dockerPorts: "", + isDocker: false + }; } diff --git a/public/template/component/server.html b/public/template/component/server.html index 657a710..cf5f3b0 100644 --- a/public/template/component/server.html +++ b/public/template/component/server.html @@ -143,7 +143,8 @@ }, methods: { toDocker: function () { - var that = this; + // var that = this; + PAGE.selectServerName = this.oldServerName; TOOLS.popWind({ style: { maxWidth: "600px", @@ -152,8 +153,8 @@ title: "Minecraft Docker 配置", template: "template/dialog/docker_config.html", callback: function (result) { - if (!result) return; - console.log(result) + // if (!result) return; + // console.log(result) } }); }, diff --git a/public/template/dialog/docker_config.html b/public/template/dialog/docker_config.html index a6e0c4a..b20689a 100644 --- a/public/template/dialog/docker_config.html +++ b/public/template/dialog/docker_config.html @@ -9,7 +9,7 @@ 启用 Docker 容器

- 启动命令 + 命令模板
@@ -35,23 +35,27 @@ \ No newline at end of file diff --git a/route/websocket/docker.js b/route/websocket/docker.js index dbba351..c2bdce6 100644 --- a/route/websocket/docker.js +++ b/route/websocket/docker.js @@ -80,4 +80,32 @@ WebSocketObserver().listener('docker/new', (data) => { WebSocketObserver().listener('docker/res', (data) => { if (!permssion.isMaster(data.WsSession)) return; response.wsSend(data.ws, 'docker/res', MCSERVER.PAGE.DockerRes); -}) \ No newline at end of file +}) + +//获取配置 +WebSocketObserver().listener('docker/config', (data) => { + if (!permssion.isMaster(data.WsSession)) return; + let serverName = data.body || ""; + if (serverName) { + let mcserver = serverModel.ServerManager().getServer(serverName); + response.wsSend(data.ws, 'docker/config', mcserver.dataModel.dockerConfig); + } +}); + + +//设置配置 +WebSocketObserver().listener('docker/setconfig', (data) => { + if (!permssion.isMaster(data.WsSession)) return; + // { + // serverName: "xxxx", + // dockerConfig: { ... } + // } + let jsonObj = JSON.parse(data.body); + if (jsonObj.serverName) { + let serverName = jsonObj.serverName; + let mcserver = serverModel.ServerManager().getServer(serverName); + mcserver.dataModel.dockerConfig = jsonObj.dockerConfig; + mcserver.dataModel.save(); + response.wsMsgWindow(data.ws, '操作成功,数据已保存'); + } +}); \ No newline at end of file