Skip to content

Commit e75e5d1

Browse files
committedDec 8, 2024·
fix: wtf did I do in last commit
1 parent 81df730 commit e75e5d1

File tree

2 files changed

+6
-41
lines changed

2 files changed

+6
-41
lines changed
 

‎src/plugins.ts

+4-32
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { z } from 'zod'
22
import fs from 'fs/promises'
33
import path from 'path'
44
import { Component, MotdSchema } from './motd'
5-
import { ConnectionController, OutboundSchema } from './proxy'
5+
import { OutboundSchema } from './proxy'
66
import { fromError } from 'zod-validation-error'
77
import { ConfigSchema } from './config'
88

@@ -43,6 +43,7 @@ export interface Context {
4343
playerName?: string
4444
config?: any
4545
fullConfig: z.infer<typeof ConfigSchema> // 添加 fullConfig 属性,确保其为必填项
46+
terminator?: Function // 添加 terminator 属性
4647
on(event: 'motd', handler: MotdHandler, pre?: boolean): void
4748
on(event: 'login', handler: LoginHandler, pre?: boolean): void
4849
on(
@@ -51,9 +52,6 @@ export interface Context {
5152
pre?: boolean,
5253
): void
5354
temp?(callback: Handler): void
54-
registerConnection(host: string, controller: ConnectionController): void
55-
unregisterConnection(host: string): void
56-
getConnectionController(host: string): ConnectionController | undefined
5755
}
5856

5957
// 插件的接口
@@ -82,7 +80,6 @@ export class PluginLoader {
8280
motd: [],
8381
}
8482
private fullConfig: z.infer<typeof ConfigSchema> = ConfigSchema.parse({}) // 保存完整的配置
85-
private connectionControllers: Map<string, ConnectionController> = new Map()
8683

8784
// 加载单个内置插件
8885
private async loadBuiltinPlugin(
@@ -109,9 +106,6 @@ export class PluginLoader {
109106
} else this.eventHandlers[event].push(handler)
110107
}
111108
},
112-
registerConnection: this.registerConnection.bind(this),
113-
unregisterConnection: this.unregisterConnection.bind(this),
114-
getConnectionController: this.getConnectionController.bind(this),
115109
}
116110

117111
// 调用插件的 apply 方法进行初始化
@@ -206,9 +200,6 @@ export class PluginLoader {
206200
} else this.eventHandlers[event].push(handler)
207201
}
208202
},
209-
registerConnection: this.registerConnection.bind(this),
210-
unregisterConnection: this.unregisterConnection.bind(this),
211-
getConnectionController: this.getConnectionController.bind(this),
212203
}
213204

214205
// 调用插件的 apply 方法进行初始化
@@ -237,18 +228,17 @@ export class PluginLoader {
237228
host: string,
238229
playerName: string,
239230
ip: string,
231+
terminator: Function, // 应当传入 clientSocket.end()
240232
): Promise<LoaderLoginResult> {
241233
// 创建临时回调函数队列
242234
const tempHandlers: Array<LoginHandler> = []
243235

244236
// 创建完整的上下文,包括 temp 方法
245237
const ctx: Context = {
246-
registerConnection: this.registerConnection.bind(this),
247-
unregisterConnection: this.unregisterConnection.bind(this),
248-
getConnectionController: this.getConnectionController.bind(this),
249238
host,
250239
playerName,
251240
ip,
241+
terminator,
252242
fullConfig: this.fullConfig, // 传入完整的配置
253243
on: (event, handler, pre = false) => {
254244
if (this.eventHandlers[event]) {
@@ -346,9 +336,6 @@ export class PluginLoader {
346336

347337
// 创建完整的上下文,包括 temp 方法
348338
const ctx: Context = {
349-
registerConnection: this.registerConnection.bind(this),
350-
unregisterConnection: this.unregisterConnection.bind(this),
351-
getConnectionController: this.getConnectionController.bind(this),
352339
host,
353340
ip,
354341
fullConfig: this.fullConfig, // 传入完整的配置
@@ -434,9 +421,6 @@ export class PluginLoader {
434421
} else this.eventHandlers[event].push(handler)
435422
}
436423
},
437-
registerConnection: this.registerConnection.bind(this),
438-
unregisterConnection: this.unregisterConnection.bind(this),
439-
getConnectionController: this.getConnectionController.bind(this),
440424
}
441425

442426
for (const handler of this.eventHandlers['disconnect']) {
@@ -467,16 +451,4 @@ export class PluginLoader {
467451
motd: [],
468452
}
469453
}
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-
}
482454
}

‎src/proxy.ts

+2-9
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,6 @@ export class MinecraftProxy {
231231
FML: null,
232232
}
233233

234-
const controller = new ConnectionController(clientSocket)
235-
globalThis.pluginLoader.registerConnection(
236-
clientSocket.data.host!,
237-
controller,
238-
)
239-
240234
logger.debug(
241235
`${colorHash(clientSocket.data.connId)} Connection established`,
242236
)
@@ -272,8 +266,6 @@ export class MinecraftProxy {
272266
`${colorHash(clientSocket.data.connId)} Connection closed`,
273267
)
274268

275-
globalThis.pluginLoader.unregisterConnection(clientSocket.data.host!)
276-
277269
if (clientSocket.data.host && clientSocket.data.username) {
278270
await globalThis.pluginLoader.disconnect(
279271
clientSocket.data.host,
@@ -471,6 +463,7 @@ export class MinecraftProxy {
471463
clientSocket.data.host!,
472464
username,
473465
clientSocket.data.originIP!.toString(),
466+
() => clientSocket.end(),
474467
)
475468
if (loginResult.type === LoginResultType.REJECT) {
476469
logger.warn(
@@ -559,7 +552,7 @@ export class MinecraftProxy {
559552
headers = Buffer.from(pp.build())
560553
}
561554

562-
// 构造��手包
555+
// 构造握手包
563556
const remoteHostWithFML = outbound.removeFMLSignature
564557
? remoteHost
565558
: clientSocket.data.FML === 1

0 commit comments

Comments
 (0)
Please sign in to comment.