|
17 | 17 |
|
18 | 18 | package com.velocitypowered.proxy.connection.client; |
19 | 19 |
|
| 20 | +import com.velocitypowered.api.event.connection.PluginMessageEvent; |
20 | 21 | import com.velocitypowered.api.event.player.CookieReceiveEvent; |
21 | 22 | import com.velocitypowered.api.event.player.PlayerClientBrandEvent; |
22 | 23 | import com.velocitypowered.api.event.player.configuration.PlayerConfigurationEvent; |
23 | 24 | import com.velocitypowered.api.event.player.configuration.PlayerFinishConfigurationEvent; |
24 | 25 | import com.velocitypowered.api.event.player.configuration.PlayerFinishedConfigurationEvent; |
| 26 | +import com.velocitypowered.api.proxy.messages.ChannelIdentifier; |
25 | 27 | import com.velocitypowered.proxy.VelocityServer; |
26 | 28 | import com.velocitypowered.proxy.connection.MinecraftConnection; |
27 | 29 | import com.velocitypowered.proxy.connection.MinecraftSessionHandler; |
| 30 | +import com.velocitypowered.proxy.connection.backend.BungeeCordMessageResponder; |
28 | 31 | import com.velocitypowered.proxy.connection.backend.VelocityServerConnection; |
29 | 32 | import com.velocitypowered.proxy.connection.player.resourcepack.ResourcePackResponseBundle; |
30 | 33 | import com.velocitypowered.proxy.protocol.MinecraftPacket; |
|
41 | 44 | import com.velocitypowered.proxy.protocol.packet.config.KnownPacksPacket; |
42 | 45 | import com.velocitypowered.proxy.protocol.util.PluginMessageUtil; |
43 | 46 | import io.netty.buffer.ByteBuf; |
| 47 | +import io.netty.buffer.ByteBufUtil; |
44 | 48 | import io.netty.buffer.Unpooled; |
45 | 49 | import java.util.concurrent.CompletableFuture; |
46 | 50 | import java.util.concurrent.TimeUnit; |
@@ -123,8 +127,32 @@ public boolean handle(final PluginMessagePacket packet) { |
123 | 127 | brandChannel = packet.getChannel(); |
124 | 128 | // Client sends `minecraft:brand` packet immediately after Login, |
125 | 129 | // but at this time the backend server may not be ready |
| 130 | + } else if (BungeeCordMessageResponder.isBungeeCordMessage(packet)) { |
| 131 | + return true; |
126 | 132 | } else if (serverConn != null) { |
127 | | - serverConn.ensureConnected().write(packet.retain()); |
| 133 | + byte[] bytes = ByteBufUtil.getBytes(packet.content()); |
| 134 | + ChannelIdentifier id = this.server.getChannelRegistrar().getFromId(packet.getChannel()); |
| 135 | + |
| 136 | + if (id == null) { |
| 137 | + serverConn.getPlayer().getConnection().write(packet.retain()); |
| 138 | + return true; |
| 139 | + } |
| 140 | + |
| 141 | + // Handling this stuff async means that we should probably pause |
| 142 | + // the connection while we toss this off into another pool |
| 143 | + serverConn.getPlayer().getConnection().setAutoReading(false); |
| 144 | + this.server.getEventManager() |
| 145 | + .fire(new PluginMessageEvent(serverConn.getPlayer(), serverConn, id, bytes)) |
| 146 | + .thenAcceptAsync(pme -> { |
| 147 | + if (pme.getResult().isAllowed() && serverConn.getConnection() != null) { |
| 148 | + serverConn.ensureConnected().write(new PluginMessagePacket( |
| 149 | + pme.getIdentifier().getId(), Unpooled.wrappedBuffer(bytes))); |
| 150 | + } |
| 151 | + serverConn.getPlayer().getConnection().setAutoReading(true); |
| 152 | + }, player.getConnection().eventLoop()).exceptionally((ex) -> { |
| 153 | + logger.error("Exception while handling plugin message packet for {}", player, ex); |
| 154 | + return null; |
| 155 | + }); |
128 | 156 | } |
129 | 157 | return true; |
130 | 158 | } |
|
0 commit comments