Compare commits
28 Commits
v0.20.0-al
...
v0.21.2
| Author | SHA1 | Date | |
|---|---|---|---|
| 7fc70a92d5 | |||
| df6da12a8a | |||
| 082f2b8f73 | |||
| 7cd85f3f34 | |||
| 073cf6aaac | |||
| 43aa39b86f | |||
| cb58fbdb6c | |||
| 86aacf1a1f | |||
| 47413c6766 | |||
| 4ee8fc9a20 | |||
| 8d0484eefb | |||
| 579d89ae89 | |||
| 010f561766 | |||
| 848aacd991 | |||
| ab5559b26f | |||
| 46729b9cf0 | |||
| 83cad2f52e | |||
| a5cb084767 | |||
| 16ab108186 | |||
| a1df719dc9 | |||
| 41e5754492 | |||
| 866d1dd62c | |||
| 8056d3060d | |||
| b8440b83de | |||
| b55e662f81 | |||
| db526e9444 | |||
| 1b0ea9fa05 | |||
| 143c960da5 |
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "0.20.0-alpha.0",
|
||||
"version": "0.21.2",
|
||||
"useWorkspaces": true,
|
||||
"npmClient": "yarn",
|
||||
"packages": [
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
"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"
|
||||
"lp": "lerna publish --registry https://registry.npmjs.org",
|
||||
"lpb": "lerna publish --registry https://registry.npmjs.org --canary --pre-dist-tag beta"
|
||||
},
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/amqp",
|
||||
"version": "0.20.0-alpha.0",
|
||||
"version": "0.21.2",
|
||||
"description": "MiaoScript amqp package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,17 +19,17 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.20.0-alpha.0",
|
||||
"@ccms/common": "^0.19.0",
|
||||
"@ccms/container": "^0.19.0"
|
||||
"@ccms/api": "^0.21.2",
|
||||
"@ccms/common": "^0.21.2",
|
||||
"@ccms/container": "^0.21.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ccms/nashorn": "^0.19.0",
|
||||
"@ccms/nashorn": "^0.21.2",
|
||||
"@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.5.5"
|
||||
"typescript": "^4.6.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/api",
|
||||
"version": "0.20.0-alpha.0",
|
||||
"version": "0.21.2",
|
||||
"description": "MiaoScript api package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,9 +19,9 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/common": "^0.19.0",
|
||||
"@ccms/container": "^0.19.0",
|
||||
"@ccms/polyfill": "^0.20.0-alpha.0",
|
||||
"@ccms/common": "^0.21.2",
|
||||
"@ccms/container": "^0.21.2",
|
||||
"@ccms/polyfill": "^0.21.2",
|
||||
"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.5.5"
|
||||
"typescript": "^4.6.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,45 @@
|
||||
import { injectable } from "@ccms/container"
|
||||
|
||||
export namespace database {
|
||||
export const DataBaseManager = Symbol("DataBaseManager");
|
||||
export const DataSource = Symbol("DataSource");
|
||||
export const DataBase = Symbol("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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/bukkit",
|
||||
"version": "0.20.0-alpha.0",
|
||||
"version": "0.21.2",
|
||||
"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.5.5"
|
||||
"typescript": "^4.6.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.20.0-alpha.0",
|
||||
"@ccms/common": "^0.19.0",
|
||||
"@ccms/container": "^0.19.0"
|
||||
"@ccms/api": "^0.21.2",
|
||||
"@ccms/common": "^0.21.2",
|
||||
"@ccms/container": "^0.21.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/bungee",
|
||||
"version": "0.20.0-alpha.0",
|
||||
"version": "0.21.2",
|
||||
"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.5.5"
|
||||
"typescript": "^4.6.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.20.0-alpha.0",
|
||||
"@ccms/common": "^0.19.0",
|
||||
"@ccms/container": "^0.19.0"
|
||||
"@ccms/api": "^0.21.2",
|
||||
"@ccms/common": "^0.21.2",
|
||||
"@ccms/container": "^0.21.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"private": true,
|
||||
"name": "@ccms/client",
|
||||
"version": "0.19.0",
|
||||
"version": "0.21.0",
|
||||
"description": "MiaoScript client package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -24,14 +24,14 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.25.0",
|
||||
"minecraft-protocol": "^1.30.0",
|
||||
"axios": "^0.27.2",
|
||||
"minecraft-protocol": "^1.34.0",
|
||||
"minecraft-protocol-forge": "^1.0.0",
|
||||
"proxy-agent": "^5.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^17.0.17",
|
||||
"@types/node": "^17.0.25",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.5.5"
|
||||
"typescript": "^4.6.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@ccms/common",
|
||||
"version": "0.19.0",
|
||||
"description": "MiaoScript api package",
|
||||
"version": "0.21.2",
|
||||
"description": "MiaoScript common package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
"minecraft",
|
||||
@@ -19,11 +19,11 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ccms/nashorn": "^0.19.0",
|
||||
"@ccms/nashorn": "^0.21.2",
|
||||
"@javatypes/jdk": "^0.0.3",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.5.5"
|
||||
"typescript": "^4.6.3"
|
||||
},
|
||||
"gitHead": "562e2d00175c9d3a99c8b672aa07e6d92706a027"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/compile",
|
||||
"version": "0.19.0",
|
||||
"version": "0.21.0",
|
||||
"description": "MiaoScript compile package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -21,6 +21,6 @@
|
||||
"devDependencies": {
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.5.5"
|
||||
"typescript": "^4.6.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/container",
|
||||
"version": "0.19.0",
|
||||
"version": "0.21.2",
|
||||
"description": "MiaoScript container package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,10 +19,10 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ccms/nashorn": "^0.19.0",
|
||||
"@ccms/nashorn": "^0.21.2",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.5.5"
|
||||
"typescript": "^4.6.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"inversify": "^6.0.1",
|
||||
|
||||
@@ -1,38 +1,9 @@
|
||||
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,6 +5,7 @@ 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"
|
||||
|
||||
/**
|
||||
* 注册一个命名对象
|
||||
@@ -49,9 +50,11 @@ export const JavaClass = (className: string) => {
|
||||
*/
|
||||
export const JSClass = (className: string) => {
|
||||
return function (target: object, propertyKey: string, index?: number) {
|
||||
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!')
|
||||
_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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,6 +91,59 @@ 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
|
||||
|
||||
30
packages/container/src/utils.ts
Normal file
30
packages/container/src/utils.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
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.20.0-alpha.0",
|
||||
"description": "MiaoScript api package",
|
||||
"version": "0.21.2",
|
||||
"description": "MiaoScript core package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
"minecraft",
|
||||
@@ -21,11 +21,11 @@
|
||||
"devDependencies": {
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.5.5"
|
||||
"typescript": "^4.6.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.20.0-alpha.0",
|
||||
"@ccms/container": "^0.19.0"
|
||||
"@ccms/api": "^0.21.2",
|
||||
"@ccms/container": "^0.21.2"
|
||||
},
|
||||
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
||||
}
|
||||
|
||||
@@ -3,7 +3,11 @@ 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 {
|
||||
@@ -106,9 +110,22 @@ function loadCoreScript(name) {
|
||||
}
|
||||
}
|
||||
|
||||
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')
|
||||
global.ScriptSlowExecuteTime = 50
|
||||
loadMiaoScriptConfig()
|
||||
global.ScriptEngineVersion = require('../package.json').version
|
||||
global.setGlobal('loadCoreScript', loadCoreScript)
|
||||
loadCoreScript('initialize')
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/database",
|
||||
"version": "0.20.0-alpha.0",
|
||||
"version": "0.21.2",
|
||||
"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.5.5"
|
||||
"typescript": "^4.6.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.20.0-alpha.0",
|
||||
"@ccms/container": "^0.19.0"
|
||||
"@ccms/api": "^0.21.2",
|
||||
"@ccms/container": "^0.21.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,69 +1,63 @@
|
||||
import { Model } from './model'
|
||||
import { database } from '@ccms/api'
|
||||
import { JSClass, postConstruct } from '@ccms/container'
|
||||
|
||||
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
|
||||
}
|
||||
const Properties = Java.type('java.util.Properties')
|
||||
|
||||
/**
|
||||
* 数据库封装类
|
||||
*/
|
||||
export class DataBase {
|
||||
export class DataBase extends database.DataBase {
|
||||
private dataSource: javax.sql.DataSource
|
||||
private jdbcTemplate: org.springframework.jdbc.core.JdbcTemplate
|
||||
|
||||
constructor(dbConfig: DataBaseConfig) {
|
||||
@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()
|
||||
if (!dbConfig.url) { throw new Error('DataBase url can\'t be null!') }
|
||||
this.createDataSource(dbConfig)
|
||||
this.initialize()
|
||||
}
|
||||
|
||||
private createDataSource(dbConfig: DataBaseConfig) {
|
||||
private createDataSource(dbConfig: database.DataBaseConfig) {
|
||||
if (typeof dbConfig.url === "string") {
|
||||
if (!dbConfig.username || !dbConfig.password) {
|
||||
throw new Error('DataBase username or password can\'t be null!')
|
||||
}
|
||||
let config = new HikariConfig()
|
||||
let config = new this.HikariConfig()
|
||||
if (dbConfig.driverClassName) {
|
||||
config.setDriverClassName(dbConfig.driverClassName)
|
||||
}
|
||||
config.setUsername(dbConfig.username)
|
||||
config.setPassword(dbConfig.password)
|
||||
if (dbConfig.username) {
|
||||
config.setUsername(dbConfig.username)
|
||||
}
|
||||
if (dbConfig.password) {
|
||||
config.setPassword(dbConfig.password)
|
||||
}
|
||||
config.setJdbcUrl(dbConfig.url)
|
||||
this.dataSource = new HikariDataSource(config)
|
||||
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)
|
||||
} else {
|
||||
this.dataSource = dbConfig.url
|
||||
}
|
||||
}
|
||||
|
||||
@postConstruct()
|
||||
private initialize() {
|
||||
this.jdbcTemplate = new JdbcTemplate(this.dataSource)
|
||||
this.jdbcTemplate = new this.JdbcTemplate(this.dataSource)
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行SQL查询
|
||||
* @param sql SQL语句
|
||||
* @param args 参数
|
||||
*/
|
||||
query<T>(sql: string, ...args: any[]): Array<T> {
|
||||
let startTime = Date.now()
|
||||
@@ -75,6 +69,7 @@ export class DataBase {
|
||||
/**
|
||||
* 执行SQL更新
|
||||
* @param sql SQL语句
|
||||
* @param args 参数
|
||||
*/
|
||||
update(sql: string, ...args: any[]): number {
|
||||
let startTime = Date.now()
|
||||
@@ -83,6 +78,16 @@ export class 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,5 +2,11 @@
|
||||
/// <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'
|
||||
@@ -1,25 +1,23 @@
|
||||
import { plugin, database } from '@ccms/api'
|
||||
import { provideSingleton, inject, postConstruct } from '@ccms/container'
|
||||
import { DataBase, DataBaseConfig } from './database'
|
||||
import { database } from '@ccms/api'
|
||||
import { provideSingleton } from '@ccms/container'
|
||||
import { DataBase } from './database'
|
||||
|
||||
@provideSingleton(database.DataBaseManager)
|
||||
export class DataBaseManager {
|
||||
@inject(plugin.PluginInstance)
|
||||
private instance: any
|
||||
|
||||
private beanFactory: any
|
||||
export class DataBaseManager extends database.DataBaseManager {
|
||||
private mainDatabase: DataBase
|
||||
private databases: { [key: string]: DataBase } = {}
|
||||
private databases = new Map<string, DataBase>()
|
||||
|
||||
@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)
|
||||
}
|
||||
constructor() {
|
||||
super()
|
||||
process.on('exit', () => this.disable())
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置主数据库
|
||||
* @param mainDatabase 主数据库
|
||||
*/
|
||||
setMainDatabase(mainDatabase: DataBase) {
|
||||
this.mainDatabase = mainDatabase
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,18 +34,28 @@ export class DataBaseManager {
|
||||
* @param name 数据库名称 用于代码 database Name use at code
|
||||
* @param config 数据库配置
|
||||
*/
|
||||
createDatabase(name: string, config: DataBaseConfig) {
|
||||
Java.synchronized(() => {
|
||||
if (this.databases[name]) return this.databases[name]
|
||||
return this.databases[name] = new DataBase(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)
|
||||
}, 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[name]
|
||||
return this.databases.get(name)
|
||||
}
|
||||
|
||||
disable() {
|
||||
Object.values(this.databases).forEach((ds) => ds?.close())
|
||||
this.databases.forEach((db) => db.close())
|
||||
this.databases.clear()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ ms.plugin.initialize: "初始化 MiaoScript 插件系统: 实例: {plugin} 加
|
||||
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 +45,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.20.0-alpha.0",
|
||||
"version": "0.21.2",
|
||||
"description": "MiaoScript i18n package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,11 +19,11 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ccms/nashorn": "^0.19.0",
|
||||
"@ccms/nashorn": "^0.21.2",
|
||||
"@types/js-yaml": "^4.0.5",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.5.5"
|
||||
"typescript": "^4.6.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"js-yaml": "^4.1.0"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/keyvalue",
|
||||
"version": "0.20.0-alpha.0",
|
||||
"version": "0.21.2",
|
||||
"description": "MiaoScript keyvalue package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,18 +19,18 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.20.0-alpha.0",
|
||||
"@ccms/common": "^0.19.0",
|
||||
"@ccms/container": "^0.19.0"
|
||||
"@ccms/api": "^0.21.2",
|
||||
"@ccms/common": "^0.21.2",
|
||||
"@ccms/container": "^0.21.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ccms/nashorn": "^0.19.0",
|
||||
"@ccms/nashorn": "^0.21.2",
|
||||
"@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.5.5"
|
||||
"typescript": "^4.6.3"
|
||||
},
|
||||
"gitHead": "2589633069d24f646ac09261b1b2304c21d4ea75"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/molang",
|
||||
"version": "0.19.0",
|
||||
"version": "0.21.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.17",
|
||||
"@types/node": "^17.0.25",
|
||||
"rimraf": "^3.0.2",
|
||||
"tslib": "^2.3.1",
|
||||
"typescript": "^4.5.5"
|
||||
"typescript": "^4.6.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@ccms/nashorn",
|
||||
"version": "0.19.0",
|
||||
"description": "MiaoScript api package",
|
||||
"version": "0.21.2",
|
||||
"description": "MiaoScript nashorn package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
"minecraft",
|
||||
@@ -22,6 +22,6 @@
|
||||
"devDependencies": {
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.5.5"
|
||||
"typescript": "^4.6.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,18 @@ 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
|
||||
@@ -71,6 +82,7 @@ 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.19.0",
|
||||
"version": "0.21.2",
|
||||
"description": "MiaoScript nodejs package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,11 +19,11 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ccms/nashorn": "^0.19.0",
|
||||
"@ccms/nashorn": "^0.21.2",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"tslib": "^2.3.1",
|
||||
"typescript": "^4.5.5"
|
||||
"typescript": "^4.6.3"
|
||||
},
|
||||
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/nukkit",
|
||||
"version": "0.20.0-alpha.0",
|
||||
"version": "0.21.2",
|
||||
"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.5.5"
|
||||
"typescript": "^4.6.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.20.0-alpha.0",
|
||||
"@ccms/common": "^0.19.0",
|
||||
"@ccms/container": "^0.19.0"
|
||||
"@ccms/api": "^0.21.2",
|
||||
"@ccms/common": "^0.21.2",
|
||||
"@ccms/container": "^0.21.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@ccms/plugin",
|
||||
"version": "0.20.0-alpha.0",
|
||||
"description": "MiaoScript api package",
|
||||
"version": "0.21.2",
|
||||
"description": "MiaoScript plugin package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
"minecraft",
|
||||
@@ -23,13 +23,14 @@
|
||||
"@types/js-yaml": "^4.0.5",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.5.5"
|
||||
"typescript": "^4.6.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.20.0-alpha.0",
|
||||
"@ccms/common": "^0.19.0",
|
||||
"@ccms/container": "^0.19.0",
|
||||
"@ccms/i18n": "^0.20.0-alpha.0",
|
||||
"@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",
|
||||
"crypto-js": "^4.1.1",
|
||||
"js-yaml": "^4.1.0"
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ export class PluginCommandManager {
|
||||
let cmdKey = 'cmd' + subcommand
|
||||
if (!cmdSubCache.includes(subcommand)) {
|
||||
if (!pluginInstance[cmd.executor].apply(pluginInstance, [sender, command, args])) {
|
||||
subcommand && pluginInstance.logger.sender(sender, '§4未知的子命令: §c' + subcommand)
|
||||
subcommand && pluginInstance.logger.sender(sender, `§4未知的命令: §b/${command} §c${subcommand}`)
|
||||
pluginInstance.logger.sender(
|
||||
sender,
|
||||
pluginInstance['cmdhelp'] ?
|
||||
|
||||
3
packages/plugin/src/config/config.ts
Normal file
3
packages/plugin/src/config/config.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from "./loader"
|
||||
export * from "./interfaces"
|
||||
export * from "./file-config"
|
||||
2
packages/plugin/src/config/loader/index.ts
Normal file
2
packages/plugin/src/config/loader/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from './json-loader'
|
||||
export * from './yaml-loader'
|
||||
@@ -1,10 +1,11 @@
|
||||
import './scanner/ms-scanner'
|
||||
import '@ccms/verify'
|
||||
import './scanner/js-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'
|
||||
@@ -17,3 +18,5 @@ 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) {
|
||||
try {
|
||||
if (this.container.isBoundNamed(plugin.Plugin, metadata.name)) {
|
||||
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)
|
||||
} catch {
|
||||
} else {
|
||||
this.container.bind(plugin.Plugin).to(metadata.target).inSingletonScope().whenTargetNamed(metadata.name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,7 +283,6 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
||||
try {
|
||||
return this.buildPlugin(metadata)
|
||||
} catch (error: any) {
|
||||
console.console(`§4无法加载插件 §b${metadata.name} §4构建插件失败!`)
|
||||
console.ex(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,132 +0,0 @@
|
||||
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 Utf8 from "crypto-js/enc-utf8"
|
||||
import * as AES from "crypto-js/aes"
|
||||
|
||||
const SCANNER_TYPE_NAME = 'ms'
|
||||
|
||||
@provideSingletonNamed(plugin.PluginScanner, SCANNER_TYPE_NAME)
|
||||
export class SecretJSFileScanner implements plugin.PluginScanner {
|
||||
type: string = SCANNER_TYPE_NAME
|
||||
|
||||
constructor() {
|
||||
global.setGlobal('MiaoScriptPackageCenterQQCache', {})
|
||||
global.setGlobal('MiaoScriptPackageCenterInfoCache', {})
|
||||
global.setGlobal('MiaoScriptPackageCenterTokenCache', {})
|
||||
global.setGlobal('MiaoScriptPackageCenterResultCache', {})
|
||||
}
|
||||
|
||||
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)
|
||||
let encryptPlugin: any
|
||||
// @ts-ignore load plugin not use cache
|
||||
metadata.instance = require(metadata.file.toString(), {
|
||||
cache: false,
|
||||
beforeCompile: (source: string) => {
|
||||
try {
|
||||
encryptPlugin = JSON.parse(source)
|
||||
} catch (error) {
|
||||
encryptPlugin = require(metadata.file.toString())
|
||||
}
|
||||
if (!encryptPlugin || !encryptPlugin.encrypt) {
|
||||
let filename = metadata.file.toString()
|
||||
filename = filename.startsWith(root) ? filename.split(root)[1] : filename
|
||||
throw new Error(`无效的加密插件: ${filename}.`)
|
||||
}
|
||||
let qq = encryptPlugin.qq
|
||||
let token = this.decrypt(encryptPlugin.token, qq, encryptPlugin.timestamp)
|
||||
global.MiaoScriptPackageCenterQQCache[encryptPlugin.name] = qq
|
||||
global.MiaoScriptPackageCenterInfoCache[encryptPlugin.name] = encryptPlugin
|
||||
global.MiaoScriptPackageCenterTokenCache[encryptPlugin.name] = token
|
||||
let encrypt = encryptPlugin.encrypt
|
||||
try {
|
||||
let needUpdate = Date.now() / 1000 - encryptPlugin.timestamp > 3 * 24 * 60 * 60
|
||||
console.console(`§6[§b圈云授权系统§6] §6加密插件: §b${encryptPlugin.name} §e授权效验中...`)
|
||||
let result = http.post('https://ms.yumc.pw/api/plugin/check', {
|
||||
"pid": encryptPlugin.pid,
|
||||
"qq": qq,
|
||||
"token": token,
|
||||
"source": needUpdate
|
||||
})
|
||||
if (!result) { throw new Error(`授权服务器请求失败.`) }
|
||||
global.MiaoScriptPackageCenterResultCache[encryptPlugin.name] = result
|
||||
if (result.code != 200) {
|
||||
throw new Error(`授权效验失败: ${result.msg}.`)
|
||||
}
|
||||
console.console(`§6[§b圈云授权系统§6] §6加密插件: §b${encryptPlugin.name} §a授权效验通过 正在构建插件...`)
|
||||
if (needUpdate) {
|
||||
if (!result.data) {
|
||||
throw new Error(`授权效验失败: 服务器返回异常数据.`)
|
||||
}
|
||||
base.save(metadata.file, result.data.encrypt)
|
||||
return result.data.source
|
||||
}
|
||||
return this.decrypt(encrypt, qq, token)
|
||||
} catch (error) {
|
||||
console.console(`§6[§b圈云授权系统§6] §6加密插件: §b${encryptPlugin.name} §c授权效验失败: §4${error}.`)
|
||||
}
|
||||
if (Date.now() / 1000 - encryptPlugin.timestamp > 7 * 24 * 60 * 60) {
|
||||
throw new Error(`授权效验失败: 离线授权已过期.`)
|
||||
}
|
||||
console.console(`§6[§b圈云授权系统§6] §6加密插件: §b${encryptPlugin.name} §e离线授权效验通过 正在解密插件...`)
|
||||
let decrypt = this.decrypt(encrypt, qq, token)
|
||||
console.console(`§6[§b圈云授权系统§6] §6加密插件: §b${encryptPlugin.name} §a离线解密成功 正在构建插件...`)
|
||||
return decrypt
|
||||
},
|
||||
afterCompile: () => {
|
||||
delete global.MiaoScriptPackageCenterResultCache[encryptPlugin.name].data
|
||||
global.MiaoScriptPackageCenterResultCache[encryptPlugin.name].timestamp = Date.now()
|
||||
}
|
||||
})
|
||||
return metadata
|
||||
}
|
||||
|
||||
private decrypt(encrypt: string, key: string, iv: string) {
|
||||
return AES.decrypt(encrypt,
|
||||
Utf8.parse(`${key}`.padEnd(16, "\0").substring(0, 16)), {
|
||||
iv: Utf8.parse(`${iv}`.padEnd(16, "\0").substring(0, 16))
|
||||
}).toString(Utf8)
|
||||
}
|
||||
|
||||
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(".ms")) {
|
||||
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.20.0-alpha.0",
|
||||
"version": "0.21.2",
|
||||
"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.20.0-alpha.0",
|
||||
"@ccms/nodejs": "^0.19.0",
|
||||
"core-js": "^3.21.0"
|
||||
"@ccms/i18n": "^0.21.2",
|
||||
"@ccms/nodejs": "^0.21.2",
|
||||
"core-js": "^3.22.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ccms/nashorn": "^0.19.0",
|
||||
"@ccms/nashorn": "^0.21.2",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.5.5"
|
||||
"typescript": "^4.6.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/protocol",
|
||||
"version": "0.19.0",
|
||||
"version": "0.21.0",
|
||||
"description": "MiaoScript protocol package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -22,6 +22,6 @@
|
||||
"devDependencies": {
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.5.5"
|
||||
"typescript": "^4.6.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@ccms/sponge",
|
||||
"version": "0.20.0-alpha.0",
|
||||
"description": "MiaoScript api package",
|
||||
"version": "0.21.2",
|
||||
"description": "MiaoScript sponge 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.5.5"
|
||||
"typescript": "^4.6.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.20.0-alpha.0",
|
||||
"@ccms/common": "^0.19.0",
|
||||
"@ccms/container": "^0.19.0"
|
||||
"@ccms/api": "^0.21.2",
|
||||
"@ccms/common": "^0.21.2",
|
||||
"@ccms/container": "^0.21.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/spring",
|
||||
"version": "0.20.0-alpha.0",
|
||||
"version": "0.21.2",
|
||||
"description": "MiaoScript spring package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -21,12 +21,12 @@
|
||||
"devDependencies": {
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.5.5"
|
||||
"typescript": "^4.6.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.20.0-alpha.0",
|
||||
"@ccms/common": "^0.19.0",
|
||||
"@ccms/container": "^0.19.0",
|
||||
"@ccms/database": "^0.20.0-alpha.0"
|
||||
"@ccms/api": "^0.21.2",
|
||||
"@ccms/common": "^0.21.2",
|
||||
"@ccms/container": "^0.21.2",
|
||||
"@ccms/database": "^0.21.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/web",
|
||||
"version": "0.20.0-alpha.0",
|
||||
"version": "0.21.2",
|
||||
"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.5.5"
|
||||
"typescript": "^4.6.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.20.0-alpha.0",
|
||||
"@ccms/container": "^0.19.0"
|
||||
"@ccms/api": "^0.21.2",
|
||||
"@ccms/container": "^0.21.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/websocket",
|
||||
"version": "0.20.0-alpha.0",
|
||||
"version": "0.21.2",
|
||||
"description": "MiaoScript websocket package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -23,10 +23,10 @@
|
||||
"parseuri": "^0.0.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ccms/nashorn": "^0.19.0",
|
||||
"@ccms/nashorn": "^0.21.2",
|
||||
"@javatypes/tomcat-websocket-api": "^0.0.3",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.5.5"
|
||||
"typescript": "^4.6.3"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user