LoginPhaseProxy 是一款略显“简单”的 Velocity 插件,它允许你将来自后端服务器的 LoginPluginMessagePacket(登录插件消息包)代理转发给玩家,并将来自玩家的 LoginPluginResponsePacket(登录插件响应包)代理转发回后端服务器。这对于依赖登录插件消息通信才能正常工作的模组化后端服务器非常有用,例如 AutoModpack。
? 何时使用
欢迎通过 Issue 或 Pull Request 提出新的使用场景建议!
❓ 它解决了什么问题(详细说明)

常规设置 ⦁ 使用 Figma 制作
在常规的 Velocity 设置中,当玩家连接到代理时,他们会经历(P ↔ V)登录阶段,与 Velocity 交换数据包,直到代理发送 Server Login Success Packet(服务器登录成功包),从而完成(P ↔ V)登录阶段并触发后端连接过程。随后,后端服务器会进行其自身的(V ↔ B)登录阶段,在此期间它可能会向 Velocity 发送 Login Plugin Message Packets(登录插件消息包)。然而,由于(P ↔ V)登录阶段已经完成,这些消息无法转发给玩家,因此 Velocity 会以空数据的 Login Plugin Response Packet(登录插件响应包)作为回应,因为它不知道如何处理这些消息。这对于依赖登录插件消息通信才能正常工作的模组化后端服务器(如 AutoModpack)来说是个问题,因为它们无法在登录阶段向玩家发送必要的数据,导致玩家无法加入后端服务器。本插件试图通过代理玩家与后端服务器之间的登录插件消息通信来解决此问题,使模组化后端服务器能够毫无问题地与 Velocity 配合工作。
✨ 它是如何工作的(详细说明)
基本上就是黑魔法 ??。它使用 Java Reflection(Java 反射)来访问 Velocity 的内部类 ProxyServer -> ConnectionManager[1],以重写 serverChannelInitializer[2] 和 backendChannelInitializer[3],从而分别拦截 Velocity 与玩家(P <-> V)[4] 以及后端服务器(V <-> S)[5] 之间的通信。

插件实现 ⦁ 使用 Figma 制作
在此之后,我们的插件会监听登录阶段(Login Phase)的玩家连接,直到检测到 SetCompressionPacket<sup>(5)</sup>(可选)和 ServerLoginSuccessPacket<sup>(6)</sup>,将它们添加到缓冲区而不是发送给玩家,并合成发送一个 loginAcknowledgedPacket<sup>(7)</sup> 到 Velocity 管道,欺骗它认为登录阶段已完成并开始后端连接过程。为了确保 Velocity 不会干扰包拦截和发送过程,我们的插件会隐蔽地(从而不触发其 handlerRemoved 生命周期[6])从 Velocity serverChannel 管道[4]中移除在登录阶段过渡到配置阶段(Config Phase)后添加的处理程序(MinecraftCompressorAndLengthEncoder 和 MinecraftCompressDecoder,其他处理程序随后会被自然移除)。此外,我们的插件会将 MinecraftVarintLengthEncoder[4] 重新添加回来(在过渡时被移除),并将 MinecraftDecoder 的状态设置为 StateRegistry.LOGIN[4],以便正确编码和解码数据包。
如果后端服务器在其登录阶段发送了 LoginPluginMessagePacket<sup>(10)</sup>,我们的插件将拦截它并将其发送给玩家(11);如果玩家发送了 LoginPluginResponsePacket<sup>(12)</sup>,我们的插件将拦截它并将其发送给后端服务器(13)。这样,我们可以有效地在玩家和后端服务器之间代理 LoginPluginMessagePacket 和 LoginPluginResponsePacket,使修改版后端服务器能够与 Velocity 无缝协作。然后,当后端服务器通过发送 ServerLoginSuccessPacket<sup>(15)</sup> 结束登录阶段时,我们的插件会将缓冲的包刷新发送给玩家,完成登录阶段并允许玩家正常加入后端服务器。此后,如果用户在登录阶段完成后发送了 LoginAcknowledgedPacket(clientProtocolVersion >= ProtocolVersion.MINECRAFT_1_20_2)(16),我们的插件将简单地忽略它,因为此时不应由玩家发送该包。最后,插件会将 MinecraftDecoder 的状态恢复为其之前的状态(配置阶段)。
所以,基本上就是黑魔法 ??。太棒了!
? 鸣谢
- Skidam,他激发了我创建此插件的灵感!
- lucas-gcp,他支持了我并协助进行了测试!
- Suerion,他协助进行测试并提供了宝贵的反馈!
- 所有为这个插件做出贡献的人,无论是报告问题、建议功能还是贡献代码!
LoginPhaseProxy is a somewhat "simple" Velocity Plugin that allows you to proxy the LoginPluginMessagePacket from backend server to the player and LoginPluginResponsePacket from the player to the backend server. This is useful for modded backend servers that rely on Login Plugin Message communication to work, such as AutoModpack.
? When to use
You're welcome to suggest new use cases via Issue or Pull Request!
❓ What does it solve (detailed)

