Commit graph

53 commits

Author SHA1 Message Date
Ryan Johnson 4226201fed
Replace log crate with tracing (#157)
The `tracing` crate seems to be the go-to
logging/profiling/instrumentation solution nowadays. Perhaps in the
future we could use `tracing` for profiling instead of (or in addition
to) the `perf`-based `cargo flamegraph` command. This would sidestep the
issue of `rayon` polluting the output. I conducted an initial experiment
by adding some more spans but wasn't very happy with the result.

Log messages have also been improved. There is some additional context
and events are raised when clients are added/removed from the server.
2022-11-16 18:22:44 -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
Tert0 c707ed1d04
Proxy Support (#48)
This PR adds Proxy Support.

Closes #39

Co-authored-by: Ryan Johnson <ryanj00a@gmail.com>
2022-10-21 19:50:13 -07:00
Ryan Johnson ce457a3d20
Add prelude module to valence. (#128)
This removes boilerplate code in the examples and reduces friction when getting started.
2022-10-21 04:54:32 -07:00
Ryan Johnson 056b4ebd32
Correctly encode biomes (#112) 2022-10-13 18:19:35 -07:00
Ryan Johnson 153cde1a04
Chunk Rewrite With Paletted Containers (#91)
The current approach to managing chunk data is misconceived. This new approach uses genuine paletted containers and does not suffer from complexities caused by caching. As a result, memory usage (according to htop) in the terrain example with render distance = 32 has gone from 785 megs to 137 megs. That's 17.4% of the memory it used to use. Terrain generation speed was not affected.
2022-10-07 15:52:55 -07:00
Ryan 65dc561868 Document and rename default_client_event to handle_event_default. 2022-09-11 21:59:05 -07:00
Ryan bc470f3eb3 Consistent logo file names 2022-09-11 00:20:17 -07:00
Ryan Johnson ca4f47c768
Implement the player sample (#47)
Verify that it works by hovering your mouse over the player count in the
cow_sphere example.
2022-09-10 16:02:12 -07:00
Ryan 5c9a6c973c Add --all-targets to actions 2022-09-09 22:35:24 -07:00
Ryan Johnson 20546e2fb8
Split Chunk into loaded and unloaded types (#37)
These changes will pave the way for nonblocking terrain generation in `terrain.rs`.
2022-09-08 19:33:24 -07:00
Ryan 7d55dfb964 Simplify position conversion 2022-09-05 22:12:28 -07:00
SirJosh3917 08ee7acacf
Fix order of chunk creation in conway's example (#27)
This would typically go unnoticed, but upon expanding the and making meaningful use of both directions, this being an issue arises.
2022-09-05 20:16:21 -07:00
Tristan F 10a8de3bbd
Add action bar support (#15)
* Action bar + conway

* Docs for action bar

* Apply suggestions

* fmt
2022-09-05 17:23:32 -07:00
Mrln 42dfcef57d
Add ClientEvent::InteractWithBlock (#26)
* Add ClientEvent::InteractWithBlock

* Add an example of ClientEvent::InteractWithBlock to the conway example
2022-09-05 17:01:39 -07:00
Tristan F df3e5b12bb
Add custom sound effect packet and sound example to conway (#12)
* Add custom sound effect packet, sound example

* Small logic cleanup

* More sound packets

* fmt

* Apply suggestions
2022-09-05 15:37:59 -07:00
Ryan 30e05bb373 cargo fmt 2022-09-04 22:21:24 -07:00
Tristan F d7e229e0a9 Make default client event 2022-09-04 15:42:08 -04:00
Ryan f3c96403e0 Slow down conway example 2022-09-03 01:40:09 -07:00
Ryan 6e0a7e0a88 Allow pausing and clearing the conway example 2022-08-31 04:51:13 -07:00
Ryan 2a266fb091 Change rustfmt settings 2022-08-28 21:31:07 -07:00
Ryan 793a795732 Check protocol version during login 2022-08-14 15:18:22 -07:00
Ryan 003c2e3649 Enable authentication in examples 2022-08-10 10:32:05 -07:00
Ryan b2310db7b7 Fix chunks loading multiple times
The default chunk view distance has also been lowered to 2 since that is the most conservative guess.
2022-08-10 10:27:25 -07:00
Ryan 3649a8ca99 Make superflat option per client rather than per world 2022-08-09 15:09:51 -07:00
Ryan a5a560220c New player list implementation 2022-08-09 14:44:04 -07:00
Ryan 1838c290a0 Extract slotmap logic into separate modules 2022-08-08 18:42:39 -07:00
Ryan 49d63a39c0 Clean up client and fix names 2022-08-05 12:36:34 -07:00
Ryan 6b5e795f81 Rename entity data 2022-08-02 19:02:05 -07:00
Ryan e21fd70160 Restructure packet module 2022-07-29 05:34:29 -07:00
Ryan 35c697ff93 Rename *Data to *State 2022-07-27 19:21:11 -07:00
Ryan 2e22946ffc Rewrite the entity generator 2022-07-27 07:10:35 -07:00
Ryan b604dafe73 Add combat example 2022-07-17 21:29:44 -07:00
Ryan 865ab76699 Add custom data 2022-07-15 20:40:39 -07:00
Ryan a36b5163f7 Implement attack and movement speed 2022-07-12 20:47:53 -07:00
Ryan 9d0363ac4e Add logo 2022-07-12 16:54:36 -07:00
Ryan 3f150b4c8a Document most items 2022-07-11 05:08:02 -07:00
Ryan 24cf864ed1 Don't export items arbitrarily at the crate root 2022-07-06 18:27:59 -07:00
Ryan bfba7a1d11 Swing correct hand 2022-07-05 19:28:29 -07:00
Ryan 3ac711ca74 Use idiomatic names
The Rust stdlib uses "Kind" instead of "Type".
2022-07-05 19:21:52 -07:00
Ryan fcda380f2a Improve entity event API 2022-07-05 18:08:40 -07:00
Ryan c4590a45fc Fix entity create/delete bugs 2022-07-04 16:30:37 -07:00
Ryan 6c0eef1ae7 Add more client events 2022-07-04 15:51:28 -07:00
Ryan 0d07b3659f Store entity events in the entity struct 2022-07-04 00:24:55 -07:00
Ryan e8451da55e Add entity status codes 2022-07-03 23:17:51 -07:00
Ryan fb09ab7f8c Spawn player entities in the conway example 2022-07-03 20:31:20 -07:00
Ryan a6bb67ecfe Fix client respawning 2022-07-03 18:45:11 -07:00
Ryan 79cb4c159a Store entities and clients per server rather than per world 2022-07-03 15:31:24 -07:00
Ryan 985ecf3922 Don't send untranslated error messages to clients 2022-07-02 16:23:58 -07:00