Implementation of Minecraft protocols : ping, query and icon.

mcutils - Implementation of Minecraft protocols in Go

logo

Informations

test workflow

General

All protocols are implemented in Go, without any external dependency. All protocols should be supported on any platform/architecture as long as Go can compile them.

All protocols have been implemented using wiki.vg. All of them are 100% compliant with the standard described there.

This project also contains an helper in communication with tcp/udp, called pkg/networking.

This project has no dependency.

Supported protocols

All protocols implementations support SRV record resolving.

Rcon implementation supports fragmented response packets.

CLI

Install

go install github.com/xrjr/mcutils/cmd/mcutils

Usage

$ mcutils ping <hostname> <port>
Example : mcutils ping localhost 25565

$ mcutils query <basic|full> <hostname> <port>
Example : mcutils query basic localhost 25565

$ mcutils rcon <hostname> <port> <password> <command>
Example : mcutils rcon localhost 25575 mypassword "say hello"

How to use (simple way) ?

Ping

// Ping returns the server list ping infos (JSON-like object), and latency of a minecraft server.
properties, latency, err := ping.Ping("localhost", 25565)

Query

// QueryBasic returns the basic stat of a minecraft server.
basicStat, err := query.QueryBasic("localhost", 25565)

// QueryBasic returns the full stat of a minecraft server.
fullStat, err := query.QueryFull("localhost", 25565)

Rcon

// Rcon executes a command on a minecraft server, and returns the response of that command.
response, err := rcon.Rcon("localhost", 25575, "password", "command")

How to use (full control way) ?

Ping

pingclient := ping.NewClient("localhost", 25565)

// Connect opens the connection, and can raise an error for example if the server is unreachable
err := pingclient.Connect()

// Handshake is the base request of ping, the one that displays number of players, MOTD, etc...
// If all went well, hs contains a field Properties which contains a golang-usable JSON Object
hs, err := pingclient.Handshake()

// Ping is a request that basically do nothing and is just used for measuring the latency
// pong contains the latency in ms
pong, err := pingclient.Ping()

// Disconnect closes the connection
err = pingclient.Disconnect()

Query

queryclient := query.NewClient("localhost", 25565)

// Connect opens the connection, and can raise an error for example if the server is unreachable
err := queryclient.Connect()

// Handshake request is used to get the challenge token, needed for questing basic and full stat
challengeToken, err := queryclient.Handshake()

// BasicStat returns several informations about the server like number of players, maximum number of players, etc... in a fully predictable way
bs, err := queryclient.BasicStat(challengeToken)

// FullStat returns several informations (more than BasicStat) in a JSON format, plus the list of connected players
fs, err := queryclient.FullStat(challengeToken)

// Disconnect closes the connection
queryclient.Disconnect()

Rcon

rconclient := rcon.NewClient("localhost", 25575)

// Connect opens the connection, and can raise an error for example if the server is unreachable
err := rconclient.Connect()

// Authenticate request is used to authenticate the connection.
// If the authentication succeeds, ok will be true, and if it fails, ok will be false.
// err will be nil unless there is a communication problem with the server
ok, err := rconclient.Authenticate("password")

// Command will execute the given command on the server, and the output text will be returned in res
res, err := rconclient.Command("playerlist")

