1
0
Fork 0
mirror of https://github.com/italicsjenga/valence.git synced 2025-02-03 17:16:34 +11:00
Commit graph

58 commits

Author SHA1 Message Date
Ryan Johnson
420f2d1b7c
Move protocol code to valence_protocol + redesigns ()
Closes  

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  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
emortaldev
b1561eda73
Fix proxy joins () 2022-11-12 06:32:00 -08:00
Ryan
923fabe890 Fix missing tokio context on client disconnect
The `PlayPacketController` might spawn a tokio task, but it was not in a
tokio context when that happened. This is because tokio contexts are
thread-local, but rayon tasks run in their own thread pool.
2022-11-09 18:30:44 -08:00
Ryan Johnson
ff136c2a4a
Clean up Config docs and add compression threshold () 2022-11-01 20:27:08 -07:00
Ryan Johnson
f4714cf255
Redesign packet processing and improve Client update procedure. ()
Closes 
Closes 
Closes 

# 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 .
- 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
56ebcaf50d
Add Username<S> type ()
There are a number of places where usernames are passed around. Using this type ensures that the contained string is actually a valid username and not some other kind of string. For instance you can use it as a function argument to indicate that only valid usernames are accepted, or return it from a function to indicate that only valid usernames are produced.

This is analogous to the existing `Ident<S>` type.
2022-10-22 20:17:06 -07:00
Tert0
c707ed1d04
Proxy Support ()
This PR adds Proxy Support.

Closes 

Co-authored-by: Ryan Johnson <ryanj00a@gmail.com>
2022-10-21 19:50:13 -07:00
Carson McManus
59ca1ab573
Set up Inventory module ()
This is a very rough version of the inventory module and associated features. This will be a good base to start building something more robust.

- adds a player inventory to all clients
- makes clients keep track of what inventory they have open
- adds very naive state sync for inventories

related:  

# Test plans

### Building

1. run `building` example
2. pick any block from creative
3. place it
4. pick a different block from creative
5. place 2
6. break the last one
7. see that both remaining blocks don't become dirt

### Chest inventories

1. run `chest` example
2. sneak to give yourself a stone block
3. open the chest (it's invisible on top of the stone block)
4. place stone in chest
5. see the stone moving around in the chest

## Known Issues

To be fixed in later PRs

- It's very easy to duplicate items if you take the stone out of the chest on the same tick as the server trying to move the item.
- The chest is invisible when you spawn in. It appears if you break it.
- `get_slot` and `set_slot` can panic.
2022-10-15 19:47:02 -07:00
Ryan Johnson
056b4ebd32
Correctly encode biomes () 2022-10-13 18:19:35 -07:00
Ryan Johnson
153cde1a04
Chunk Rewrite With Paletted Containers ()
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
e985bae469 Use StatusCode in auth server response check 2022-10-04 23:35:34 -07:00
Terminator
ef64296159
Implement prevent-proxy-connections
This adds the `prevent-proxy-connections` server property and implements it into valence.

Note that if the server is in offline mode, this changes nothing.

By default, proxy connections are allowed.

Fixes 
2022-10-01 10:42:43 -07:00
Ryan
1dc5d84ba9 Add biomes example (which is currently broken due to bugs in chunk module) 2022-09-23 19:10:11 -07:00
Ryan
28b26b2aae Reorganize registry codec stuff and fix some bugs 2022-09-23 04:51:26 -07:00
Tim Satke
d9b7008827
Add methods to Config to use a custom session server ()
* Add methods to Config to use a custom session server

Added new methods to the Config trait, that enables
implementors to use a custom session server host
or even a fully custom URL.

* Fix error in documentation

* Make format_session_server_url return a String
2022-09-19 20:23:39 -07:00
EmperialDev
419d317736
Migrating the packets to wiki.vg ()
Addresses . Migrating all the packet names to wiki.vg's instead of fabric's.
2022-09-16 21:29:48 -07:00
Ryan Johnson
ca4f47c768
Implement the player sample ()
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
c955ab8799 Resolve remaining clippy warnings 2022-09-07 11:36:12 -07:00
Ryan
f7a35f356e Update rust docs 2022-09-02 00:06:45 -07:00
Ryan
5fb46178dd Don't hide the protocol module behind a feature 2022-08-31 19:20:49 -07:00
Ryan
79399c153e Update to 1.19.2 2022-08-30 18:41:17 -07:00
Ryan
793a795732 Check protocol version during login 2022-08-14 15:18:22 -07:00
Ryan
55cb595740 Improve chunks API 2022-08-10 20:09:10 -07:00
Ryan
e27144bc01 Direct bits per idx for biomes depends on the size of the biome registry 2022-08-10 19:15:53 -07:00
Ryan
a5a560220c New player list implementation 2022-08-09 14:44:04 -07:00
Ryan
fb9220bf58 Implement outgoing packet buffering 2022-08-05 23:10:25 -07:00
Ryan
49d63a39c0 Clean up client and fix names 2022-08-05 12:36:34 -07:00
Ryan
e21fd70160 Restructure packet module 2022-07-29 05:34:29 -07:00
Ryan
959e2b2deb Rename packets
Use yarn packet names (with some exceptions) for better consistency. We should also avoid using Mojang names for things in the future.
2022-07-29 04:49:08 -07:00
Ryan
35c697ff93 Rename *Data to *State 2022-07-27 19:21:11 -07:00
Ryan
865ab76699 Add custom data 2022-07-15 20:40:39 -07:00
Ryan
4b83801066 Clean up docs and fix clippy issues 2022-07-14 23:18:20 -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
70476973b6 Ignore "unexpected EOF" errors 2022-07-06 02:11:15 -07:00
Ryan
3ac711ca74 Use idiomatic names
The Rust stdlib uses "Kind" instead of "Type".
2022-07-05 19:21:52 -07:00
Ryan
4aca4e24a7 Don't load entities with the same UUID as the client 2022-07-04 00:48:21 -07:00
Ryan
79cb4c159a Store entities and clients per server rather than per world 2022-07-03 15:31:24 -07:00
Ryan
a259bdf840 Add the packet inspector proxy 2022-07-01 15:29:31 -07:00
Ryan
9a87fda211 Rename packets 2022-06-30 14:18:29 -07:00
Ryan
6ef634ca2c Use Rust 1.62.0 features 2022-06-30 13:22:08 -07:00
Ryan
560163fd2e Expose the protocol API behind a feature flag
This could be useful for building proxies or clients in the future.
2022-06-30 11:53:57 -07:00
Ryan
806ffa4f42 Remove &mut wrappers
The mutable reference wappers were causing more problems than they were
solving. We will document the dangers of mem::swap later.
2022-06-29 11:09:00 -07:00
Ryan
e97df76a75 Don't tamper with the texture payload
The texture payload (skin + cape URL) that we get from the auth server
needs to stay intact so the signature is not invalidated. However, skins
still aren't loading. Not sure what's up with that.
2022-06-28 18:29:29 -07:00
Ryan
055dd03ffc Implement the player list 2022-06-27 17:52:23 -07:00
Ryan
d7d922399a Add more client events 2022-06-24 16:11:15 -07:00
Ryan
a9cdff3dca Get authentication working again 2022-06-22 23:33:38 -07:00
Ryan
c86b8286ce Update to 1.19
Authentication is currently broken. Looks like the EncryptionResponse
packet changed.
2022-06-21 04:55:32 -07:00
Ryan
004f84370d Use the spatial index in client updates 2022-06-19 01:01:48 -07:00
Ryan
d709eb5ec8 Add spatial index 2022-06-19 00:25:25 -07:00