Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RawPlayDataChannel is not supported during ServerSideConnectionEvent.Join #3901

Open
A248 opened this issue Sep 28, 2023 · 2 comments
Open
Labels
status: needs triage This label is automatically applied to new issues and pull requests to indicate they require triage type: bug Something isn't working

Comments

@A248
Copy link
Contributor

A248 commented Sep 28, 2023

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 A248 added status: needs triage This label is automatically applied to new issues and pull requests to indicate they require triage type: bug Something isn't working labels Sep 28, 2023
@AlexandreArcil
Copy link
Contributor

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

@A248
Copy link
Contributor Author

A248 commented Oct 1, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage This label is automatically applied to new issues and pull requests to indicate they require triage type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants