valence/crates/packet_inspector
Joel Ellis f0027aa097
Colorise the inspector output based on S2C or C2S (#242)
<!-- Please make sure that your PR is aligned with the guidelines in
CONTRIBUTING.md to the best of your ability. -->
<!-- Good PRs have tests! Make sure you have sufficient test coverage.
-->

## Description

<!-- Describe the changes you've made. You may include any justification
you want here. -->
I've used the popular `owo-colors` library to colourise the output of
the `packet_inspector`.
This makes it a lot easier to see who's sending what for debugging
purposes.

In future, I'd like to be able to filter out common, low-information
packets like `SetPlayerPosition` and `KeepAlive` as well, but that's not
in this PR.


![image](https://user-images.githubusercontent.com/28905212/218880818-69c0461c-bd23-45c4-9fd4-7c5868be4b67.png)

## Test Plan

No tests - just eyeball 😄.
2023-02-14 15:31:17 -08:00
..
src Colorise the inspector output based on S2C or C2S (#242) 2023-02-14 15:31:17 -08:00
Cargo.toml Colorise the inspector output based on S2C or C2S (#242) 2023-02-14 15:31:17 -08:00
README.md Update packet inspector README 2023-01-11 22:58:00 -08: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 -i and -e flags accept a regex to filter packets according to their name. The -i regex includes matching packets while the -e regex excludes matching packets.

For instance, if you only want to print the packets Foo, Bar, and Baz, you can use a regex such as ^(Foo|Bar|Baz)$ with the -i flag.

cargo r -r -p packet_inspector -- 127.0.0.1:25566 127.0.0.1:25565 -i '^(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