-
-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split incoming/outgoing packet registry, transition protocol states c…
…orrectly (#841) * 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 <[email protected]> * Update protocol/src/main/java/org/geysermc/mcprotocollib/protocol/MinecraftProtocol.java Co-authored-by: chris <[email protected]> * Update protocol/src/main/java/org/geysermc/mcprotocollib/protocol/MinecraftProtocol.java Co-authored-by: chris <[email protected]> * 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 <[email protected]> * 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 7f8affb. * 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 4e2b64d. * Revert "Cancel packet using exception rather than return" This reverts commit 6507e77. * 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 <[email protected]> * 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 <[email protected]>
- Loading branch information
1 parent
b2c9268
commit f846035
Showing
22 changed files
with
447 additions
and
160 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
28 changes: 28 additions & 0 deletions
28
protocol/src/main/java/org/geysermc/mcprotocollib/network/tcp/FlushHandler.java
This file contains 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,28 @@ | ||
package org.geysermc.mcprotocollib.network.tcp; | ||
|
||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.channel.ChannelOutboundHandlerAdapter; | ||
import io.netty.channel.ChannelPromise; | ||
|
||
/** | ||
* Sending a {@link FlushPacket} will ensure all before were sent. | ||
* This handler makes sure it's dropped before it reaches the encoder. | ||
* This logic is similar to the Minecraft UnconfiguredPipelineHandler.OutboundConfigurationTask. | ||
*/ | ||
public class FlushHandler extends ChannelOutboundHandlerAdapter { | ||
public static final FlushPacket FLUSH_PACKET = new FlushPacket(); | ||
|
||
@Override | ||
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { | ||
if (msg == FLUSH_PACKET) { | ||
promise.setSuccess(); | ||
} else { | ||
super.write(ctx, msg, promise); | ||
} | ||
} | ||
|
||
public static class FlushPacket { | ||
private FlushPacket() { | ||
} | ||
} | ||
} |
This file contains 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
20 changes: 20 additions & 0 deletions
20
protocol/src/main/java/org/geysermc/mcprotocollib/network/tcp/TcpFlowControlHandler.java
This file contains 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,20 @@ | ||
package org.geysermc.mcprotocollib.network.tcp; | ||
|
||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.handler.flow.FlowControlHandler; | ||
|
||
/** | ||
* A flow control handler for TCP connections. | ||
* When auto-read is disabled, this will halt decoding of packets until auto-read is re-enabled. | ||
* This is needed because auto-read still allows packets to be decoded, even if the channel is not reading anymore from the network. | ||
* This can happen when the channel already read a packet, but the packet is not yet decoded. | ||
* This will halt all decoding until the channel is ready to process more packets. | ||
*/ | ||
public class TcpFlowControlHandler extends FlowControlHandler { | ||
@Override | ||
public void read(ChannelHandlerContext ctx) throws Exception { | ||
if (ctx.channel().config().isAutoRead()) { | ||
super.read(ctx); | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.