// Disconnect closes the connection
rconclient.Disconnect()
Comments
  • Ping taking forever to fail

    Ping taking forever to fail

    Hey,

    when the ping handshake is being executed on an old protocol server like 1.6.4 it takes like 15+ seconds until it returns the error. When using the command, it returns an error instantly, for some reason.

    After some troubleshooting, I could only find out that it hangs with the first call of in.ReadUVarInt() but I couldn't figure out what's causing it. https://github.com/xrjr/mcutils/blob/master/pkg/ping/client.go#L37

  • Slow ping performance

    Slow ping performance

    After completing the implementation and replacing mcping I have noticed that a lot of ping requests timeout with a timeout of 3 seconds and a global timeout of 6 seconds. I'm running workers to handle almost 1k ping requests at the same time.

    With mcping this takes less than 2 seconds to process all 1k addresses with a timeout of 1 second for each request.

    mcutils finishes after 4-5 seconds, causing it to frequently hit the global timeout while the per-request timeout is lower. Reducing the DialTimeout and ReadTimeout from 3 seconds to 1 (to have the same timeout as mcping), results in a time less than 3 seconds but with a lot more requests failing with a timeout.

    So it seems that mcutils takes a lot longer to process the requests. Is there any way this can be improved?

  • Raw ping response for legacy servers

    Raw ping response for legacy servers

    As stated in the Wiki, a server running Forge will add additional information about the installed mods, https://wiki.vg/Minecraft_Forge_Handshake.

    On the latest versions you can access it using the ping.JSON map, but for legacy servers the handshake is parsed into ping.LegacyPingInfos without the option of getting the raw map response.

    Thank you so much for all the work!

  • Query fails with IO timeout on Forge modpack server

    Query fails with IO timeout on Forge modpack server

    Hi there, as noted over in itzg/mc-monitor#22 I encounter a problem when running the query protocol against a Forge server:

    root@d89b9e0a7935:/go# time mcutils query full <HOST> 25565
    Error : read udp 172.17.0.2:59234->45.32.240.165:25565: i/o timeout.
    Usage : mcutils query <basic|full> <hostname> <port>
    
    real    0m5.017s
    user    0m0.003s
    sys     0m0.000s
    

    Same result regardless of basic or full query request. It's pretty clear it's hitting the default 5 second timeout but ping seems to work just fine. For easier repro the ping result is available in a gist here: https://gist.github.com/chloeruka/c892c718204260faa6a578f7983ad654

    mcutils version: mcutils v1.3.2 Minecraft server version: 1.16.5 Server detail: Forge Mod Loader (modded) running Enigmatica 6 v1.5.1

    If I find the time to investigate this one this long weekend I'll add whatever I find.

  • Possible forever query

    Possible forever query

    Hey, I have a small problem. I'm trying to query many servers in goroutines using producer-consumer pattern but it seems that the package has deadlock somewhere. Is it possible to maybe implement some kind of timeout? My consumers are getting clogged after some time and after some investigation it seems that query is responsible for that lock. I'm not sure what's going on internally in lib, haven't been digging into it. It would be great if anyone could look into it, if you need more details please dont hestitate to ask.

  • Error when calling Disconnect on already closed connection

    Error when calling Disconnect on already closed connection

    Hey,

    I'm getting the following error when calling pingclient.Disconnect() when the connection was already closed.

    panic: runtime error: invalid memory address or nil pointer dereference
    [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x668b98]
    
    goroutine 80565 [running]:
    github.com/xrjr/mcutils/pkg/ping.(*PingClient).Disconnect(0xc000ef5f68)
            /go/src/gocode/vendor/github.com/xrjr/mcutils/pkg/ping/client.go:197 +0x18
    main.retrieveMinecraft({0xc000239734, 0x66c38d}, 0x0)
            /go/src/gocode/cmd/main/main.go:114 +0x2f7
    created by main.queryServers.func1
            /go/src/gocode/cmd/main/main.go:182 +0x1ef
    
  • Panic fix for bedrock ping

    Panic fix for bedrock ping

    I understand that there should be an implementation strictly in accordance with the protocol, but the situation with Minecraft servers is such that not all servers implement in accordance with the protocol The use of the ErrInvalidData error was also skipped

    Information about https://wiki.vg/Raknet_Protocol#Unconnected_Pong at odds with reality

    On some servers (perhaps even on many), there is no information about the numbered game mode in the response. The same goes for IPv4 and IPv6 ports

    For example: surgical.aternos.me:47706 bmpe.pw:19998 electroncraft.ru:19132

Minecraft Server List Ping library written in Go

minequery Minecraft Server List Ping library written in Go. Features Modern Mine

Dec 28, 2022
Golang pow implementation client <-> server over UDP and TCP protocols
Golang pow implementation client <-> server over UDP and TCP protocols

Client <-> server over UDP and TCP pow protocol Denial-of-Service-attacks are a typical situation when providing services over a network. A method for

Jan 13, 2022
🚥 Yet another pinger: A high-performance ICMP ping implementation build on top of BPF technology.

