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

Add ServerCustomPayloadEvent #4589

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

BlueTree242
Copy link

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.

Copy link
Member

@onebeastchris onebeastchris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I've added a few comments.

@onebeastchris onebeastchris added the PR: Feature When a PR implements a new feature label Apr 22, 2024
BlueTree242 and others added 4 commits April 22, 2024 14:05
Co-authored-by: chris <github@onechris.mozmail.com>
…t clear

Co-authored-by: chris <github@onechris.mozmail.com>
Co-authored-by: chris <github@onechris.mozmail.com>
@BlueTree242
Copy link
Author

Alright all requested changes are done :)

Copy link
Member

@onebeastchris onebeastchris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, missed these

@BlueTree242
Copy link
Author

Alright done

@BlueTree242
Copy link
Author

Done

@Redned235
Copy link
Member

Redned235 commented Apr 23, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: Feature When a PR implements a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants