feat: support token check & compatible more server
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
99a264677a
commit
dd88e63d1a
@ -60,12 +60,10 @@ export class MiaoConsole extends interfaces.Plugin {
|
|||||||
count++
|
count++
|
||||||
}).later(20).timer(40).submit()
|
}).later(20).timer(40).submit()
|
||||||
try {
|
try {
|
||||||
let server = Java.type('net.minecraft.server.v1_12_R1.MinecraftServer');
|
this.rootLogger = reflect.on(org.bukkit.Bukkit.getServer()).get('console').get('LOGGER').get().parent;
|
||||||
this.rootLogger = server.LOGGER.parent;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
try {
|
try {
|
||||||
this.rootLogger = reflect.on(org.spongepowered.api.Sponge.getServer()).get('field_147145_h').get();
|
this.rootLogger = reflect.on(org.spongepowered.api.Sponge.getServer()).get('field_147145_h').get().parent;
|
||||||
this.rootLogger = this.rootLogger.parent.parent;
|
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.error('§6初始化日志代理器失败 §4错误: §c' + ex)
|
console.error('§6初始化日志代理器失败 §4错误: §c' + ex)
|
||||||
console.ex(ex);
|
console.ex(ex);
|
||||||
@ -84,7 +82,10 @@ export class MiaoConsole extends interfaces.Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
disable() {
|
disable() {
|
||||||
this.socketIOServer?.close()
|
if (this.socketIOServer) {
|
||||||
|
this.socketIOServer.close()
|
||||||
|
global.eventCenter.removeAllListeners('log');
|
||||||
|
}
|
||||||
if (this.container.isBound(io.Instance)) {
|
if (this.container.isBound(io.Instance)) {
|
||||||
this.container.unbind(io.Instance)
|
this.container.unbind(io.Instance)
|
||||||
}
|
}
|
||||||
@ -106,9 +107,15 @@ export class MiaoConsole extends interfaces.Plugin {
|
|||||||
|
|
||||||
startSocketIOServer() {
|
startSocketIOServer() {
|
||||||
let namespace = this.socketIOServer.of('/MiaoConsole')
|
let namespace = this.socketIOServer.of('/MiaoConsole')
|
||||||
|
global.eventCenter.on('log', (msg) => namespace.emit('log', msg))
|
||||||
namespace.on('connect', (client: SocketIOSocket) => {
|
namespace.on('connect', (client: SocketIOSocket) => {
|
||||||
global.eventCenter.on('log', (msg) => client.emit('log', msg))
|
this.logger.console(`§6客户端 §b${client.id} §a请求链接 §4Token: §c${client.handshake.query.token} ...`)
|
||||||
this.logger.console(`§6客户端 §b${client.id} §a新建连接...`)
|
if (!client.handshake.query.token) {
|
||||||
|
client.emit('log', `§4无效的请求 请提供Token后再次登录!`)
|
||||||
|
client.disconnect(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.logger.console(`§6客户端 §b${client.id} §a新建连接 接受日志转发...`)
|
||||||
client.on('type', (fn) => {
|
client.on('type', (fn) => {
|
||||||
fn && fn(this.serverType)
|
fn && fn(this.serverType)
|
||||||
client.emit('log', `Currect Server Version is ${this.server.getVersion()}`)
|
client.emit('log', `Currect Server Version is ${this.server.getVersion()}`)
|
||||||
|
Loading…
Reference in New Issue
Block a user