Normal Setup ⦁ Made in Figma
On a normal Velocity setup, when a player connects to the proxy, they go through the (P ↔ V) Login Phase, exchanging packets with the Velocity until the proxy sends a Server Login Success Packet, completing the (P ↔ V) Login Phase and triggering the backend connection process. The backend server then goes through its own (V ↔ B) Login Phase, where it may send Login Plugin Message Packets to the Velocity, and they can't be forwarded to the player, because the (P ↔ V) Login Phase is already complete, so Velocity reponds them with an empty data Login Plugin Response Packet, as it doesn't know how to handle them. This is a problem for modded backend servers that rely on Login Plugin Message communication to work, such as AutoModpack, as they won't be able to send the necessary data to the player during the Login Phase, and the player won't be able to join the backend server. This plugin tries to solve this issue by proxying the Login Plugin Message communication between the player and the backend server, allowing modded backend servers to work with Velocity without any issues.
✨ How it works (detailed)
Basically black magic ??. It uses Java Reflection to access the internal Velocity classes ProxyServer -> ConnectionManager[1] to override the serverChannelInitializer[2] and backendChannelInitializer[3], so it can intercept the Velocity communication with the player (P <-> V)[4] and backend server (V <-> S)[5], respectively.

Plugin Implementation ⦁ Made in Figma
With that, our plugin watches the Login Phase player connection until it sees a SetCompressionPacket(5) (optionally) and ServerLoginSuccessPacket(6), adding them to a buffer instead of sending them to the player and synthetically sends a loginAcknowledgedPacket(7) to the Velocity pipeline, tricking it into thinking the Login Phase is complete and starting the backend connection process. To make sure the Velocity doesn't mess the packet interception and sending process, our plugin removes stealthly (so that it doesn't trigger it's handlerRemoved lifecycle[6]) the handlers from the Velocity serverChannel pipeline[4] that were added after the Login Phase to Config Phase transition (MinecraftCompressorAndLengthEncoder and MinecraftCompressDecoder, others are removed naturally afterwards). Also, our plugin adds the MinecraftVarintLengthEncoder[4] back (was removed at the transition) and sets the MinecraftDecoder state to StateRegistry.LOGIN[4] so the packets are properly encoded and decoded.
If the backend server sends a LoginPluginMessagePacket(10) during its Login Phase, our plugin will intercept it and send it to the player(11), and if the player sends a LoginPluginResponsePacket(12), our plugin will intercept it and send it to the backend server(13). This way, we can effectively proxy the LoginPluginMessagePacket and LoginPluginResponsePacket between the player and the backend server, allowing modded backend servers to work with Velocity without any issues. Then, when the backend server ends the Login Phase sending the ServerLoginSuccessPacket(15), our plugin will flush the buffered packets to the player, completing the Login Phase and allowing the player to join the backend server as normal. Afterwards, if the user sends a LoginAcknowledgedPacket (clientProtocolVersion >= ProtocolVersion.MINECRAFT_1_20_2)(16) after the Login Phase is complete, our plugin will simply ignore it, as it is not expected to be sent by the player at that point. Finally, the plugin will restore the MinecraftDecoder state to its previous state (Config Phase).
So, yeah, basically black magic ??. Yayyyy!
? Acknowledgements
- Skidam, who inspired me to create this plugin!
- lucas-gcp, who supported me and helped with testing!
- Suerion, who helped with testing and provided valuable feedback!
- All contributors who contributed to this plugin, whether by reporting issues, suggesting features, or contributing code!
评论 0
登录后参与评分
还没有评论,来抢沙发吧