2020-06-02 09:50:47 +00:00
|
|
|
import * as reflect from '@ccms/common/dist/reflect'
|
2020-10-13 01:24:58 +00:00
|
|
|
import { injectable, Autowired, ContainerInstance, Container, postConstruct } from '@ccms/container'
|
2020-06-02 09:50:47 +00:00
|
|
|
|
2020-10-13 01:24:58 +00:00
|
|
|
import { constants } from './constants'
|
2020-09-22 07:29:12 +00:00
|
|
|
|
2019-09-07 04:23:15 +00:00
|
|
|
export namespace server {
|
2020-01-15 08:48:18 +00:00
|
|
|
/**
|
|
|
|
* Runtime ServerType
|
|
|
|
*/
|
2020-06-02 09:50:47 +00:00
|
|
|
export const ServerType = Symbol("ServerType")
|
2020-01-15 08:48:18 +00:00
|
|
|
/**
|
|
|
|
* Runtime Console
|
|
|
|
*/
|
2020-06-02 09:50:47 +00:00
|
|
|
export const Console = Symbol("Console")
|
2020-01-15 08:48:18 +00:00
|
|
|
/**
|
|
|
|
* Runtime Server Instance
|
|
|
|
*/
|
2020-06-02 09:50:47 +00:00
|
|
|
export const ServerInstance = Symbol("ServerInstance")
|
2021-08-03 09:30:53 +00:00
|
|
|
export interface NativePlugin {
|
|
|
|
name: string
|
|
|
|
version: string
|
|
|
|
authors?: string | string[]
|
|
|
|
enable: boolean
|
|
|
|
depends?: string[]
|
|
|
|
softDepends?: string[]
|
|
|
|
/**
|
|
|
|
* 插件本体
|
|
|
|
*/
|
|
|
|
origin: any
|
|
|
|
[key: string]: any
|
|
|
|
}
|
2020-10-13 01:24:58 +00:00
|
|
|
@injectable()
|
|
|
|
export abstract class NativePluginManager {
|
2021-08-03 09:30:53 +00:00
|
|
|
list(): NativePlugin[] {
|
2020-12-07 03:12:49 +00:00
|
|
|
throw new Error("Method not implemented.")
|
|
|
|
}
|
2020-10-13 01:24:58 +00:00
|
|
|
has(name: string): boolean {
|
|
|
|
return true
|
|
|
|
}
|
2021-08-03 09:30:53 +00:00
|
|
|
get(name: string): NativePlugin {
|
2020-12-07 03:12:49 +00:00
|
|
|
throw new Error("Method not implemented.")
|
|
|
|
}
|
2022-04-01 09:18:32 +00:00
|
|
|
enable(name: string): NativePlugin {
|
2020-10-13 01:24:58 +00:00
|
|
|
throw new Error("Method not implemented.")
|
|
|
|
}
|
2022-04-01 09:18:32 +00:00
|
|
|
disable(name: string): NativePlugin {
|
2020-10-13 01:24:58 +00:00
|
|
|
throw new Error("Method not implemented.")
|
|
|
|
}
|
2022-04-01 09:18:32 +00:00
|
|
|
reload(name: string): NativePlugin {
|
2020-10-13 01:24:58 +00:00
|
|
|
throw new Error("Method not implemented.")
|
|
|
|
}
|
|
|
|
delete(name: string): boolean {
|
|
|
|
throw new Error("Method not implemented.")
|
|
|
|
}
|
|
|
|
}
|
2020-01-15 08:48:18 +00:00
|
|
|
/**
|
|
|
|
* MiaoScript Server
|
|
|
|
*/
|
2020-06-02 09:50:47 +00:00
|
|
|
@injectable()
|
2020-09-22 09:33:59 +00:00
|
|
|
export abstract class Server {
|
2020-06-02 09:50:47 +00:00
|
|
|
getVersion(): string {
|
|
|
|
throw new Error("Method not implemented.")
|
|
|
|
}
|
2020-09-22 09:33:59 +00:00
|
|
|
getPlayer(name: string): any {
|
2020-06-02 09:50:47 +00:00
|
|
|
throw new Error("Method not implemented.")
|
|
|
|
}
|
|
|
|
getOnlinePlayers(): any[] {
|
|
|
|
throw new Error("Method not implemented.")
|
|
|
|
}
|
2020-09-22 09:33:59 +00:00
|
|
|
getConsoleSender(): any {
|
2020-06-02 09:50:47 +00:00
|
|
|
throw new Error("Method not implemented.")
|
|
|
|
}
|
2020-09-22 09:33:59 +00:00
|
|
|
getService(service: string): any {
|
2020-06-02 09:50:47 +00:00
|
|
|
throw new Error("Method not implemented.")
|
|
|
|
}
|
2021-10-25 07:54:38 +00:00
|
|
|
broadcast(message: string, permission: string) {
|
|
|
|
throw new Error("Method not implemented.")
|
|
|
|
}
|
|
|
|
broadcastMessage(message: string) {
|
|
|
|
throw new Error("Method not implemented.")
|
|
|
|
}
|
2020-09-22 09:33:59 +00:00
|
|
|
dispatchCommand(sender: string | any, command: string): boolean {
|
2020-06-02 09:50:47 +00:00
|
|
|
throw new Error("Method not implemented.")
|
|
|
|
}
|
|
|
|
dispatchConsoleCommand(command: string): boolean {
|
|
|
|
throw new Error("Method not implemented.")
|
|
|
|
}
|
|
|
|
getPluginsFolder(): string {
|
|
|
|
throw new Error("Method not implemented.")
|
|
|
|
}
|
2020-09-22 09:33:59 +00:00
|
|
|
getDedicatedServer?(): any {
|
2020-06-02 09:50:47 +00:00
|
|
|
throw new Error("Method not implemented.")
|
|
|
|
}
|
2020-09-22 09:33:59 +00:00
|
|
|
getNettyPipeline(): any {
|
2020-06-02 09:50:47 +00:00
|
|
|
throw new Error("Method not implemented.")
|
|
|
|
}
|
2020-09-22 09:33:59 +00:00
|
|
|
getRootLogger(): any {
|
2020-06-02 09:50:47 +00:00
|
|
|
throw new Error("Method not implemented.")
|
|
|
|
}
|
2020-09-22 09:33:59 +00:00
|
|
|
}
|
|
|
|
@injectable()
|
|
|
|
export class ServerChecker {
|
2020-10-13 01:24:58 +00:00
|
|
|
@Autowired(ServerType)
|
2020-09-22 09:33:59 +00:00
|
|
|
private serverType: string
|
2020-10-13 01:24:58 +00:00
|
|
|
|
2020-09-22 09:33:59 +00:00
|
|
|
check(servers: string[]) {
|
|
|
|
// Not set servers -> allow
|
|
|
|
if (!servers || !servers.length) return true
|
|
|
|
// include !type -> deny
|
|
|
|
let denyServers = servers.filter(svr => svr.startsWith("!"))
|
|
|
|
if (denyServers.length !== 0) {
|
|
|
|
return !denyServers.includes(`!${this.serverType}`)
|
|
|
|
} else {
|
|
|
|
// only include -> allow
|
|
|
|
return servers.includes(this.serverType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@injectable()
|
|
|
|
export abstract class ReflectServer extends server.Server {
|
2020-10-13 01:24:58 +00:00
|
|
|
@Autowired(ContainerInstance)
|
|
|
|
private container: Container
|
|
|
|
|
2020-09-22 09:33:59 +00:00
|
|
|
protected pipeline: any
|
|
|
|
protected rootLogger: any
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super()
|
|
|
|
}
|
|
|
|
|
2020-10-13 01:24:58 +00:00
|
|
|
@postConstruct()
|
2020-06-02 09:50:47 +00:00
|
|
|
protected reflect() {
|
|
|
|
try {
|
|
|
|
let consoleServer = this.getDedicatedServer()
|
|
|
|
this.reflectPipeline(consoleServer)
|
|
|
|
this.reflectRootLogger(consoleServer)
|
2021-12-25 17:21:06 +00:00
|
|
|
} catch (error: any) {
|
2020-06-02 09:50:47 +00:00
|
|
|
console.error('Error When Reflect MinecraftServer!', error)
|
|
|
|
console.ex(error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
protected reflectPipeline(consoleServer: any) {
|
|
|
|
let connection: any
|
|
|
|
let promise: any
|
|
|
|
for (const method of constants.Reflect.Method.getServerConnection) {
|
|
|
|
try {
|
|
|
|
connection = reflect.on(consoleServer).call(method).get()
|
|
|
|
if (connection.class.name.indexOf('ServerConnection') !== -1
|
|
|
|
|| connection.class.name.indexOf('NetworkSystem') !== -1) { break }
|
|
|
|
connection = undefined
|
2021-12-25 17:21:06 +00:00
|
|
|
} catch (error: any) {
|
2020-10-13 01:24:58 +00:00
|
|
|
if (global.debug) {
|
|
|
|
console.ex(error)
|
|
|
|
}
|
|
|
|
}
|
2020-06-02 09:50:47 +00:00
|
|
|
}
|
|
|
|
if (!connection) { console.error("Can't found ServerConnection!"); return }
|
|
|
|
for (const field of constants.Reflect.Field.listeningChannels) {
|
|
|
|
try {
|
|
|
|
promise = reflect.on(connection).get(field).get().get(0)
|
|
|
|
if (promise.class.name.indexOf('Promise') !== -1) { break }
|
|
|
|
promise = undefined
|
2021-12-25 17:21:06 +00:00
|
|
|
} catch (error: any) {
|
2020-10-13 01:24:58 +00:00
|
|
|
if (global.debug) {
|
|
|
|
console.ex(error)
|
|
|
|
}
|
|
|
|
}
|
2020-06-02 09:50:47 +00:00
|
|
|
}
|
|
|
|
if (!promise) { console.error("Can't found listeningChannels!"); return }
|
|
|
|
this.pipeline = reflect.on(promise).get('channel').get().pipeline()
|
2020-10-13 01:24:58 +00:00
|
|
|
this.container.bind(constants.ServiceIdentifier.NettyPipeline).toConstantValue(this.pipeline)
|
2020-06-02 09:50:47 +00:00
|
|
|
}
|
|
|
|
protected reflectRootLogger(consoleServer: any) {
|
|
|
|
try {
|
2022-07-06 13:57:36 +00:00
|
|
|
this.rootLogger = reflect.on(consoleServer).get('LOGGER').get()
|
2021-12-25 17:21:06 +00:00
|
|
|
} catch (error: any) {
|
2020-10-13 01:24:58 +00:00
|
|
|
if (global.debug) {
|
|
|
|
console.ex(error)
|
|
|
|
}
|
|
|
|
try {
|
2022-07-06 13:57:36 +00:00
|
|
|
this.rootLogger = reflect.on(consoleServer).get(0).get()
|
2021-12-25 17:21:06 +00:00
|
|
|
} catch (error: any) {
|
2020-10-13 01:24:58 +00:00
|
|
|
if (global.debug) {
|
|
|
|
console.ex(error)
|
|
|
|
}
|
|
|
|
}
|
2020-06-02 09:50:47 +00:00
|
|
|
}
|
|
|
|
if (this.rootLogger && this.rootLogger.class.name.indexOf('Logger') === -1) {
|
|
|
|
console.error('Error Logger Class: ' + this.rootLogger.class.name)
|
|
|
|
this.rootLogger = undefined
|
|
|
|
}
|
|
|
|
// get root logger
|
|
|
|
for (let index = 0; index < 5 && this.rootLogger.parent; index++) {
|
|
|
|
this.rootLogger = this.rootLogger.parent
|
|
|
|
}
|
|
|
|
if (!this.rootLogger) { console.error("Can't found rootLogger!") }
|
2020-10-13 01:24:58 +00:00
|
|
|
this.container.bind(constants.ServiceIdentifier.RootLogger).toConstantValue(this.rootLogger)
|
2020-06-02 09:50:47 +00:00
|
|
|
}
|
2019-11-04 12:18:30 +00:00
|
|
|
}
|
2019-09-07 04:23:15 +00:00
|
|
|
}
|