valence/packet_inspector
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
..
src Move protocol code to valence_protocol + redesigns (#153) 2022-11-13 06:10:42 -08:00
Cargo.toml Move protocol code to valence_protocol + redesigns (#153) 2022-11-13 06:10:42 -08:00
README.md Packet filtering (#67) 2022-09-16 05:31:37 -07:00

What's This?

The packet inspector is a very simple Minecraft proxy for viewing the contents of packets as they are sent/received. It uses Valence's protocol facilities to print packet contents. This was made for three purposes:

  • Check that packets between Valence and client are matching your expectations.
  • Check that packets between vanilla server and client are parsed correctly by Valence.
  • Understand how the protocol works between the vanilla server and client.

Usage

First, start a server

cargo r -r --example conway

In a separate terminal, start the packet inspector.

cargo r -r -p packet_inspector -- 127.0.0.1:25566 127.0.0.1:25565

The client must connect to localhost:25566. You should see the packets in stdout.

The third argument to the packet inspector is an optional regular expression compatible with the regex crate. Packets with names that match the regex are printed while those that don't are ignored. If the regex is not provided then the empty string is assumed and all packets are considered matching.

If you're only interested in packets Foo, Bar, and Baz, you can use a regex such as ^(Foo|Bar|Baz)$.

cargo r -r -p packet_inspector -- 127.0.0.1:25566 127.0.0.1:25565 '^(Foo|Bar|Baz)$'

Packets are printed to stdout while errors are printed to stderr. If you only want to see errors in your terminal, direct stdout elsewhere.

cargo r -r -p packet_inspector -- 127.0.0.1:25566 127.0.0.1:25565 > log.txt

Quick start with Vanilla Server via Docker

Start the server

docker run -e EULA=TRUE -e ONLINE_MODE=false -d -p 25565:25565 --name mc itzg/minecraft-server

View server logs

docker logs -f mc

Server Rcon

docker exec -i mc rcon-cli

In a separate terminal, start the packet inspector.

cargo r -r -p packet_inspector -- 127.0.0.1:25566 127.0.0.1:25565

Open Minecraft and connect to localhost:25566.

Clean up

docker stop mc
docker rm mc