Commit graph

11 commits

Author SHA1 Message Date
Ryan Johnson ab2e1081ed
Re-export common items at the root of valence_protocol (#156) 2022-11-14 22:30:20 -08:00
Ryan Johnson 420f2d1b7c
Move protocol code to valence_protocol + redesigns (#153)
Closes #83 

This PR aims to move all of Valence's networking code to the new
`valence_protocol` crate. Anything not specific to valence is going in
the new crate. It also redesigns the way packets are defined and makes a
huge number of small additions and improvements. It should be much
easier to see where code is supposed to go from now on.

`valence_protocol` is a new library which enables interactions with
Minecraft's protocol. It is completely decoupled from valence and can be
used to build new clients, servers, tools, etc.

There are two additions that will help with #5 especially:
- It is now easy to define new packets or modifications of existing
packets. Not all packets need to be bidirectional.
- The `CachedEncode` type has been created. This is used to safely cache
redundant calls to `Encode::encode`.
2022-11-13 06:10:42 -08:00
Ryan Johnson f4714cf255
Redesign packet processing and improve Client update procedure. (#146)
Closes #82
Closes #43
Closes #64

# Changes and Improvements
- Packet encoding/decoding happens within `Client` instead of being sent
over a channel first. This is better for performance and lays the
groundwork for #83.
- Reduce the amount of copying necessary by leveraging the `bytes` crate
and recent changes to `EncodePacket`. Performance is noticeably improved
with maximum players in the `rust-mc-bot` test going from 750 to 1050.
- Packet encoding/decoding code is decoupled from IO. This is easier to
understand and more suitable for a future protocol lib.
- Precise control over the number of bytes that are buffered for
sending/receiving. This is important for limiting maximum memory usage
correctly.
- "packet controllers" are introduced, which are convenient structures
for managing packet IO before and during the play state.
- `byte_channel` module is created to help implement the
`PlayPacketController`. This is essentially a channel of bytes
implemented with an `Arc<Mutex<BytesMut>>`.
- Error handling in the update procedure for clients was improved using
`anyhow::Result<()>` to exit as early as possible. The `client` module
is a bit cleaner as a result.
- The `LoginPlay` packet is always sent before all other play packets.
We no longer have to worry about the behavior of packets sent before
that packet. Most packet deferring performed currently can be
eliminated.
- The packet_inspector was rewritten in response to the above changes.
- Timeouts on IO operations behave better.

# Known Issues
- The packet_inspector now re-encodes packets rather than just decoding
them. This will cause problems when trying to use it with the vanilla
server because there are missing clientbound packets and other issues.
This will be fixed when the protocol module is moved to a separate
crate.
2022-11-01 03:11:51 -07:00
Ryan Johnson 71d82c5330
Add encoded_len method to Encode trait. (#125)
This allows packets to calculate their exact length up front.
This isn't currently tested or being used for anything, but that will come in later changes.
2022-10-19 01:52:02 -07:00
Ryan 9b8fbc5d82 Better "encryption enabled" message in packet_inspector 2022-10-19 01:42:32 -07:00
EmperialDev 419d317736
Migrating the packets to wiki.vg (#62)
Addresses #56. Migrating all the packet names to wiki.vg's instead of fabric's.
2022-09-16 21:29:48 -07:00
Ryan Johnson 0a75f103aa
Packet filtering (#67)
* Add `PacketName`

* Fix inefficiency in codec.rs

* Add regex argument to packet_inspector

* Reorder imports

* Make the regex arg optional

* Update README
2022-09-16 05:31:37 -07:00
Ryan 067d753267 Move packet_inspector README.md to correct directory 2022-09-05 22:18:13 -07:00
Ryan Johnson 9ab54cc930
Tweak packet_inspector README 2022-09-05 21:25:30 -07:00
Ryan Johnson 62f7a039cc
Create README for packet_inspector 2022-09-05 18:33:27 -07:00
Ryan 27033c758e Update packet_inspector 2022-09-01 00:57:02 -07:00