* Restore old codec behaviour to solve autoread disconnect race conditions.
* Move all uses of PacketProtocol to MinecraftProtocol
Also removes the unsafe cast in the sending event. A modern instanceof cast should be used instead.
* Do never manually call exceptionCaught
This better handles disconnecting.
* Readd some of the disconnect packet fixes
* Switch back encryption and compression too
* Fix retaining read issues
* Prevent encoding memory leak
* Remove useless generics
* Remove wrapper exceptions
* Readd DecoderException and EncoderException
* Staticify all serialization helpers
First of all, why am I changing the whole API so that MinecraftCodecHelper is now static instead of an instance? The reason is that these methods are better used statically. Right now the biggest issue with MCPL I see is its reliance on "serialization instances" that are being passed around everywhere. Why were those even made in the first place? Because there was a belief a few years ago that MCPL could somehow ever support multiple versions of Minecraft. The idea is good however it is unrealistic. Packets change heavily between versions and rarely do serialization types. Serialization instances were made with the idea somehow you could implement multiple codechelpers for each version and "downgrade" packets and bind them together using UnsupportedOperationException. In my opinion this is not a route MCPL should be taking. Instead my plan is to add a module that allows ViaVersion to be used with MCPL to allow the desired multi-version support.
Without having to pass serialization instances around, the API becomes a lot simpler. Especially with the removal of the parent class of ItemCodecHelper. (Which previously extended MinecraftCodecHelper for some reason)
Now it is clear what you're calling and there are way more lambda/inlining opportunities around the codebase.
This makes the API more similar to the approach Velocity and ViaVersion are also taking with their static serialization methods.
Classes renamed:
- MinecraftCodecHelper -> MinecraftTypes
- ItemCodecHelper -> ItemTypes
Classes removed:
- PacketCodecHelper interface (not needed anymore)
- BasePacketCodec (merged into MinecraftTypes)
Why was BasePacketCodec not renamed to BaseTypes? Because this library is slowly going to more and more specialize on only minecraft, not needing to retain a special implementation for developers who use it just for PacketLib.
* Update comments
* Reimplement session structure
Benefits are clear, developers can easily provide custom behaviour by overriding the server and client classes to provide custom channels (like geyser does for localchannel) and also custom channel handlers can be provided, like for ViaVersion support.
Transfers were moved to a flag. There are now ClientSession and ServerSession interfaces which extend Session. This way a ServerSession doesn't have connect methods.
Binding to UnixDomainSockets or any other type of SocketAddress is now supported and the client can connect to those too.
Tcp was renamed to Net because now non-tcp protocols like local channels and udp (for bedrock ViaBedrock) can be used.
* Split up server groups and share channel initializer code
This allows us to share more code between server and client. Additionally, the split worker groups allow mcpl to handle server packets more closely to vanilla and reduce timeouts during load.
* Allow more code sharing for custom implementations
* Fill in arbitrary values for remote address if ipv6 client connects to ipv4 server and vice verse
* Use proper separator for ipv6
* Fix channel method signature
* Update protocol/src/main/java/org/geysermc/mcprotocollib/protocol/ClientListener.java
Co-authored-by: chris <github@onechris.mozmail.com>
* Update protocol/src/main/java/org/geysermc/mcprotocollib/protocol/ClientListener.java
Co-authored-by: chris <github@onechris.mozmail.com>
* Update protocol/src/main/java/org/geysermc/mcprotocollib/network/net/NetClientSession.java
Co-authored-by: chris <github@onechris.mozmail.com>
* Add log
* Implement resolving InetSocketAddresses is unresolved
* Rename net package and drop prefix for most classes
* Move session and server into their own packages
* Rename Net prefix to network
* Add ClientNetworkSession factory and pass props properly when following redirects
---------
Co-authored-by: chris <github@onechris.mozmail.com>
* Initial code changes
* Make it compile
* Small inlining
* Make less detectable by anticheats and fix keepalive during configuration
* Fix keepalive edge case
* Properly switch inbound protocol in server listener
* Add flow control
* Make toggling automatic keepalive work in another way
* Remove ping pong packets again
* Address review
* Handle keepalive in configuration
* Only spawn keepalive after login is acknowledged
* Prevent very unlikely race conditions with keepalive being switched during a task
* Add debug log for packet serialization and state switching
* Add one more debug print
* Update protocol/src/main/java/org/geysermc/mcprotocollib/network/Session.java
Co-authored-by: chris <github@onechris.mozmail.com>
* Update protocol/src/main/java/org/geysermc/mcprotocollib/protocol/MinecraftProtocol.java
Co-authored-by: chris <github@onechris.mozmail.com>
* Update protocol/src/main/java/org/geysermc/mcprotocollib/protocol/MinecraftProtocol.java
Co-authored-by: chris <github@onechris.mozmail.com>
* Mark packet as nonnull
* Fix outbound writing race conditions
* Ensure packets are always sent on the event loop
This replicates the same approach Mojang uses in their networking code.
* Reduce log verbosity
* Put errors into debug
* Update protocol/src/main/java/org/geysermc/mcprotocollib/network/tcp/TcpClientSession.java
Co-authored-by: chris <github@onechris.mozmail.com>
* Add comment to always running in event loop
* Handle auto read earlier to prevent race conditions
* Make instance dynamic
* Revert "Make instance dynamic"
This reverts commit 7f8affbdc5.
* Make flush packet priority
* Do not hide original line that is the cause of the exception
* Cancel packet using exception rather than return
* Properly iterate through parents
* Set log level to debug for unit tests
* Revert "Properly iterate through parents"
This reverts commit 4e2b64d983.
* Revert "Cancel packet using exception rather than return"
This reverts commit 6507e77bbe.
* Add write length filter
* Reuse bytebuf for fake flush to avoid unnecessary allocations
* Make tests happy
* Remake dropping packets
* Update protocol/src/main/java/org/geysermc/mcprotocollib/network/tcp/TcpServer.java
Co-authored-by: chris <github@onechris.mozmail.com>
* Fix space
* Rename to flush packet
* Add mojmap reference
* Share keepalive code
* Fix compilation
* Revert a tiny bit closer to vanilla
* Inline lambda
* Inherit annotation
* Inherit annotation 2
* Use checkerframework annotation
* Fixup grammar slightly
* Add reset states method
* Add log marker for packet logging
---------
Co-authored-by: chris <github@onechris.mozmail.com>
This basically makes MinecraftCodec stateless and removes unused APIs.
The MinecraftCodecHelper has a state for an unused registry API, which is not needed at all. Developers can just send their own registry as seen in ServerListener. These only exist because there was an attempt at allowing multi-version support inside MinecraftCodecHelper, but that's not gonna be necessary if ViaVersion support gets added to MCPL.
The option to add back logic for multi-version support is fully open for the future. I didn't remove MinecraftCodecHelper being instance-based, so it's fully possible to readd the multi-version logic back in the future. Just level events and sounds being dynamic is not enough for multi-version support and thus should be removed to streamline the API.
This also removes many workarounds from the code that cause possible inconsistency. Often the MinecraftCodecHelper gets initialized in the tests with empty parameters. This removes them as parameters and removes the need to provide them by moving them to the object itself.
PacketCodecs were also improved to decrease the inheritance issues and streamline the code flow and remove the UnsupportedOperationExceptions being needed.
BufferedPacket was also removed since it's useless for Minecraft.
* Use translatable components like vanilla and cleanup type casts
Just a few messages becoming dynamic using translatable components like vanilla instead of being hardcoded.
* Use checkerframework
* Readd disconnect string methods
* Do not make nullable
* Make code more readable before changes
* Use proper kyori methods
* Make PlayerInfo and VersionInfo optional
* Sort ServerStatusInfo fields in the way they appear in the packet
* Initial work on moving over mcauth
* Initial work on importing MinecraftAuth
* Make compile
* Remove extra headers code
* Switch to different http utils
* Merge changes
* Cleanup
* Remove unused exceptions and constructors
* Implement proxies
* Fixup proxy stuff
* Cleanup
* Remove SR license header
* Remove custom exceptions
* Move auth into main module
Auth has become so small that it's not worth keeping separate
* Make ProxyInfo be part of network again
* Fix indent
* Allow null id and name in GameProfile
* Fix remaining logs
* Make texture checker more accurate
* Fix spaces
* Update dependencies
* Remove usage of var
* Use faster approach for reading raw uuids.
* Use built-in ResourceLocation type
* Use kyori Key instead of built-in type
* Fix missing keys
* Fix packets with incorrect resource location types
* Fix more packets with invalid resource locations
* Update jigsaw packet to use ResourceLocation
* Fix test compilation
* Fully use Key for ResourceProperties
* Fix all Key.key() warnings
* Fix HolderSet revert
* Address review
Changes:
- Removed NetInput/NetOutput and replaced them with ByteBuf
- Added PacketSerializer to PacketDefinition
- Added packet codecs which implementations can supply with custom readers/writers for buffers
With the way this lib used to previously work, any time the protocol state changed, all the packet maps got cleared and had new packets inserted into them depending on the protocol state. This was unnecessarily expensive and although called rarely, it was not ideal.
The packet codecs added are static, immutable and can be reused across sessions. The codec system also opens up the door for multi-version capability in the future.