-
-
Couldn't load subscription status.
- Fork 773
Geyser Networking API #5685
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
Open
Redned235
wants to merge
5
commits into
master
Choose a base branch
from
feature/networking-api
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,217
−6
Open
Geyser Networking API #5685
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9b2ad0b
Initial draft of the Geyser Networking API
Redned235 43d3747
Add additional packet constructors for use in channel defining
Redned235 8d7fe09
Merge master
Redned235 3049c77
Address comments
Redned235 86b1ac9
Missed this
Redned235 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...rc/main/java/org/geysermc/geyser/api/event/bedrock/SessionDefineNetworkChannelsEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * Copyright (c) 2025 GeyserMC. http://geysermc.org | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| * THE SOFTWARE. | ||
| * | ||
| * @author GeyserMC | ||
| * @link https://github.com/GeyserMC/Geyser | ||
| */ | ||
|
|
||
| package org.geysermc.geyser.api.event.bedrock; | ||
|
|
||
| import org.checkerframework.checker.nullness.qual.NonNull; | ||
| import org.geysermc.geyser.api.connection.GeyserConnection; | ||
| import org.geysermc.geyser.api.event.connection.ConnectionEvent; | ||
| import org.geysermc.geyser.api.network.NetworkChannel; | ||
| import org.geysermc.geyser.api.network.message.MessageBuffer; | ||
| import org.geysermc.geyser.api.network.message.MessageCodec; | ||
| import org.geysermc.geyser.api.network.message.MessageFactory; | ||
|
|
||
| /** | ||
| * Called whenever Geyser is registering network channels. | ||
| * @since 2.8.2 | ||
| */ | ||
| public abstract class SessionDefineNetworkChannelsEvent extends ConnectionEvent { | ||
|
|
||
| public SessionDefineNetworkChannelsEvent(@NonNull GeyserConnection connection) { | ||
| super(connection); | ||
| } | ||
|
|
||
| /** | ||
| * Registers a new network channel with a message factory. | ||
| * | ||
| * @param channel the channel to register | ||
| * @param messageFactory the factory to create messages from the buffer | ||
| */ | ||
| public abstract void register(@NonNull NetworkChannel channel, @NonNull MessageFactory<MessageBuffer> messageFactory); | ||
|
|
||
| /** | ||
| * Registers a new network channel with a message factory. | ||
| * | ||
| * @param channel the channel to register | ||
| * @param codec the codec to use to encode/decode the buffer | ||
| * @param messageFactory the factory to create messages from the buffer | ||
| */ | ||
| public abstract <T extends MessageBuffer> void register(@NonNull NetworkChannel channel, @NonNull MessageCodec<T> codec, @NonNull MessageFactory<T> messageFactory); | ||
| } |
101 changes: 101 additions & 0 deletions
101
api/src/main/java/org/geysermc/geyser/api/event/java/ServerReceiveNetworkMessageEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| /* | ||
| * Copyright (c) 2025 GeyserMC. http://geysermc.org | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| * THE SOFTWARE. | ||
| * | ||
| * @author GeyserMC | ||
| * @link https://github.com/GeyserMC/Geyser | ||
| */ | ||
|
|
||
| package org.geysermc.geyser.api.event.java; | ||
|
|
||
| import org.checkerframework.checker.nullness.qual.NonNull; | ||
| import org.geysermc.event.Cancellable; | ||
| import org.geysermc.geyser.api.connection.GeyserConnection; | ||
| import org.geysermc.geyser.api.event.connection.ConnectionEvent; | ||
| import org.geysermc.geyser.api.network.MessageDirection; | ||
| import org.geysermc.geyser.api.network.NetworkChannel; | ||
| import org.geysermc.geyser.api.network.message.Message; | ||
|
|
||
| /** | ||
| * Called when Geyser receives a network message from the server. | ||
| * @since 2.8.2 | ||
| */ | ||
| public final class ServerReceiveNetworkMessageEvent extends ConnectionEvent implements Cancellable { | ||
| private final NetworkChannel channel; | ||
| private final Message<?> message; | ||
| private final MessageDirection direction; | ||
| private boolean cancelled = false; | ||
|
|
||
| public ServerReceiveNetworkMessageEvent(@NonNull GeyserConnection connection, @NonNull NetworkChannel channel, @NonNull Message<?> message, @NonNull MessageDirection direction) { | ||
| super(connection); | ||
|
|
||
| this.channel = channel; | ||
| this.message = message; | ||
| this.direction = direction; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the channel that received the message. | ||
| * <p> | ||
| * See {@link NetworkChannel} for more information. | ||
| * | ||
| * @return the channel that received the message | ||
| */ | ||
| @NonNull | ||
| public NetworkChannel channel() { | ||
| return this.channel; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the message that was received. | ||
| * | ||
| * @return the received message | ||
| */ | ||
| @NonNull | ||
| public Message<?> message() { | ||
| return this.message; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the direction of the message. | ||
| * | ||
| * @return the direction of the message | ||
| */ | ||
| @NonNull | ||
| public MessageDirection direction() { | ||
| return this.direction; | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| public boolean isCancelled() { | ||
| return this.cancelled; | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| public void setCancelled(boolean cancelled) { | ||
| this.cancelled = cancelled; | ||
| } | ||
| } |
83 changes: 83 additions & 0 deletions
83
api/src/main/java/org/geysermc/geyser/api/network/ExtensionNetworkChannel.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /* | ||
| * Copyright (c) 2025 GeyserMC. http://geysermc.org | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| * THE SOFTWARE. | ||
| * | ||
| * @author GeyserMC | ||
| * @link https://github.com/GeyserMC/Geyser | ||
| */ | ||
|
|
||
| package org.geysermc.geyser.api.network; | ||
|
|
||
| import org.checkerframework.checker.nullness.qual.NonNull; | ||
| import org.geysermc.geyser.api.extension.Extension; | ||
| import org.geysermc.geyser.api.util.Identifier; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * Represents a network channel associated with an extension. | ||
| * @since 2.8.2 | ||
| */ | ||
| public class ExtensionNetworkChannel implements NetworkChannel { | ||
| private final Extension extension; | ||
| private final String channel; | ||
|
|
||
| protected ExtensionNetworkChannel(@NonNull Extension extension, @NonNull String channel) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing nonnull enforcement |
||
| this.extension = extension; | ||
| this.channel = channel; | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| @NonNull | ||
| public Identifier identifier() { | ||
| return Identifier.of(this.extension.description().id(), this.channel); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| public boolean isPacket() { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (o == null || !NetworkChannel.class.isAssignableFrom(o.getClass())) return false; | ||
| NetworkChannel that = (NetworkChannel) o; | ||
| return Objects.equals(this.identifier(), that.identifier()); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(this.identifier()); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "ExtensionNetworkChannel{" + | ||
| "extension=" + this.extension.description().id() + | ||
| ", channel='" + this.channel + '\'' + | ||
| '}'; | ||
| } | ||
| } | ||
81 changes: 81 additions & 0 deletions
81
api/src/main/java/org/geysermc/geyser/api/network/ExternalNetworkChannel.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /* | ||
| * Copyright (c) 2025 GeyserMC. http://geysermc.org | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| * THE SOFTWARE. | ||
| * | ||
| * @author GeyserMC | ||
| * @link https://github.com/GeyserMC/Geyser | ||
| */ | ||
|
|
||
| package org.geysermc.geyser.api.network; | ||
|
|
||
| import org.checkerframework.checker.nullness.qual.NonNull; | ||
| import org.geysermc.geyser.api.util.Identifier; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * Represents a network channel not associated with any specific extension. | ||
| * <p> | ||
| * This can be used for external communication channels, like mods or plugins. | ||
| * @since 2.8.2 | ||
| */ | ||
| public class ExternalNetworkChannel implements NetworkChannel { | ||
| private final Identifier identifier; | ||
|
|
||
| protected ExternalNetworkChannel(@NonNull Identifier identifier) { | ||
| this.identifier = identifier; | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| @NonNull | ||
| public Identifier identifier() { | ||
| return this.identifier; | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| public boolean isPacket() { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (o == null || !NetworkChannel.class.isAssignableFrom(o.getClass())) return false; | ||
| NetworkChannel that = (NetworkChannel) o; | ||
| return Objects.equals(this.identifier(), that.identifier()); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(this.identifier()); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "ExternalNetworkChannel{" + | ||
| "identifier='" + this.identifier + '\'' + | ||
| '}'; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's make this an interface + geyser impl?