Compare commits

...

37 Commits

Author SHA1 Message Date
08b72cd05a v0.6.7 2020-05-15 18:24:24 +08:00
6e38da18bc feat: add npm publish script 2020-05-15 16:50:12 +08:00
2957150096 feat: link .npmignore file 2020-05-15 16:46:47 +08:00
c13ff26971 v0.6.6 2020-05-15 16:20:21 +08:00
104d1b18d6 feat: support nukkit getRootLogger
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-15 16:10:55 +08:00
db9746b641 feat: support bungee log forward
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-15 15:49:23 +08:00
6f18fe0990 feat: support get root Logger
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-15 15:48:38 +08:00
b33358cf59 feat: add token check
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-15 14:29:13 +08:00
bc29221b9c feat: support config auto save
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-15 14:28:40 +08:00
dd88e63d1a feat: support token check & compatible more server
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-14 19:05:07 +08:00
99a264677a feat: optimize import
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-14 19:04:19 +08:00
805f7ad521 feat: support handshark & boardcast
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-14 19:03:41 +08:00
e6aba870da feat: update dep version
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-14 09:56:13 +08:00
321cb18cb9 feat: support log forward to client
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-13 18:42:41 +08:00
430edacd3f feat: complate upgrade
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-13 18:42:05 +08:00
ac88c15113 feat: add global eventCenter & static console source map
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-13 18:41:05 +08:00
2185b1a2f8 v0.6.5 2020-05-12 14:35:26 +08:00
c14e20e269 feat: optimize framework
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-12 14:22:31 +08:00
45a1c43dd8 feat: complate deploy access check
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-12 00:07:05 +08:00
9226e1ab4f feat: ignore if trace.fileName is empty
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-11 22:13:31 +08:00
287585d8f5 feat: add node shim
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-11 22:13:03 +08:00
b323d16123 v0.6.4 2020-05-11 17:52:13 +08:00
85240608a1 feat: add npmignore
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-11 17:46:57 +08:00
6f9b458e6a v0.6.3 2020-05-11 17:32:02 +08:00
64159b621f feat: support address arg
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-11 17:24:26 +08:00
393ae6ce25 feat: support online load plugin
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-11 17:22:45 +08:00
b9b80ecb83 feat: support blockly online debug
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-11 17:22:15 +08:00
57e2845ad9 feat: compatible blockly plugin
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-11 17:20:50 +08:00
e03a4f9b34 feat: add i18n load tip
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-11 17:19:44 +08:00
72015ec132 feat: ignore jar:file stack info
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-10 16:25:04 +08:00
3e329233ce feat: add incremental compiler config
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-10 16:24:19 +08:00
b53d9e8a4e remove: plugins public file 2020-05-08 18:42:17 +08:00
331357f1a2 feat: support basic plugin... 2020-05-08 18:41:56 +08:00
ec809fb013 feat: update init command... 2020-05-08 10:11:30 +08:00
e38e772b17 feat: update gitpod init command... 2020-05-08 10:05:47 +08:00
2b56b1e573 feat: add gitpod config... 2020-05-08 09:53:18 +08:00
2df09b2472 feat: complate deploy feature 2020-05-08 00:50:30 +08:00
78 changed files with 656 additions and 564 deletions

10
.gitpod.Dockerfile vendored Normal file
View File

@@ -0,0 +1,10 @@
FROM gitpod/workspace-full
USER gitpod
# Install custom tools, runtime, etc. using apt-get
# For example, the command below would install "bastet" - a command line tetris clone:
#
# RUN sudo apt-get -q update && # sudo apt-get install -yq bastet && # sudo rm -rf /var/lib/apt/lists/*
#
# More information: https://www.gitpod.io/docs/config-docker/

5
.gitpod.yml Normal file
View File

@@ -0,0 +1,5 @@
tasks:
- init: yarn && yarn bs && yarn build
command: yarn watch
# image:
# file: .gitpod.Dockerfile

View File

@@ -20,3 +20,4 @@ wallaby.js
.vscode
.theia
type_definitions
tsconfig.tsbuildinfo

View File

@@ -1,5 +1,5 @@
{
"version": "0.6.2",
"version": "0.6.7",
"useWorkspaces": true,
"npmClient": "yarn",
"packages": [

View File

@@ -12,12 +12,13 @@
"build": "lerna run build --scope=\"@ccms/!(plugins)\"",
"build:plugins": "lerna run build --scope=\"@ccms/plugins\"",
"ug": "yarn upgrade-interactive --latest",
"np": "lerna exec \"npm publish --registry https://registry.npmjs.org\" --scope=\"@ccms/!(client|plugins|types)\"",
"lp": "lerna publish"
},
"workspaces": [
"packages/*"
],
"devDependencies": {
"lerna": "^3.20.2"
"lerna": "^3.21.0"
}
}
}

1
packages/api/.npmignore Symbolic link
View File

@@ -0,0 +1 @@
../../.npmignore

View File

@@ -1,6 +1,6 @@
{
"name": "@ccms/api",
"version": "0.6.1",
"version": "0.6.7",
"description": "MiaoScript api package",
"keywords": [
"miaoscript",
@@ -19,8 +19,8 @@
"test": "echo \"Error: run tests from root\" && exit 1"
},
"dependencies": {
"@ccms/container": "^0.6.0",
"@ccms/ployfill": "^0.6.1",
"@ccms/container": "^0.6.7",
"@ccms/ployfill": "^0.6.7",
"base64-js": "^1.3.1",
"source-map-builder": "^0.0.7"
},
@@ -28,6 +28,6 @@
"@types/base64-js": "^1.2.5",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"typescript": "^3.8.3"
"typescript": "^3.9.2"
}
}

View File