yap Yet-Another-Pinger: A high-performance ICMP ping implementation build on top of BPF technology. yap uses the gopacket library to receive and handl

Nov 9, 2022
PinGo is a standalone and feature-rich tool for common IP-based reachability checking tasks. Ping or Trace and Observe in real-time the statistics.

pingo As a network champion from designing and implementing to troubleshooting large scale networks - I know that is usually not easy for administrato

Sep 26, 2022
🚀Gev is a lightweight, fast non-blocking TCP network library based on Reactor mode. Support custom protocols to quickly and easily build high-performance servers.
🚀Gev is a lightweight, fast non-blocking TCP network library based on Reactor mode. Support custom protocols to quickly and easily build high-performance servers.

gev 中文 | English gev is a lightweight, fast non-blocking TCP network library based on Reactor mode. Support custom protocols to quickly and easily bui

Jan 6, 2023
Encode and Decode Message Length Indicators for TCP/IP socket based protocols

SimpleMLI A Message Length Indicator Encoder/Decoder Message Length Indicators (MLI) are commonly used in communications over raw TCP/IP sockets. This

Nov 24, 2022
Bee is a tool to scan ports by TCP and UDP protocols

Bee - Port scan tool ?? Bee is a tool to scan ports by TCP and UDP protocols Building from Source Code First, we compile the source code with the ligh

Oct 10, 2021
DNS Ping: to check packet loss and latency issues with DNS servers

DNSping DNS Ping checks packet loss and latency issues with DNS servers Installation If you have golang, easiest install is go get -u fortio.org/dnspi

Nov 18, 2022
Prometheus exporter for ping metrics such as RTT, packet loss, and jitter to any number of hosts.

ping_exporter Command ping_exporter provides a Prometheus exporter for ping metrics such as RTT, packet loss, and jitter to any number of hosts. Usage

Sep 24, 2022
Package for downloading things from a string URL using a variety of protocols.

go-getter is a library for Go (golang) for downloading files or directories from various sources using a URL as the primary form of input.

Jan 6, 2023
ping 和 http get 请求探测 适配 nightingale

n9e-probe 功能 ping 和 http get 请求探测 适配 nightingale 指标 ping metric 说明 ping.latency ping 请求的延迟,单位是毫秒。-1 表示 ping 不通 tag 说明 ip 探测的目标 ip region 如果配置了,则插入 reg

Sep 27, 2022
[FORK] ICMP Ping library for Go

forked from go-ping/ping go get -u github.com/gandaldf/ping go-ping A simple but powerful ICMP echo (ping) library for Go, inspired by go-fastping. He

Oct 21, 2021
Ping library for Golang with multi-host support

pingo Fast and lightweight ping library for Golang with multi-host support. Features ICMP sockets: UDP port 0 means "let the kernel pick a free number

Nov 9, 2022
A little ping pong service that implements rate limiting with golang

Fred the Guardian Introduction Writing a little ping pong service that implements rate limiting with the programming language golang. Requirements Web

Jan 2, 2022
HCio is a straightforward way to ping Healthchecks.io checks directly from a Go application

HCio HCio is a straightforward way to ping Healthchecks.io checks directly from a Go application. Getting Started Create a simple Check: check := hcio

Nov 20, 2022
Vmessping - A ping prober for vmess:// links in common seen formats

VMessPing A ping prober for vmess:// links in common seen formats. vmessping sup

Jan 9, 2022
QUIC-PING: A UDP client for sending QUIC PINGs.

QUIC-PING A UDP client for sending "QUIC PING"s. What is a QUIC PING? A QUIC Initial packet with random payload and the version 0xbabababa to force Ve

Dec 14, 2022
Server-tool - A simple tool to run and create Minecraft servers

Server Tool A simple tool to run and maintain different Minecraft servers. This

Dec 15, 2022
A vote botting wrapper for GoLang designed for Minecraft: Pocket Servers.

libvote A vote botting wrapper for GoLang designed for Minecraft: Pocket Servers by Jviguy and JustTal. Disclaimer Usage of libvote requires your own

Apr 17, 2022