Sponge icon indicating copy to clipboard operation
Sponge copied to clipboard

RawPlayDataChannel is not supported during ServerSideConnectionEvent.Join

Open A248 opened this issue 2 years ago • 2 comments

Affected Product(s)

SpongeVanilla

Version

spongevanilla-1.16.5-8.1.0-RC1175

Operating System

Linux

Java Version

17.0.8.1

Plugins/Mods

LibertyBans 1.1.0-SNAPSHOT, LuckPerms-Sponge 5.4.55.

Describe the bug

I'm using the bungeecord:main channel and attempting to send data during ServerSideConnectionEvent.Join. The channel returns that it is unsupported during this event.

However, RawPlayDataChannel is documented to support sending to clients during the play phase. Surely, is ServerSideConnectionEvent.Join not in the play phase?

Steps to reproduce:

  1. Configure SpongeVanilla in proxy mode
  2. Obtain bungeecord:main in ServerSideConnectionEvent.Join
  3. Check if the client supports this channel
	@Listener(order = Order.EARLY)
	public void onJoin(ServerSideConnectionEvent.Join event) {
		ServerPlayer player = event.player();
		Game game = Sponge.game();
		RawPlayDataChannel channel = game.channelManager()
				.ofType(ResourceKey.of("bungeecord", "main"), RawDataChannel.class)
				.play();
		boolean supported = channel.isSupportedBy(player.connection());
		System.out.println("Supported: " + supported);
	}

Link to logs

N/A

A248 avatar Sep 28 '23 14:09 A248

Hello, ServerSideConnectionEvent.Join is called during the server tick and the channel bungeecord:main is registered right after because it is in a task. So a fix is to execute your code in a task

@Listener(order = Order.EARLY)
public void onJoin(ServerSideConnectionEvent.Join event) {
   Task task = Task.builder().execute(() -> {
       ServerPlayer player = event.player();
       Game game = Sponge.game();
       RawPlayDataChannel channel = game.channelManager()
               .ofType(ResourceKey.of("bungeecord", "main"), RawDataChannel.class)
               .play();
       boolean supported = channel.isSupportedBy(player.connection());
       System.out.println("Supported: " + supported);
   }).plugin(this.plugin).build();
   Sponge.server().scheduler().submit(task);
}

It works on my side Capture d’écran du 2023-10-01 14-31-13

AlexandreArcil avatar Oct 01 '23 12:10 AlexandreArcil

That might work. However, that behavior isn't documented anywhere to my knowledge -- if anything, the documentation even suggests otherwise. It's quite surprising that the join event works slightly differently: the player is in the play phase at this point, after all.

Why doesn't Sponge register this channel before the join event? That would make API use more approachable and avoid creating this edge case relating to the join event.

A248 avatar Oct 01 '23 22:10 A248