GlowstoneMC / Glowstone

A fast, customizable and compatible open source server for Minecraft: Java Edition
https://glowstone.net
Other
1.88k stars 270 forks source link

Packet API #441

Open DenAbr opened 7 years ago

DenAbr commented 7 years ago

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!](https://www.bountysource.com/issues/42722196-packet-api?utm_campaign=plugin&utm_content=tracker%2F14691067&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F14691067&utm_medium=issues&utm_source=github).
gdude2002 commented 7 years ago

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

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

DenAbr commented 7 years ago

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

gdude2002 commented 7 years ago

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?

DenAbr commented 7 years ago

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

gdude2002 commented 7 years ago

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.

DenAbr commented 7 years ago

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

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

mastercoms commented 7 years ago

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.

DenAbr commented 7 years ago

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

mastercoms commented 7 years ago

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 commented 7 years ago

@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.

DenAbr commented 7 years ago

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

kamcio96 commented 7 years ago

@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
DenAbr commented 7 years ago

This is good but this API also needs async events

alula commented 7 years ago

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

kamcio96 commented 7 years ago

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

aramperes commented 7 years ago

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

DenAbr commented 7 years ago

Working ProtocolLib would be great thing.

gdude2002 commented 7 years ago

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 commented 7 years ago

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