Glowstone icon indicating copy to clipboard operation
Glowstone copied to clipboard

Packet API

Open DenAbr opened this issue 7 years ago • 19 comments

Are there any plans for implementing api for interacting with packet(eg. interception of packet sending/receiving)?


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

DenAbr avatar Mar 06 '17 10:03 DenAbr

This is already possible and has been done successfully by ProtocolSupport.

https://github.com/ProtocolSupport/ProtocolSupport/tree/master/src/protocolsupport/zplatform/impl/glowstone

gdude2002 avatar Mar 06 '17 10:03 gdude2002

I'm interested in some built-in feature without injecting any stuff

DenAbr avatar Mar 06 '17 11:03 DenAbr

I'm not really sure what such a feature would provide over the usual injection techniques.

Do you have some specific use-case in mind?

gdude2002 avatar Mar 06 '17 11:03 gdude2002

I'm just talking about packet send/receive events(like in this branch) or ability to register (sync/async)packet listeners(like in ProtocolLib)

DenAbr avatar Mar 06 '17 11:03 DenAbr

Alright, well I'll assign this to @mastercoms for now and he'll get back to you on it when he can, but I don't anticipate there being much extra on top of Netty.

gdude2002 avatar Mar 06 '17 11:03 gdude2002

Well, I tried to implement this feature as how I imagine it

https://github.com/DenAbr/Glowstone/commit/b9dfda9e7f3692c06c978b7703e0b7ce4ad2ff02

DenAbr avatar Mar 06 '17 11:03 DenAbr

It's a great idea, but it's not good for us to just implement it right away, as that was why the packets branch PR was closed.

It would be better to start a discussion for designing and planning the packet API on the forums, and continue from there.

mastercoms avatar Mar 06 '17 11:03 mastercoms

It's been a few months but there is no any progress...

DenAbr avatar Mar 06 '17 12:03 DenAbr

Yes, unfortunately, in the time that we've had, we've found other things to do that to us felt more valuable for us to do in that time than the packet API. Though, a packet API would be a very nice addition, and perhaps you could get the discussion going on our forums and if you're interested enough, present a design for a packet API and perhaps continue your fork with what you'd like to see in a packet API.

mastercoms avatar Mar 06 '17 13:03 mastercoms

@DenAbr If my comments make you think that I'm not interested in having a packet API, please understand that I am completely supportive of a packet API. But also understand we have only have 1 or 2 active devs working on this project at any given time, and it's extremely hard for me at least to do every single feature or fix that I want to do, so I have to put off some things to later. It's unfortunate that we have to make sacrifices like this, but due to the lack of developers, we have no choice.

mastercoms avatar Mar 06 '17 20:03 mastercoms

I understand this and this is good that you support packet api. It gives me hope

DenAbr avatar Mar 07 '17 09:03 DenAbr

@DenAbr Is it good api for you? 😉

public class GlowstoneTest extends JavaPlugin implements Listener {

    @Override
    public void onEnable() {
        Bukkit.getPluginManager().registerEvents(this, this);
    }

    @EventHandler
    public void onSessionInit(SessionInitEvent event) {
        event.getSession().enablePacketEvents();
    }

    @EventHandler
    public void onPacketSend(PacketSendEvent event) {
        Message message = event.getMessage();
        if (message instanceof StatusResponseMessage) {
            System.out.println("Status reponse: " + ((StatusResponseMessage) message).getJson());
        } else if (message instanceof JoinGameMessage) {
            System.out.println("Join Message: " + message.toString());
        }
    }

    @EventHandler
    public void onPacketReceive(PacketReceiveEvent event) {
        Message message = event.getMessage();
        if (message instanceof HandshakeMessage) {
            HandshakeMessage hs = (HandshakeMessage) message;
            System.out.println("Handshake: " + hs.getAddress() + ":" + hs.getPort() + " v" + hs.getVersion());
        }
    }
}

log:

12:53:01 [INFO] Ready for connections.
12:53:03 [INFO] Handshake: localhost:25565 v316
12:53:03 [INFO] Status reponse: {"modinfo":{"modList":[],"type":"VANILLA"},"players":{"max":20,"online":0},"description":{"text":"A Glowstone server"},"version":{"protocol":316,"name":"1.11.2"}}
12:54:51 [INFO] Handshake: localhost:25565 v316
12:54:51 [INFO] Join Message: JoinGameMessage(id=0, mode=0, dimension=0, difficulty=2, maxPlayers=20, levelType=default, reducedDebugInfo=false)
12:54:52 [INFO] kamcio96 [/127.0.0.1:49968] connected, UUID: 143a0fb4-11e7-39f2-95ad-cff9a7acdc10
12:54:52 [INFO] kamcio96 joined the game

kamcio96 avatar Mar 07 '17 11:03 kamcio96

This is good but this API also needs async events

DenAbr avatar Mar 07 '17 13:03 DenAbr

Good API, what do you think about implementing it in official Bukkit API?

alula avatar Mar 08 '17 13:03 alula

I'm planing add it in glowstone, not in bukkit/glowkit :wink: "Unofficial packet events" :smile:

kamcio96 avatar Mar 08 '17 14:03 kamcio96

What I would suggest is to get ProtocolLib working on Glowstone. A brand new API would be cool, but instead of "reinventing the wheel", we could port it.

Also, many plugins already use ProtocolLib, and developers have gotten used to its API. Designing a new one would be kind-of pointless in my opinion.

ProtocolLib repo: https://github.com/aadnk/ProtocolLib

aramperes avatar Apr 05 '17 02:04 aramperes

Working ProtocolLib would be great thing.

DenAbr avatar Apr 05 '17 05:04 DenAbr

If we're interested in this, maybe we could contact the developer of ProtocolLib and ask if we can help them add Glowstone support?

gdude2002 avatar Apr 05 '17 10:04 gdude2002

Feel free to add reactions to https://github.com/dmulloy2/ProtocolLib/issues/308 if you like

gdude2002 avatar Apr 05 '17 19:04 gdude2002