Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 08b72cd05a | |||
| 6e38da18bc | |||
| 2957150096 | |||
| c13ff26971 | |||
| 104d1b18d6 | |||
| db9746b641 | |||
| 6f18fe0990 | |||
| b33358cf59 | |||
| bc29221b9c | |||
| dd88e63d1a | |||
| 99a264677a | |||
| 805f7ad521 | |||
| e6aba870da | |||
| 321cb18cb9 | |||
| 430edacd3f | |||
| ac88c15113 |
@@ -20,3 +20,4 @@ wallaby.js
|
|||||||
.vscode
|
.vscode
|
||||||
.theia
|
.theia
|
||||||
type_definitions
|
type_definitions
|
||||||
|
tsconfig.tsbuildinfo
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"version": "0.6.5",
|
"version": "0.6.7",
|
||||||
"useWorkspaces": true,
|
"useWorkspaces": true,
|
||||||
"npmClient": "yarn",
|
"npmClient": "yarn",
|
||||||
"packages": [
|
"packages": [
|
||||||
|
|||||||
@@ -12,12 +12,13 @@
|
|||||||
"build": "lerna run build --scope=\"@ccms/!(plugins)\"",
|
"build": "lerna run build --scope=\"@ccms/!(plugins)\"",
|
||||||
"build:plugins": "lerna run build --scope=\"@ccms/plugins\"",
|
"build:plugins": "lerna run build --scope=\"@ccms/plugins\"",
|
||||||
"ug": "yarn upgrade-interactive --latest",
|
"ug": "yarn upgrade-interactive --latest",
|
||||||
|
"np": "lerna exec \"npm publish --registry https://registry.npmjs.org\" --scope=\"@ccms/!(client|plugins|types)\"",
|
||||||
"lp": "lerna publish"
|
"lp": "lerna publish"
|
||||||
},
|
},
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"packages/*"
|
"packages/*"
|
||||||
],
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"lerna": "^3.20.2"
|
"lerna": "^3.21.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
1
packages/api/.npmignore
Symbolic link
1
packages/api/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/api",
|
"name": "@ccms/api",
|
||||||
"version": "0.6.5",
|
"version": "0.6.7",
|
||||||
"description": "MiaoScript api package",
|
"description": "MiaoScript api package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -19,8 +19,8 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/container": "^0.6.0",
|
"@ccms/container": "^0.6.7",
|
||||||
"@ccms/ployfill": "^0.6.5",
|
"@ccms/ployfill": "^0.6.7",
|
||||||
"base64-js": "^1.3.1",
|
"base64-js": "^1.3.1",
|
||||||
"source-map-builder": "^0.0.7"
|
"source-map-builder": "^0.0.7"
|
||||||
},
|
},
|
||||||
@@ -28,6 +28,6 @@
|
|||||||
"@types/base64-js": "^1.2.5",
|
"@types/base64-js": "^1.2.5",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^3.8.3"
|
"typescript": "^3.9.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ enum LogLevel {
|
|||||||
export class MiaoScriptConsole implements Console {
|
export class MiaoScriptConsole implements Console {
|
||||||
Console: NodeJS.ConsoleConstructor;
|
Console: NodeJS.ConsoleConstructor;
|
||||||
|
|
||||||
private sourceMaps: { [key: string]: SourceMapBuilder } = {};
|
private static sourceMaps: { [key: string]: SourceMapBuilder } = {};
|
||||||
private sourceFileMaps: { [key: string]: string } = {};
|
private static sourceFileMaps: { [key: string]: string } = {};
|
||||||
private _name: string = '';
|
private _name: string = '';
|
||||||
private _level: LogLevel = LogLevel.INFO;
|
private _level: LogLevel = LogLevel.INFO;
|
||||||
|
|
||||||
@@ -93,8 +93,8 @@ export class MiaoScriptConsole implements Console {
|
|||||||
readSourceMap(fileName: string, lineNumber: number) {
|
readSourceMap(fileName: string, lineNumber: number) {
|
||||||
try {
|
try {
|
||||||
if (fileName.endsWith('js')) {
|
if (fileName.endsWith('js')) {
|
||||||
if (this.sourceMaps[fileName] === undefined) {
|
if (MiaoScriptConsole.sourceMaps[fileName] === undefined) {
|
||||||
this.sourceMaps[fileName] = null
|
MiaoScriptConsole.sourceMaps[fileName] = null
|
||||||
let sourceLine = base.read(fileName).split('\n');
|
let sourceLine = base.read(fileName).split('\n');
|
||||||
let lastLine = sourceLine[sourceLine.length - 1]
|
let lastLine = sourceLine[sourceLine.length - 1]
|
||||||
if (lastLine.startsWith('//# sourceMappingURL=')) {
|
if (lastLine.startsWith('//# sourceMappingURL=')) {
|
||||||
@@ -109,14 +109,14 @@ export class MiaoScriptConsole implements Console {
|
|||||||
if (file.exists()) { sourceContent = base.read(file) }
|
if (file.exists()) { sourceContent = base.read(file) }
|
||||||
}
|
}
|
||||||
if (sourceContent) {
|
if (sourceContent) {
|
||||||
this.sourceMaps[fileName] = new SourceMapBuilder(JSON.parse(sourceContent))
|
MiaoScriptConsole.sourceMaps[fileName] = new SourceMapBuilder(JSON.parse(sourceContent))
|
||||||
this.sourceFileMaps[fileName] = Paths.get(fileName, '..', this.sourceMaps[fileName].sources[0]).toFile().getCanonicalPath();
|
MiaoScriptConsole.sourceFileMaps[fileName] = Paths.get(fileName, '..', MiaoScriptConsole.sourceMaps[fileName].sources[0]).toFile().getCanonicalPath();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.sourceMaps[fileName]) {
|
if (MiaoScriptConsole.sourceMaps[fileName]) {
|
||||||
let sourceMapping = this.sourceMaps[fileName].getSource(lineNumber, 25, true, true);
|
let sourceMapping = MiaoScriptConsole.sourceMaps[fileName].getSource(lineNumber, 25, true, true);
|
||||||
fileName = this.sourceFileMaps[fileName]
|
fileName = MiaoScriptConsole.sourceFileMaps[fileName]
|
||||||
if (sourceMapping && lineNumber != sourceMapping.mapping.sourceLine) { lineNumber = sourceMapping.mapping.sourceLine; }
|
if (sourceMapping && lineNumber != sourceMapping.mapping.sourceLine) { lineNumber = sourceMapping.mapping.sourceLine; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ export namespace server {
|
|||||||
getPluginsFolder(): string;
|
getPluginsFolder(): string;
|
||||||
getNativePluginManager(): NativePluginManager;
|
getNativePluginManager(): NativePluginManager;
|
||||||
getNettyPipeline(): any;
|
getNettyPipeline(): any;
|
||||||
|
getRootLogger(): any;
|
||||||
sendJson(sender: string | any, json: object | string): void;
|
sendJson(sender: string | any, json: object | string): void;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
packages/bukkit/.npmignore
Symbolic link
1
packages/bukkit/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/bukkit",
|
"name": "@ccms/bukkit",
|
||||||
"version": "0.6.5",
|
"version": "0.6.7",
|
||||||
"description": "MiaoScript bukkit package",
|
"description": "MiaoScript bukkit package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -21,11 +21,11 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^3.8.3"
|
"typescript": "^3.9.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.6.5",
|
"@ccms/api": "^0.6.7",
|
||||||
"@ccms/common": "^0.6.4",
|
"@ccms/common": "^0.6.7",
|
||||||
"@ccms/container": "^0.6.0"
|
"@ccms/container": "^0.6.7"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,10 +10,11 @@ let Bukkit = org.bukkit.Bukkit;
|
|||||||
export class BukkitServer implements server.Server {
|
export class BukkitServer implements server.Server {
|
||||||
private pluginsFolder: string;
|
private pluginsFolder: string;
|
||||||
private pipeline: any;
|
private pipeline: any;
|
||||||
|
private rootLogger: any;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.pluginsFolder = Bukkit.getUpdateFolderFile().getParentFile().getCanonicalPath();
|
this.pluginsFolder = Bukkit.getUpdateFolderFile().getParentFile().getCanonicalPath();
|
||||||
this.reflectPipeline()
|
this.reflect()
|
||||||
}
|
}
|
||||||
|
|
||||||
getPlayer(name: string) {
|
getPlayer(name: string) {
|
||||||
@@ -49,6 +50,9 @@ export class BukkitServer implements server.Server {
|
|||||||
getNettyPipeline() {
|
getNettyPipeline() {
|
||||||
return this.pipeline;
|
return this.pipeline;
|
||||||
}
|
}
|
||||||
|
getRootLogger() {
|
||||||
|
return this.rootLogger;
|
||||||
|
}
|
||||||
sendJson(sender: string | any, json: object | string): void {
|
sendJson(sender: string | any, json: object | string): void {
|
||||||
if (typeof sender === "string") {
|
if (typeof sender === "string") {
|
||||||
sender = this.getPlayer(sender)
|
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()
|
let consoleServer = reflect.on(Bukkit.getServer()).get('console').get()
|
||||||
|
this.reflectPipeline(consoleServer)
|
||||||
|
this.reflectRootLogger(consoleServer)
|
||||||
|
}
|
||||||
|
|
||||||
|
private reflectPipeline(consoleServer: any) {
|
||||||
let connection: any;
|
let connection: any;
|
||||||
let promise: any;
|
let promise: any;
|
||||||
for (const method of constants.Reflect.Method.getServerConnection) {
|
for (const method of constants.Reflect.Method.getServerConnection) {
|
||||||
try {
|
try {
|
||||||
connection = reflect.on(consoleServer).call(method).get()
|
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;
|
connection = undefined;
|
||||||
} catch (error) { }
|
} catch (error) { }
|
||||||
}
|
}
|
||||||
@@ -81,4 +91,12 @@ export class BukkitServer implements server.Server {
|
|||||||
if (!promise) { console.error("Can't found listeningChannels!"); return }
|
if (!promise) { console.error("Can't found listeningChannels!"); return }
|
||||||
this.pipeline = reflect.on(promise).get('channel').get().pipeline()
|
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
1
packages/bungee/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/bungee",
|
"name": "@ccms/bungee",
|
||||||
"version": "0.6.5",
|
"version": "0.6.7",
|
||||||
"description": "MiaoScript bungee package",
|
"description": "MiaoScript bungee package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -21,11 +21,11 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^3.8.3"
|
"typescript": "^3.9.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.6.5",
|
"@ccms/api": "^0.6.7",
|
||||||
"@ccms/common": "^0.6.4",
|
"@ccms/common": "^0.6.7",
|
||||||
"@ccms/container": "^0.6.0"
|
"@ccms/container": "^0.6.7"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ let Bungee: net.md_5.bungee.api.ProxyServer = base.getInstance().getProxy();
|
|||||||
export class BungeeServer implements server.Server {
|
export class BungeeServer implements server.Server {
|
||||||
private pluginsFolder: string;
|
private pluginsFolder: string;
|
||||||
private pipeline: any;
|
private pipeline: any;
|
||||||
|
private rootLogger: any;
|
||||||
|
|
||||||
@inject(task.TaskManager)
|
@inject(task.TaskManager)
|
||||||
private task: task.TaskManager
|
private task: task.TaskManager
|
||||||
@@ -35,6 +36,11 @@ export class BungeeServer implements server.Server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).later(10).timer(20).submit()
|
}).later(10).timer(20).submit()
|
||||||
|
try {
|
||||||
|
this.rootLogger = Bungee.getLogger()
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Can't found rootLogger!")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getPlayer(name: string) {
|
getPlayer(name: string) {
|
||||||
@@ -70,6 +76,9 @@ export class BungeeServer implements server.Server {
|
|||||||
getNettyPipeline() {
|
getNettyPipeline() {
|
||||||
return this.pipeline;
|
return this.pipeline;
|
||||||
}
|
}
|
||||||
|
getRootLogger() {
|
||||||
|
return this.rootLogger;
|
||||||
|
}
|
||||||
sendJson(sender: string | any, json: string): void {
|
sendJson(sender: string | any, json: string): void {
|
||||||
throw new Error("Method not implemented.");
|
throw new Error("Method not implemented.");
|
||||||
}
|
}
|
||||||
|
|||||||
1
packages/client/.npmignore
Symbolic link
1
packages/client/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
"name": "@ccms/client",
|
"name": "@ccms/client",
|
||||||
"version": "0.6.3",
|
"version": "0.6.7",
|
||||||
"description": "MiaoScript client package",
|
"description": "MiaoScript client package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -26,6 +26,6 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^3.8.3"
|
"typescript": "^3.9.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
packages/common/.npmignore
Symbolic link
1
packages/common/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/common",
|
"name": "@ccms/common",
|
||||||
"version": "0.6.4",
|
"version": "0.6.7",
|
||||||
"description": "MiaoScript api package",
|
"description": "MiaoScript api package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -21,10 +21,10 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^3.8.3"
|
"typescript": "^3.9.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/nashorn": "^0.6.4"
|
"@ccms/nashorn": "^0.6.7"
|
||||||
},
|
},
|
||||||
"gitHead": "562e2d00175c9d3a99c8b672aa07e6d92706a027"
|
"gitHead": "562e2d00175c9d3a99c8b672aa07e6d92706a027"
|
||||||
}
|
}
|
||||||
|
|||||||
1
packages/compile/.npmignore
Symbolic link
1
packages/compile/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/compile",
|
"name": "@ccms/compile",
|
||||||
"version": "0.6.0",
|
"version": "0.6.7",
|
||||||
"description": "MiaoScript compile package",
|
"description": "MiaoScript compile package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -21,6 +21,6 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^3.8.3"
|
"typescript": "^3.9.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
packages/container/.npmignore
Symbolic link
1
packages/container/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/container",
|
"name": "@ccms/container",
|
||||||
"version": "0.6.0",
|
"version": "0.6.7",
|
||||||
"description": "MiaoScript container package",
|
"description": "MiaoScript container package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^3.8.3"
|
"typescript": "^3.9.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"inversify": "^5.0.1",
|
"inversify": "^5.0.1",
|
||||||
|
|||||||
1
packages/core/.npmignore
Symbolic link
1
packages/core/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/core",
|
"name": "@ccms/core",
|
||||||
"version": "0.6.5",
|
"version": "0.6.7",
|
||||||
"description": "MiaoScript api package",
|
"description": "MiaoScript api package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -21,11 +21,11 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^3.8.3"
|
"typescript": "^3.9.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.6.5",
|
"@ccms/api": "^0.6.7",
|
||||||
"@ccms/container": "^0.6.0"
|
"@ccms/container": "^0.6.7"
|
||||||
},
|
},
|
||||||
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { plugin, server, task, constants } from '@ccms/api'
|
|||||||
import { DefaultContainer as container, inject, provideSingleton, ContainerInstance, buildProviderModule } from '@ccms/container'
|
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 })
|
console.i18n("ms.core.ioc.completed", { scope: global.scope, time: (Date.now() - containerStartTime) / 1000 })
|
||||||
import http from '@ccms/common/dist/http'
|
import http from '@ccms/common/dist/http'
|
||||||
|
import { EventEmitter } from 'events'
|
||||||
|
|
||||||
@provideSingleton(MiaoScriptCore)
|
@provideSingleton(MiaoScriptCore)
|
||||||
class MiaoScriptCore {
|
class MiaoScriptCore {
|
||||||
@@ -25,6 +26,7 @@ class MiaoScriptCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadServerConsole() {
|
loadServerConsole() {
|
||||||
|
global.setGlobal('eventCenter', new EventEmitter(), { writable: false, configurable: false });
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
global.setGlobal('console', new this.Console(), { writable: false, configurable: false })
|
global.setGlobal('console', new this.Console(), { writable: false, configurable: false })
|
||||||
}
|
}
|
||||||
|
|||||||
1
packages/i18n/.npmignore
Symbolic link
1
packages/i18n/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -43,4 +43,6 @@ ms.plugin.manager.build.error: "§6Load Plugin From §b{file} §6failed. §4Erro
|
|||||||
ms.plugin.manager.build.update: "Auto Update Plugin {name} ..."
|
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.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.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..."
|
ms.plugin.manager.config.save.default: "[{plugin}] config {name}.{format} not exists. auto create from default variable..."
|
||||||
|
|||||||
@@ -43,4 +43,6 @@ ms.plugin.manager.build.error: "§6从文件 §b{file} §6加载插件失败 §4
|
|||||||
ms.plugin.manager.build.update: "自动更新插件 {name} ..."
|
ms.plugin.manager.build.update: "自动更新插件 {name} ..."
|
||||||
ms.plugin.manager.build.not.extends: "§4发现错误的插件 §b{source} §4未继承接口 interfaces.Plugin, 将不会被载入到服务器!"
|
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.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} 不存在. 从默认值自动创建保存..."
|
ms.plugin.manager.config.save.default: "[{plugin}] 配置 {name}.{format} 不存在. 从默认值自动创建保存..."
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/i18n",
|
"name": "@ccms/i18n",
|
||||||
"version": "0.6.4",
|
"version": "0.6.7",
|
||||||
"description": "MiaoScript i18n package",
|
"description": "MiaoScript i18n package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -22,10 +22,10 @@
|
|||||||
"@types/js-yaml": "^3.12.3",
|
"@types/js-yaml": "^3.12.3",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^3.8.3"
|
"typescript": "^3.9.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/nashorn": "^0.6.4",
|
"@ccms/nashorn": "^0.6.7",
|
||||||
"js-yaml": "^3.13.1"
|
"js-yaml": "^3.13.1"
|
||||||
},
|
},
|
||||||
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
test
|
|
||||||
typings
|
|
||||||
bundled
|
|
||||||
build
|
|
||||||
coverage
|
|
||||||
docs
|
|
||||||
wiki
|
|
||||||
gulpfile.js
|
|
||||||
bower.json
|
|
||||||
karma.conf.js
|
|
||||||
tsconfig.json
|
|
||||||
typings.json
|
|
||||||
CONTRIBUTING.md
|
|
||||||
ISSUE_TEMPLATE.md
|
|
||||||
PULL_REQUEST_TEMPLATE.md
|
|
||||||
tslint.json
|
|
||||||
wallaby.js
|
|
||||||
.travis.yml
|
|
||||||
.gitignore
|
|
||||||
.vscode
|
|
||||||
.theia
|
|
||||||
type_definitions
|
|
||||||
1
packages/nashorn/.npmignore
Symbolic link
1
packages/nashorn/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/nashorn",
|
"name": "@ccms/nashorn",
|
||||||
"version": "0.6.4",
|
"version": "0.6.7",
|
||||||
"description": "MiaoScript api package",
|
"description": "MiaoScript api package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -22,6 +22,6 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^3.8.3"
|
"typescript": "^3.9.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ declare global {
|
|||||||
logger: any;
|
logger: any;
|
||||||
debug: boolean;
|
debug: boolean;
|
||||||
level: string;
|
level: string;
|
||||||
|
eventCenter: EventEmitter;
|
||||||
NashornEngineStartTime: number;
|
NashornEngineStartTime: number;
|
||||||
setGlobal: (key: string, value: any, config?: PropertyDescriptor & ThisType<any>) => void;
|
setGlobal: (key: string, value: any, config?: PropertyDescriptor & ThisType<any>) => void;
|
||||||
noop: () => void;
|
noop: () => void;
|
||||||
@@ -70,6 +71,9 @@ declare global {
|
|||||||
console(...args: any): void;
|
console(...args: any): void;
|
||||||
i18n(name: string, ...params: any[]): void;
|
i18n(name: string, ...params: any[]): void;
|
||||||
}
|
}
|
||||||
|
interface ProxyConstructor {
|
||||||
|
newProxy<T extends object>(target: T, handler: ProxyHandler<T>): T;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { };
|
export { };
|
||||||
|
|||||||
1
packages/nodejs/.npmignore
Symbolic link
1
packages/nodejs/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/nodejs",
|
"name": "@ccms/nodejs",
|
||||||
"version": "0.6.4",
|
"version": "0.6.7",
|
||||||
"description": "MiaoScript nodejs package",
|
"description": "MiaoScript nodejs package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -21,10 +21,10 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^3.8.3"
|
"typescript": "^3.9.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/nashorn": "^0.6.4"
|
"@ccms/nashorn": "^0.6.7"
|
||||||
},
|
},
|
||||||
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
||||||
}
|
}
|
||||||
|
|||||||
1
packages/nukkit/.npmignore
Symbolic link
1
packages/nukkit/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/nukkit",
|
"name": "@ccms/nukkit",
|
||||||
"version": "0.6.5",
|
"version": "0.6.7",
|
||||||
"description": "MiaoScript nukkit package",
|
"description": "MiaoScript nukkit package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -21,11 +21,11 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^3.8.3"
|
"typescript": "^3.9.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.6.5",
|
"@ccms/api": "^0.6.7",
|
||||||
"@ccms/common": "^0.6.4",
|
"@ccms/common": "^0.6.7",
|
||||||
"@ccms/container": "^0.6.0"
|
"@ccms/container": "^0.6.7"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,9 @@ export class NukkitServer implements server.Server {
|
|||||||
getNettyPipeline() {
|
getNettyPipeline() {
|
||||||
throw new Error("Method not implemented.");
|
throw new Error("Method not implemented.");
|
||||||
}
|
}
|
||||||
|
getRootLogger() {
|
||||||
|
return Packages.org.apache.logging.log4j.LogManager.getRootLogger()
|
||||||
|
}
|
||||||
sendJson(sender: string | any, json: object | string): void {
|
sendJson(sender: string | any, json: object | string): void {
|
||||||
throw new Error("Method not implemented.");
|
throw new Error("Method not implemented.");
|
||||||
}
|
}
|
||||||
|
|||||||
1
packages/ployfill/.npmignore
Symbolic link
1
packages/ployfill/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/ployfill",
|
"name": "@ccms/ployfill",
|
||||||
"version": "0.6.5",
|
"version": "0.6.7",
|
||||||
"description": "MiaoScript ployfill package",
|
"description": "MiaoScript ployfill package",
|
||||||
"author": "MiaoWoo <admin@yumc.pw>",
|
"author": "MiaoWoo <admin@yumc.pw>",
|
||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
@@ -14,13 +14,13 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/i18n": "^0.6.4",
|
"@ccms/i18n": "^0.6.7",
|
||||||
"@ccms/nashorn": "^0.6.4",
|
"@ccms/nashorn": "^0.6.7",
|
||||||
"core-js": "^3.6.4"
|
"core-js": "^3.6.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^3.8.3"
|
"typescript": "^3.9.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
packages/plugin/.npmignore
Symbolic link
1
packages/plugin/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/plugin",
|
"name": "@ccms/plugin",
|
||||||
"version": "0.6.5",
|
"version": "0.6.7",
|
||||||
"description": "MiaoScript api package",
|
"description": "MiaoScript api package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -22,13 +22,13 @@
|
|||||||
"@types/js-yaml": "^3.12.3",
|
"@types/js-yaml": "^3.12.3",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^3.8.3"
|
"typescript": "^3.9.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.6.5",
|
"@ccms/api": "^0.6.7",
|
||||||
"@ccms/common": "^0.6.4",
|
"@ccms/common": "^0.6.7",
|
||||||
"@ccms/container": "^0.6.0",
|
"@ccms/container": "^0.6.7",
|
||||||
"@ccms/i18n": "^0.6.4",
|
"@ccms/i18n": "^0.6.7",
|
||||||
"js-yaml": "^3.13.1"
|
"js-yaml": "^3.13.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export class YamlPluginConfig implements PluginConfigLoader {
|
|||||||
return yaml.safeLoad(content);
|
return yaml.safeLoad(content);
|
||||||
}
|
}
|
||||||
dump(variable: any): string {
|
dump(variable: any): string {
|
||||||
return yaml.safeDump(variable);
|
return yaml.safeDump(variable, { skipInvalid: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -100,6 +100,10 @@ export namespace interfaces {
|
|||||||
* 配置文件格式 默认 yml
|
* 配置文件格式 默认 yml
|
||||||
*/
|
*/
|
||||||
format?: string;
|
format?: string;
|
||||||
|
/**
|
||||||
|
* 是否为只读(关闭时将不会自动保存)
|
||||||
|
*/
|
||||||
|
readonly?: boolean;
|
||||||
}
|
}
|
||||||
export type PluginLike = Plugin | string;
|
export type PluginLike = Plugin | string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
@inject(plugin.PluginInstance)
|
@inject(plugin.PluginInstance)
|
||||||
private pluginInstance: any
|
private pluginInstance: any
|
||||||
@inject(plugin.PluginFolder)
|
@inject(plugin.PluginFolder)
|
||||||
private pluginFolder: string;
|
private pluginFolder: string
|
||||||
@inject(server.ServerType)
|
@inject(server.ServerType)
|
||||||
private serverType: string
|
private serverType: string
|
||||||
@inject(command.Command)
|
@inject(command.Command)
|
||||||
@@ -33,11 +33,11 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
if (this.pluginInstance !== null && this.initialized !== true) {
|
if (this.pluginInstance !== null && this.initialized !== true) {
|
||||||
// 如果plugin不等于null 则代表是正式环境
|
// 如果plugin不等于null 则代表是正式环境
|
||||||
console.i18n('ms.plugin.initialize', { plugin: this.pluginInstance, loader: Thread.currentThread().contextClassLoader })
|
console.i18n('ms.plugin.initialize', { plugin: this.pluginInstance, loader: Thread.currentThread().contextClassLoader })
|
||||||
console.i18n('ms.plugin.event.map', { count: this.EventManager.mapEventName().toFixed(0), type: this.serverType });
|
console.i18n('ms.plugin.event.map', { count: this.EventManager.mapEventName().toFixed(0), type: this.serverType })
|
||||||
this.pluginRequireMap = new Map()
|
this.pluginRequireMap = new Map()
|
||||||
this.pluginInstanceMap = new Map()
|
this.pluginInstanceMap = new Map()
|
||||||
this.pluginMetadataMap = getPluginSources();
|
this.pluginMetadataMap = getPluginSources()
|
||||||
this.initialized = true;
|
this.initialized = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,11 +69,11 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
* @param file java.io.File
|
* @param file java.io.File
|
||||||
*/
|
*/
|
||||||
loadFromFile(file: string): interfaces.Plugin {
|
loadFromFile(file: string): interfaces.Plugin {
|
||||||
let metadata = this.loadPlugin(file);
|
let metadata = this.loadPlugin(file)
|
||||||
let plugin = this.buildPlugin(metadata && metadata.description ? metadata.description : this.pluginMetadataMap.get(file.toString()))
|
let plugin = this.buildPlugin(metadata && metadata.description ? metadata.description : this.pluginMetadataMap.get(file.toString()))
|
||||||
this.load(plugin)
|
this.load(plugin)
|
||||||
this.enable(plugin)
|
this.enable(plugin)
|
||||||
return plugin;
|
return plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
load(...args: any[]): void {
|
load(...args: any[]): void {
|
||||||
@@ -96,6 +96,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
disable(...args: any[]): void {
|
disable(...args: any[]): void {
|
||||||
this.checkAndGet(args[0]).forEach((plugin: interfaces.Plugin) => {
|
this.checkAndGet(args[0]).forEach((plugin: interfaces.Plugin) => {
|
||||||
this.runPluginStage(plugin, 'disable', () => {
|
this.runPluginStage(plugin, 'disable', () => {
|
||||||
|
this.saveConfig(plugin)
|
||||||
this.unregistryCommand(plugin)
|
this.unregistryCommand(plugin)
|
||||||
this.unregistryListener(plugin)
|
this.unregistryListener(plugin)
|
||||||
})
|
})
|
||||||
@@ -197,14 +198,14 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
private createPlugin(file: string) {
|
private createPlugin(file: string) {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
let instance = require(file, { cache: false })
|
let instance = require(file, { cache: false })
|
||||||
this.pluginRequireMap.set(file, instance);
|
this.pluginRequireMap.set(file, instance)
|
||||||
return instance;
|
return instance
|
||||||
}
|
}
|
||||||
|
|
||||||
private buildPlugins() {
|
private buildPlugins() {
|
||||||
let metadatas = [];
|
let metadatas = []
|
||||||
let pluginMetadatas = getPluginMetadatas()
|
let pluginMetadatas = getPluginMetadatas()
|
||||||
for (const [_, metadata] of pluginMetadatas) { metadatas.push(metadata); }
|
for (const [_, metadata] of pluginMetadatas) { metadatas.push(metadata) }
|
||||||
for (const [_, instance] of this.pluginRequireMap) { if (instance.description) { this.buildPlugin(instance.description) } }
|
for (const [_, instance] of this.pluginRequireMap) { if (instance.description) { this.buildPlugin(instance.description) } }
|
||||||
for (const metadata of metadatas) {
|
for (const metadata of metadatas) {
|
||||||
if (!this.allowProcess(metadata.servers)) { continue }
|
if (!this.allowProcess(metadata.servers)) { continue }
|
||||||
@@ -213,7 +214,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private buildPlugin(metadata: interfaces.PluginMetadata) {
|
private buildPlugin(metadata: interfaces.PluginMetadata) {
|
||||||
let pluginInstance: interfaces.Plugin;
|
let pluginInstance: interfaces.Plugin
|
||||||
switch (metadata.type) {
|
switch (metadata.type) {
|
||||||
case "ioc":
|
case "ioc":
|
||||||
try {
|
try {
|
||||||
@@ -227,15 +228,15 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
console.i18n("ms.plugin.manager.initialize.error", { name: metadata.name, ex })
|
console.i18n("ms.plugin.manager.initialize.error", { name: metadata.name, ex })
|
||||||
console.ex(ex)
|
console.ex(ex)
|
||||||
}
|
}
|
||||||
break;
|
break
|
||||||
case "basic":
|
case "basic":
|
||||||
pluginInstance = this.pluginRequireMap.get(metadata.source.toString())
|
pluginInstance = this.pluginRequireMap.get(metadata.source.toString())
|
||||||
break;
|
break
|
||||||
default:
|
default:
|
||||||
throw new Error('§4不支持的插件类型 请检查加载器是否正常启用!')
|
throw new Error('§4不支持的插件类型 请检查加载器是否正常启用!')
|
||||||
}
|
}
|
||||||
this.pluginInstanceMap.set(metadata.name, pluginInstance)
|
this.pluginInstanceMap.set(metadata.name, pluginInstance)
|
||||||
return pluginInstance;
|
return pluginInstance
|
||||||
}
|
}
|
||||||
|
|
||||||
private bindPlugin(metadata: interfaces.PluginMetadata) {
|
private bindPlugin(metadata: interfaces.PluginMetadata) {
|
||||||
@@ -251,15 +252,35 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private loadConfig(plugin: interfaces.Plugin) {
|
private loadConfig(plugin: interfaces.Plugin) {
|
||||||
let configs = getPluginConfigMetadata(plugin);
|
let configs = getPluginConfigMetadata(plugin)
|
||||||
for (let [_, config] of configs) {
|
for (let [_, config] of configs) {
|
||||||
let configFile = fs.concat(root, this.pluginFolder, plugin.description.name, config.name + '.' + config.format)
|
try {
|
||||||
let configFactory = getConfigLoader(config.format);
|
let configFile = fs.concat(root, this.pluginFolder, plugin.description.name, config.name + '.' + config.format)
|
||||||
if (!fs.exists(configFile)) {
|
let configFactory = getConfigLoader(config.format)
|
||||||
base.save(configFile, configFactory.dump(plugin[config.variable]))
|
if (!fs.exists(configFile)) {
|
||||||
console.i18n("ms.plugin.manager.config.save.default", { plugin: plugin.description.name, name: config.name, format: config.format })
|
base.save(configFile, configFactory.dump(plugin[config.variable]))
|
||||||
} else {
|
console.i18n("ms.plugin.manager.config.save.default", { plugin: plugin.description.name, name: config.name, format: config.format })
|
||||||
plugin[config.variable] = configFactory.load(base.read(configFile));
|
} 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -299,7 +320,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private execPluginStage(pluginInstance: interfaces.Plugin, stageName: string) {
|
private execPluginStage(pluginInstance: interfaces.Plugin, stageName: string) {
|
||||||
let stages = getPluginStageMetadata(pluginInstance, stageName);
|
let stages = getPluginStageMetadata(pluginInstance, stageName)
|
||||||
for (const stage of stages) {
|
for (const stage of stages) {
|
||||||
if (!this.allowProcess(stage.servers)) { continue }
|
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 })
|
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
1
packages/plugins/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
"name": "@ccms/plugins",
|
"name": "@ccms/plugins",
|
||||||
"version": "0.6.5",
|
"version": "0.6.7",
|
||||||
"description": "MiaoScript plugins package",
|
"description": "MiaoScript plugins package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -22,11 +22,11 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^3.8.3"
|
"typescript": "^3.9.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.6.5",
|
"@ccms/api": "^0.6.7",
|
||||||
"@ccms/container": "^0.6.0",
|
"@ccms/container": "^0.6.7",
|
||||||
"@ccms/plugin": "^0.6.5"
|
"@ccms/plugin": "^0.6.7"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,12 @@
|
|||||||
/// <reference types="@ccms/types/dist/typings/sponge" />
|
/// <reference types="@ccms/types/dist/typings/sponge" />
|
||||||
/// <reference types="@ccms/types/dist/typings/bungee" />
|
/// <reference types="@ccms/types/dist/typings/bungee" />
|
||||||
|
|
||||||
import { plugin as pluginApi, server, task } from '@ccms/api'
|
import { plugin as pluginApi, server, task, constants } from '@ccms/api'
|
||||||
import { plugin, interfaces, cmd } from '@ccms/plugin'
|
import { plugin, interfaces, cmd, tab, enable, config, disable } from '@ccms/plugin'
|
||||||
import { inject, ContainerInstance, Container } from '@ccms/container'
|
import { inject, ContainerInstance, Container } from '@ccms/container'
|
||||||
import io, { Server as SocketIOServer, Socket as SocketIOSocket } from '@ccms/websocket'
|
import io, { Server as SocketIOServer, Socket as SocketIOSocket } from '@ccms/websocket'
|
||||||
import * as fs from '@ccms/common/dist/fs'
|
import * as fs from '@ccms/common/dist/fs'
|
||||||
|
import * as reflect from '@ccms/common/dist/reflect'
|
||||||
|
|
||||||
const suffixMap = {
|
const suffixMap = {
|
||||||
ts: 'typescript',
|
ts: 'typescript',
|
||||||
@@ -14,7 +15,13 @@ const suffixMap = {
|
|||||||
yml: 'yaml'
|
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 {
|
export class MiaoConsole extends interfaces.Plugin {
|
||||||
@inject(ContainerInstance)
|
@inject(ContainerInstance)
|
||||||
private container: Container
|
private container: Container
|
||||||
@@ -27,25 +34,69 @@ export class MiaoConsole extends interfaces.Plugin {
|
|||||||
@inject(pluginApi.PluginManager)
|
@inject(pluginApi.PluginManager)
|
||||||
private pluginManager: pluginApi.PluginManager
|
private pluginManager: pluginApi.PluginManager
|
||||||
@inject(pluginApi.PluginFolder)
|
@inject(pluginApi.PluginFolder)
|
||||||
private pluginFolder: string;
|
private pluginFolder: string
|
||||||
|
|
||||||
private pipeline: any;
|
private token: string
|
||||||
private socketIOServer: SocketIOServer;
|
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()
|
@cmd()
|
||||||
mconsole(sender: any, command: string, args: string[]) {
|
mconsole(sender: any, command: string, args: string[]) {
|
||||||
if (args[0] == 'reload') {
|
let cmdKey = 'cmd' + (args[0] || 'help')
|
||||||
// @ts-ignore
|
if (!this[cmdKey]) {
|
||||||
require.clear('websocket');
|
console.sender(sender, '§4未知的子命令: §c' + cmdKey)
|
||||||
this.pluginManager.reload(this);
|
console.sender(sender, `§6请执行 §b/${command} §ahelp §6查看帮助!`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let tfunc = new Function('pipeline', args.join(' '))
|
args.shift()
|
||||||
tfunc.apply(this, [this.pipeline])
|
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() {
|
enable() {
|
||||||
let count = 0;
|
let count = 0
|
||||||
let wait = this.task.create(() => {
|
let wait = this.task.create(() => {
|
||||||
this.pipeline = this.server.getNettyPipeline()
|
this.pipeline = this.server.getNettyPipeline()
|
||||||
if (this.pipeline) {
|
if (this.pipeline) {
|
||||||
@@ -56,27 +107,92 @@ export class MiaoConsole extends interfaces.Plugin {
|
|||||||
if (count > 30) { wait.cancel() }
|
if (count > 30) { wait.cancel() }
|
||||||
count++
|
count++
|
||||||
}).later(20).timer(40).submit()
|
}).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() {
|
disable() {
|
||||||
this.socketIOServer?.close()
|
if (this.socketIOServer) {
|
||||||
|
this.socketIOServer.close()
|
||||||
|
global.eventCenter.removeAllListeners('log')
|
||||||
|
}
|
||||||
if (this.container.isBound(io.Instance)) {
|
if (this.container.isBound(io.Instance)) {
|
||||||
this.container.unbind(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() {
|
createSocketIOServer() {
|
||||||
this.socketIOServer = io(this.pipeline, {
|
this.socketIOServer = io(this.pipeline, {
|
||||||
path: '/ws',
|
path: '/ws',
|
||||||
root: '/home/project/TSWorkSpace/ms/packages/plugins/public'
|
root: fs.concat(root, 'wwwroot')
|
||||||
});
|
})
|
||||||
this.container.bind(io.Instance).toConstantValue(this.socketIOServer)
|
this.container.bind(io.Instance).toConstantValue(this.socketIOServer)
|
||||||
}
|
}
|
||||||
|
|
||||||
startSocketIOServer() {
|
startSocketIOServer() {
|
||||||
let namespace = this.socketIOServer.of('/MiaoConsole')
|
let namespace = this.socketIOServer.of('/MiaoConsole')
|
||||||
|
global.eventCenter.on('log', (msg) => namespace.emit('log', msg))
|
||||||
namespace.on('connect', (client: SocketIOSocket) => {
|
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) => {
|
client.on('type', (fn) => {
|
||||||
fn && fn(this.serverType)
|
fn && fn(this.serverType)
|
||||||
client.emit('log', `Currect Server Version is ${this.server.getVersion()}`)
|
client.emit('log', `Currect Server Version is ${this.server.getVersion()}`)
|
||||||
@@ -89,7 +205,7 @@ export class MiaoConsole extends interfaces.Plugin {
|
|||||||
try {
|
try {
|
||||||
client.emit('log', this.runCode(code, namespace, client))
|
client.emit('log', this.runCode(code, namespace, client))
|
||||||
} catch (ex) {
|
} 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) => {
|
client.on('edit', (file: string, fn) => {
|
||||||
@@ -101,12 +217,11 @@ export class MiaoConsole extends interfaces.Plugin {
|
|||||||
if (!fs.exists(file)) { return fn('§6插件 §a' + name + ' §6尚未安装 §c请先创建空文件 或安装插件!') }
|
if (!fs.exists(file)) { return fn('§6插件 §a' + name + ' §6尚未安装 §c请先创建空文件 或安装插件!') }
|
||||||
try {
|
try {
|
||||||
base.save(file, content)
|
base.save(file, content)
|
||||||
this.pluginManager.reload(name);
|
this.pluginManager.reload(name)
|
||||||
fn('§6插件 §a' + name + ' §6更新成功!')
|
fn('§6插件 §a' + name + ' §6更新成功!')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(error)
|
this.logger.error(error)
|
||||||
fn('§6插件 §a' + name + ' §4更新异常 错误: ' + error)
|
fn('§6插件 §a' + name + ' §4更新异常 错误: ' + error)
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
client.on('error', (error) => {
|
client.on('error', (error) => {
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ let langMap = {
|
|||||||
'download.finish': '§6插件 §b{name} §a下载完毕 开始加载 ...',
|
'download.finish': '§6插件 §b{name} §a下载完毕 开始加载 ...',
|
||||||
'install.finish': '§6插件 §b{name} §a安装成功!',
|
'install.finish': '§6插件 §b{name} §a安装成功!',
|
||||||
'update.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.token.not.exists': '§4请先配置发布Token!',
|
||||||
'deploy.success': '§6插件 §b{name} §a发布成功! §6服务器返回: §a{msg}',
|
'deploy.success': '§6插件 §b{name} §a发布成功! §6服务器返回: §a{msg}',
|
||||||
'deploy.fail': '§6插件 §b{name} §c发布失败! §6服务器返回: §c{msg}',
|
'deploy.fail': '§6插件 §b{name} §c发布失败! §6服务器返回: §c{msg}',
|
||||||
@@ -49,7 +50,7 @@ let langMap = {
|
|||||||
|
|
||||||
let fallbackMap = langMap
|
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 {
|
export class MiaoScriptPackageManager extends interfaces.Plugin {
|
||||||
@inject(pluginApi.PluginManager)
|
@inject(pluginApi.PluginManager)
|
||||||
private pluginManager: pluginApi.PluginManager;
|
private pluginManager: pluginApi.PluginManager;
|
||||||
@@ -85,7 +86,7 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
main(sender: any, command: string, args: string[]) {
|
main(sender: any, command: string, args: string[]) {
|
||||||
let cmdKey = 'cmd' + args[0]
|
let cmdKey = 'cmd' + (args[0] || 'help')
|
||||||
if (!this[cmdKey]) {
|
if (!this[cmdKey]) {
|
||||||
this.i18n(sender, 'main.command.not.exists', { command: args[0] })
|
this.i18n(sender, 'main.command.not.exists', { command: args[0] })
|
||||||
this.i18n(sender, 'main.command.help.tip', { command })
|
this.i18n(sender, 'main.command.help.tip', { command })
|
||||||
@@ -109,7 +110,7 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmdlist(sender: any, type: string = 'cloud') {
|
cmdlist(sender: any, type: string = 'cloud') {
|
||||||
if (type == "install") {
|
if (type == "i" || type == "install") {
|
||||||
this.i18n(sender, 'list.install.header')
|
this.i18n(sender, 'list.install.header')
|
||||||
this.pluginManager.getPlugins().forEach((plugin) => {
|
this.pluginManager.getPlugins().forEach((plugin) => {
|
||||||
this.i18n(sender, 'list.install.body', plugin.description);
|
this.i18n(sender, 'list.install.body', plugin.description);
|
||||||
@@ -136,7 +137,8 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmdupgrade(sender: any, name: string) {
|
cmdupgrade(sender: any, name: string) {
|
||||||
if (name == "system") {
|
if (!name) { return this.i18n(sender, 'upgrade.confirm'); }
|
||||||
|
if (name == "comfirm") {
|
||||||
let enginePath = fs.path(fs.file(fs.concat(root, 'node_modules', '@ccms')))
|
let enginePath = fs.path(fs.file(fs.concat(root, 'node_modules', '@ccms')))
|
||||||
if (enginePath.startsWith(root)) {
|
if (enginePath.startsWith(root)) {
|
||||||
base.delete(enginePath);
|
base.delete(enginePath);
|
||||||
@@ -195,9 +197,10 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
|
|||||||
|
|
||||||
cmdrun(sender: any, ...args: any[]) {
|
cmdrun(sender: any, ...args: any[]) {
|
||||||
try {
|
try {
|
||||||
var script = args.join(' ');
|
let script = args.join(' ');
|
||||||
this.i18n(sender, 'run.script', { script })
|
this.i18n(sender, 'run.script', { script })
|
||||||
this.i18n(sender, 'run.result', { result: eval(script) || this.translate.translate('run.noresult') })
|
let result = eval(script);
|
||||||
|
this.i18n(sender, 'run.result', { result: result == undefined ? this.translate.translate('run.noresult') : result + '' })
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
this.logger.sender(sender, this.logger.stack(ex));
|
this.logger.sender(sender, this.logger.stack(ex));
|
||||||
}
|
}
|
||||||
@@ -258,11 +261,15 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
|
|||||||
this.taskManager.create(() => {
|
this.taskManager.create(() => {
|
||||||
this.i18n(sender, 'download.start', { name })
|
this.i18n(sender, 'download.start', { name })
|
||||||
this.i18n(sender, 'download.url', { url: this.packageCache[name].url })
|
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)
|
http.download(this.packageCache[name].url, pluginFile)
|
||||||
this.i18n(sender, 'download.finish', { name })
|
this.i18n(sender, 'download.finish', { name })
|
||||||
this.pluginManager.loadFromFile(pluginFile)
|
if (!update) {
|
||||||
this.i18n(sender, update ? 'update.finish' : 'install.finish', { name })
|
this.pluginManager.loadFromFile(fs.file(pluginFile))
|
||||||
|
this.i18n(sender, 'install.finish', { name })
|
||||||
|
} else {
|
||||||
|
this.i18n(sender, 'update.finish', { name })
|
||||||
|
}
|
||||||
}).async().submit()
|
}).async().submit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
packages/sponge/.npmignore
Symbolic link
1
packages/sponge/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/sponge",
|
"name": "@ccms/sponge",
|
||||||
"version": "0.6.5",
|
"version": "0.6.7",
|
||||||
"description": "MiaoScript api package",
|
"description": "MiaoScript api package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -21,11 +21,11 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^3.8.3"
|
"typescript": "^3.9.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.6.5",
|
"@ccms/api": "^0.6.7",
|
||||||
"@ccms/common": "^0.6.4",
|
"@ccms/common": "^0.6.7",
|
||||||
"@ccms/container": "^0.6.0"
|
"@ccms/container": "^0.6.7"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,10 +11,11 @@ const File = Java.type("java.io.File");
|
|||||||
export class SpongeServer implements server.Server {
|
export class SpongeServer implements server.Server {
|
||||||
private pluginsFolder: string;
|
private pluginsFolder: string;
|
||||||
private pipeline: any;
|
private pipeline: any;
|
||||||
|
private rootLogger: any;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.pluginsFolder = new File(base.getInstance().getClass().getProtectionDomain().getCodeSource().getLocation().getPath()).getParentFile().getCanonicalPath()
|
this.pluginsFolder = new File(base.getInstance().getClass().getProtectionDomain().getCodeSource().getLocation().getPath()).getParentFile().getCanonicalPath()
|
||||||
this.reflectPipeline()
|
this.reflect()
|
||||||
}
|
}
|
||||||
|
|
||||||
getPlayer(name: string) {
|
getPlayer(name: string) {
|
||||||
@@ -50,20 +51,27 @@ export class SpongeServer implements server.Server {
|
|||||||
getNettyPipeline() {
|
getNettyPipeline() {
|
||||||
return this.pipeline;
|
return this.pipeline;
|
||||||
}
|
}
|
||||||
|
getRootLogger() {
|
||||||
|
return this.rootLogger;
|
||||||
|
}
|
||||||
sendJson(sender: string | any, json: string): void {
|
sendJson(sender: string | any, json: string): void {
|
||||||
if (typeof sender === "string") {
|
if (typeof sender === "string") {
|
||||||
sender = this.getPlayer(sender)
|
sender = this.getPlayer(sender)
|
||||||
}
|
}
|
||||||
sender.sendMessage(TextSerializers.JSON.deserialize(json))
|
sender.sendMessage(TextSerializers.JSON.deserialize(json))
|
||||||
}
|
}
|
||||||
private reflectPipeline() {
|
private reflect() {
|
||||||
let consoleServer = reflect.on(Sponge.getServer()).get()
|
let consoleServer = reflect.on(Sponge.getServer()).get()
|
||||||
|
this.reflectPipeline(consoleServer)
|
||||||
|
this.reflectRootLogger(consoleServer)
|
||||||
|
}
|
||||||
|
private reflectPipeline(consoleServer: any) {
|
||||||
let connection: any;
|
let connection: any;
|
||||||
let promise: any;
|
let promise: any;
|
||||||
for (const method of constants.Reflect.Method.getServerConnection) {
|
for (const method of constants.Reflect.Method.getServerConnection) {
|
||||||
try {
|
try {
|
||||||
connection = reflect.on(consoleServer).call(method).get()
|
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;
|
connection = undefined;
|
||||||
} catch (error) { }
|
} catch (error) { }
|
||||||
}
|
}
|
||||||
@@ -78,4 +86,11 @@ export class SpongeServer implements server.Server {
|
|||||||
if (!promise) { console.error("Can't found listeningChannels!"); return }
|
if (!promise) { console.error("Can't found listeningChannels!"); return }
|
||||||
this.pipeline = reflect.on(promise).get('channel').get().pipeline()
|
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
1
packages/types/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/types",
|
"name": "@ccms/types",
|
||||||
"version": "0.6.0",
|
"version": "0.6.7",
|
||||||
"description": "MiaoScript types package",
|
"description": "MiaoScript types package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
|
|||||||
1
packages/websocket/.npmignore
Symbolic link
1
packages/websocket/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/websocket",
|
"name": "@ccms/websocket",
|
||||||
"version": "0.6.4",
|
"version": "0.6.7",
|
||||||
"description": "MiaoScript websocket package",
|
"description": "MiaoScript websocket package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -21,9 +21,9 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^3.8.3"
|
"typescript": "^3.9.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/nashorn": "^0.6.4"
|
"@ccms/nashorn": "^0.6.7"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 { 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 CharsetUtil = Java.type('io.netty.util.CharsetUtil')
|
||||||
|
|
||||||
const HttpServerCodec = Java.type('io.netty.handler.codec.http.HttpServerCodec')
|
const HttpServerCodec = Java.type('io.netty.handler.codec.http.HttpServerCodec')
|
||||||
const ChunkedWriteHandler = Java.type('io.netty.handler.stream.ChunkedWriteHandler')
|
const ChunkedWriteHandler = Java.type('io.netty.handler.stream.ChunkedWriteHandler')
|
||||||
const HttpObjectAggregator = Java.type('io.netty.handler.codec.http.HttpObjectAggregator')
|
const HttpObjectAggregator = Java.type('io.netty.handler.codec.http.HttpObjectAggregator')
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ export class Adapter extends EventEmitter implements SocketIO.Adapter {
|
|||||||
var socket: Socket;
|
var socket: Socket;
|
||||||
|
|
||||||
packet.nsp = this.nsp.name;
|
packet.nsp = this.nsp.name;
|
||||||
// let encodedPackets = this.parser.encode(packet)
|
let encodedPackets = this.parser.encode(packet)
|
||||||
if (rooms.length) {
|
if (rooms.length) {
|
||||||
for (var i = 0; i < rooms.length; i++) {
|
for (var i = 0; i < rooms.length; i++) {
|
||||||
var room = self.rooms[rooms[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;
|
if (ids[id] || ~except.indexOf(id)) continue;
|
||||||
socket = self.nsp.connected[id];
|
socket = self.nsp.connected[id];
|
||||||
if (socket) {
|
if (socket) {
|
||||||
socket.packet(packet, packetOpts);
|
socket.packet(encodedPackets as any, packetOpts);
|
||||||
ids[id] = true;
|
ids[id] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,7 +94,7 @@ export class Adapter extends EventEmitter implements SocketIO.Adapter {
|
|||||||
if (self.sids.hasOwnProperty(id)) {
|
if (self.sids.hasOwnProperty(id)) {
|
||||||
if (~except.indexOf(id)) continue;
|
if (~except.indexOf(id)) continue;
|
||||||
socket = self.nsp.connected[id];
|
socket = self.nsp.connected[id];
|
||||||
if (socket) socket.packet(packet, packetOpts);
|
if (socket) socket.packet(encodedPackets as any, packetOpts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,8 +62,8 @@ export class Client extends EventEmitter implements SocketIO.Client {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
packet(packet: Packet, opts?: any) {
|
packet(packet: Packet, opts: any = { preEncoded: false }) {
|
||||||
this.conn.send(parser.encode(packet))
|
this.conn.send(opts.preEncoded ? packet as unknown as string : parser.encode(packet))
|
||||||
}
|
}
|
||||||
onclose(reason?: string) {
|
onclose(reason?: string) {
|
||||||
// debug('client close with reason %s', reason);
|
// debug('client close with reason %s', reason);
|
||||||
|
|||||||
@@ -727,6 +727,16 @@ export declare namespace SocketIO {
|
|||||||
*/
|
*/
|
||||||
del(id: string, room: string, callback?: (err?: any) => void): void;
|
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
|
* Removes a socket from all the rooms that it's joined
|
||||||
* @param id The ID of the socket that we're removing
|
* @param id The ID of the socket that we're removing
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { Socket } from './socket';
|
|||||||
import { Adapter } from './adapter';
|
import { Adapter } from './adapter';
|
||||||
import { Server } from './index'
|
import { Server } from './index'
|
||||||
import { Packet } from './packet';
|
import { Packet } from './packet';
|
||||||
import { SubPacketTypes } from './types';
|
import { PacketTypes, SubPacketTypes } from './types';
|
||||||
|
|
||||||
export class Namespace extends EventEmitter implements SocketIO.Namespace {
|
export class Namespace extends EventEmitter implements SocketIO.Namespace {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -78,7 +78,9 @@ export class Namespace extends EventEmitter implements SocketIO.Namespace {
|
|||||||
}
|
}
|
||||||
// set up packet object
|
// set up packet object
|
||||||
var packet = {
|
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
|
data: args
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -103,6 +103,11 @@ export class Parser {
|
|||||||
p.nsp = '/';
|
p.nsp = '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handle namespace query
|
||||||
|
if (p.nsp.indexOf('?') !== -1) {
|
||||||
|
p.nsp = p.nsp.split('?')[0];
|
||||||
|
}
|
||||||
|
|
||||||
// look up id
|
// look up id
|
||||||
let next = str.charAt(i + 1);
|
let next = str.charAt(i + 1);
|
||||||
if ('' !== next && !isNaN(Number(next))) {
|
if ('' !== next && !isNaN(Number(next))) {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { Packet } from './packet';
|
|||||||
import { PacketTypes, SubPacketTypes } from './types';
|
import { PacketTypes, SubPacketTypes } from './types';
|
||||||
import { Client } from './client';
|
import { Client } from './client';
|
||||||
import { Namespace } from './namespace';
|
import { Namespace } from './namespace';
|
||||||
|
import * as querystring from 'querystring'
|
||||||
|
|
||||||
export class Socket extends EventEmitter implements SocketIO.Socket {
|
export class Socket extends EventEmitter implements SocketIO.Socket {
|
||||||
nsp: Namespace;
|
nsp: Namespace;
|
||||||
@@ -45,7 +46,7 @@ export class Socket extends EventEmitter implements SocketIO.Socket {
|
|||||||
this.acks = {};
|
this.acks = {};
|
||||||
this.connected = true;
|
this.connected = true;
|
||||||
this.disconnected = false;
|
this.disconnected = false;
|
||||||
// this.handshake = this.buildHandshake(query);
|
this.handshake = this.buildHandshake(query);
|
||||||
this.fns = [];
|
this.fns = [];
|
||||||
this.flags = {};
|
this.flags = {};
|
||||||
this._rooms = [];
|
this._rooms = [];
|
||||||
@@ -97,6 +98,14 @@ export class Socket extends EventEmitter implements SocketIO.Socket {
|
|||||||
fn && fn(null);
|
fn && fn(null);
|
||||||
return this;
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
leave(name: string, fn?: Function): SocketIO.Socket {
|
leave(name: string, fn?: Function): SocketIO.Socket {
|
||||||
@@ -127,16 +136,21 @@ export class Socket extends EventEmitter implements SocketIO.Socket {
|
|||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
buildHandshake(query): SocketIO.Handshake {
|
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 {
|
return {
|
||||||
headers: this.request.headers(),
|
headers: headers,
|
||||||
time: (new Date) + '',
|
time: (new Date) + '',
|
||||||
address: this.conn.remoteAddress,
|
address: this.conn.remoteAddress + '',
|
||||||
xdomain: !!this.request.headers.origin,
|
xdomain: !!headers['origin'],
|
||||||
secure: !!this.request.connection.encrypted,
|
secure: false,
|
||||||
issued: +(new Date),
|
issued: +(new Date),
|
||||||
url: this.request.url,
|
url: requestUri,
|
||||||
query: Object.assign(query, requestQuery)
|
query: Object.assign(query, querystring.parse(requestUri.indexOf('?') != -1 ? requestUri.split('?')[1] : ''))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
emit(event: string, ...args: any[]): boolean {
|
emit(event: string, ...args: any[]): boolean {
|
||||||
@@ -183,10 +197,11 @@ export class Socket extends EventEmitter implements SocketIO.Socket {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
packet(packet: Packet, opts?: any) {
|
packet(packet: Packet, opts: any = { preEncoded: false }) {
|
||||||
packet.nsp = this.nsp.name;
|
if (!opts.preEncoded) {
|
||||||
opts = opts || {};
|
packet.nsp = this.nsp.name;
|
||||||
opts.compress = false !== opts.compress;
|
opts.compress = false !== opts.compress;
|
||||||
|
}
|
||||||
this.client.packet(packet, opts);
|
this.client.packet(packet, opts);
|
||||||
}
|
}
|
||||||
onconnect() {
|
onconnect() {
|
||||||
|
|||||||
Reference in New Issue
Block a user