@@ -2,7 +2,7 @@ import { z } from 'zod'
2
2
import fs from 'fs/promises'
3
3
import path from 'path'
4
4
import { Component , MotdSchema } from './motd'
5
- import { ConnectionController , OutboundSchema } from './proxy'
5
+ import { OutboundSchema } from './proxy'
6
6
import { fromError } from 'zod-validation-error'
7
7
import { ConfigSchema } from './config'
8
8
@@ -43,6 +43,7 @@ export interface Context {
43
43
playerName ?: string
44
44
config ?: any
45
45
fullConfig : z . infer < typeof ConfigSchema > // 添加 fullConfig 属性,确保其为必填项
46
+ terminator ?: Function // 添加 terminator 属性
46
47
on ( event : 'motd' , handler : MotdHandler , pre ?: boolean ) : void
47
48
on ( event : 'login' , handler : LoginHandler , pre ?: boolean ) : void
48
49
on (
@@ -51,9 +52,6 @@ export interface Context {
51
52
pre ?: boolean ,
52
53
) : void
53
54
temp ?( callback : Handler ) : void
54
- registerConnection ( host : string , controller : ConnectionController ) : void
55
- unregisterConnection ( host : string ) : void
56
- getConnectionController ( host : string ) : ConnectionController | undefined
57
55
}
58
56
59
57
// 插件的接口
@@ -82,7 +80,6 @@ export class PluginLoader {
82
80
motd : [ ] ,
83
81
}
84
82
private fullConfig : z . infer < typeof ConfigSchema > = ConfigSchema . parse ( { } ) // 保存完整的配置
85
- private connectionControllers : Map < string , ConnectionController > = new Map ( )
86
83
87
84
// 加载单个内置插件
88
85
private async loadBuiltinPlugin (
@@ -109,9 +106,6 @@ export class PluginLoader {
109
106
} else this . eventHandlers [ event ] . push ( handler )
110
107
}
111
108
} ,
112
- registerConnection : this . registerConnection . bind ( this ) ,
113
- unregisterConnection : this . unregisterConnection . bind ( this ) ,
114
- getConnectionController : this . getConnectionController . bind ( this ) ,
115
109
}
116
110
117
111
// 调用插件的 apply 方法进行初始化
@@ -206,9 +200,6 @@ export class PluginLoader {
206
200
} else this . eventHandlers [ event ] . push ( handler )
207
201
}
208
202
} ,
209
- registerConnection : this . registerConnection . bind ( this ) ,
210
- unregisterConnection : this . unregisterConnection . bind ( this ) ,
211
- getConnectionController : this . getConnectionController . bind ( this ) ,
212
203
}
213
204
214
205
// 调用插件的 apply 方法进行初始化
@@ -237,18 +228,17 @@ export class PluginLoader {
237
228
host : string ,
238
229
playerName : string ,
239
230
ip : string ,
231
+ terminator : Function , // 应当传入 clientSocket.end()
240
232
) : Promise < LoaderLoginResult > {
241
233
// 创建临时回调函数队列
242
234
const tempHandlers : Array < LoginHandler > = [ ]
243
235
244
236
// 创建完整的上下文,包括 temp 方法
245
237
const ctx : Context = {
246
- registerConnection : this . registerConnection . bind ( this ) ,
247
- unregisterConnection : this . unregisterConnection . bind ( this ) ,
248
- getConnectionController : this . getConnectionController . bind ( this ) ,
249
238
host,
250
239
playerName,
251
240
ip,
241
+ terminator,
252
242
fullConfig : this . fullConfig , // 传入完整的配置
253
243
on : ( event , handler , pre = false ) => {
254
244
if ( this . eventHandlers [ event ] ) {
@@ -346,9 +336,6 @@ export class PluginLoader {
346
336
347
337
// 创建完整的上下文,包括 temp 方法
348
338
const ctx : Context = {
349
- registerConnection : this . registerConnection . bind ( this ) ,
350
- unregisterConnection : this . unregisterConnection . bind ( this ) ,
351
- getConnectionController : this . getConnectionController . bind ( this ) ,
352
339
host,
353
340
ip,
354
341
fullConfig : this . fullConfig , // 传入完整的配置
@@ -434,9 +421,6 @@ export class PluginLoader {
434
421
} else this . eventHandlers [ event ] . push ( handler )
435
422
}
436
423
} ,
437
- registerConnection : this . registerConnection . bind ( this ) ,
438
- unregisterConnection : this . unregisterConnection . bind ( this ) ,
439
- getConnectionController : this . getConnectionController . bind ( this ) ,
440
424
}
441
425
442
426
for ( const handler of this . eventHandlers [ 'disconnect' ] ) {
@@ -467,16 +451,4 @@ export class PluginLoader {
467
451
motd : [ ] ,
468
452
}
469
453
}
470
-
471
- registerConnection ( host : string , controller : ConnectionController ) {
472
- this . connectionControllers . set ( host , controller )
473
- }
474
-
475
- unregisterConnection ( host : string ) {
476
- this . connectionControllers . delete ( host )
477
- }
478
-
479
- getConnectionController ( host : string ) : ConnectionController | undefined {
480
- return this . connectionControllers . get ( host )
481
- }
482
454
}
0 commit comments