Geyser icon indicating copy to clipboard operation
Geyser copied to clipboard

Add ServerCustomPayloadEvent

Open BlueTree242 opened this issue 2 months ago • 4 comments

This pull request adds ServerCustomPayloadEvent to the plugin's API. This allows extensions/addons to understand some special custom payloads (also known as plugin messages) and act accordingly. This event is not called when floodgate custom payloads are received.

BlueTree242 avatar Apr 22 '24 08:04 BlueTree242

Alright all requested changes are done :)

BlueTree242 avatar Apr 22 '24 12:04 BlueTree242

Alright done

BlueTree242 avatar Apr 22 '24 12:04 BlueTree242

Done

BlueTree242 avatar Apr 22 '24 13:04 BlueTree242

I think having an event for custom payloads is a feature that would be great to have in the API, however I think it should be a bit higher-level than this. I'm thinking a more polished network API is the direction I'd want to go with Geyser, since messing with raw buffers on an API level is not the greatest.

The design I'm thinking of is a bit of a hybrid between the Fabric and Forge APIs, namely enforcing registering custom channels with message handlers. Something along the lines of:

@Subscribe
public void onDefineNetworkChannels(GeyserDefineNetworkChannelsEvent event) {
    event.register(NetworkChannel.of(this, "my_message"), MyMessage::new)
}

With a message looking like:

public record MyMessage(int num) {
    public MyMessage(MessageBuffer buffer) {
        this(buffer.read(MessageType.INT));
    }

    public void encode(MessageBuffer buffer) {
        buffer.write(MessageType.INT, this.num);
    }
}

And sending being handled by running:

GeyserConnection connection = ...
GeyserApi.api().networkManager().send(connection, new MyMessage(5));

MessageType is just a wrapper for the value we write to the buffer, and will contain a read/write that directly interfaces with buffers (so custom extensions can provide their own readers/writers for value types needed).

All of this would happen over custom payload packets under the hood, but just means we can offer something higher level than just having a raw binary and enforcing a proper codec.

With something like this, the event would then need to be modified to instead have a NetworkChannel (instead of a string) and a MessageBuffer.

I know this is something that is far larger in scope than what is done here, however if you'd like to work on something like this, feel free to reach out on Discord and I'd be happy to go into more detail and offer support where needed. Also very welcome to feedback and suggestions too.

Redned235 avatar Apr 23 '24 16:04 Redned235