Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9d891b5596 | |||
| 87b7c66282 | |||
| c8df79a072 | |||
| 2aef84604b | |||
| dbecad996a | |||
| c4aded50f1 | |||
| 93b361a2ac | |||
| 923bf102de | |||
| 4a90455131 | |||
| 2ff57d1c0b |
@@ -1,4 +1,3 @@
|
||||
src
|
||||
test
|
||||
typings
|
||||
bundled
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "0.21.2",
|
||||
"version": "0.19.7",
|
||||
"useWorkspaces": true,
|
||||
"npmClient": "yarn",
|
||||
"packages": [
|
||||
|
||||
@@ -13,8 +13,7 @@
|
||||
"ug": "yarn upgrade-interactive --latest",
|
||||
"np": "./script/push.sh",
|
||||
"lsp": "npm login --registry=https://registry.npmjs.org --scope=@ccms",
|
||||
"lp": "lerna publish --registry https://registry.npmjs.org",
|
||||
"lpb": "lerna publish --registry https://registry.npmjs.org --canary --pre-dist-tag beta"
|
||||
"lp": "lerna publish --registry https://registry.npmjs.org"
|
||||
},
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/amqp",
|
||||
"version": "0.21.2",
|
||||
"version": "0.19.6",
|
||||
"description": "MiaoScript amqp package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,17 +19,17 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.21.2",
|
||||
"@ccms/common": "^0.21.2",
|
||||
"@ccms/container": "^0.21.2"
|
||||
"@ccms/api": "^0.19.6",
|
||||
"@ccms/common": "^0.19.0",
|
||||
"@ccms/container": "^0.19.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ccms/nashorn": "^0.21.2",
|
||||
"@ccms/nashorn": "^0.19.0",
|
||||
"@javatypes/amqp-client": "^0.0.3",
|
||||
"@javatypes/spring-amqp": "^0.0.3",
|
||||
"@javatypes/spring-rabbit": "^0.0.3",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.6.3"
|
||||
"typescript": "^4.5.5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/api",
|
||||
"version": "0.21.2",
|
||||
"version": "0.19.6",
|
||||
"description": "MiaoScript api package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,9 +19,9 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/common": "^0.21.2",
|
||||
"@ccms/container": "^0.21.2",
|
||||
"@ccms/polyfill": "^0.21.2",
|
||||
"@ccms/common": "^0.19.0",
|
||||
"@ccms/container": "^0.19.0",
|
||||
"@ccms/polyfill": "^0.19.0",
|
||||
"base64-js": "^1.5.1",
|
||||
"source-map-builder": "^0.0.7"
|
||||
},
|
||||
@@ -29,6 +29,6 @@
|
||||
"@types/base64-js": "^1.3.0",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.6.3"
|
||||
"typescript": "^4.5.5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,45 +1,5 @@
|
||||
import { injectable } from "@ccms/container"
|
||||
|
||||
export namespace database {
|
||||
export const DataSource = Symbol("DataSource")
|
||||
/**
|
||||
* 数据库配置
|
||||
*/
|
||||
export interface DataBaseConfig {
|
||||
/**
|
||||
* 数据库连接串
|
||||
*/
|
||||
url: string | javax.sql.DataSource
|
||||
/**
|
||||
* 数据库驱动
|
||||
*/
|
||||
driverClassName?: string
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
username?: string
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
password?: string
|
||||
/**
|
||||
* 链接属性
|
||||
*/
|
||||
properties?: { [key: string]: any }
|
||||
}
|
||||
|
||||
@injectable()
|
||||
export abstract class DataBaseManager {
|
||||
abstract setMainDatabase(mainDatabase: DataBase): void
|
||||
abstract getMainDatabase(): DataBase
|
||||
abstract createDatabase(name: string, config: DataBaseConfig): DataBase
|
||||
abstract removeDatabase(name: string): boolean
|
||||
abstract getDatabase(name: string): DataBase
|
||||
}
|
||||
@injectable()
|
||||
export abstract class DataBase {
|
||||
abstract query<T>(sql: string, ...args: any[]): Array<T>
|
||||
abstract update(sql: string, ...args: any[]): number
|
||||
abstract execute(sql: string): void
|
||||
}
|
||||
export const DataBaseManager = Symbol("DataBaseManager");
|
||||
export const DataSource = Symbol("DataSource");
|
||||
export const DataBase = Symbol("DataBase");
|
||||
}
|
||||
|
||||
@@ -133,12 +133,7 @@ export namespace event {
|
||||
// @ts-ignore
|
||||
let executor = exec.name || exec.executor || '[anonymous]'
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
var listener = this.register(
|
||||
eventCls,
|
||||
this.execute(name, exec, eventCls),
|
||||
priority,
|
||||
ignoreCancel
|
||||
)
|
||||
var listener = this.register(eventCls, this.execute(name, exec, eventCls), priority, ignoreCancel)
|
||||
var listenerMap = this.listenerMap
|
||||
// add to cache Be used for close plugin to close event
|
||||
if (!listenerMap[name]) listenerMap[name] = []
|
||||
@@ -146,21 +141,11 @@ export namespace event {
|
||||
if (off['offed']) return
|
||||
off['offed'] = true
|
||||
this.unregister(eventCls, listener)
|
||||
console.debug(i18n.translate("ms.api.event.unregister", {
|
||||
name,
|
||||
event: this.class2Name(eventCls),
|
||||
exec: executor
|
||||
}))
|
||||
console.debug(i18n.translate("ms.api.event.unregister", { name, event: this.class2Name(eventCls), exec: executor }))
|
||||
}
|
||||
listenerMap[name].push(off)
|
||||
// noinspection JSUnresolvedVariable
|
||||
console.debug(i18n.translate("ms.api.event.register", {
|
||||
name,
|
||||
event: this.class2Name(eventCls),
|
||||
exec: executor,
|
||||
priority,
|
||||
ignore: ignoreCancel
|
||||
}))
|
||||
console.debug(i18n.translate("ms.api.event.register", { name, event: this.class2Name(eventCls), exec: executor }))
|
||||
return off
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/bukkit",
|
||||
"version": "0.21.2",
|
||||
"version": "0.19.6",
|
||||
"description": "MiaoScript bukkit package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -22,11 +22,11 @@
|
||||
"@javatypes/spigot-api": "^0.0.3",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.6.3"
|
||||
"typescript": "^4.5.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.21.2",
|
||||
"@ccms/common": "^0.21.2",
|
||||
"@ccms/container": "^0.21.2"
|
||||
"@ccms/api": "^0.19.6",
|
||||
"@ccms/common": "^0.19.0",
|
||||
"@ccms/container": "^0.19.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/bungee",
|
||||
"version": "0.21.2",
|
||||
"version": "0.19.6",
|
||||
"description": "MiaoScript bungee package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -22,11 +22,11 @@
|
||||
"@javatypes/bungee-api": "^0.0.3",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.6.3"
|
||||
"typescript": "^4.5.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.21.2",
|
||||
"@ccms/common": "^0.21.2",
|
||||
"@ccms/container": "^0.21.2"
|
||||
"@ccms/api": "^0.19.6",
|
||||
"@ccms/common": "^0.19.0",
|
||||
"@ccms/container": "^0.19.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"private": true,
|
||||
"name": "@ccms/client",
|
||||
"version": "0.21.0",
|
||||
"version": "0.19.0",
|
||||
"description": "MiaoScript client package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -24,14 +24,14 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.27.2",
|
||||
"minecraft-protocol": "^1.34.0",
|
||||
"axios": "^0.25.0",
|
||||
"minecraft-protocol": "^1.30.0",
|
||||
"minecraft-protocol-forge": "^1.0.0",
|
||||
"proxy-agent": "^5.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^17.0.25",
|
||||
"@types/node": "^17.0.17",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.6.3"
|
||||
"typescript": "^4.5.5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@ccms/common",
|
||||
"version": "0.21.2",
|
||||
"description": "MiaoScript common package",
|
||||
"version": "0.19.0",
|
||||
"description": "MiaoScript api package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
"minecraft",
|
||||
@@ -19,11 +19,11 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ccms/nashorn": "^0.21.2",
|
||||
"@ccms/nashorn": "^0.19.0",
|
||||
"@javatypes/jdk": "^0.0.3",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.6.3"
|
||||
"typescript": "^4.5.5"
|
||||
},
|
||||
"gitHead": "562e2d00175c9d3a99c8b672aa07e6d92706a027"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/compile",
|
||||
"version": "0.21.0",
|
||||
"version": "0.19.0",
|
||||
"description": "MiaoScript compile package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -21,6 +21,6 @@
|
||||
"devDependencies": {
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.6.3"
|
||||
"typescript": "^4.5.5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/container",
|
||||
"version": "0.21.2",
|
||||
"version": "0.19.0",
|
||||
"description": "MiaoScript container package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,10 +19,10 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ccms/nashorn": "^0.21.2",
|
||||
"@ccms/nashorn": "^0.19.0",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.6.3"
|
||||
"typescript": "^4.5.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"inversify": "^6.0.1",
|
||||
|
||||
@@ -1,9 +1,38 @@
|
||||
import { interfaces, Container } from "inversify"
|
||||
import { _proxyGetter } from "./utils"
|
||||
|
||||
let _container: Container
|
||||
|
||||
const ContainerInstance = Symbol.for("@ccms/ioc:Container")
|
||||
const INJECTION = Symbol.for("INJECTION")
|
||||
|
||||
function _proxyGetter(
|
||||
proto: any,
|
||||
key: string,
|
||||
resolve: () => any,
|
||||
doCache: boolean
|
||||
) {
|
||||
function getter(this: object) {
|
||||
if (doCache && !Reflect.hasMetadata(INJECTION, this, key)) {
|
||||
Reflect.defineMetadata(INJECTION, resolve(), this, key)
|
||||
}
|
||||
if (Reflect.hasMetadata(INJECTION, this, key)) {
|
||||
return Reflect.getMetadata(INJECTION, this, key)
|
||||
} else {
|
||||
return resolve()
|
||||
}
|
||||
}
|
||||
|
||||
function setter(this: object, newVal: any) {
|
||||
Reflect.defineMetadata(INJECTION, newVal, this, key)
|
||||
}
|
||||
|
||||
Object.defineProperty(proto, key, {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get: getter,
|
||||
set: setter
|
||||
})
|
||||
}
|
||||
|
||||
function initContainer(container: Container) {
|
||||
Reflect.defineMetadata(ContainerInstance, container, Reflect)
|
||||
|
||||
@@ -5,7 +5,6 @@ import { initContainer, getContainer } from './decorators'
|
||||
import { interfaces, Container, inject, named } from 'inversify'
|
||||
import { fluentProvide } from 'inversify-binding-decorators'
|
||||
import { ioc } from "./constants"
|
||||
import { _proxyGetter } from "./utils"
|
||||
|
||||
/**
|
||||
* 注册一个命名对象
|
||||
@@ -50,11 +49,9 @@ export const JavaClass = (className: string) => {
|
||||
*/
|
||||
export const JSClass = (className: string) => {
|
||||
return function (target: object, propertyKey: string, index?: number) {
|
||||
_proxyGetter(target, propertyKey, () => {
|
||||
try { return Java.type(className) } catch (error: any) { }
|
||||
try { return base.getClass(className).static } catch (error: any) { }
|
||||
console.warn('JSClass', className, 'Inject target', target.constructor.name, 'propertyKey', propertyKey, 'failed!')
|
||||
}, true)
|
||||
try { target[propertyKey] = Java.type(className); return } catch (error: any) { }
|
||||
try { target[propertyKey] = base.getClass(className).static; return } catch (error: any) { }
|
||||
console.warn('JSClass', className, 'Inject target', target.constructor.name, 'propertyKey', propertyKey, 'failed!')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,59 +88,6 @@ export const Resource = (resourceName?: string | any) => {
|
||||
}
|
||||
}
|
||||
|
||||
const DocumentBuilderFactory = Java.type('javax.xml.parsers.DocumentBuilderFactory')
|
||||
|
||||
export const MavenDepend = (groupId: string, artifactId: string, version: string, recursion = false) => {
|
||||
return function (target: any) {
|
||||
loadMavenDepend(groupId, artifactId, version, recursion)
|
||||
}
|
||||
}
|
||||
|
||||
const loadedMavenDepend = new Set<string>()
|
||||
|
||||
export function loadMavenDepend(groupId: string, artifactId: string, version: string, recursion = false) {
|
||||
try {
|
||||
const key = `${groupId}:${artifactId}:${version}`
|
||||
if (loadedMavenDepend.has(key)) { return }
|
||||
console.info('loading maven dependency', key)
|
||||
let [pom, _] = base.loadMavenDepend(groupId, artifactId, version)
|
||||
loadedMavenDepend.add(key)
|
||||
if (recursion) {
|
||||
let doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(pom)
|
||||
let dependencies = doc.getElementsByTagName("dependency")
|
||||
let size = dependencies.length
|
||||
if (!size) { return }
|
||||
console.debug(key, 'found', size, 'dependencies loading...')
|
||||
for (let i = 0; i < size; i++) {
|
||||
const dependency = dependencies.item(i)
|
||||
const gav = dependency.getChildNodes()
|
||||
const length = gav.length
|
||||
const dependencyVersion = { groupId: '', artifactId: '', version: '' }
|
||||
for (let j = 0; j < length; j++) {
|
||||
const prop = gav.item(j)
|
||||
switch (prop.getNodeName()) {
|
||||
case "groupId":
|
||||
dependencyVersion.groupId = prop.getTextContent()
|
||||
break
|
||||
case "artifactId":
|
||||
dependencyVersion.artifactId = prop.getTextContent()
|
||||
break
|
||||
case "version":
|
||||
dependencyVersion.version = prop.getTextContent()
|
||||
break
|
||||
}
|
||||
}
|
||||
loadMavenDepend(dependencyVersion.groupId, dependencyVersion.artifactId, dependencyVersion.version, recursion)
|
||||
}
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.warn('attachMavenDepend failed. Error: ' + error)
|
||||
if (global.debug) {
|
||||
console.ex(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const reduceMetadata = (ctx: interfaces.Context): any => {
|
||||
return ctx.currentRequest.target.metadata.reduce((result, entry, index) => {
|
||||
result[entry.key] = entry.value
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
const INJECTION = Symbol.for("INJECTION")
|
||||
|
||||
export function _proxyGetter(
|
||||
proto: any,
|
||||
key: string,
|
||||
resolve: () => any,
|
||||
doCache: boolean
|
||||
) {
|
||||
function getter(this: object) {
|
||||
if (doCache && !Reflect.hasMetadata(INJECTION, this, key)) {
|
||||
Reflect.defineMetadata(INJECTION, resolve(), this, key)
|
||||
}
|
||||
if (Reflect.hasMetadata(INJECTION, this, key)) {
|
||||
return Reflect.getMetadata(INJECTION, this, key)
|
||||
} else {
|
||||
return resolve()
|
||||
}
|
||||
}
|
||||
|
||||
function setter(this: object, newVal: any) {
|
||||
Reflect.defineMetadata(INJECTION, newVal, this, key)
|
||||
}
|
||||
|
||||
Object.defineProperty(proto, key, {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get: getter,
|
||||
set: setter
|
||||
})
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@ccms/core",
|
||||
"version": "0.21.2",
|
||||
"description": "MiaoScript core package",
|
||||
"version": "0.19.6",
|
||||
"description": "MiaoScript api package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
"minecraft",
|
||||
@@ -21,11 +21,11 @@
|
||||
"devDependencies": {
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.6.3"
|
||||
"typescript": "^4.5.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.21.2",
|
||||
"@ccms/container": "^0.21.2"
|
||||
"@ccms/api": "^0.19.6",
|
||||
"@ccms/container": "^0.19.0"
|
||||
},
|
||||
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
||||
}
|
||||
|
||||
14
packages/core/src/exit.js
Normal file
14
packages/core/src/exit.js
Normal file
@@ -0,0 +1,14 @@
|
||||
function upgradeModules(core) {
|
||||
if (base.version && global.ScriptEngineVersion != core['dist-tags']['latest']) {
|
||||
var Paths = Java.type('java.nio.file.Paths')
|
||||
base.save(Paths.get(root, "upgrade"), core['dist-tags']['latest'])
|
||||
console.info('@ccms/core found new version ' + core['dist-tags']['latest'] + ' will upgrade after reboot!')
|
||||
}
|
||||
}
|
||||
function exit() {
|
||||
var http = require('@ccms/common/dist/http').default
|
||||
upgradeModules(http.get('https://registry.npmmirror.com/@ccms/core'))
|
||||
|
||||
console.debug('exit finish!')
|
||||
}
|
||||
exit()
|
||||
@@ -3,11 +3,7 @@ console.i18n("ms.core.ioc.initialize", { scope: global.scope })
|
||||
import { plugin, server, task, constants } from '@ccms/api'
|
||||
import { DefaultContainer as container, provideSingleton, ContainerInstance, buildProviderModule, Autowired } from '@ccms/container'
|
||||
console.i18n("ms.core.ioc.completed", { scope: global.scope, time: (Date.now() - containerStartTime) / 1000 })
|
||||
import * as yaml from 'js-yaml'
|
||||
import http from '@ccms/common/dist/http'
|
||||
import * as fs from '@ccms/common/dist/fs'
|
||||
|
||||
const UUID = Java.type('java.util.UUID')
|
||||
|
||||
@provideSingleton(MiaoScriptCore)
|
||||
class MiaoScriptCore {
|
||||
@@ -54,7 +50,14 @@ class MiaoScriptCore {
|
||||
this.pluginManager.disable(this.pluginManager.getPlugins())
|
||||
this.taskManager.disable()
|
||||
process.emit('core.after.disable')
|
||||
loadCoreScript('exit')
|
||||
try {
|
||||
engineLoad({
|
||||
script: http.get("https://ms.yumc.pw/api/plugin/download/name/exit"),
|
||||
name: 'core/exit.js'
|
||||
})
|
||||
} catch (error: any) {
|
||||
console.debug(error)
|
||||
}
|
||||
process.emit('core.before.exit')
|
||||
process.exit(0)
|
||||
console.i18n("ms.core.engine.disable.finish", {
|
||||
@@ -95,40 +98,18 @@ function detectServer(): constants.ServerType {
|
||||
throw Error('Unknow Server Type...')
|
||||
}
|
||||
|
||||
function loadCoreScript(name) {
|
||||
try {
|
||||
let scriptname = name + (global.debug ? '-debug' : '')
|
||||
engineLoad({
|
||||
script: http.get(`https://ms.yumc.pw/api/plugin/download/name/${scriptname}`),
|
||||
name: `core/${scriptname}.js`
|
||||
})
|
||||
} catch (error: any) {
|
||||
if (global.debug) {
|
||||
console.debug(error)
|
||||
console.ex(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function loadMiaoScriptConfig() {
|
||||
let configFile = fs.concat(root, 'config.yml')
|
||||
if (!fs.exists(configFile)) {
|
||||
global.ScriptEngineConfig = base.save(configFile, yaml.dump({
|
||||
uuid: UUID.randomUUID().toString(),
|
||||
slow_execute: 50
|
||||
}))
|
||||
} else {
|
||||
global.ScriptEngineConfig = yaml.load(base.read(configFile))
|
||||
}
|
||||
global.ScriptSlowExecuteTime = global.ScriptEngineConfig.slow_execute || 50
|
||||
}
|
||||
|
||||
function initialize() {
|
||||
process.emit('core.before.initialize')
|
||||
loadMiaoScriptConfig()
|
||||
global.ScriptSlowExecuteTime = 30
|
||||
global.ScriptEngineVersion = require('../package.json').version
|
||||
global.setGlobal('loadCoreScript', loadCoreScript)
|
||||
loadCoreScript('initialize')
|
||||
try {
|
||||
engineLoad({
|
||||
script: http.get("https://ms.yumc.pw/api/plugin/download/name/initialize"),
|
||||
name: 'core/initialize.js'
|
||||
})
|
||||
} catch (error: any) {
|
||||
console.debug(error)
|
||||
}
|
||||
try {
|
||||
let corePackageStartTime = new Date().getTime()
|
||||
container.bind(ContainerInstance).toConstantValue(container)
|
||||
@@ -160,12 +141,8 @@ function initialize() {
|
||||
process.emit('core.after.initialize')
|
||||
return disable
|
||||
} catch (error: any) {
|
||||
if (console.console) {
|
||||
console.i18n("ms.core.initialize.error", { error })
|
||||
console.ex(error)
|
||||
} else {
|
||||
error.printStackTrace()
|
||||
}
|
||||
console.i18n("ms.core.initialize.error", { error })
|
||||
console.ex(error)
|
||||
return () => console.i18n('ms.core.engine.disable.abnormal')
|
||||
}
|
||||
}
|
||||
|
||||
51
packages/core/src/initialize.js
Normal file
51
packages/core/src/initialize.js
Normal file
@@ -0,0 +1,51 @@
|
||||
var fs = require('@ccms/common/dist/fs')
|
||||
function updateJar() {
|
||||
if (!base.version) {
|
||||
var pluginFolder = fs.file(fs.concat(root, '..'))
|
||||
var updateFolder = fs.concat(pluginFolder, 'update')
|
||||
}
|
||||
}
|
||||
function upgradeModules(core) {
|
||||
if (base.version && global.ScriptEngineVersion != core['dist-tags']['latest']) {
|
||||
var Paths = Java.type('java.nio.file.Paths')
|
||||
base.save(Paths.get(root, "upgrade"), core['dist-tags']['latest'])
|
||||
console.info('@ccms/core found new version ' + core['dist-tags']['latest'] + ' will upgrade after reboot!')
|
||||
}
|
||||
}
|
||||
function initialize() {
|
||||
var mspmc = 'https://ms.yumc.pw/api/plugin/download/name/'
|
||||
|
||||
var http = require('@ccms/common/dist/http').default
|
||||
|
||||
var pluginFolder = fs.concat(root, 'plugins')
|
||||
var updateFolder = fs.concat(pluginFolder, 'update')
|
||||
var pluginFile = fs.concat(pluginFolder, 'MiaoScriptPackageManager.js')
|
||||
if (!fs.exists(pluginFile)) {
|
||||
fs.mkdirs(pluginFile)
|
||||
base.save(fs.concat(updateFolder, 'MiaoScriptPackageManager.auto.install'), '.')
|
||||
}
|
||||
fs.list(updateFolder).forEach(function (path) {
|
||||
var file = path.toFile()
|
||||
if (file.exists()) {
|
||||
var filename = file.getName()
|
||||
if (filename.endsWith(".auto.install")) {
|
||||
var pluginName = filename.replace('.auto.install', '')
|
||||
var pluginFile = fs.concat(pluginFolder, pluginName + '.js')
|
||||
if (!fs.exists(pluginFile)) {
|
||||
var pluginTemp = pluginFile + '.tmp'
|
||||
http.download(mspmc + pluginName, pluginTemp)
|
||||
fs.move(pluginTemp, pluginFile, true)
|
||||
}
|
||||
base.delete(file)
|
||||
}
|
||||
}
|
||||
})
|
||||
try {
|
||||
Java.type("org.bukkit.Bukkit")
|
||||
updateJar()
|
||||
} catch (ignore) {
|
||||
}
|
||||
upgradeModules(http.get('https://registry.npmmirror.com/@ccms/core'))
|
||||
console.debug('initialize finish!')
|
||||
}
|
||||
initialize()
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/database",
|
||||
"version": "0.21.2",
|
||||
"version": "0.19.6",
|
||||
"description": "MiaoScript database package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -22,10 +22,10 @@
|
||||
"@javatypes/spring-jdbc": "^0.0.3",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.6.3"
|
||||
"typescript": "^4.5.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.21.2",
|
||||
"@ccms/container": "^0.21.2"
|
||||
"@ccms/api": "^0.19.6",
|
||||
"@ccms/container": "^0.19.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,63 +1,69 @@
|
||||
import { database } from '@ccms/api'
|
||||
import { JSClass, postConstruct } from '@ccms/container'
|
||||
import { Model } from './model'
|
||||
|
||||
const Properties = Java.type('java.util.Properties')
|
||||
const HikariDataSource = Java.type('com.zaxxer.hikari.HikariDataSource')
|
||||
const HikariConfig = Java.type('com.zaxxer.hikari.HikariConfig')
|
||||
const JdbcTemplate = Java.type('org.springframework.jdbc.core.JdbcTemplate')
|
||||
|
||||
/**
|
||||
* 数据库配置
|
||||
*/
|
||||
export interface DataBaseConfig {
|
||||
/**
|
||||
* 数据库连接串
|
||||
*/
|
||||
url: string | javax.sql.DataSource
|
||||
/**
|
||||
* 数据库驱动
|
||||
*/
|
||||
driverClassName?: string
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
username?: string
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
password?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据库封装类
|
||||
*/
|
||||
export class DataBase extends database.DataBase {
|
||||
export class DataBase {
|
||||
private dataSource: javax.sql.DataSource
|
||||
private jdbcTemplate: org.springframework.jdbc.core.JdbcTemplate
|
||||
|
||||
@JSClass('com.zaxxer.hikari.HikariDataSource')
|
||||
private HikariDataSource: any
|
||||
@JSClass('com.zaxxer.hikari.HikariConfig')
|
||||
private HikariConfig: any
|
||||
@JSClass('org.springframework.jdbc.core.JdbcTemplate')
|
||||
private JdbcTemplate: typeof org.springframework.jdbc.core.JdbcTemplate
|
||||
|
||||
constructor(dbConfig: database.DataBaseConfig) {
|
||||
super()
|
||||
constructor(dbConfig: DataBaseConfig) {
|
||||
if (!dbConfig.url) { throw new Error('DataBase url can\'t be null!') }
|
||||
this.createDataSource(dbConfig)
|
||||
this.initialize()
|
||||
}
|
||||
|
||||
private createDataSource(dbConfig: database.DataBaseConfig) {
|
||||
private createDataSource(dbConfig: DataBaseConfig) {
|
||||
if (typeof dbConfig.url === "string") {
|
||||
let config = new this.HikariConfig()
|
||||
if (!dbConfig.username || !dbConfig.password) {
|
||||
throw new Error('DataBase username or password can\'t be null!')
|
||||
}
|
||||
let config = new HikariConfig()
|
||||
if (dbConfig.driverClassName) {
|
||||
config.setDriverClassName(dbConfig.driverClassName)
|
||||
}
|
||||
if (dbConfig.username) {
|
||||
config.setUsername(dbConfig.username)
|
||||
}
|
||||
if (dbConfig.password) {
|
||||
config.setPassword(dbConfig.password)
|
||||
}
|
||||
config.setUsername(dbConfig.username)
|
||||
config.setPassword(dbConfig.password)
|
||||
config.setJdbcUrl(dbConfig.url)
|
||||
if (dbConfig.properties) {
|
||||
let properties = new Properties()
|
||||
for (const key in dbConfig.properties) {
|
||||
properties.setProperty(key, dbConfig.properties[key])
|
||||
}
|
||||
config.setDataSourceProperties(properties)
|
||||
}
|
||||
this.dataSource = new this.HikariDataSource(config)
|
||||
this.dataSource = new HikariDataSource(config)
|
||||
} else {
|
||||
this.dataSource = dbConfig.url
|
||||
}
|
||||
}
|
||||
|
||||
@postConstruct()
|
||||
private initialize() {
|
||||
this.jdbcTemplate = new this.JdbcTemplate(this.dataSource)
|
||||
this.jdbcTemplate = new JdbcTemplate(this.dataSource)
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行SQL查询
|
||||
* @param sql SQL语句
|
||||
* @param args 参数
|
||||
*/
|
||||
query<T>(sql: string, ...args: any[]): Array<T> {
|
||||
let startTime = Date.now()
|
||||
@@ -69,7 +75,6 @@ export class DataBase extends database.DataBase {
|
||||
/**
|
||||
* 执行SQL更新
|
||||
* @param sql SQL语句
|
||||
* @param args 参数
|
||||
*/
|
||||
update(sql: string, ...args: any[]): number {
|
||||
let startTime = Date.now()
|
||||
@@ -78,16 +83,6 @@ export class DataBase extends database.DataBase {
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行SQL语句
|
||||
* @param sql SQL语句
|
||||
*/
|
||||
execute(sql: string): void {
|
||||
let startTime = Date.now()
|
||||
this.jdbcTemplate.execute(sql)
|
||||
console.debug(java.lang.String.format(`\n[DB] execute \nSQL : sql} \nCOST : ${Date.now() - startTime}ms`))
|
||||
}
|
||||
|
||||
close() {
|
||||
//@ts-ignore
|
||||
this.dataSource.close()
|
||||
|
||||
@@ -2,11 +2,5 @@
|
||||
/// <reference types="@javatypes/jdk" />
|
||||
/// <reference types="@javatypes/spring-jdbc" />
|
||||
|
||||
import { loadMavenDepend } from '@ccms/container'
|
||||
|
||||
loadMavenDepend('com.h2database', 'h2', '2.1.212')
|
||||
loadMavenDepend("com.zaxxer", "HikariCP", "4.0.3")
|
||||
loadMavenDepend("org.springframework", "spring-jdbc", "5.3.19", true)
|
||||
|
||||
export * from './database'
|
||||
export * from './manager'
|
||||
export * from './manager'
|
||||
@@ -1,23 +1,25 @@
|
||||
import { database } from '@ccms/api'
|
||||
import { provideSingleton } from '@ccms/container'
|
||||
import { DataBase } from './database'
|
||||
import { plugin, database } from '@ccms/api'
|
||||
import { provideSingleton, inject, postConstruct } from '@ccms/container'
|
||||
import { DataBase, DataBaseConfig } from './database'
|
||||
|
||||
@provideSingleton(database.DataBaseManager)
|
||||
export class DataBaseManager extends database.DataBaseManager {
|
||||
export class DataBaseManager {
|
||||
@inject(plugin.PluginInstance)
|
||||
private instance: any
|
||||
|
||||
private beanFactory: any
|
||||
private mainDatabase: DataBase
|
||||
private databases = new Map<string, DataBase>()
|
||||
private databases: { [key: string]: DataBase } = {}
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
process.on('exit', () => this.disable())
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置主数据库
|
||||
* @param mainDatabase 主数据库
|
||||
*/
|
||||
setMainDatabase(mainDatabase: DataBase) {
|
||||
this.mainDatabase = mainDatabase
|
||||
@postConstruct()
|
||||
initialize() {
|
||||
try {
|
||||
this.beanFactory = this.instance.getAutowireCapableBeanFactory()
|
||||
let mainDatasource = this.beanFactory.getBean(Packages.javax.sql.DataSource.class)
|
||||
this.mainDatabase = new DataBase({ url: mainDatasource })
|
||||
} catch (error: any) {
|
||||
console.ex(error)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,28 +36,18 @@ export class DataBaseManager extends database.DataBaseManager {
|
||||
* @param name 数据库名称 用于代码 database Name use at code
|
||||
* @param config 数据库配置
|
||||
*/
|
||||
createDatabase(name: string, config: database.DataBaseConfig) {
|
||||
return Java.synchronized(() => {
|
||||
if (!this.databases.has(name)) {
|
||||
this.databases.set(name, new DataBase(config))
|
||||
}
|
||||
return this.databases.get(name)
|
||||
createDatabase(name: string, config: DataBaseConfig) {
|
||||
Java.synchronized(() => {
|
||||
if (this.databases[name]) return this.databases[name]
|
||||
return this.databases[name] = new DataBase(config)
|
||||
}, this.databases)()
|
||||
}
|
||||
|
||||
removeDatabase(name: string) {
|
||||
if (this.databases.has(name)) {
|
||||
this.databases.get(name).close()
|
||||
}
|
||||
return this.databases.delete(name)
|
||||
}
|
||||
|
||||
getDatabase(name: string) {
|
||||
return this.databases.get(name)
|
||||
return this.databases[name]
|
||||
}
|
||||
|
||||
disable() {
|
||||
this.databases.forEach((db) => db.close())
|
||||
this.databases.clear()
|
||||
Object.values(this.databases).forEach((ds) => ds?.close())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ ms.core.plugin.initialize: "Initialization MiaoScript Plugin System. Please wait
|
||||
ms.core.plugin.completed: "MiaoScript Plugin System loading completed({time}s)!"
|
||||
ms.core.engine.completed: "MiaoScript ScriptEngine loading completed... Done({time}s)!"
|
||||
ms.core.engine.disable: "Disable MiaoScript Engine..."
|
||||
ms.core.engine.disable.finish: "MiaoScript framework {loader} engine {version} 关闭完成... 耗时({time}s)!"
|
||||
ms.core.engine.disable.abnormal: "abnormal Initialization MiaoScript Engine. Skip disable step..."
|
||||
|
||||
ms.api.event.resource.not.found: "Can't Mapping Event Because not found Resources {resource}!"
|
||||
@@ -22,20 +21,16 @@ ms.api.event.not.found: "§6Plugin §b{name} §6register {event} error. event no
|
||||
ms.api.event.execute.slow: "§cWARN! §6Plugin §b{name} §6execute §d{event} §6evnet §ccost §4{cost}ms !"
|
||||
ms.api.event.execute.error: "§6Plugin §b{name} §6execute §d{event} §6event error §4{ex}"
|
||||
ms.api.event.listen.plugin.name.empty: "Plugin name can't be empty!"
|
||||
ms.api.event.register: "[{name}] register event {event} priority {priority} ignoreCancelled {ignore}"
|
||||
ms.api.event.register: "[{name}] register event {event}"
|
||||
ms.api.event.unregister: "[{name}] unregister event {event}"
|
||||
|
||||
ms.api.command.register.input.error: "CommandExec Must be a function... Input: {exec}"
|
||||
ms.api.command.register: "[{plugin}] register command {name}({cmd})..."
|
||||
ms.api.command.unregister: "[{plugin}] unregister command {name}..."
|
||||
ms.api.command.execute.slow: "§cWarn. §6Player §a{player} §6exec §b{plugin} §6Plugin §d{command} {args} §6Command §cCost §4{cost}ms !"
|
||||
ms.api.command.execute.error: "§6Player {player} §6exec §b{plugin} §6Plugin Command §d{command} {args} §6error §4{ex}"
|
||||
ms.api.command.tab.completer.slow: "§cWarn. §6Player §a{player} §6exec §b{plugin} §6Plugin §d{command} {args} §6TabComplete §cCost §4{cost}ms !"
|
||||
ms.api.command.tab.completer.error: "§6Player {player} §6exec §b{plugin} §6Plugin TabComplete §d{command} {args} §6error §4{ex}"
|
||||
|
||||
ms.plugin.initialize: "Initialization MiaoScript Plugin System: Plugin: {plugin} Loader: {loader}..."
|
||||
ms.plugin.event.map: "Total {count} {type} Event Mapping Complate..."
|
||||
ms.plugin.event.map.error: "Mapping {type} Event Failed. Error: {error}"
|
||||
ms.plugin.manager.scan: "Scanner {scanner} Scanning Plugins in {folder} ..."
|
||||
ms.plugin.manager.scan.finish: "Scanner {scanner} Found {size} Plugins in {folder} Start Build..."
|
||||
ms.plugin.manager.initialize.error: "§6Plugin §b{name} §6initialize error §4{ex}"
|
||||
|
||||
@@ -22,9 +22,8 @@ ms.api.event.not.found: "§6插件 §b{name} §6注册事件 §c{event} §6失
|
||||
ms.api.event.execute.slow: "§c注意! §6插件 §b{name} §6处理 §d{event} §6事件 §c耗时 §4{cost}ms !"
|
||||
ms.api.event.execute.error: "§6插件 §b{name} §6处理 §d{event} §6事件时发生异常 §4{ex}"
|
||||
ms.api.event.listen.plugin.name.empty: "插件名称为空 请检查传入参数!"
|
||||
ms.api.event.register: "[{name}] 注册事件 {event} => 执行器 {exec} 优先级 {priority} 忽略取消 {ignore}"
|
||||
ms.api.event.register: "[{name}] 注册事件 {event} => 执行器 {exec}"
|
||||
ms.api.event.unregister: "[{name}] 注销事件 {event} => 执行器 {exec}"
|
||||
|
||||
ms.api.command.register.input.error: "CommandExec 必须为一个函数... 输入: {exec}"
|
||||
ms.api.command.register: "[{plugin}] 注册命令 {name}({cmd})..."
|
||||
ms.api.command.unregister: "[{plugin}] 注销命令 {name}..."
|
||||
@@ -35,9 +34,8 @@ ms.api.command.tab.completer.error: "§6玩家 §a{player} §6执行 §b{plugin}
|
||||
|
||||
ms.plugin.initialize: "初始化 MiaoScript 插件系统: 实例: {plugin} 加载器: {loader}..."
|
||||
ms.plugin.event.map: "总计 {count} 个 {type} 事件 映射完成..."
|
||||
ms.plugin.event.map.error: "映射 {type} 事件 异常 将无法使用事件简称. Error: {error}"
|
||||
ms.plugin.manager.scan: "扫描器 {scanner} 扫描 {folder} 中的插件..."
|
||||
ms.plugin.manager.scan.finish: "扫描器 {scanner} 在 {folder} 中 发现 {size} 个插件 开始编译..."
|
||||
ms.plugin.manager.scan.finish: "扫描器 {scanner} 在 {folder} 中 发现 {size} 个插件 开始构建..."
|
||||
ms.plugin.manager.initialize.error: "§6插件 §b{name} §6初始化错误 §4{ex}"
|
||||
ms.plugin.manager.stage: "{stage} {plugin} 版本 {version} 作者 {author}"
|
||||
ms.plugin.manager.stage.exec: "[{plugin}] 执行 {stage} 阶段函数 {name} 匹配类型 {servers}..."
|
||||
@@ -45,7 +43,7 @@ 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: "插件 {name}({version}) 编译完成 来源: {file}({scanner}) 引导: {loader} 编译耗时: {cost}s."
|
||||
ms.plugin.manager.build: "插件 {name}({version}) 构建完成 来源: {file}({scanner}) 引导: {loader} 构建耗时: {cost}s."
|
||||
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, 将不会被载入到服务器!"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/i18n",
|
||||
"version": "0.21.2",
|
||||
"version": "0.19.0",
|
||||
"description": "MiaoScript i18n package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,11 +19,11 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ccms/nashorn": "^0.21.2",
|
||||
"@ccms/nashorn": "^0.19.0",
|
||||
"@types/js-yaml": "^4.0.5",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.6.3"
|
||||
"typescript": "^4.5.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"js-yaml": "^4.1.0"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/keyvalue",
|
||||
"version": "0.21.2",
|
||||
"version": "0.19.6",
|
||||
"description": "MiaoScript keyvalue package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,18 +19,18 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.21.2",
|
||||
"@ccms/common": "^0.21.2",
|
||||
"@ccms/container": "^0.21.2"
|
||||
"@ccms/api": "^0.19.6",
|
||||
"@ccms/common": "^0.19.0",
|
||||
"@ccms/container": "^0.19.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ccms/nashorn": "^0.21.2",
|
||||
"@ccms/nashorn": "^0.19.0",
|
||||
"@javatypes/amqp-client": "^0.0.3",
|
||||
"@javatypes/spring-amqp": "^0.0.3",
|
||||
"@javatypes/spring-rabbit": "^0.0.3",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.6.3"
|
||||
"typescript": "^4.5.5"
|
||||
},
|
||||
"gitHead": "2589633069d24f646ac09261b1b2304c21d4ea75"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/molang",
|
||||
"version": "0.21.0",
|
||||
"version": "0.19.0",
|
||||
"description": "A fast parser for Minecraft's MoLang",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
@@ -21,9 +21,9 @@
|
||||
},
|
||||
"homepage": "https://github.com/solvedDev/MoLang#readme",
|
||||
"devDependencies": {
|
||||
"@types/node": "^17.0.25",
|
||||
"@types/node": "^17.0.17",
|
||||
"rimraf": "^3.0.2",
|
||||
"tslib": "^2.3.1",
|
||||
"typescript": "^4.6.3"
|
||||
"typescript": "^4.5.5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@ccms/nashorn",
|
||||
"version": "0.21.2",
|
||||
"description": "MiaoScript nashorn package",
|
||||
"version": "0.19.0",
|
||||
"description": "MiaoScript api package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
"minecraft",
|
||||
@@ -22,6 +22,6 @@
|
||||
"devDependencies": {
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.6.3"
|
||||
"typescript": "^4.5.5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,18 +49,7 @@ declare global {
|
||||
logger: any
|
||||
debug: boolean
|
||||
level: string
|
||||
/**
|
||||
* 引擎配置
|
||||
*/
|
||||
ScriptEngineConfig: any
|
||||
/**
|
||||
* 引擎版本
|
||||
*/
|
||||
ScriptEngineVersion: string
|
||||
/**
|
||||
* 引擎渠道
|
||||
*/
|
||||
ScriptEngineChannel: string
|
||||
ScriptSlowExecuteTime: number
|
||||
ScriptEngineStartTime: number
|
||||
setGlobal: (key: string, value: any, config?: PropertyDescriptor & ThisType<any>) => void
|
||||
@@ -82,7 +71,6 @@ declare global {
|
||||
getProxyClass(): any
|
||||
getJavaScriptTaskClass(): any
|
||||
getInstance(): any
|
||||
loadMavenDepend(groupId: string, artifactId: string, version: string): [any, any]
|
||||
read(path: string): string
|
||||
save(path: string, content: string): void
|
||||
delete(path: string): void
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/nodejs",
|
||||
"version": "0.21.2",
|
||||
"version": "0.19.0",
|
||||
"description": "MiaoScript nodejs package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,11 +19,11 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ccms/nashorn": "^0.21.2",
|
||||
"@ccms/nashorn": "^0.19.0",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"tslib": "^2.3.1",
|
||||
"typescript": "^4.6.3"
|
||||
"typescript": "^4.5.5"
|
||||
},
|
||||
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/nukkit",
|
||||
"version": "0.21.2",
|
||||
"version": "0.19.6",
|
||||
"description": "MiaoScript nukkit package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -22,11 +22,11 @@
|
||||
"@javatypes/nukkit-api": "^0.0.3",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.6.3"
|
||||
"typescript": "^4.5.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.21.2",
|
||||
"@ccms/common": "^0.21.2",
|
||||
"@ccms/container": "^0.21.2"
|
||||
"@ccms/api": "^0.19.6",
|
||||
"@ccms/common": "^0.19.0",
|
||||
"@ccms/container": "^0.19.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@ccms/plugin",
|
||||
"version": "0.21.2",
|
||||
"description": "MiaoScript plugin package",
|
||||
"version": "0.19.7",
|
||||
"description": "MiaoScript api package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
"minecraft",
|
||||
@@ -19,19 +19,18 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/crypto-js": "^4.1.1",
|
||||
"@types/js-yaml": "^4.0.5",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.6.3"
|
||||
"typescript": "^4.5.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.21.2",
|
||||
"@ccms/common": "^0.21.2",
|
||||
"@ccms/container": "^0.21.2",
|
||||
"@ccms/i18n": "^0.21.2",
|
||||
"@ccms/verify": "^0.21.1",
|
||||
"@ccms/api": "^0.19.6",
|
||||
"@ccms/common": "^0.19.0",
|
||||
"@ccms/container": "^0.19.0",
|
||||
"@ccms/i18n": "^0.19.0",
|
||||
"crypto-js": "^4.1.1",
|
||||
"js-yaml": "^4.1.0"
|
||||
"js-yaml": "^4.1.0",
|
||||
"yaml": "^1.10.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,34 +54,37 @@ export class PluginCommandManager {
|
||||
cmdExecutor = (sender: any, command: string, args: string[]) => {
|
||||
let subcommand = args[0]
|
||||
let cmdKey = 'cmd' + subcommand
|
||||
if (!cmdSubCache.includes(subcommand)) {
|
||||
if (!pluginInstance[cmd.executor].apply(pluginInstance, [sender, command, args])) {
|
||||
subcommand && pluginInstance.logger.sender(sender, `§4未知的命令: §b/${command} §c${subcommand}`)
|
||||
pluginInstance.logger.sender(
|
||||
sender,
|
||||
pluginInstance['cmdhelp'] ?
|
||||
`§6请执行 §b/${command} §ahelp §6查看帮助!` :
|
||||
[
|
||||
`§6插件: §b${pluginInstance.description.name}`,
|
||||
`§6版本: §a${pluginInstance.description.version}`
|
||||
]
|
||||
)
|
||||
}
|
||||
let subcommandexec = pluginInstance[cmdKey]
|
||||
if (!subcommandexec) {
|
||||
subcommandexec = pluginInstance['cmdmain']
|
||||
subcommand = 'main'
|
||||
} else {
|
||||
args.shift()
|
||||
}
|
||||
if (!subcommandexec) {
|
||||
subcommand && pluginInstance.logger.sender(sender, '§4未知的子命令: §c' + subcommand)
|
||||
pluginInstance.logger.sender(
|
||||
sender,
|
||||
pluginInstance['cmdhelp'] ?
|
||||
`§6请执行 §b/${command} §ahelp §6查看帮助!` :
|
||||
[
|
||||
`§6插件: §b${pluginInstance.description.name}`,
|
||||
`§6版本: §a${pluginInstance.description.version}`
|
||||
]
|
||||
)
|
||||
return
|
||||
}
|
||||
let subcommandexec = pluginInstance[cmdKey]
|
||||
let permission: string
|
||||
if (cmd.permission && sender.hasPermission) {
|
||||
if (typeof cmd.permission == "string") {
|
||||
permission = cmd.permission as string
|
||||
} else {
|
||||
permission = `${pluginInstance.description.name.toLocaleLowerCase()}.${command}.${subcommand || 'main'}`
|
||||
permission = `${pluginInstance.description.name.toLocaleLowerCase()}.${command}.${subcommand}`
|
||||
}
|
||||
if (!sender.hasPermission(permission)) {
|
||||
return pluginInstance.logger.sender(sender, `§c你需要 ${permission} 权限 才可执行此命令.`)
|
||||
}
|
||||
}
|
||||
args.shift()
|
||||
return subcommandexec.apply(pluginInstance, [sender, ...args])
|
||||
}
|
||||
let originCompleter = cmdCompleter
|
||||
|
||||
@@ -1,36 +1,59 @@
|
||||
import { plugin } from '@ccms/api'
|
||||
import { Autowired, Container, ContainerInstance, postConstruct, provideSingleton } from '@ccms/container'
|
||||
|
||||
import * as yaml from 'js-yaml'
|
||||
import * as fs from '@ccms/common/dist/fs'
|
||||
import { plugin } from '@ccms/api'
|
||||
import { provideSingleton } from '@ccms/container'
|
||||
|
||||
import { interfaces } from './interfaces'
|
||||
import { getPluginConfigMetadata } from './utils'
|
||||
|
||||
import { PluginConfigLoader } from './config/interfaces'
|
||||
import './config/loader/json-loader'
|
||||
import './config/loader/yaml-loader'
|
||||
export interface PluginConfigLoader {
|
||||
load(content: string): any
|
||||
dump(variable: any): string
|
||||
}
|
||||
|
||||
export class YamlPluginConfig implements PluginConfigLoader {
|
||||
load(content: string) {
|
||||
return yaml.load(content)
|
||||
}
|
||||
dump(variable: any): string {
|
||||
return yaml.dump(variable, { skipInvalid: true, lineWidth: 120 })
|
||||
}
|
||||
}
|
||||
|
||||
export class JsonPluginConfig implements PluginConfigLoader {
|
||||
load(content: string) {
|
||||
return JSON.parse(content)
|
||||
}
|
||||
dump(variable: any): string {
|
||||
return JSON.stringify(variable, undefined, 4)
|
||||
}
|
||||
}
|
||||
|
||||
export interface PluginConfig {
|
||||
/**
|
||||
* Save Config to File
|
||||
*/
|
||||
readonly save?: () => void
|
||||
/**
|
||||
* Reload Config from File
|
||||
*/
|
||||
readonly reload?: () => void
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
@provideSingleton(PluginConfigManager)
|
||||
export class PluginConfigManager {
|
||||
@Autowired(ContainerInstance)
|
||||
private container: Container
|
||||
|
||||
private configLoaderMap = new Map<string, PluginConfigLoader>()
|
||||
|
||||
constructor() {
|
||||
this.configLoaderMap.set("json", new JsonPluginConfig())
|
||||
let yaml = new YamlPluginConfig()
|
||||
this.configLoaderMap.set("yml", yaml)
|
||||
this.configLoaderMap.set("yaml", yaml)
|
||||
process.on('plugin.before.load', this.loadConfig.bind(this))
|
||||
process.on('plugin.after.disable', this.saveConfig.bind(this))
|
||||
}
|
||||
|
||||
@postConstruct()
|
||||
initialize() {
|
||||
let configLoader = this.container.getAll<PluginConfigLoader>(PluginConfigLoader)
|
||||
configLoader.forEach((scanner) => {
|
||||
console.debug(`loading config loader ${scanner.type}...`)
|
||||
this.configLoaderMap.set(scanner.type, scanner)
|
||||
})
|
||||
}
|
||||
|
||||
getConfigLoader(format: string) {
|
||||
if (!this.configLoaderMap.has(format)) { throw new Error(`Unsupport config format ${format} !`) }
|
||||
return this.configLoaderMap.get(format)
|
||||
@@ -50,17 +73,13 @@ export class PluginConfigManager {
|
||||
}
|
||||
}
|
||||
|
||||
createConfig(plugin: plugin.Plugin, metadata: interfaces.ConfigMetadata, value: any) {
|
||||
private defienConfigProp(plugin: plugin.Plugin, metadata: interfaces.ConfigMetadata, value: any) {
|
||||
Object.defineProperties(value, {
|
||||
'save': { value: () => this.saveConfig0(plugin, metadata) },
|
||||
'reload': { value: () => this.loadConfig0(plugin, metadata) }
|
||||
})
|
||||
return value
|
||||
}
|
||||
|
||||
private defienConfigProp(plugin: plugin.Plugin, metadata: interfaces.ConfigMetadata, value: any) {
|
||||
Object.defineProperty(plugin, metadata.variable, {
|
||||
value: this.createConfig(plugin, metadata, value),
|
||||
value,
|
||||
configurable: true
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
export * from "./loader"
|
||||
export * from "./interfaces"
|
||||
export * from "./file-config"
|
||||
@@ -1,65 +0,0 @@
|
||||
import * as fs from '@ccms/common/dist/fs'
|
||||
|
||||
import { PluginConfig, PluginConfigLoader } from './interfaces'
|
||||
|
||||
export class PluginFileConfig implements PluginConfig {
|
||||
private loader: PluginConfigLoader
|
||||
private file: string
|
||||
constructor(loader: PluginConfigLoader, file: string, def = {}) {
|
||||
this.loader = loader
|
||||
this.file = file
|
||||
if (fs.exists(file)) {
|
||||
this.reload()
|
||||
} else {
|
||||
Object.assign(this, def)
|
||||
}
|
||||
this.initialize()
|
||||
}
|
||||
|
||||
initialize() {
|
||||
}
|
||||
|
||||
save() {
|
||||
base.save(this.file, this.loader.dump(this))
|
||||
}
|
||||
|
||||
reload() {
|
||||
Object.assign(this, this.loader.load(base.read(this.file)))
|
||||
}
|
||||
}
|
||||
|
||||
export class PluginConfigFolder {
|
||||
private loader: PluginConfigLoader
|
||||
private folder: string
|
||||
|
||||
private configCache = new Map<string, PluginFileConfig>()
|
||||
|
||||
constructor(loader: PluginConfigLoader, folder: string) {
|
||||
this.loader = loader
|
||||
this.folder = folder
|
||||
}
|
||||
|
||||
createConfig(path: string, def = {}) {
|
||||
return new PluginFileConfig(this.loader, path, def)
|
||||
}
|
||||
|
||||
getConfig(name: string, def = {}) {
|
||||
let path = fs.concat(this.folder, name)
|
||||
if (!this.configCache.has(path)) {
|
||||
this.configCache.set(path, this.createConfig(path, def))
|
||||
}
|
||||
return this.configCache.get(path)
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.configCache.clear()
|
||||
}
|
||||
|
||||
save() {
|
||||
this.configCache.forEach((config) => config.save())
|
||||
}
|
||||
|
||||
reload() {
|
||||
this.configCache.forEach((config) => config.reload())
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
export const PluginConfigLoader = Symbol.for('PluginConfigLoader')
|
||||
export interface PluginConfigLoader {
|
||||
type: string
|
||||
load(content: string): any
|
||||
dump(variable: any): string
|
||||
}
|
||||
|
||||
export interface PluginConfig {
|
||||
/**
|
||||
* Save Config to File
|
||||
*/
|
||||
readonly save?: () => void
|
||||
/**
|
||||
* Reload Config from File
|
||||
*/
|
||||
readonly reload?: () => void
|
||||
[key: string]: any
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
export * from './json-loader'
|
||||
export * from './yaml-loader'
|
||||
@@ -1,18 +0,0 @@
|
||||
import { provideSingletonNamed } from '@ccms/container'
|
||||
|
||||
import { PluginConfigLoader } from '../interfaces'
|
||||
|
||||
const LOADER_TYPE_NAME = 'json'
|
||||
|
||||
@provideSingletonNamed(PluginConfigLoader, LOADER_TYPE_NAME)
|
||||
export class JsonPluginConfig implements PluginConfigLoader {
|
||||
type: string = LOADER_TYPE_NAME
|
||||
|
||||
load(content: string) {
|
||||
return JSON.parse(content)
|
||||
}
|
||||
|
||||
dump(variable: any): string {
|
||||
return JSON.stringify(variable, undefined, 4)
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
import * as yaml from 'js-yaml'
|
||||
import { provideSingletonNamed } from '@ccms/container'
|
||||
|
||||
import { PluginConfigLoader } from '../interfaces'
|
||||
|
||||
const LOADER_TYPE_NAME = 'yml'
|
||||
|
||||
@provideSingletonNamed(PluginConfigLoader, LOADER_TYPE_NAME)
|
||||
export class YamlPluginConfig implements PluginConfigLoader {
|
||||
type: string = LOADER_TYPE_NAME
|
||||
|
||||
load(content: string) {
|
||||
return yaml.load(content)
|
||||
}
|
||||
|
||||
dump(variable: any): string {
|
||||
return yaml.dump(variable, { skipInvalid: true, lineWidth: 120 })
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
import '@ccms/verify'
|
||||
import './scanner/js-scanner'
|
||||
import './scanner/mjs-scanner'
|
||||
|
||||
import './loader/ioc-loader'
|
||||
import './loader/basic-loader'
|
||||
|
||||
export * from './config'
|
||||
export * from './config/config'
|
||||
export * from './manager'
|
||||
export * from './decorators'
|
||||
export * from './interfaces'
|
||||
@@ -18,5 +17,3 @@ export {
|
||||
config as Config,
|
||||
playerdata as PlayerData
|
||||
} from './decorators'
|
||||
|
||||
import '@ccms/database'
|
||||
|
||||
@@ -63,13 +63,13 @@ export class IocLoader implements plugin.PluginLoader {
|
||||
}
|
||||
|
||||
private bindPlugin(metadata: plugin.PluginMetadata) {
|
||||
if (this.container.isBoundNamed(plugin.Plugin, metadata.name)) {
|
||||
try {
|
||||
let pluginInstance = this.container.getNamed<plugin.Plugin>(plugin.Plugin, metadata.name)
|
||||
if (pluginInstance.description.source + '' !== metadata.source + '') {
|
||||
console.i18n('ms.plugin.manager.build.duplicate', { exists: pluginInstance.description.source, source: metadata.source })
|
||||
}
|
||||
this.container.rebind(plugin.Plugin).to(metadata.target).inSingletonScope().whenTargetNamed(metadata.name)
|
||||
} else {
|
||||
} catch {
|
||||
this.container.bind(plugin.Plugin).to(metadata.target).inSingletonScope().whenTargetNamed(metadata.name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,13 +64,9 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
||||
initialize() {
|
||||
if (this.pluginInstance === undefined) { throw new Error("Can't found Plugin Instance!") }
|
||||
if (this.initialized !== true) {
|
||||
process.emit('plugin.manager.before.initialize', this)
|
||||
process.emit('plugin.manager.before.initialize')
|
||||
console.i18n('ms.plugin.initialize', { plugin: this.pluginInstance, loader: Thread.currentThread().contextClassLoader })
|
||||
try {
|
||||
console.i18n('ms.plugin.event.map', { count: this.eventManager.mapEventName(), type: this.serverType })
|
||||
} catch (error) {
|
||||
console.i18n('ms.plugin.event.map.error', { error })
|
||||
}
|
||||
console.i18n('ms.plugin.event.map', { count: this.eventManager.mapEventName(), type: this.serverType })
|
||||
let pluginScanner = this.container.getAll<plugin.PluginScanner>(plugin.PluginScanner)
|
||||
pluginScanner.forEach((scanner) => {
|
||||
console.debug(`loading plugin sacnner ${scanner.type}...`)
|
||||
@@ -82,14 +78,14 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
||||
this.loaderMap.set(loader.type, loader)
|
||||
})
|
||||
this.initialized = true
|
||||
process.emit('plugin.manager.after.initialize', this)
|
||||
process.emit('plugin.manager.after.initialize')
|
||||
}
|
||||
}
|
||||
|
||||
scan(folder: string): void {
|
||||
if (!folder) { throw new Error('plugin scan folder can\'t be empty!') }
|
||||
this.initialize()
|
||||
process.emit('plugin.manager.before.scan', folder, this)
|
||||
process.emit('plugin.manager.before.scan', folder)
|
||||
for (const [, scanner] of this.sacnnerMap) {
|
||||
try {
|
||||
console.i18n('ms.plugin.manager.scan', { scanner: scanner.type, folder })
|
||||
@@ -108,13 +104,13 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
||||
console.ex(error)
|
||||
}
|
||||
}
|
||||
process.emit('plugin.manager.after.scan', folder, this)
|
||||
process.emit('plugin.manager.after.scan', folder)
|
||||
}
|
||||
|
||||
build(): void {
|
||||
process.emit('plugin.manager.before.build', this)
|
||||
process.emit('plugin.manager.before.build')
|
||||
this.buildPlugins()
|
||||
process.emit('plugin.manager.after.build', this)
|
||||
process.emit('plugin.manager.after.build')
|
||||
}
|
||||
|
||||
private logStage(plugin: plugin.Plugin, stage: string) {
|
||||
@@ -148,6 +144,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
||||
console.i18n("ms.plugin.manager.initialize.error", { name: loadMetadata.file, ex: error })
|
||||
console.ex(error)
|
||||
}
|
||||
console.console(`§6scanner: §b${loadMetadata.scanner.type} §ccan\'t load §6file §b${loadMetadata.file}. §eskip!`)
|
||||
}
|
||||
|
||||
private loaderRequirePlugin(loadMetadata: plugin.PluginLoadMetadata, loader: plugin.PluginLoader) {
|
||||
@@ -198,9 +195,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
||||
let scanner = this.sacnnerMap.get(ext)
|
||||
if (!scanner) { throw new Error(`plugin scanner ${ext} can't found in sacnnerMap.`) }
|
||||
let metadata = this.loadAndRequirePlugin(scanner.read(file))
|
||||
this.buildPlugin(metadata)
|
||||
let plugin = metadata.target
|
||||
if (!plugin) { throw new Error(`plugin scanner ${ext} can't found in sacnnerMap.`) }
|
||||
let plugin = this.buildPlugin(metadata)
|
||||
this.load(plugin)
|
||||
this.enable(plugin)
|
||||
return plugin
|
||||
@@ -260,10 +255,10 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
||||
if (metadata?.depends?.length) {
|
||||
this.lazyMetadataMap.set(key, metadata)
|
||||
} else {
|
||||
this.tryBuildPlugin(metadata)
|
||||
this.buildPlugin(metadata)
|
||||
}
|
||||
})
|
||||
this.lazyMetadataMap.forEach((metadata, key) => this.tryBuildPlugin(metadata))
|
||||
this.lazyMetadataMap.forEach((metadata, key) => this.buildPlugin(metadata))
|
||||
}
|
||||
|
||||
private checkDepends(depends: string | string[]) {
|
||||
@@ -278,29 +273,24 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
||||
for (const depend of depends) { if (!this.nativePluginManager.has(depend)) loseDepends.push(depend) }
|
||||
return loseDepends
|
||||
}
|
||||
|
||||
private tryBuildPlugin(metadata: plugin.PluginMetadata) {
|
||||
private buildPlugin(metadata: plugin.PluginMetadata) {
|
||||
process.emit(`plugin.before.build`, metadata)
|
||||
try {
|
||||
return this.buildPlugin(metadata)
|
||||
if (this.instanceMap.has(metadata.name)) { throw new Error(`Plugin ${metadata.name} is already load from ${metadata.source}...`) }
|
||||
if (!this.loaderMap.has(metadata.type)) { throw new Error(`§4无法加载插件 §b${metadata.name} §4请检查 §c${metadata.type} §4加载器是否正常启用!`) }
|
||||
if (!this.serverChecker.check(metadata.servers)) { throw new Error(`§6插件 §b${metadata.name} §c服务器类型不兼容(${metadata.servers.join(',')}) §6忽略加载...`) }
|
||||
let loseDepends = this.checkDepends(metadata.depends) || []
|
||||
if (loseDepends.length) { throw new Error(`§4无法加载插件 §b${metadata.name} §4请检查脚本依赖 §3[${loseDepends.join(',')}] §4是否安装完整!`) }
|
||||
let loseNativeDepends = this.checkNativeDepends(metadata.nativeDepends) || []
|
||||
if (loseNativeDepends.length) { throw new Error(`§4无法加载插件 §b${metadata.name} §4请检查插件依赖 §3[${loseNativeDepends.join(',')}] §4是否安装完整!`) }
|
||||
let pluginInstance = this.loaderMap.get(metadata.type).build(metadata)
|
||||
if (!pluginInstance) { throw new Error(`§4加载器 §c${metadata.type} §4加载插件 §c${metadata.name} §4失败!`) }
|
||||
this.instanceMap.set(metadata.name, pluginInstance)
|
||||
process.emit(`plugin.after.build`, metadata, pluginInstance)
|
||||
return pluginInstance
|
||||
} catch (error: any) {
|
||||
console.console(`§4无法加载插件 §b${metadata.name} §4构建插件失败!`)
|
||||
console.ex(error)
|
||||
}
|
||||
}
|
||||
|
||||
private buildPlugin(metadata: plugin.PluginMetadata) {
|
||||
process.emit(`plugin.before.build`, metadata)
|
||||
if (this.instanceMap.has(metadata.name)) { throw new Error(`Plugin ${metadata.name} is already load from ${metadata.source}...`) }
|
||||
if (!this.loaderMap.has(metadata.type)) { throw new Error(`§4无法加载插件 §b${metadata.name} §4请检查 §c${metadata.type} §4加载器是否正常启用!`) }
|
||||
if (!this.serverChecker.check(metadata.servers)) { throw new Error(`§6插件 §b${metadata.name} §c服务器类型不兼容(${metadata.servers.join(',')}) §6忽略加载...`) }
|
||||
let loseDepends = this.checkDepends(metadata.depends) || []
|
||||
if (loseDepends.length) { throw new Error(`§4无法加载插件 §b${metadata.name} §4请检查脚本依赖 §3[${loseDepends.join(',')}] §4是否安装完整!`) }
|
||||
let loseNativeDepends = this.checkNativeDepends(metadata.nativeDepends) || []
|
||||
if (loseNativeDepends.length) { throw new Error(`§4无法加载插件 §b${metadata.name} §4请检查插件依赖 §3[${loseNativeDepends.join(',')}] §4是否安装完整!`) }
|
||||
let pluginInstance = this.loaderMap.get(metadata.type).build(metadata)
|
||||
if (!pluginInstance) { throw new Error(`§4加载器 §c${metadata.type} §4加载插件 §c${metadata.name} §4失败!`) }
|
||||
metadata.target = pluginInstance
|
||||
this.instanceMap.set(metadata.name, pluginInstance)
|
||||
process.emit(`plugin.after.build`, metadata, pluginInstance)
|
||||
return pluginInstance
|
||||
}
|
||||
}
|
||||
|
||||
131
packages/plugin/src/scanner/mjs-scanner.ts
Normal file
131
packages/plugin/src/scanner/mjs-scanner.ts
Normal file
@@ -0,0 +1,131 @@
|
||||
import { plugin } from "@ccms/api"
|
||||
import http from '@ccms/common/dist/http'
|
||||
import { provideSingletonNamed } from "@ccms/container"
|
||||
|
||||
import * as fs from '@ccms/common/dist/fs'
|
||||
|
||||
import * as CryptoJS from "crypto-js"
|
||||
|
||||
const SCANNER_TYPE_NAME = 'mjs'
|
||||
|
||||
@provideSingletonNamed(plugin.PluginScanner, SCANNER_TYPE_NAME)
|
||||
export class SecretJSFileScanner implements plugin.PluginScanner {
|
||||
type: string = SCANNER_TYPE_NAME
|
||||
|
||||
constructor() {
|
||||
global.setGlobal('MiaoScriptPackageCenterTokenCache', {})
|
||||
global.setGlobal('MiaoScriptPackageCenterQQCache', {})
|
||||
}
|
||||
|
||||
scan(target: any): plugin.PluginLoadMetadata[] {
|
||||
return this.scanFolder(fs.concat(root, target)).map((file) => this.read(file))
|
||||
}
|
||||
|
||||
read(file: any): plugin.PluginLoadMetadata {
|
||||
return { file, type: this.type, scanner: this, loaded: false }
|
||||
}
|
||||
|
||||
load(metadata: plugin.PluginLoadMetadata): plugin.PluginLoadMetadata {
|
||||
if (metadata.type !== this.type) { return }
|
||||
this.updatePlugin(metadata.file)
|
||||
//@ts-ignore load plugin not use cache
|
||||
metadata.instance = require(metadata.file.toString(), {
|
||||
cache: false,
|
||||
hook: (origin) => {
|
||||
let info = JSON.parse(origin)
|
||||
if (!info || !info.encrypt) {
|
||||
return this.exportErrorPlugin(
|
||||
metadata.file,
|
||||
`console.console('§4无效的加密插件: §c${metadata.file}')`
|
||||
)
|
||||
}
|
||||
let qq = info.qq
|
||||
let encrypt = info.encrypt
|
||||
let token = this.decrypt(info.token, qq, info.timestamp)
|
||||
global.MiaoScriptPackageCenterQQCache[info.name] = qq
|
||||
global.MiaoScriptPackageCenterTokenCache[info.name] = token
|
||||
try {
|
||||
let result = http.post('https://ms.yumc.pw/api/plugin/check', `{
|
||||
"pid": ${info.pid},
|
||||
"qq": ${qq},
|
||||
"token": "${token}",
|
||||
"source": true
|
||||
}`)
|
||||
if (result.code != 200) {
|
||||
return this.exportErrorPlugin(
|
||||
info.name,
|
||||
`console.console('§6[§b圈云授权系统§6] §6插件: §b${info.name} §c授权效验失败: §4${result.msg}')`
|
||||
)
|
||||
}
|
||||
if (!result.data) {
|
||||
return this.exportErrorPlugin(
|
||||
info.name,
|
||||
`console.console('§6[§b圈云授权系统§6] §6插件: §b${info.name} §c服务器返回异常数据.')`
|
||||
)
|
||||
}
|
||||
base.save(metadata.file, result.data.encrypt)
|
||||
return result.data.source
|
||||
} catch (error) {
|
||||
}
|
||||
if (Date.now() / 1000 - info.timestamp > 7 * 24 * 60 * 60) {
|
||||
return this.exportErrorPlugin(
|
||||
info.name,
|
||||
`console.console('§6[§b圈云授权系统§6] §6插件: §b${info.name} §c离线授权已过期.')`
|
||||
)
|
||||
}
|
||||
return this.decrypt(encrypt, qq, token)
|
||||
}
|
||||
})
|
||||
return metadata
|
||||
}
|
||||
|
||||
private decrypt(encrypt, key, iv) {
|
||||
return CryptoJS.AES.decrypt(encrypt,
|
||||
CryptoJS.enc.Utf8.parse(`${key}`.padEnd(16, "\0").substring(0, 16)), {
|
||||
iv: CryptoJS.enc.Utf8.parse(`${iv}`.padEnd(16, "\0").substring(0, 16))
|
||||
}).toString(CryptoJS.enc.Utf8)
|
||||
}
|
||||
|
||||
private exportErrorPlugin(name, src) {
|
||||
return `module.exports = {
|
||||
description: {
|
||||
name: "${name}",
|
||||
version: "未授权",
|
||||
author: "未授权",
|
||||
type: "basic",
|
||||
source: __filename,
|
||||
target: this
|
||||
},
|
||||
load: function () { ${src} }
|
||||
}`
|
||||
}
|
||||
|
||||
private scanFolder(folder: any): string[] {
|
||||
var files = []
|
||||
this.checkUpdateFolder(folder)
|
||||
// must check file is exist maybe is a illegal symbolic link file
|
||||
fs.list(folder).forEach((path: any) => {
|
||||
let file = path.toFile()
|
||||
if (file.exists() && (file.getName().endsWith(".mjs.json") || file.getName().endsWith(".mjs"))) {
|
||||
files.push(file)
|
||||
}
|
||||
})
|
||||
return files
|
||||
}
|
||||
|
||||
private checkUpdateFolder(path: any) {
|
||||
var update = fs.file(path, "update")
|
||||
if (!update.exists()) {
|
||||
update.mkdirs()
|
||||
}
|
||||
}
|
||||
|
||||
private updatePlugin(file: any) {
|
||||
var update = fs.file(fs.file(fs.file(file).parentFile, 'update'), file.name)
|
||||
if (update.exists()) {
|
||||
console.i18n("ms.plugin.manager.build.update", { name: file.name })
|
||||
fs.move(update, file, true)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/polyfill",
|
||||
"version": "0.21.2",
|
||||
"version": "0.19.0",
|
||||
"description": "MiaoScript polyfill package",
|
||||
"author": "MiaoWoo <admin@yumc.pw>",
|
||||
"homepage": "https://github.com/circlecloud/ms.git",
|
||||
@@ -14,14 +14,14 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/i18n": "^0.21.2",
|
||||
"@ccms/nodejs": "^0.21.2",
|
||||
"core-js": "^3.22.1"
|
||||
"@ccms/i18n": "^0.19.0",
|
||||
"@ccms/nodejs": "^0.19.0",
|
||||
"core-js": "^3.21.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ccms/nashorn": "^0.21.2",
|
||||
"@ccms/nashorn": "^0.19.0",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.6.3"
|
||||
"typescript": "^4.5.5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/protocol",
|
||||
"version": "0.21.0",
|
||||
"version": "0.19.0",
|
||||
"description": "MiaoScript protocol package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -22,6 +22,6 @@
|
||||
"devDependencies": {
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.6.3"
|
||||
"typescript": "^4.5.5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@ccms/sponge",
|
||||
"version": "0.21.2",
|
||||
"description": "MiaoScript sponge package",
|
||||
"version": "0.19.6",
|
||||
"description": "MiaoScript api package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
"minecraft",
|
||||
@@ -22,11 +22,11 @@
|
||||
"@javatypes/sponge-api": "^0.0.3",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.6.3"
|
||||
"typescript": "^4.5.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.21.2",
|
||||
"@ccms/common": "^0.21.2",
|
||||
"@ccms/container": "^0.21.2"
|
||||
"@ccms/api": "^0.19.6",
|
||||
"@ccms/common": "^0.19.0",
|
||||
"@ccms/container": "^0.19.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/spring",
|
||||
"version": "0.21.2",
|
||||
"version": "0.19.6",
|
||||
"description": "MiaoScript spring package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -21,12 +21,12 @@
|
||||
"devDependencies": {
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.6.3"
|
||||
"typescript": "^4.5.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.21.2",
|
||||
"@ccms/common": "^0.21.2",
|
||||
"@ccms/container": "^0.21.2",
|
||||
"@ccms/database": "^0.21.2"
|
||||
"@ccms/api": "^0.19.6",
|
||||
"@ccms/common": "^0.19.0",
|
||||
"@ccms/container": "^0.19.0",
|
||||
"@ccms/database": "^0.19.6"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/web",
|
||||
"version": "0.21.2",
|
||||
"version": "0.19.6",
|
||||
"description": "MiaoScript web package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -26,10 +26,10 @@
|
||||
"@javatypes/tomcat": "^0.0.3",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.6.3"
|
||||
"typescript": "^4.5.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.21.2",
|
||||
"@ccms/container": "^0.21.2"
|
||||
"@ccms/api": "^0.19.6",
|
||||
"@ccms/container": "^0.19.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/websocket",
|
||||
"version": "0.21.2",
|
||||
"version": "0.19.0",
|
||||
"description": "MiaoScript websocket package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -23,10 +23,10 @@
|
||||
"parseuri": "^0.0.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ccms/nashorn": "^0.21.2",
|
||||
"@ccms/nashorn": "^0.19.0",
|
||||
"@javatypes/tomcat-websocket-api": "^0.0.3",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.6.3"
|
||||
"typescript": "^4.5.5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
import * as server from "../server"
|
||||
// const http = require("http")
|
||||
// const Server = require("./server")
|
||||
import { Server } from './server'
|
||||
@@ -17,7 +18,7 @@ import { Server } from './server'
|
||||
|
||||
function attach(srv, options) {
|
||||
const engine = new Server(options)
|
||||
engine.attach(srv, options)
|
||||
engine.attach(server.attach(srv, options), options)
|
||||
return engine
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/// <reference types="@ccms/nashorn" />
|
||||
/// <reference types="@javatypes/tomcat-websocket-api" />
|
||||
|
||||
import * as server from './server'
|
||||
import { Server, ServerOptions } from './socket.io'
|
||||
|
||||
interface SocketIOStatic {
|
||||
@@ -39,21 +38,9 @@ interface SocketIOStatic {
|
||||
|
||||
type SocketStatic = SocketIOStatic & { Instance?: symbol }
|
||||
|
||||
let singletonServer: Server
|
||||
|
||||
// @ts-ignore
|
||||
let io: SocketStatic = function io(pipeline: any, options: Partial<JavaServerOptions>, singleton = true) {
|
||||
if (singleton) {
|
||||
if (!singletonServer) {
|
||||
singletonServer = new Server(server.attach(pipeline, options), options)
|
||||
process.emit('websocket.create', singletonServer)
|
||||
process.on('exit', () => {
|
||||
singletonServer.close()
|
||||
})
|
||||
}
|
||||
return singletonServer
|
||||
}
|
||||
return new Server(server.attach(pipeline, options), options)
|
||||
let io: SocketStatic = function (pipeline: any, options: Partial<ServerOptions>) {
|
||||
return new Server(pipeline, options)
|
||||
}
|
||||
io.Instance = Symbol("@ccms/websocket")
|
||||
export default io
|
||||
|
||||
@@ -19,7 +19,6 @@ export enum ServerEvent {
|
||||
export interface JavaServerOptions extends ServerOptions {
|
||||
event?: EventEmitter
|
||||
root?: string
|
||||
httpRequestHandler?: (ctx, request) => void
|
||||
}
|
||||
|
||||
export abstract class WebSocketServer extends EventEmitter {
|
||||
@@ -31,6 +30,7 @@ export abstract class WebSocketServer extends EventEmitter {
|
||||
this.instance = instance
|
||||
this.options = options
|
||||
this.clients = new Map()
|
||||
console.debug('create websocket server from ' + this.constructor.name)
|
||||
this.initialize()
|
||||
}
|
||||
protected onconnect(handler: any) {
|
||||
@@ -56,7 +56,7 @@ export abstract class WebSocketServer extends EventEmitter {
|
||||
if (this.clients.has(id)) {
|
||||
this.clients.has(id) && callback(this.clients.get(id))
|
||||
} else {
|
||||
console.trace('ignore execute', handler, 'callback', callback)
|
||||
console.debug('ignore execute', handler, 'callback', callback)
|
||||
}
|
||||
}
|
||||
public close() {
|
||||
@@ -75,7 +75,7 @@ export const attach = (instance, options) => {
|
||||
options = Object.assign({
|
||||
event: new EventEmitter(),
|
||||
path: '/ws',
|
||||
root: root + Java.type("java.io.File").separatorChar + 'wwwroot',
|
||||
root: root + '/wwwroot',
|
||||
}, options)
|
||||
let WebSocketServerImpl = undefined
|
||||
if (instance.class.name.startsWith('io.netty.channel')) {
|
||||
@@ -83,6 +83,5 @@ export const attach = (instance, options) => {
|
||||
} else {
|
||||
WebSocketServerImpl = require("./tomcat").TomcatWebSocketServer
|
||||
}
|
||||
console.debug('create websocket server from ' + WebSocketServerImpl.name)
|
||||
return new WebSocketServerImpl(instance, options)
|
||||
}
|
||||
|
||||
@@ -23,46 +23,40 @@ export class HttpRequestHandler extends HttpRequestHandlerAdapter {
|
||||
super()
|
||||
this.root = options.root
|
||||
this.ws = options.path
|
||||
if (options.httpRequestHandler) {
|
||||
this.httpRequestHandler = options.httpRequestHandler
|
||||
}
|
||||
}
|
||||
channelRead0(ctx: any, request: any) {
|
||||
if (request.getUri().startsWith(this.ws)) {
|
||||
ctx.channel().attr(AttributeKeys.Request).set(request)
|
||||
ctx.fireChannelRead(request.retain())
|
||||
} else {
|
||||
this.httpRequestHandler(ctx, request)
|
||||
ctx.executor().execute(new Runnable({
|
||||
run: () => {
|
||||
if (HttpHeaders.is100ContinueExpected(request)) {
|
||||
ctx.writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE))
|
||||
}
|
||||
let filename = request.getUri().split('?')[0].substr(1)
|
||||
let file = new File(this.root, filename || 'index.html')
|
||||
if (!file.exists() || !file.isFile()) {
|
||||
ctx.write(new DefaultHttpResponse(request.getProtocolVersion(), HttpResponseStatus.NOT_FOUND))
|
||||
ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT).addListener(ChannelFutureListener.CLOSE)
|
||||
return
|
||||
}
|
||||
let response = new DefaultHttpResponse(request.getProtocolVersion(), HttpResponseStatus.OK)
|
||||
response.headers().set(HttpHeaders.Names.CONTENT_TYPE, "text/html charset=UTF-8")
|
||||
let raf = new RandomAccessFile(file, 'r')
|
||||
let keepAlive = HttpHeaders.isKeepAlive(request)
|
||||
if (keepAlive) {
|
||||
response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, file.length())
|
||||
response.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.KEEP_ALIVE)
|
||||
}
|
||||
ctx.write(response)
|
||||
ctx.write(new DefaultFileRegion(raf.getChannel(), 0, raf.length()))
|
||||
let future = ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT)
|
||||
if (!keepAlive) {
|
||||
future.addListener(ChannelFutureListener.CLOSE)
|
||||
}
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
httpRequestHandler(ctx: any, request: any) {
|
||||
ctx.executor().execute(new Runnable({
|
||||
run: () => {
|
||||
if (HttpHeaders.is100ContinueExpected(request)) {
|
||||
ctx.writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE))
|
||||
}
|
||||
let filename = request.getUri().split('?')[0].substr(1)
|
||||
let file = new File(this.root, filename || 'index.html')
|
||||
if (!file.exists() || !file.isFile()) {
|
||||
ctx.write(new DefaultHttpResponse(request.getProtocolVersion(), HttpResponseStatus.NOT_FOUND))
|
||||
ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT).addListener(ChannelFutureListener.CLOSE)
|
||||
return
|
||||
}
|
||||
let response = new DefaultHttpResponse(request.getProtocolVersion(), HttpResponseStatus.OK)
|
||||
response.headers().set(HttpHeaders.Names.CONTENT_TYPE, "text/html charset=UTF-8")
|
||||
let raf = new RandomAccessFile(file, 'r')
|
||||
let keepAlive = HttpHeaders.isKeepAlive(request)
|
||||
if (keepAlive) {
|
||||
response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, file.length())
|
||||
response.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.KEEP_ALIVE)
|
||||
}
|
||||
ctx.write(response)
|
||||
ctx.write(new DefaultFileRegion(raf.getChannel(), 0, raf.length()))
|
||||
let future = ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT)
|
||||
if (!keepAlive) {
|
||||
future.addListener(ChannelFutureListener.CLOSE)
|
||||
}
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user