@@ -21,8 +21,8 @@ enum LogLevel {
export class MiaoScriptConsole implements Console {
Console: NodeJS.ConsoleConstructor;
private sourceMaps: { [key: string]: SourceMapBuilder } = {};
private sourceFileMaps: { [key: string]: string } = {};
private static sourceMaps: { [key: string]: SourceMapBuilder } = {};
private static sourceFileMaps: { [key: string]: string } = {};
private _name: string = '';
private _level: LogLevel = LogLevel.INFO;
@@ -93,8 +93,8 @@ export class MiaoScriptConsole implements Console {
readSourceMap(fileName: string, lineNumber: number) {
try {
if (fileName.endsWith('js')) {
if (this.sourceMaps[fileName] === undefined) {
this.sourceMaps[fileName] = null
if (MiaoScriptConsole.sourceMaps[fileName] === undefined) {
MiaoScriptConsole.sourceMaps[fileName] = null
let sourceLine = base.read(fileName).split('\n');
let lastLine = sourceLine[sourceLine.length - 1]
if (lastLine.startsWith('//# sourceMappingURL=')) {
@@ -109,14 +109,14 @@ export class MiaoScriptConsole implements Console {
if (file.exists()) { sourceContent = base.read(file) }
}
if (sourceContent) {
this.sourceMaps[fileName] = new SourceMapBuilder(JSON.parse(sourceContent))
this.sourceFileMaps[fileName] = Paths.get(fileName, '..', this.sourceMaps[fileName].sources[0]).toFile().getCanonicalPath();
MiaoScriptConsole.sourceMaps[fileName] = new SourceMapBuilder(JSON.parse(sourceContent))
MiaoScriptConsole.sourceFileMaps[fileName] = Paths.get(fileName, '..', MiaoScriptConsole.sourceMaps[fileName].sources[0]).toFile().getCanonicalPath();
}
}
}
if (this.sourceMaps[fileName]) {
let sourceMapping = this.sourceMaps[fileName].getSource(lineNumber, 25, true, true);
fileName = this.sourceFileMaps[fileName]
if (MiaoScriptConsole.sourceMaps[fileName]) {
let sourceMapping = MiaoScriptConsole.sourceMaps[fileName].getSource(lineNumber, 25, true, true);
fileName = MiaoScriptConsole.sourceFileMaps[fileName]
if (sourceMapping && lineNumber != sourceMapping.mapping.sourceLine) { lineNumber = sourceMapping.mapping.sourceLine; }
}
}
@@ -136,6 +136,7 @@ export class MiaoScriptConsole implements Console {
stack = Arrays.asList(stack)
}
stack.forEach(trace => {
if (!trace.fileName || trace.fileName.startsWith('jar:file:')) { return }
if (trace.className.startsWith('<')) {
let { fileName, lineNumber } = this.readSourceMap(trace.fileName, trace.lineNumber)
if (fileName.startsWith(root)) { fileName = fileName.split(root)[1] }

View File

@@ -21,6 +21,9 @@ export namespace event {
@injectable()
export abstract class Event {
// export EventPriority to blockly
public EventPriority = EventPriority;
private mapEvent = [];
private listenerMap = [];

View File

@@ -31,6 +31,7 @@ export namespace server {
getPluginsFolder(): string;
getNativePluginManager(): NativePluginManager;
getNettyPipeline(): any;
getRootLogger(): any;
sendJson(sender: string | any, json: object | string): void;
}
}

1
packages/bukkit/.npmignore Symbolic link
View File

@@ -0,0 +1 @@
../../.npmignore

View File

@@ -1,6 +1,6 @@
{
"name": "@ccms/bukkit",
"version": "0.6.2",
"version": "0.6.7",
"description": "MiaoScript bukkit package",
"keywords": [
"miaoscript",
@@ -21,11 +21,11 @@
"devDependencies": {
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"typescript": "^3.8.3"
"typescript": "^3.9.2"
},
"dependencies": {
"@ccms/api": "^0.6.1",
"@ccms/common": "^0.6.2",
"@ccms/container": "^0.6.0"
"@ccms/api": "^0.6.7",
"@ccms/common": "^0.6.7",
"@ccms/container": "^0.6.7"
}
}

View File

@@ -10,10 +10,11 @@ let Bukkit = org.bukkit.Bukkit;
export class BukkitServer implements server.Server {
private pluginsFolder: string;
private pipeline: any;
private rootLogger: any;
constructor() {
this.pluginsFolder = Bukkit.getUpdateFolderFile().getParentFile().getCanonicalPath();
this.reflectPipeline()
this.reflect()
}
getPlayer(name: string) {
@@ -49,6 +50,9 @@ export class BukkitServer implements server.Server {
getNettyPipeline() {
return this.pipeline;
}
getRootLogger() {
return this.rootLogger;
}
sendJson(sender: string | any, json: object | string): void {
if (typeof sender === "string") {
sender = this.getPlayer(sender)
@@ -59,14 +63,20 @@ export class BukkitServer implements server.Server {
}
}
private reflectPipeline() {
private reflect() {
let consoleServer = reflect.on(Bukkit.getServer()).get('console').get()
this.reflectPipeline(consoleServer)
this.reflectRootLogger(consoleServer)
}
private reflectPipeline(consoleServer: any) {
let connection: any;
let promise: any;
for (const method of constants.Reflect.Method.getServerConnection) {
try {
connection = reflect.on(consoleServer).call(method).get()
if (connection.class.name.indexOf('ServerConnection') !== -1) { break; }
if (connection.class.name.indexOf('ServerConnection') !== -1
|| connection.class.name.indexOf('NetworkSystem') !== -1) { break; }
connection = undefined;
} catch (error) { }
}
@@ -81,4 +91,12 @@ export class BukkitServer implements server.Server {
if (!promise) { console.error("Can't found listeningChannels!"); return }
this.pipeline = reflect.on(promise).get('channel').get().pipeline()
}
private reflectRootLogger(consoleServer: any) {
try {
this.rootLogger = reflect.on(consoleServer).get('LOGGER').get().parent
} catch (error) {
console.error("Can't found rootLogger!")
}
}
}

1
packages/bungee/.npmignore Symbolic link
View File

@@ -0,0 +1 @@
../../.npmignore

View File

@@ -1,6 +1,6 @@
{
"name": "@ccms/bungee",
"version": "0.6.2",
"version": "0.6.7",
"description": "MiaoScript bungee package",
"keywords": [
"miaoscript",
@@ -21,11 +21,11 @@
"devDependencies": {
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"typescript": "^3.8.3"
"typescript": "^3.9.2"
},
"dependencies": {
"@ccms/api": "^0.6.1",
"@ccms/common": "^0.6.2",
"@ccms/container": "^0.6.0"
"@ccms/api": "^0.6.7",
"@ccms/common": "^0.6.7",
"@ccms/container": "^0.6.7"
}
}

View File

@@ -9,6 +9,7 @@ let Bungee: net.md_5.bungee.api.ProxyServer = base.getInstance().getProxy();
export class BungeeServer implements server.Server {
private pluginsFolder: string;
private pipeline: any;
private rootLogger: any;
@inject(task.TaskManager)
private task: task.TaskManager
@@ -35,6 +36,11 @@ export class BungeeServer implements server.Server {
}
}
}).later(10).timer(20).submit()
try {
this.rootLogger = Bungee.getLogger()
} catch (error) {
console.error("Can't found rootLogger!")
}
}
getPlayer(name: string) {
@@ -70,6 +76,9 @@ export class BungeeServer implements server.Server {
getNettyPipeline() {
return this.pipeline;
}
getRootLogger() {
return this.rootLogger;
}
sendJson(sender: string | any, json: string): void {
throw new Error("Method not implemented.");
}

1
packages/client/.npmignore Symbolic link
View File

@@ -0,0 +1 @@
../../.npmignore

View File

@@ -1,7 +1,7 @@
{
"private": true,
"name": "@ccms/client",
"version": "0.6.0",
"version": "0.6.7",
"description": "MiaoScript client package",
"keywords": [
"miaoscript",
@@ -26,6 +26,6 @@
},
"devDependencies": {
"rimraf": "^3.0.2",
"typescript": "^3.8.3"
"typescript": "^3.9.2"
}
}

View File

@@ -6,7 +6,9 @@ import { attachEvents } from './event'
let username = process.argv[2] || 'Mr_jtb'
let version = process.argv[3] || '1.12.2'
let client = createConnection('192.168.2.5', 25577, username)
let address = process.argv[4] || '192.168.2.5:25577'
let realAddress = address.split(":");
let client = createConnection(realAddress[0], parseInt(realAddress[1] || "25565"), username)
function createConnection(host: string, port: number, username: string) {
let client = createClient({

1
packages/common/.npmignore Symbolic link
View File

@@ -0,0 +1 @@
../../.npmignore

View File

@@ -1,6 +1,6 @@
{
"name": "@ccms/common",
"version": "0.6.2",
"version": "0.6.7",
"description": "MiaoScript api package",
"keywords": [
"miaoscript",
@@ -21,10 +21,10 @@
"devDependencies": {
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"typescript": "^3.8.3"
"typescript": "^3.9.2"
},
"dependencies": {
"@ccms/nashorn": "^0.6.1"
"@ccms/nashorn": "^0.6.7"
},
"gitHead": "562e2d00175c9d3a99c8b672aa07e6d92706a027"
}

View File

@@ -27,7 +27,7 @@ function request(config: RequestConfig) {
for (const header in config.headers) {
xhr.setRequestHeader(header, config.headers[header]);
}
xhr.send(config.data);
xhr.send(typeof config.data === "string" ? config.data : JSON.stringify(config.data));
if ((xhr.getResponseHeader("Content-Type") + '').indexOf('application/json') != -1) {
xhr.responseType = "json"
}

1
packages/compile/.npmignore Symbolic link
View File

@@ -0,0 +1 @@
../../.npmignore

View File

@@ -1,6 +1,6 @@
{
"name": "@ccms/compile",
"version": "0.6.0",
"version": "0.6.7",
"description": "MiaoScript compile package",
"keywords": [
"miaoscript",
@@ -21,6 +21,6 @@
"devDependencies": {
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"typescript": "^3.8.3"
"typescript": "^3.9.2"
}
}

View File

@@ -0,0 +1 @@
../../.npmignore

View File

@@ -1,6 +1,6 @@
{
"name": "@ccms/container",
"version": "0.6.0",
"version": "0.6.7",
"description": "MiaoScript container package",
"keywords": [
"miaoscript",
@@ -21,7 +21,7 @@
"devDependencies": {
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"typescript": "^3.8.3"
"typescript": "^3.9.2"
},
"dependencies": {
"inversify": "^5.0.1",

1
packages/core/.npmignore Symbolic link
View File

@@ -0,0 +1 @@
../../.npmignore

View File

@@ -1,6 +1,6 @@
{
"name": "@ccms/core",
"version": "0.6.1",
"version": "0.6.7",
"description": "MiaoScript api package",
"keywords": [
"miaoscript",
@@ -21,11 +21,11 @@
"devDependencies": {
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"typescript": "^3.8.3"
"typescript": "^3.9.2"
},
"dependencies": {
"@ccms/api": "^0.6.1",
"@ccms/container": "^0.6.0"
"@ccms/api": "^0.6.7",
"@ccms/container": "^0.6.7"
},
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
}

View File

@@ -1,52 +1,59 @@
let containerStartTime = Date.now();
console.i18n("ms.core.ioc.initialize", { scope: global.scope });
let containerStartTime = Date.now()
console.i18n("ms.core.ioc.initialize", { scope: global.scope })
import { plugin, server, task, constants } from '@ccms/api'
import { DefaultContainer as container, inject, provideSingleton, ContainerInstance, buildProviderModule } from '@ccms/container'
console.i18n("ms.core.ioc.completed", { scope: global.scope, time: (Date.now() - containerStartTime) / 1000 })
import http from '@ccms/common/dist/http'
import { EventEmitter } from 'events'
@provideSingleton(MiaoScriptCore)
class MiaoScriptCore {
@inject(server.Console)
private Console: Console;
private Console: Console
@inject(task.TaskManager)
private taskManager: task.TaskManager;
private taskManager: task.TaskManager
@inject(plugin.PluginFolder)
private pluginFolder: string;
private pluginFolder: string
@inject(plugin.PluginManager)
private pluginManager: plugin.PluginManager;
private pluginManager: plugin.PluginManager
enable() {
this.loadServerConsole();
this.loadTaskFunction();
this.loadServerConsole()
this.loadTaskFunction()
global.level = "TRACE"
this.loadPlugins();
return () => this.disable();
this.loadPlugins()
return () => this.disable()
}
loadServerConsole() {
global.setGlobal('eventCenter', new EventEmitter(), { writable: false, configurable: false });
//@ts-ignore
global.setGlobal('console', new this.Console())
global.setGlobal('console', new this.Console(), { writable: false, configurable: false })
}
loadTaskFunction() {
global.setGlobal('setTimeout', (func: Function, tick: number, async: boolean = false) => this.taskManager.create(func).later(tick).async(async).submit())
global.setGlobal('setInterval', (func: Function, tick: number, async: boolean = false) => this.taskManager.create(func).timer(tick).async(async).submit())
global.setGlobal('setTimeout', (func: Function, tick: number, async: boolean = false) => {
this.taskManager.create(func).later(tick).async(async).submit()
}, { writable: false, configurable: false })
global.setGlobal('setInterval', (func: Function, tick: number, async: boolean = false) => {
this.taskManager.create(func).timer(tick).async(async).submit()
}, { writable: false, configurable: false })
}
loadPlugins() {
let loadPluginStartTime = new Date().getTime()
console.i18n("ms.core.plugin.initialize")
this.pluginManager.scan(this.pluginFolder);
this.pluginManager.build();
this.pluginManager.load();
this.pluginManager.enable();
this.pluginManager.scan(this.pluginFolder)
this.pluginManager.build()
this.pluginManager.load(this.pluginManager.getPlugins())
this.pluginManager.enable(this.pluginManager.getPlugins())
console.i18n("ms.core.plugin.completed", { time: (new Date().getTime() - loadPluginStartTime) / 1000 })
}
disable() {
console.i18n("ms.core.engine.disable")
this.pluginManager.disable();
this.taskManager.disable();
this.pluginManager.disable(this.pluginManager.getPlugins())
this.taskManager.disable()
//@ts-ignore
require.disable()
}
@@ -54,22 +61,22 @@ class MiaoScriptCore {
function detectServer(): constants.ServerType {
try {
Java.type("org.bukkit.Bukkit");
Java.type("org.bukkit.Bukkit")
return constants.ServerType.Bukkit
} catch (ex) {
}
try {
Java.type("org.spongepowered.api.Sponge");
Java.type("org.spongepowered.api.Sponge")
return constants.ServerType.Sponge
} catch (ex) {
}
try {
Java.type("cn.nukkit.Nukkit");
Java.type("cn.nukkit.Nukkit")
return constants.ServerType.Nukkit
} catch (ex) {
}
try {
Java.type("net.md_5.bungee.api.ProxyServer");
Java.type("net.md_5.bungee.api.ProxyServer")
return constants.ServerType.Bungee
} catch (ex) {
}
@@ -77,27 +84,29 @@ function detectServer(): constants.ServerType {
}
function initialize() {
// @ts-ignore
try { engineLoad({ script: http.get("http://ms.yumc.pw/api/plugin/download/name/initialize"), name: 'core/initialize.js' }) } catch (error) { console.debug(error) }
try {
let corePackageStartTime = new Date().getTime()
container.bind(ContainerInstance).toConstantValue(container);
container.bind(plugin.PluginInstance).toConstantValue(base.getInstance());
container.bind(plugin.PluginFolder).toConstantValue('plugins');
let type = detectServer();
console.i18n("ms.core.initialize.detect", { scope: global.scope, type });
container.bind(server.ServerType).toConstantValue(type);
console.i18n("ms.core.package.initialize", { scope: global.scope, type });
require(`${global.scope}/${type}`).default(container);
container.bind(ContainerInstance).toConstantValue(container)
container.bind(plugin.PluginInstance).toConstantValue(base.getInstance())
container.bind(plugin.PluginFolder).toConstantValue('plugins')
let type = detectServer()
console.i18n("ms.core.initialize.detect", { scope: global.scope, type })
container.bind(server.ServerType).toConstantValue(type)
console.i18n("ms.core.package.initialize", { scope: global.scope, type })
require(`${global.scope}/${type}`).default(container)
require(`${global.scope}/plugin`)
container.load(buildProviderModule());
console.i18n("ms.core.package.completed", { scope: global.scope, type, time: (Date.now() - corePackageStartTime) / 1000 });
container.load(buildProviderModule())
console.i18n("ms.core.package.completed", { scope: global.scope, type, time: (Date.now() - corePackageStartTime) / 1000 })
let disable = container.get<MiaoScriptCore>(MiaoScriptCore).enable()
console.i18n("ms.core.engine.completed", { time: (Date.now() - global.NashornEngineStartTime) / 1000 });
return disable;
console.i18n("ms.core.engine.completed", { time: (Date.now() - global.NashornEngineStartTime) / 1000 })
return disable
} catch (error) {
console.i18n("ms.core.initialize.error", { error });
console.i18n("ms.core.initialize.error", { error })
console.ex(error)
return () => console.i18n('ms.core.engine.disable.abnormal')
}
}
export default initialize();
export default initialize()

1
packages/i18n/.npmignore Symbolic link
View File

@@ -0,0 +1 @@
../../.npmignore

View File

@@ -1,3 +1,4 @@
ms.i18n.completed: "Internationalization component initialization completed. Current Language: English"
ms.ployfill.initialize: "Initialization Java Nashorn ployfill. Please wait..."
ms.ployfill.completed: "Java Nashorn ployfill loading completed... Cost ({time}s)!"
@@ -38,7 +39,10 @@ ms.plugin.manager.stage.exec.error: "§6Plugin §b{plugin} §6exec §d{executor}
ms.plugin.manager.stage.load: "Loading"
ms.plugin.manager.stage.enable: "Enabling"
ms.plugin.manager.stage.disable: "Disabling"
ms.plugin.manager.build.error: "§6Load Plugin From §b{file} §6failed. §4Error: §c{error}"
ms.plugin.manager.build.update: "Auto Update Plugin {name} ..."
ms.plugin.manager.build.not.extends: "§4Found error plugin §b{source} §4it's not extends interfaces.Plugin, the plugin will be ignore!"
ms.plugin.manager.build.exists: "§4Found duplicate plugin §b{exists} §4and §b{source}§4. the first plugin will be ignore!"
ms.plugin.manager.config.load.error: "[{plugin}] config {name}.{format} load failed. Error: {error}"
ms.plugin.manager.config.save.error: "[{plugin}] config {name}.{format} save failed. Error: {error}"
ms.plugin.manager.config.save.default: "[{plugin}] config {name}.{format} not exists. auto create from default variable..."

View File

@@ -1,3 +1,4 @@
ms.i18n.completed: "国际化组件 初始化完成 当前语言: 简体中文"
ms.ployfill.initialize: "加载 Java Nashorn 补丁. 请稍候..."
ms.ployfill.completed: "Java Nashorn 补丁 加载完成... 耗时 ({time}s)!"
@@ -38,7 +39,10 @@ ms.plugin.manager.stage.exec.error: "§6插件 §b{plugin} §6执行 §d{executo
ms.plugin.manager.stage.load: "加载"
ms.plugin.manager.stage.enable: "启用"
ms.plugin.manager.stage.disable: "关闭"
ms.plugin.manager.build.error: "§6从文件 §b{file} §6加载插件失败 §4错误: §c{error}"
ms.plugin.manager.build.update: "自动更新插件 {name} ..."
ms.plugin.manager.build.not.extends: "§4发现错误的插件 §b{source} §4未继承接口 interfaces.Plugin, 将不会被载入到服务器!"
ms.plugin.manager.build.duplicate: "§4发现已存在插件 §b{exists} §4和 §b{source}§4 存在冲突. 已存在插件将会被替换!"
ms.plugin.manager.config.load.error: "[{plugin}] 配置 {name}.{format} 加载失败. 错误: {error}"
ms.plugin.manager.config.save.error: "[{plugin}] 配置 {name}.{format} 保存失败. 错误: {error}"
ms.plugin.manager.config.save.default: "[{plugin}] 配置 {name}.{format} 不存在. 从默认值自动创建保存..."

View File

@@ -1,6 +1,6 @@
{
"name": "@ccms/i18n",
"version": "0.6.1",
"version": "0.6.7",
"description": "MiaoScript i18n package",
"keywords": [
"miaoscript",
@@ -22,10 +22,10 @@
"@types/js-yaml": "^3.12.3",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"typescript": "^3.8.3"
"typescript": "^3.9.2"
},
"dependencies": {
"@ccms/nashorn": "^0.6.1",
"@ccms/nashorn": "^0.6.7",
"js-yaml": "^3.13.1"
},
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"

View File

@@ -45,6 +45,7 @@ export class Translate {
console.i18n = (name: string, param?: TranslateParam) => {
console.log(this.translate(name, param))
}
console.i18n('ms.i18n.completed')
}
readYamlFile(dir: string, name: string) {

1
packages/nashorn/.npmignore Symbolic link
View File

@@ -0,0 +1 @@
../../.npmignore

View File

@@ -1,6 +1,6 @@
{
"name": "@ccms/nashorn",
"version": "0.6.1",
"version": "0.6.7",
"description": "MiaoScript api package",
"keywords": [
"miaoscript",
@@ -22,6 +22,6 @@
"devDependencies": {
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"typescript": "^3.8.3"
"typescript": "^3.9.2"
}
}

View File

@@ -45,8 +45,9 @@ declare global {
logger: any;
debug: boolean;
level: string;
eventCenter: EventEmitter;
NashornEngineStartTime: number;
setGlobal: (key: string, value: any) => void;
setGlobal: (key: string, value: any, config?: PropertyDescriptor & ThisType<any>) => void;
noop: () => void;
console: Console;
}
@@ -70,6 +71,9 @@ declare global {
console(...args: any): void;
i18n(name: string, ...params: any[]): void;
}
interface ProxyConstructor {
newProxy<T extends object>(target: T, handler: ProxyHandler<T>): T;
}
}
export { };

1
packages/nodejs/.npmignore Symbolic link
View File

@@ -0,0 +1 @@
../../.npmignore

View File

@@ -1,6 +1,6 @@
{
"name": "@ccms/nodejs",
"version": "0.6.1",
"version": "0.6.7",
"description": "MiaoScript nodejs package",
"keywords": [
"miaoscript",
@@ -21,10 +21,10 @@
"devDependencies": {
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"typescript": "^3.8.3"
"typescript": "^3.9.2"
},
"dependencies": {
"@ccms/nashorn": "^0.6.1"
"@ccms/nashorn": "^0.6.7"
},
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
}

1
packages/nukkit/.npmignore Symbolic link
View File

@@ -0,0 +1 @@
../../.npmignore

View File

@@ -1,6 +1,6 @@
{
"name": "@ccms/nukkit",
"version": "0.6.2",
"version": "0.6.7",
"description": "MiaoScript nukkit package",
"keywords": [
"miaoscript",
@@ -21,11 +21,11 @@
"devDependencies": {
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"typescript": "^3.8.3"
"typescript": "^3.9.2"
},
"dependencies": {
"@ccms/api": "^0.6.1",
"@ccms/common": "^0.6.2",
"@ccms/container": "^0.6.0"
"@ccms/api": "^0.6.7",
"@ccms/common": "^0.6.7",
"@ccms/container": "^0.6.7"
}
}

View File

@@ -45,6 +45,9 @@ export class NukkitServer implements server.Server {
getNettyPipeline() {
throw new Error("Method not implemented.");
}
getRootLogger() {
return Packages.org.apache.logging.log4j.LogManager.getRootLogger()
}
sendJson(sender: string | any, json: object | string): void {
throw new Error("Method not implemented.");
}

View File

@@ -0,0 +1 @@
../../.npmignore

View File

@@ -1,6 +1,6 @@
{
"name": "@ccms/ployfill",
"version": "0.6.1",
"version": "0.6.7",
"description": "MiaoScript ployfill package",
"author": "MiaoWoo <admin@yumc.pw>",
"homepage": "https://github.com/circlecloud/ms.git",
@@ -14,13 +14,13 @@
"test": "echo \"Error: run tests from root\" && exit 1"
},
"dependencies": {
"@ccms/i18n": "^0.6.1",
"@ccms/nashorn": "^0.6.1",
"core-js": "^3.6.4"
"@ccms/i18n": "^0.6.7",
"@ccms/nashorn": "^0.6.7",
"core-js": "^3.6.5"
},
"devDependencies": {
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"typescript": "^3.8.3"
"typescript": "^3.9.2"
}
}

View File

@@ -6,6 +6,7 @@ i18n.initialize();
console.i18n("ms.ployfill.initialize");
require('./es5-ext');
require('core-js');
require('./node-shim');
global.setGlobal('Proxy', require('./proxy').Proxy)
global.setGlobal('XMLHttpRequest', require('./xml-http-request').XMLHttpRequest)
global.setGlobal('Blob', require('blob-polyfill').Blob)

View File

@@ -0,0 +1,8 @@
global.setGlobal('process', {
env: {
__noSuchProperty__: (prop) => {
return Packages.java.lang.System.getenv(prop)
}
},
platform: Packages.java.lang.System.getProperty("os.name")
}, {})

View File

@@ -82,10 +82,12 @@ export class XMLHttpRequest {
private _url: string;
private _async: boolean;
private _mimeType: string;
private _requestHeaders: HttpHeader = {};
private _status: number = 0;
private _statusText: string = null;
private _response: any;
private _responseText: any;
private _responseURL: string;
private _responseHeaders: HttpHeader = {};
@@ -114,10 +116,10 @@ export class XMLHttpRequest {
return this._statusText;
}
get response() {
return this._response ? JSON.parse(this._response) : this._response;
return this._response || this.get();
}
get responseText() {
return this._response;
return this._responseText;
}
get responseXML() {
return this._response;
@@ -126,17 +128,17 @@ export class XMLHttpRequest {
return this._responseURL;
}
onload() { }
onerror(ex: Error) { }
onabort() { }
onprogress() { }
ontimeout(ex: Error) { }
onloadend() { }
onloadstart() { }
onreadystatechange() { }
public onload: () => void;
public onerror: (ex: Error) => void;
public onabort: () => void;
public onprogress: () => void;
public ontimeout: (ex: Error) => void;
public onloadend: () => void;
public onloadstart: () => void;
public onreadystatechange: () => void;
setRequestHeader(key: string, val: string) {
this._connection.setRequestProperty(key, val);
this._requestHeaders[key] = val;
}
getResponseHeader(key: string): string {
return this._responseHeaders[key];
@@ -151,6 +153,8 @@ export class XMLHttpRequest {
this._mimeType = mimeType;
}
open(method: RequestMethod, url: string, async: boolean = true, user?: string, password?: string) {
if (this._readyState !== ReadyState.UNSENT) { throw new Error(`Error Status ${this._readyState}!`) }
this._method = method;
this._url = url;
this._async = async;
@@ -169,33 +173,39 @@ export class XMLHttpRequest {
this.setReadyState(ReadyState.OPENED);
}
send(body?: string | object): Future<string> {
for (const header in this._requestHeaders) {
this._connection.setRequestProperty(header, this._requestHeaders[header]);
}
if (this._readyState !== ReadyState.OPENED) { throw new Error(`Error Status ${this._readyState}!`) }
let future = executor.submit(new Callable({ call: () => this._send(body) }));
if (!this._async) { future.get() }
return future;
}
get() {
switch (this._responseType) {
case "json":
return this.response;
case "text":
return this.responseText;
default:
throw Error(`Unsupport ResponseType: ${this._responseType} !`)
if (this._response === undefined) {
switch (this._responseType) {
case "json":
return this._response = JSON.parse(this._responseText);
case "text":
return this._response = this._responseText;
default:
throw Error(`Unsupport ResponseType: ${this._responseType} !`)
}
}
return this._response;
}
abort() {
this._connection.disconnect();
this.onabort();
this.onabort && this.onabort();
}
private _send(body?: string | object) {
try {
this._connection.connect();
this.onloadstart();
this.onloadstart && this.onloadstart();
if (body) {
let bodyType = Object.prototype.toString.call(body);
if (bodyType !== '[object String]') { throw new Error(`body(${bodyType}) must be string!`) }
if (typeof body !== "string") { throw new Error(`body(${bodyType}) must be string!`) }
var out = this._connection.getOutputStream();
out.write(new JavaString(body).getBytes(UTF_8));
out.flush();
@@ -204,15 +214,15 @@ export class XMLHttpRequest {
this.setReadyState(ReadyState.LOADING);
this._status = this._connection.getResponseCode();
this._statusText = this._connection.getResponseMessage();
this.setResponseHeaders(this._connection.getHeaderFields());
if (this._status >= 0 && this._status < 300) {
this._response = this.readOutput(this._connection.getInputStream());
this._responseText = this.readOutput(this._connection.getInputStream());
} else if (this._status >= 300 && this._status < 400) {
this._responseURL = this.getResponseHeader('Location');
} else {
this._response = this.readOutput(this._connection.getErrorStream());
this._responseText = this.readOutput(this._connection.getErrorStream());
}
this.onloadend();
this.setResponseHeaders(this._connection.getHeaderFields());
this.onloadend && this.onloadend();
} catch (ex) {
if (ex instanceof SocketTimeoutException && this.ontimeout) {
return this.ontimeout(ex)
@@ -227,7 +237,6 @@ export class XMLHttpRequest {
}
private setResponseHeaders(header: any) {
this._responseHeaders = {};
header.forEach((key: string | number, value: string | any[]) => {
this._responseHeaders[key] = value[value.length - 1]
});
@@ -235,7 +244,7 @@ export class XMLHttpRequest {
private setReadyState(state: ReadyState) {
this._readyState = state;
this.onreadystatechange();
this.onreadystatechange && this.onreadystatechange();
}
private readOutput(input: any) {

1
packages/plugin/.npmignore Symbolic link
View File

@@ -0,0 +1 @@
../../.npmignore

View File

@@ -1,6 +1,6 @@
{
"name": "@ccms/plugin",
"version": "0.6.2",
"version": "0.6.7",
"description": "MiaoScript api package",
"keywords": [
"miaoscript",
@@ -22,13 +22,13 @@
"@types/js-yaml": "^3.12.3",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"typescript": "^3.8.3"
"typescript": "^3.9.2"
},
"dependencies": {
"@ccms/api": "^0.6.1",
"@ccms/common": "^0.6.2",
"@ccms/container": "^0.6.0",
"@ccms/i18n": "^0.6.1",
"@ccms/api": "^0.6.7",
"@ccms/common": "^0.6.7",
"@ccms/container": "^0.6.7",
"@ccms/i18n": "^0.6.7",
"js-yaml": "^3.13.1"
}
}

View File

@@ -10,7 +10,7 @@ export class YamlPluginConfig implements PluginConfigLoader {
return yaml.safeLoad(content);
}
dump(variable: any): string {
return yaml.safeDump(variable);
return yaml.safeDump(variable, { skipInvalid: true });
}
}

View File

@@ -10,6 +10,7 @@ import { getPluginMetadatas, getPluginCommandMetadata, getPluginListenerMetadata
export function plugin(metadata: interfaces.PluginMetadata) {
return function (target: any) {
metadata.target = target;
metadata.type = "ioc";
decorate(injectable(), target);
Reflect.defineMetadata(METADATA_KEY.plugin, metadata, target);
const previousMetadata: Map<string, interfaces.PluginMetadata> = getPluginMetadatas();

View File

@@ -55,6 +55,10 @@ export namespace interfaces {
* 插件源文件 必须指定为 __filename
*/
source: string;
/**
* 插件类型 默认为 ioc 执行 MiaoScript 加载逻辑
*/
type?: string;
/**
* 插件本体
*/
@@ -96,6 +100,10 @@ export namespace interfaces {
* 配置文件格式 默认 yml
*/
format?: string;
/**
* 是否为只读(关闭时将不会自动保存)
*/
readonly?: boolean;
}
export type PluginLike = Plugin | string;
}

View File

@@ -16,7 +16,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
@inject(plugin.PluginInstance)
private pluginInstance: any
@inject(plugin.PluginFolder)
private pluginFolder: string;
private pluginFolder: string
@inject(server.ServerType)
private serverType: string
@inject(command.Command)
@@ -25,17 +25,19 @@ export class PluginManagerImpl implements plugin.PluginManager {
private EventManager: event.Event
private initialized: boolean = false
private pluginMap: Map<string, interfaces.Plugin>
private plugnMappings: Map<string, interfaces.PluginMetadata>
private pluginRequireMap: Map<string, any>
private pluginInstanceMap: Map<string, interfaces.Plugin>
private pluginMetadataMap: Map<string, interfaces.PluginMetadata>
initialize() {
if (this.pluginInstance !== null && this.initialized !== true) {
// 如果plugin不等于null 则代表是正式环境
console.i18n('ms.plugin.initialize', { plugin: this.pluginInstance, loader: Thread.currentThread().contextClassLoader })
this.pluginMap = new Map()
console.i18n('ms.plugin.event.map', { count: this.EventManager.mapEventName().toFixed(0), type: this.serverType });
this.initialized = true;
this.plugnMappings = getPluginSources();
console.i18n('ms.plugin.event.map', { count: this.EventManager.mapEventName().toFixed(0), type: this.serverType })
this.pluginRequireMap = new Map()
this.pluginInstanceMap = new Map()
this.pluginMetadataMap = getPluginSources()
this.initialized = true
}
}
@@ -67,11 +69,11 @@ export class PluginManagerImpl implements plugin.PluginManager {
* @param file java.io.File
*/
loadFromFile(file: string): interfaces.Plugin {
this.loadPlugin(file)
let plugin = this.buildPlugin(this.plugnMappings.get(file.toString()))
let metadata = this.loadPlugin(file)
let plugin = this.buildPlugin(metadata && metadata.description ? metadata.description : this.pluginMetadataMap.get(file.toString()))
this.load(plugin)
this.enable(plugin)
return plugin;
return plugin
}
load(...args: any[]): void {
@@ -94,6 +96,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
disable(...args: any[]): void {
this.checkAndGet(args[0]).forEach((plugin: interfaces.Plugin) => {
this.runPluginStage(plugin, 'disable', () => {
this.saveConfig(plugin)
this.unregistryCommand(plugin)
this.unregistryListener(plugin)
})
@@ -108,7 +111,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
}
getPlugins() {
return this.pluginMap
return this.pluginInstanceMap
}
private runCatch(pl: any, func: string) {
@@ -120,10 +123,11 @@ export class PluginManagerImpl implements plugin.PluginManager {
}
}
private checkAndGet(name: string | interfaces.Plugin | undefined): Map<string, interfaces.Plugin> | interfaces.Plugin[] {
if (name == undefined) { return this.pluginMap }
if (typeof name == 'string' && this.pluginMap.has(name)) { return [this.pluginMap.get(name)] }
private checkAndGet(name: string | interfaces.Plugin | undefined | any): Map<string, interfaces.Plugin> | interfaces.Plugin[] {
if (name == this.pluginInstanceMap) { return this.pluginInstanceMap }
if (typeof name == 'string' && this.pluginInstanceMap.has(name)) { return [this.pluginInstanceMap.get(name)] }
if (name instanceof interfaces.Plugin) { return [name as interfaces.Plugin] }
if (name.description || name.description.name) { return [name as interfaces.Plugin] }
throw new Error(`Plugin ${JSON.stringify(name)} not exist!`)
}
@@ -155,17 +159,19 @@ export class PluginManagerImpl implements plugin.PluginManager {
* JS类型插件预加载
*/
private loadJsPlugins(files: any[]) {
files.filter(file => file.name.endsWith(".js")).forEach(file => this.loadPlugin(file))
files.filter(file => file.name.endsWith(".js")).forEach(file => {
try {
this.loadPlugin(file)
} catch (ex) {
console.i18n("ms.plugin.manager.initialize.error", { name: file.name, ex })
console.ex(ex)
}
})
}
private loadPlugin(file: any) {
try {
this.updatePlugin(file)
this.createPlugin(file)
} catch (ex) {
console.i18n("ms.plugin.manager.initialize.error", { name: file.name, ex })
console.ex(ex)
}
this.updatePlugin(file)
return this.createPlugin(file.toString())
}
private updatePlugin(file: any) {
@@ -191,31 +197,46 @@ export class PluginManagerImpl implements plugin.PluginManager {
private createPlugin(file: string) {
//@ts-ignore
require(file + '', { cache: false })
let instance = require(file, { cache: false })
this.pluginRequireMap.set(file, instance)
return instance
}
private buildPlugins() {
let metadatas = []
let pluginMetadatas = getPluginMetadatas()
for (const [_, metadata] of pluginMetadatas) {
for (const [_, metadata] of pluginMetadatas) { metadatas.push(metadata) }
for (const [_, instance] of this.pluginRequireMap) { if (instance.description) { this.buildPlugin(instance.description) } }
for (const metadata of metadatas) {
if (!this.allowProcess(metadata.servers)) { continue }
this.buildPlugin(metadata)
}
}
private buildPlugin(metadata: interfaces.PluginMetadata) {
try {
this.bindPlugin(metadata)
let pluginInstance = this.container.getNamed<interfaces.Plugin>(plugin.Plugin, metadata.name)
if (!(pluginInstance instanceof interfaces.Plugin)) {
console.i18n('ms.plugin.manager.build.not.extends', { source: metadata.source })
return
}
this.pluginMap.set(metadata.name, pluginInstance)
return pluginInstance;
} catch (ex) {
console.i18n("ms.plugin.manager.initialize.error", { name: metadata.name, ex })
console.ex(ex)
let pluginInstance: interfaces.Plugin
switch (metadata.type) {
case "ioc":
try {
this.bindPlugin(metadata)
pluginInstance = this.container.getNamed<interfaces.Plugin>(plugin.Plugin, metadata.name)
if (!(pluginInstance instanceof interfaces.Plugin)) {
console.i18n('ms.plugin.manager.build.not.extends', { source: metadata.source })
return
}
} catch (ex) {
console.i18n("ms.plugin.manager.initialize.error", { name: metadata.name, ex })
console.ex(ex)
}
break
case "basic":
pluginInstance = this.pluginRequireMap.get(metadata.source.toString())
break
default:
throw new Error('§4不支持的插件类型 请检查加载器是否正常启用!')
}
this.pluginInstanceMap.set(metadata.name, pluginInstance)
return pluginInstance
}
private bindPlugin(metadata: interfaces.PluginMetadata) {
@@ -231,15 +252,35 @@ export class PluginManagerImpl implements plugin.PluginManager {
}
private loadConfig(plugin: interfaces.Plugin) {
let configs = getPluginConfigMetadata(plugin);
let configs = getPluginConfigMetadata(plugin)
for (let [_, config] of configs) {
let configFile = fs.concat(root, this.pluginFolder, plugin.description.name, config.name + '.' + config.format)
let configFactory = getConfigLoader(config.format);
if (!fs.exists(configFile)) {
base.save(configFile, configFactory.dump(plugin[config.variable]))
console.i18n("ms.plugin.manager.config.save.default", { plugin: plugin.description.name, name: config.name, format: config.format })
} else {
plugin[config.variable] = configFactory.load(base.read(configFile));
try {
let configFile = fs.concat(root, this.pluginFolder, plugin.description.name, config.name + '.' + config.format)
let configFactory = getConfigLoader(config.format)
if (!fs.exists(configFile)) {
base.save(configFile, configFactory.dump(plugin[config.variable]))
console.i18n("ms.plugin.manager.config.save.default", { plugin: plugin.description.name, name: config.name, format: config.format })
} else {
plugin[config.variable] = configFactory.load(base.read(configFile))
plugin[config.variable].save = () => base.save(configFile, configFactory.dump(plugin[config.variable]))
}
} catch (error) {
console.i18n("ms.plugin.manager.config.load.error", { plugin: plugin.description.name, name: config.name, format: config.format, error })
console.ex(error)
}
}
}
private saveConfig(plugin: interfaces.Plugin) {
let configs = getPluginConfigMetadata(plugin)
for (let [_, config] of configs) {
try {
let configFile = fs.concat(root, this.pluginFolder, plugin.description.name, config.name + '.' + config.format)
let configFactory = getConfigLoader(config.format)
if (!config.readonly) { base.save(configFile, configFactory.dump(plugin[config.variable])) }
} catch (error) {
console.i18n("ms.plugin.manager.config.save.error", { plugin: plugin.description.name, name: config.name, format: config.format, error })
console.ex(error)
}
}
}
@@ -279,7 +320,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
}
private execPluginStage(pluginInstance: interfaces.Plugin, stageName: string) {
let stages = getPluginStageMetadata(pluginInstance, stageName);
let stages = getPluginStageMetadata(pluginInstance, stageName)
for (const stage of stages) {
if (!this.allowProcess(stage.servers)) { continue }
console.i18n("ms.plugin.manager.stage.exec", { plugin: pluginInstance.description.name, name: stage.executor, stage: stageName, servers: stage.servers })

1
packages/plugins/.npmignore Symbolic link
View File

@@ -0,0 +1 @@
../../.npmignore

View File

@@ -1,7 +1,7 @@
{
"private": true,
"name": "@ccms/plugins",
"version": "0.6.2",
"version": "0.6.7",
"description": "MiaoScript plugins package",
"keywords": [
"miaoscript",
@@ -22,11 +22,11 @@
"devDependencies": {
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"typescript": "^3.8.3"
"typescript": "^3.9.2"
},
"dependencies": {
"@ccms/api": "^0.6.1",
"@ccms/container": "^0.6.0",
"@ccms/plugin": "^0.6.2"
"@ccms/api": "^0.6.7",
"@ccms/container": "^0.6.7",
"@ccms/plugin": "^0.6.7"
}
}

View File

@@ -1,78 +0,0 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<!-- UC应用模式 -->
<meta name="browsermode" content="application">
<!-- QQ应用模式 -->
<meta name="x5-page-mode" content="app">
<title>MiaoConsole 调试工具</title>
<script src="https://cdn.jsdelivr.net/npm/axios@0.19.0/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/avalon2@2.2.10/dist/avalon.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.4.1/dist/js/bootstrap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/js-yaml@3.13.0/dist/js-yaml.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/messenger-hubspot@1.5.0/build/js/messenger.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/messenger-hubspot@1.5.0/build/js/messenger-theme-future.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xterm@3.12.2/dist/xterm.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xterm@3.12.2/dist/addons/fit/fit.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xterm@3.12.2/dist/addons/attach/attach.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xterm@3.12.2/dist/addons/fullscreen/fullscreen.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/xterm@3.12.2/dist/xterm.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/xterm@3.12.2/dist/addons/fullscreen/fullscreen.css">
<script src="https://cdn.jsdelivr.net/npm/monaco-editor@0.18.1/min/vs/loader.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/monaco-editor@0.18.1/min/vs/editor/editor.main.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.4.1/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@3.0.1/github-markdown.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/messenger-hubspot@1.5.0/build/css/messenger.min.css">
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/messenger-hubspot@1.5.0/build/css/messenger-theme-future.min.css">
<script src="https://cdn.jsdelivr.net/npm/axios@0.19.0/dist/axios.min.js"></script>
<!-- <script src="https://raw.githubusercontent.com/imaya/zlib.js/develop/bin/gzip.min.js"></script>
<script src="https://raw.githubusercontent.com/imaya/zlib.js/develop/bin/gunzip.min.js"></script> -->
<script src="js/message.js"></script>
<script src="js/term.js"></script>
<script src="js/websocket.js"></script>
<script src="js/main.js"></script>
<script src="js/editor.js"></script>
</head>
<body noscroll="true">
<div class="container-fluid bs-docs-container" :controller="main">
<h3>欢迎使用 MiaoConsole 调试控制台</h3>
<div class="input-group">
<span class="input-group-addon">服务器地址</span>
<input id="address" class="form-control" :duplex="@server" :keydown="@connect" style="width: 100%"></input>
<a class="input-group-addon btn" :click="@connect">连接</a>
</div>
<div class="panel panel-success" style="margin-top: 10px; height: 332px;">
<div class="panel-heading">服务器日志 当前服务器类型: {{@type}}</div>
<div id="terminal" style="height: 300px; width:100%;"></div>
</div>
<div class="progress progress-striped active" :visible='@classes.total != @classes.loaded'>
<div class="progress-bar progress-bar-primary" role="progressbar" aria-valuenow="60" aria-valuemin="0"
aria-valuemax="100" :css="{width: (@classes.loaded/@classes.total*100) +'%', 'min-width': '20em'}">
<span>正在加载 {{@type}} 类型定义 {{@classes.loaded}}/{{@classes.total}}({{~~(@classes.loaded/@classes.total*100)|percent}}%) </span>
</div>
</div>
<div class="panel panel-info" :visible='@classes.total == @classes.loaded && @classes.total != 0'>
<div class="panel-heading">代码编辑器</div>
<label class="col-sm-1 control-label">代码页</label>
<label :for="el in @codes" class="radio-inline">
<input type="radio" :duplex="@code" :attr="{value:el}"> {{el}}
</label>
<div id="editor" style="height: 450px; width:100%;"></div>
</div>
</div>
</body>
</html>

View File

@@ -1,69 +0,0 @@
let editor
let monaco_path = 'https://cdn.jsdelivr.net/npm/monaco-editor@0.18.1/min'
require.config({ paths: { 'vs': monaco_path + '/vs' } });
window.MonacoEnvironment = { getWorkerUrl: () => proxy };
let proxy = URL.createObjectURL(new Blob([`self.MonacoEnvironment = {baseUrl: '${monaco_path}/'};
importScripts('${monaco_path}/vs/base/worker/workerMain.js');`], { type: 'text/javascript' }));
function loadExtraLibs(ts_d_src, filter) {
let count = 0;
axios.get(`${ts_d_src}/index.d.ts`).then(async result => {
monaco.languages.typescript.javascriptDefaults.addExtraLib(result.data, 'file:///src/typings/index.d.ts')
let classes = result.data.split('\n').map(line => line.match(/.*\.\/(.*)".*/)).filter(line => line).map(dts => dts[1])
if (filter) {
classes = classes.filter(line => filter(line))
}
main.classes.total += classes.length
for (let fname of classes) {
if (count++ % 50 == 0) { await axios.get(`${ts_d_src}/${fname}`) }
loadExtraLib(`${ts_d_src}/${fname}`, `file:///src/typings/${fname}`)
}
})
}
function loadExtraLib(url, file) {
axios.get(url).then(result => monaco.languages.typescript.javascriptDefaults.addExtraLib(result.data, file)).finally(() => main.classes.loaded++)
}
require(["vs/editor/editor.main"], async function() {
main.classes.total = 0
main.classes.loaded = 0
editor = monaco.editor.create(document.getElementById('editor'), {
value: '',
language: 'javascript',
automaticLayout: true,
scrollBeyondLastLine: false,
theme: 'vs-dark'
});
main.load(editor)
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_S, function() {
main.save(editor)
})
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_R, function() {
main.send('execCode', getSelectContent(editor) || editor.getValue())
})
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_E, function() {
main.send('execCommand', getSelectContent(editor))
})
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_Q, function() {
main.switch(editor)
})
loadExtraLibs(`https://cdn.jsdelivr.net/gh/circlecloud/ms@master/packages/types/dist/typings/jdk`, (line) => line.startsWith('java.lang'))
if (main.type !== 'unknow') {
loadExtraLibs(`https://cdn.jsdelivr.net/gh/circlecloud/ms@master/packages/types/dist/typings/${main.type}`)
}
});
function getSelectContent(editor) {
let selInfo = editor.getSelection();
if (selInfo.startLineNumber === selInfo.endLineNumber) {
return editor.getModel().getLineContent(selInfo.startLineNumber).substr(selInfo.startColumn - 1, selInfo.endColumn - selInfo.startColumn);
} else {
let first = editor.getModel().getLineContent(selInfo.startLineNumber).substr(selInfo.startColumn - 1)
let content = '\n'
for (let i = selInfo.startLineNumber + 1; i < selInfo.endLineNumber; i++) {
content += editor.getModel().getLineContent(i) + '\n'
}
let last = editor.getModel().getLineContent(selInfo.endLineNumber).substr(0, selInfo.endColumn - 1)
return first + content + last
}
}

View File

@@ -1,55 +0,0 @@
var SPLIT_LINE = '\\M\\W\\S|T|S|S/L/T/'
let serverKey = 'MiaoScript:server'
let codeStorageKey = "MiaoScript:code:"
var main = avalon.define({
$id: 'main',
server: window.localStorage.getItem(serverKey) || location.host,
type: 'unknow',
logs: '',
codes: ["default", "bukkit", "sponge", "bungee", "common", "test", "dev", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
code: 'default',
classes: {
total: 0,
loaded: 0,
},
precent: () => {
return classes.total
},
log: (info) => {
info.split("\n").forEach((line) => { term.writeln(mcColor2ANSI(line + '§r')) })
},
send: (type, content) => {
if (!ws || ws.readyState != 1) { term.writeln('Please Connect to Server first!'); return; }
ws.send(`${type}${SPLIT_LINE}${content}`);
},
connect: (event = { key: 'Enter' }) => {
if (event.key !== "Enter") {
return;
}
connectWebSocket()
},
init: () => {
if (main.server) {
main.connect()
}
},
load: (editor) => {
editor.setValue(window.localStorage.getItem(codeStorageKey + main.code) || '')
},
save: (editor) => {
window.localStorage.setItem(codeStorageKey + main.code, editor.getValue())
showMessenger('代码页 ' + main.code + ' 保存成功!')
},
switch: (editor) => {
let index = main.codes.indexOf(main.code) + 1
main.code = main.codes[index == main.codes.length ? 0 : index]
}
});
main.$watch('code', (now, old, name) => {
window.localStorage.setItem(codeStorageKey + old, editor.getValue())
showMessenger('代码页 ' + old + ' 保存成功!')
editor.setValue(window.localStorage.getItem(codeStorageKey + now) || '// empty code page ' + now)
})
main.init()

View File

@@ -1,10 +0,0 @@
$._messengerDefaults = {
extraClasses: 'messenger-fixed messenger-theme-future messenger-on-top messenger-on-right'
};
var showMessenger = function(message, type) {
return Messenger().post({
message: message,
type: type || 'info',
showClo6seButton: true
});
};

View File

@@ -1,54 +0,0 @@
Terminal.applyAddon(fit);
var term = new Terminal();
avalon.ready(() => {
term.open(document.getElementById('terminal'));
window.onresize = () => {
term.fit();
}
window.onresize()
})
term.on('data', (data) => {
if (data == '\r') {
term.writeln(data)
}
});
term.attachCustomKeyEventHandler(e => {
if (e.ctrlKey && e.key == 'c' && term.hasSelection()) {
showMessenger('内容已复制到粘贴板')
return false;
}
if (e.ctrlKey && e.key == 'v') {
return false;
}
return true;
})
var colorMap = []
colorMap['0'] = '38;5;0'
colorMap['1'] = '38;5;4'
colorMap['2'] = '38;5;2'
colorMap['3'] = '38;5;6'
colorMap['4'] = '38;5;1'
colorMap['5'] = '38;5;5'
colorMap['6'] = '38;5;3'
colorMap['7'] = '38;5;7'
colorMap['8'] = '38;5;8'
colorMap['9'] = '38;5;12'
colorMap['a'] = '38;5;10'
colorMap['b'] = '38;5;14'
colorMap['c'] = '38;5;9'
colorMap['d'] = '38;5;13'
colorMap['e'] = '38;5;11'
colorMap['f'] = '38;5;15'
colorMap['r'] = '0'
colorMap['l'] = '1'
colorMap['n'] = '4'
var regexMap = []
for (const c in colorMap) {
regexMap[colorMap[c]] = new RegExp(`§${c}`, "g")
}
function mcColor2ANSI(str) {
for (const regex in regexMap) {
str = str.replace(regexMap[regex], `\u001b[${regex}m`)
}
return str;
}

View File

@@ -1,30 +0,0 @@
var ws;
function connectWebSocket() {
if (ws && ws.readyState == 1) {
ws.close()
}
window.localStorage.setItem(serverKey, main.server)
ws = new WebSocket(`${location.protocol == 'http:' ? 'ws' : 'wss'}://${main.server}/ws`)
ws.onmessage = (event) => {
const [type, obj] = event.data.split(SPLIT_LINE)
switch (type) {
case "log":
main.log(obj)
break;
case "type":
main.type = obj;
break;
}
}
ws.onopen = () => {
main.send("execDetect", "type");
}
ws.onclose = (ev) => {
main.log(`Remote Server Close Connection... ${ev.code}`)
if (ev.code == 1006) {
setTimeout(() => {
main.connect()
}, 1000)
}
}
}

View File

@@ -2,10 +2,12 @@
/// <reference types="@ccms/types/dist/typings/sponge" />
/// <reference types="@ccms/types/dist/typings/bungee" />
import { plugin as pluginApi, server, task } from '@ccms/api'
import { plugin, interfaces, cmd } from '@ccms/plugin'
import { plugin as pluginApi, server, task, constants } from '@ccms/api'
import { plugin, interfaces, cmd, tab, enable, config, disable } from '@ccms/plugin'
import { inject, ContainerInstance, Container } from '@ccms/container'
import io, { Server as SocketIOServer, Socket as SocketIOSocket } from '@ccms/websocket'
import * as fs from '@ccms/common/dist/fs'
import * as reflect from '@ccms/common/dist/reflect'
const suffixMap = {
ts: 'typescript',
@@ -13,7 +15,13 @@ const suffixMap = {
yml: 'yaml'
}
@plugin({ name: 'MiaoConsole', version: '1.0.0', author: 'MiaoWoo', servers: ['!nukkit'], source: __filename })
let help = [
'§6========= §6[§aMiaoConsole§6] 帮助 §aBy §bMiaoWoo §6=========',
'§6/mconsole §atoken [set] §e<Token> §6- §3生成/设置 登录Token',
'§6/mconsole §areload §6- §3重载插件',
]
@plugin({ name: 'MiaoConsole', prefix: 'Console', version: '1.0.0', author: 'MiaoWoo', servers: ['!nukkit'], source: __filename })
export class MiaoConsole extends interfaces.Plugin {
@inject(ContainerInstance)
private container: Container
@@ -25,24 +33,70 @@ export class MiaoConsole extends interfaces.Plugin {
private task: task.TaskManager
@inject(pluginApi.PluginManager)
private pluginManager: pluginApi.PluginManager
@inject(pluginApi.PluginFolder)
private pluginFolder: string
private pipeline: any;
private socketIOServer: SocketIOServer;
private token: string
private pipeline: any
private socketIOServer: SocketIOServer
private rootLogger: any
private appender: any
private handler: any
@config()
private secret = { token: undefined }
load() {
if (this.secret.token) {
this.token = this.secret.token
this.logger.console(`§4已从配置文件加载永久Token 请注意服务器安全!`)
} else {
this.token = Java.type('java.util.UUID').randomUUID().toString()
this.logger.console(`§6已生成随机Token: §3${this.token} §c重启后或重新生成后失效!`)
}
}
@cmd()
mconsole(sender: any, command: string, args: string[]) {
if (args[0] == 'reload') {
// @ts-ignore
require.clear('websocket');
this.pluginManager.reload(this);
let cmdKey = 'cmd' + (args[0] || 'help')
if (!this[cmdKey]) {
console.sender(sender, '§4未知的子命令: §c' + cmdKey)
console.sender(sender, `§6请执行 §b/${command} §ahelp §6查看帮助!`)
return
}
let tfunc = new Function('pipeline', args.join(' '))
tfunc.apply(this, [this.pipeline])
args.shift()
this[cmdKey](sender, ...args)
}
cmdhelp(sender: any) {
this.logger.sender(sender, help)
}
cmdreload(sender: any) {
// @ts-ignore
require.clear('websocket')
this.pluginManager.reload(this)
return
}
cmdtoken(sender: any, sub: string, token: string) {
if (sub == "set") {
this.secret.token = this.token = token
this.logger.sender(sender, '§a已保存§6服务器登录Token:§3', this.token, '§4请勿分享给其他人 防止服务器被攻击!')
return
}
this.token = Java.type('java.util.UUID').randomUUID().toString()
this.logger.sender(sender, '§a已刷新§6服务器登录Token:§3', this.token, '§4请勿分享给其他人 防止服务器被攻击!')
}
@tab()
tabmconsole(sender: any, command: string, args: string[]) {
if (args.length === 1) { return ["reload", "token"] }
if (args[0] == "token") { return ["set"] }
}
enable() {
let count = 0;
let count = 0
let wait = this.task.create(() => {
this.pipeline = this.server.getNettyPipeline()
if (this.pipeline) {
@@ -53,27 +107,92 @@ export class MiaoConsole extends interfaces.Plugin {
if (count > 30) { wait.cancel() }
count++
}).later(20).timer(40).submit()
this.rootLogger = this.server.getRootLogger()
}
@enable({ servers: [constants.ServerType.Bukkit, constants.ServerType.Sponge] })
addLog4jForward() {
if (this.rootLogger) {
let AbstractAppender = Java.type('org.apache.logging.log4j.core.appender.AbstractAppender')
let ProxyAppender = Java.extend(AbstractAppender, {
append: (logEvent) => global.eventCenter.emit('log', logEvent.getMessage().getFormattedMessage())
})
this.appender = new ProxyAppender("ProxyLogger", null, null)
this.appender.start()
this.rootLogger.addAppender(this.appender)
this.rootLogger.setAdditive(true)
}
}
@enable({ servers: [constants.ServerType.Bungee] })
addJavaLoggerForward() {
if (this.rootLogger) {
let AbstractHandler = Java.type('java.util.logging.Handler')
let ProxyHandler = Java.extend(AbstractHandler, {
publish: (record) => global.eventCenter.emit('log', record.getMessage()),
flush: () => { },
close: () => { }
})
this.handler = new ProxyHandler()
this.rootLogger.addHandler(this.handler)
}
}
disable() {
this.socketIOServer?.close()
if (this.socketIOServer) {
this.socketIOServer.close()
global.eventCenter.removeAllListeners('log')
}
if (this.container.isBound(io.Instance)) {
this.container.unbind(io.Instance)
}
}
@disable({ servers: [constants.ServerType.Bukkit, constants.ServerType.Sponge] })
removeLog4jForward() {
try {
this.appender.stop()
this.rootLogger.removeAppender(this.appender)
} catch (error) {
console.ex(error)
}
}
@disable({ servers: [constants.ServerType.Bungee] })
removeJavaLoggerForward() {
try {
this.rootLogger.removeHandler(this.handler)
} catch (error) {
console.ex(error)
}
}
createSocketIOServer() {
this.socketIOServer = io(this.pipeline, {
path: '/ws',
root: '/home/project/TSWorkSpace/ms/packages/plugins/public'
});
root: fs.concat(root, 'wwwroot')
})
this.container.bind(io.Instance).toConstantValue(this.socketIOServer)
}
startSocketIOServer() {
let namespace = this.socketIOServer.of('/MiaoConsole')
global.eventCenter.on('log', (msg) => namespace.emit('log', msg))
namespace.on('connect', (client: SocketIOSocket) => {
this.logger.console(`§6客户端 §b${client.id} §a新建连接...`)
if (!this.token) {
this.logger.console(`§6客户端 §b${client.id} §a请求连接 §4服务器尚未设置 Token 无法连接!`)
client.emit('unauthorized')
client.disconnect(true)
return
}
this.logger.console(`§6客户端 §b${client.id} §a请求连接 §4Token: §c********`)
if (this.token != client.handshake.query.token) {
this.logger.console(`§6客户端 §b${client.id} §4无效请求 请提供正确Token后再次连接!`)
client.emit('unauthorized')
client.disconnect(true)
return
}
this.logger.console(`§6客户端 §b${client.id} §a新建连接 ${this.rootLogger ? '启动日志转发' : '§4转发日志启动失败'}...`)
client.on('type', (fn) => {
fn && fn(this.serverType)
client.emit('log', `Currect Server Version is ${this.server.getVersion()}`)
@@ -86,12 +205,29 @@ export class MiaoConsole extends interfaces.Plugin {
try {
client.emit('log', this.runCode(code, namespace, client))
} catch (ex) {
client.emit('log', '§4代码执行异常\n' + console.stack(ex).join('\n'))
client.emit('log', `§4代码执行异常 错误: ${ex}\n${console.stack(ex).join('\n')}`)
}
})
client.on('edit', (file: string, fn) => {
fn && fn(base.read(file), suffixMap[file.split('.', 2)[1]])
})
client.on('save', (name: string, content: string, fn) => {
this.logger.console(`§6客户端 §b${client.id} §6请求更新插件 §a${name} §6...`)
let file = fs.concat(root, this.pluginFolder, name + '.js')
if (!fs.exists(file)) { return fn('§6插件 §a' + name + ' §6尚未安装 §c请先创建空文件 或安装插件!') }
try {
base.save(file, content)
this.pluginManager.reload(name)
fn('§6插件 §a' + name + ' §6更新成功!')
} catch (error) {
this.logger.error(error)
fn('§6插件 §a' + name + ' §4更新异常 错误: ' + error)
}
})
client.on('error', (error) => {
this.logger.console(`§6客户端 §b${client.id} §c触发异常: ${error}`)
this.logger.error(error)
})
client.on('disconnect', () => {
this.logger.console(`§6客户端 §b${client.id} §c断开连接...`)
})

View File

@@ -9,21 +9,25 @@ import http from '@ccms/common/dist/http'
let help = [
'§6========= §6[§aMiaoScriptPackageManager§6] 帮助 §aBy §bMiaoWoo §6=========',
'§6/mpm §ainstall §e<插件名称> §6- §3安装插件',
'§6/mpm §auninstall §e<插件名称> §6- §3卸载插件',
'§6/mpm §alist [install]§6- §3列出仓库插件[已安装插件]',
'§6/mpm §aupdate §e<插件名称> §6- §3更新插件(无插件名称则更新源)',
'§6/mpm §aupgrade §e<插件名称> §6- §3及时更新插件(update需要重启生效)',
'§6/mpm §areload §e<插件名称> §6- §3重载插件(无插件名称则重载自身)',
'§6/mpm §arun §e<JS代码> §6- §3运行JS代码',
'§6/mpm §adeploy §e<插件名称> §6- §3发布插件',
'§6/mpm §crestart §6- §4重启MiaoScript脚本引擎'
'§6/mpm §ainstall §e<插件名称> §6- §3安装仓库插件',
'§6/mpm §aload §e<插件名称> §6- §3安装本地插件',
'§6/mpm §aunload §e<插件名称> §6- §3卸载已安装插件',
'§6/mpm §areload §e<插件名称> §6- §3重载已安装插件(无名称则重载自身)',
'§6/mpm §alist [i] §6- §3列出仓库插件[已安装的插件]',
'§6/mpm §aupdate §e[插件名称] §6- §3更新插件(无名称则更新源)',
'§6/mpm §aupgrade §e[插件名称] §6- §3升级插件/框架(§4无名称则升级框架§3)',
'§6/mpm §arun §e<JS代码> §6- §3运行JS代码',
'§6/mpm §adeploy §e<插件名称> §6- §3发布插件',
'§6/mpm §crestart §6- §4重启MiaoScript脚本引擎'
];
let langMap = {
'list.header.install': '§6当前 §bMiaoScript §6已安装下列插件:',
'main.command.not.exists': '§4未知的子命令: §c{command}',
'main.command.help.tip': '§6请执行 §b/{command} §ahelp §6查看帮助!',
'list.install.header': '§6当前 §bMiaoScript §6已安装下列插件:',
'list.install.body': '§6插件名称: §b{name} §6版本: §a{version} §6作者: §3{author}',
'list.header': '§6当前 §bMiaoScriptPackageCenter §6中存在下列插件:',
'list.body': '§6插件名称: §b{name} §6版本: §a{version} §6作者: §3{author}',
'list.body': '§6插件名称: §b{name} §6版本: §a{version} §6作者: §3{author} §6更新时间: §9{updated_at}',
'plugin.not.exists': '§6插件 §b{name} §c不存在!',
'plugin.unload.finish': '§6插件 §b{name} §a已卸载!',
'plugin.reload.finish': '§6插件 §b{name} §a重载完成!',
@@ -35,11 +39,18 @@ let langMap = {
'download.finish': '§6插件 §b{name} §a下载完毕 开始加载 ...',
'install.finish': '§6插件 §b{name} §a安装成功!',
'update.finish': '§6插件 §b{name} §a更新成功!',
'upgrade.confirm': '§6您正在尝试升级 §bMiaoScript §c核心 §6请执行 §b/mpm §aupgrade §cconfirm §6确认执行!',
'deploy.token.not.exists': '§4请先配置发布Token!',
'deploy.success': '§6插件 §b{name} §a发布成功! §6服务器返回: §a{msg}',
'deploy.fail': '§6插件 §b{name} §c发布失败! §6服务器返回: §c{msg}',
'run.script': '§b运行脚本:§r {script}',
'run.result': '§a返回结果:§r {result}',
'run.noresult': '§4没有返回结果!',
}
let fallbackMap = langMap
@plugin({ name: 'MiaoScriptPackageManager', prefix: 'PM', version: '1.0.0', author: 'MiaoWoo', source: __filename })
@plugin({ name: 'MiaoScriptPackageManager', prefix: 'PM', version: '1.0.1', author: 'MiaoWoo', source: __filename })
export class MiaoScriptPackageManager extends interfaces.Plugin {
@inject(pluginApi.PluginManager)
private pluginManager: pluginApi.PluginManager;
@@ -57,8 +68,6 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
private translate: Translate;
private subCommnadNameCache: string[];
load() {
this.translate = new Translate({
langMap,
@@ -77,20 +86,34 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
}
main(sender: any, command: string, args: string[]) {
let cmdKey = 'cmd' + args[0]
if (!this[cmdKey] || args[0] === 'help') {
this.logger.sender(sender, help);
let cmdKey = 'cmd' + (args[0] || 'help')
if (!this[cmdKey]) {
this.i18n(sender, 'main.command.not.exists', { command: args[0] })
this.i18n(sender, 'main.command.help.tip', { command })
return;
}
args.shift()
this[cmdKey](sender, ...args);
}
cmdhelp(sender: any) {
this.logger.sender(sender, help);
}
cmdload(sender: any, name: string) {
let pluginFile = fs.concat(__dirname + '', name);
if (!fs.exists(pluginFile)) {
this.i18n(sender, 'plugin.not.exists', { name: `${name}(${pluginFile})` })
return;
}
this.pluginManager.loadFromFile(fs.file(pluginFile));
}
cmdlist(sender: any, type: string = 'cloud') {
if (type == "install") {
this.i18n(sender, 'list.header.install')
if (type == "i" || type == "install") {
this.i18n(sender, 'list.install.header')
this.pluginManager.getPlugins().forEach((plugin) => {
this.i18n(sender, 'list.body', plugin.description);
this.i18n(sender, 'list.install.body', plugin.description);
})
} else {
this.i18n(sender, 'list.header')
@@ -113,6 +136,21 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
}
}
cmdupgrade(sender: any, name: string) {
if (!name) { return this.i18n(sender, 'upgrade.confirm'); }
if (name == "comfirm") {
let enginePath = fs.path(fs.file(fs.concat(root, 'node_modules', '@ccms')))
if (enginePath.startsWith(root)) {
base.delete(enginePath);
this.cmdrestart(sender);
}
}
if (this.checkPlugin(sender, name)) {
this.update(sender, name);
this.pluginManager.reload(name);
}
}
cmdunload(sender: any, name: string) {
if (this.checkPlugin(sender, name)) {
this.pluginManager.disable(name)
@@ -148,6 +186,7 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
try {
this.logger.sender(sender, '§6Reloading §3MiaoScript Engine...');
ScriptEngineContextHolder.disableEngine();
Packages.java.lang.System.gc();
ScriptEngineContextHolder.enableEngine();
this.logger.sender(sender, '§3MiaoScript Engine §6Reload §aSuccessful...');
} catch (ex) {
@@ -158,25 +197,27 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
cmdrun(sender: any, ...args: any[]) {
try {
var script = args.join(' ');
this.logger.sender(sender, '§b运行脚本:§r', script);
this.logger.sender(sender, '§a返回结果:§r', eval(script) || '§4没有返回结果!');
let script = args.join(' ');
this.i18n(sender, 'run.script', { script })
let result = eval(script);
this.i18n(sender, 'run.result', { result: result == undefined ? this.translate.translate('run.noresult') : result + '' })
} catch (ex) {
this.logger.sender(sender, this.logger.stack(ex));
}
}
cmddeploy(sender: any, name: any) {
if (!process.env.AccessToken) { return this.i18n(sender, 'deploy.token.not.exists') }
this.taskManager.create(() => {
if (this.checkPlugin(sender, name)) {
let plugin: interfaces.Plugin = this.pluginManager.getPlugins().get(name);
let result = http.post("http://ms.yumc.pw/api/plugin/deploy", {
let result = http.post("http://ms.yumc.pw/api/plugin/deploy?access_token=" + process.env.AccessToken, {
name,
author: plugin.description.author,
version: plugin.description.version,
source: base.read(plugin.description.source + '')
source: base.read(plugin.description.source.toString())
})
this.logger.sender(sender, result);
this.i18n(sender, result.code == 200 ? 'deploy.success' : 'deploy.fail', { name, msg: result.msg })
}
}).async().submit()
}
@@ -220,11 +261,15 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
this.taskManager.create(() => {
this.i18n(sender, 'download.start', { name })
this.i18n(sender, 'download.url', { url: this.packageCache[name].url })
let pluginFile = update ? fs.concat(this.pluginFolder, 'update', name + '.js') : fs.concat(this.pluginFolder, name + '.js')
let pluginFile = update ? fs.concat(root, this.pluginFolder, 'update', name + '.js') : fs.concat(root, this.pluginFolder, name + '.js')
http.download(this.packageCache[name].url, pluginFile)
this.i18n(sender, 'download.finish', { name })
this.pluginManager.loadFromFile(pluginFile)
this.i18n(sender, update ? 'update.finish' : 'install.finish', { name })
if (!update) {
this.pluginManager.loadFromFile(fs.file(pluginFile))
this.i18n(sender, 'install.finish', { name })
} else {
this.i18n(sender, 'update.finish', { name })
}
}).async().submit()
}
}

1
packages/sponge/.npmignore Symbolic link
View File

@@ -0,0 +1 @@
../../.npmignore

View File

@@ -1,6 +1,6 @@
{
"name": "@ccms/sponge",
"version": "0.6.2",
"version": "0.6.7",
"description": "MiaoScript api package",
"keywords": [
"miaoscript",
@@ -21,11 +21,11 @@
"devDependencies": {
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"typescript": "^3.8.3"
"typescript": "^3.9.2"
},
"dependencies": {
"@ccms/api": "^0.6.1",
"@ccms/common": "^0.6.2",
"@ccms/container": "^0.6.0"
"@ccms/api": "^0.6.7",
"@ccms/common": "^0.6.7",
"@ccms/container": "^0.6.7"
}
}

View File

@@ -11,10 +11,11 @@ const File = Java.type("java.io.File");
export class SpongeServer implements server.Server {
private pluginsFolder: string;
private pipeline: any;
private rootLogger: any;
constructor() {
this.pluginsFolder = new File(base.getInstance().getClass().getProtectionDomain().getCodeSource().getLocation().getPath()).getParentFile().getCanonicalPath()
this.reflectPipeline()
this.reflect()
}
getPlayer(name: string) {
@@ -50,20 +51,27 @@ export class SpongeServer implements server.Server {
getNettyPipeline() {
return this.pipeline;
}
getRootLogger() {
return this.rootLogger;
}
sendJson(sender: string | any, json: string): void {
if (typeof sender === "string") {
sender = this.getPlayer(sender)
}
sender.sendMessage(TextSerializers.JSON.deserialize(json))
}
private reflectPipeline() {
private reflect() {
let consoleServer = reflect.on(Sponge.getServer()).get()
this.reflectPipeline(consoleServer)
this.reflectRootLogger(consoleServer)
}
private reflectPipeline(consoleServer: any) {
let connection: any;
let promise: any;
for (const method of constants.Reflect.Method.getServerConnection) {
try {
connection = reflect.on(consoleServer).call(method).get()
if (connection.class.name.indexOf('ServerConnection') !== -1) { break; }
if (connection.class.name.indexOf('NetworkSystem') !== -1) { break; }
connection = undefined;
} catch (error) { }
}
@@ -78,4 +86,11 @@ export class SpongeServer implements server.Server {
if (!promise) { console.error("Can't found listeningChannels!"); return }
this.pipeline = reflect.on(promise).get('channel').get().pipeline()
}
private reflectRootLogger(consoleServer: any) {
try {
this.rootLogger = reflect.on(consoleServer).get('LOGGER').get().parent
} catch (error) {
console.error("Can't found rootLogger!")
}
}
}

1
packages/types/.npmignore Symbolic link
View File

@@ -0,0 +1 @@
../../.npmignore

View File

@@ -1,6 +1,6 @@
{
"name": "@ccms/types",
"version": "0.6.0",
"version": "0.6.7",
"description": "MiaoScript types package",
"keywords": [
"miaoscript",

View File

@@ -0,0 +1 @@
../../.npmignore

View File

@@ -1,6 +1,6 @@
{
"name": "@ccms/websocket",
"version": "0.6.1",
"version": "0.6.7",
"description": "MiaoScript websocket package",
"keywords": [
"miaoscript",
@@ -21,9 +21,9 @@
"devDependencies": {
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"typescript": "^3.8.3"
"typescript": "^3.9.2"
},
"dependencies": {
"@ccms/nashorn": "^0.6.1"
"@ccms/nashorn": "^0.6.7"
}
}

View File

@@ -1,13 +1,10 @@
import { EventEmitter } from 'events'
import { Keys, ServerEvent } from './constants'
import { WebSocketHandlerAdapter } from "../netty"
import { HttpRequestHandler } from './httprequest'
import { TextWebSocketFrameHandler } from './text_websocket_frame'
import { ServerOptions } from '../socket-io'
import { Keys, ServerEvent } from './constants'
import { HttpRequestHandler } from './httprequest'
import { WebSocketHandlerAdapter } from "../netty"
import { TextWebSocketFrameHandler } from './text_websocket_frame'
const CharsetUtil = Java.type('io.netty.util.CharsetUtil')
const HttpServerCodec = Java.type('io.netty.handler.codec.http.HttpServerCodec')
const ChunkedWriteHandler = Java.type('io.netty.handler.stream.ChunkedWriteHandler')
const HttpObjectAggregator = Java.type('io.netty.handler.codec.http.HttpObjectAggregator')

View File

@@ -72,7 +72,7 @@ export class Adapter extends EventEmitter implements SocketIO.Adapter {
var socket: Socket;
packet.nsp = this.nsp.name;
// let encodedPackets = this.parser.encode(packet)
let encodedPackets = this.parser.encode(packet)
if (rooms.length) {
for (var i = 0; i < rooms.length; i++) {
var room = self.rooms[rooms[i]];
@@ -83,7 +83,7 @@ export class Adapter extends EventEmitter implements SocketIO.Adapter {
if (ids[id] || ~except.indexOf(id)) continue;
socket = self.nsp.connected[id];
if (socket) {
socket.packet(packet, packetOpts);
socket.packet(encodedPackets as any, packetOpts);
ids[id] = true;
}
}
@@ -94,7 +94,7 @@ export class Adapter extends EventEmitter implements SocketIO.Adapter {
if (self.sids.hasOwnProperty(id)) {
if (~except.indexOf(id)) continue;
socket = self.nsp.connected[id];
if (socket) socket.packet(packet, packetOpts);
if (socket) socket.packet(encodedPackets as any, packetOpts);
}
}
}

View File

@@ -62,8 +62,8 @@ export class Client extends EventEmitter implements SocketIO.Client {
}
});
}
packet(packet: Packet, opts?: any) {
this.conn.send(parser.encode(packet))
packet(packet: Packet, opts: any = { preEncoded: false }) {
this.conn.send(opts.preEncoded ? packet as unknown as string : parser.encode(packet))
}
onclose(reason?: string) {
// debug('client close with reason %s', reason);

View File

@@ -727,6 +727,16 @@ export declare namespace SocketIO {
*/
del(id: string, room: string, callback?: (err?: any) => void): void;
/**
* Adds a socket to a list of room.
*
* @param {String} socket id
* @param {String} rooms
* @param {Function} callback
* @api public
*/
addAll(id: string, rooms: string | any[], fn: { (err?: any): void; bind?: any; });
/**
* Removes a socket from all the rooms that it's joined
* @param id The ID of the socket that we're removing

View File

@@ -7,7 +7,7 @@ import { Socket } from './socket';
import { Adapter } from './adapter';
import { Server } from './index'
import { Packet } from './packet';
import { SubPacketTypes } from './types';
import { PacketTypes, SubPacketTypes } from './types';
export class Namespace extends EventEmitter implements SocketIO.Namespace {
name: string;
@@ -78,7 +78,9 @@ export class Namespace extends EventEmitter implements SocketIO.Namespace {
}
// set up packet object
var packet = {
type: (this.flags.binary !== undefined ? this.flags.binary : this.hasBin(args)) ? SubPacketTypes.BINARY_EVENT : SubPacketTypes.EVENT,
type: PacketTypes.MESSAGE,
sub_type: (this.flags.binary !== undefined ? this.flags.binary : this.hasBin(args)) ? SubPacketTypes.BINARY_EVENT : SubPacketTypes.EVENT,
name: event,
data: args
}

View File

@@ -103,6 +103,11 @@ export class Parser {
p.nsp = '/';
}
// handle namespace query
if (p.nsp.indexOf('?') !== -1) {
p.nsp = p.nsp.split('?')[0];
}
// look up id
let next = str.charAt(i + 1);
if ('' !== next && !isNaN(Number(next))) {

View File

@@ -5,6 +5,7 @@ import { Packet } from './packet';
import { PacketTypes, SubPacketTypes } from './types';
import { Client } from './client';
import { Namespace } from './namespace';
import * as querystring from 'querystring'
export class Socket extends EventEmitter implements SocketIO.Socket {
nsp: Namespace;
@@ -45,7 +46,7 @@ export class Socket extends EventEmitter implements SocketIO.Socket {
this.acks = {};
this.connected = true;
this.disconnected = false;
// this.handshake = this.buildHandshake(query);
this.handshake = this.buildHandshake(query);
this.fns = [];
this.flags = {};
this._rooms = [];
@@ -97,6 +98,14 @@ export class Socket extends EventEmitter implements SocketIO.Socket {
fn && fn(null);
return this;
}
this.adapter.addAll(this.id, rooms, (err) => {
if (err) return fn && fn(err);
// debug('joined room %s', rooms);
(rooms as Array<string>).forEach((room) => {
this.rooms[room] = room;
});
fn && fn(null);
});
return this;
}
leave(name: string, fn?: Function): SocketIO.Socket {
@@ -127,16 +136,21 @@ export class Socket extends EventEmitter implements SocketIO.Socket {
// ==========================================
buildHandshake(query): SocketIO.Handshake {
let requestQuery = this.request.uri();
let requestUri = this.request.uri();
let headers = {};
let nativeHeaders = this.request.headers();
nativeHeaders.forEach(function (header) {
headers[header.getKey()] = header.getValue();
})
return {
headers: this.request.headers(),
headers: headers,
time: (new Date) + '',
address: this.conn.remoteAddress,
xdomain: !!this.request.headers.origin,
secure: !!this.request.connection.encrypted,
address: this.conn.remoteAddress + '',
xdomain: !!headers['origin'],
secure: false,
issued: +(new Date),
url: this.request.url,
query: Object.assign(query, requestQuery)
url: requestUri,
query: Object.assign(query, querystring.parse(requestUri.indexOf('?') != -1 ? requestUri.split('?')[1] : ''))
}
}
emit(event: string, ...args: any[]): boolean {
@@ -183,10 +197,11 @@ export class Socket extends EventEmitter implements SocketIO.Socket {
// @ts-ignore
return this;
}
packet(packet: Packet, opts?: any) {
packet.nsp = this.nsp.name;
opts = opts || {};
opts.compress = false !== opts.compress;
packet(packet: Packet, opts: any = { preEncoded: false }) {
if (!opts.preEncoded) {
packet.nsp = this.nsp.name;
opts.compress = false !== opts.compress;
}
this.client.packet(packet, opts);
}
onconnect() {

View File

@@ -1,5 +1,6 @@
{
"compilerOptions": {
"incremental": true,
"baseUrl": "src",
"outDir": "dist",
"target": "es5",