bedrockping

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2022 License: MIT Imports: 10 Imported by: 1

README

go-bedrockping Go Report Card GoDoc Build Status

A simple Go library to ping Minecraft Bedrock/MCPE servers.

This repository forked from ZeroErrors/go-bedrockping

Usage

Installation

Install using go get github.com/ZeroErrors/go-bedrockping

Example Usage
package main

import (
	"fmt"
	"github.com/ZeroErrors/go-bedrockping"
	"log"
	"time"
)

func main() {
	resp, err := bedrockping.Query("myip:19132", 5 * time.Second, 150 * time.Millisecond)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%d/%d players are online.", resp.PlayerCount, resp.MaxPlayers)
}

(The default port, 19132, is also available as a const, bedrockping.DefaultPort.)

Response

The response structure is described in bedrockping.Response

Documentation

Overview

Package bedrockping is a simple library to ping Minecraft Bedrock/MCPE servers.

Index

Constants

View Source
const (
	// DefaultPort is the default Minecraft Bedrock/MCPE server port.
	DefaultPort = 19132
)

Variables

This section is empty.

Functions

func ReadUTFString

func ReadUTFString(reader io.Reader) (string, error)

ReadUTFString reads a UTF-8 string with a uint16 length header.

func ReadUnconnectedPong

func ReadUnconnectedPong(reader *bufio.Reader, resp *Response) error

ReadUnconnectedPong reads the 'Unconnected Pong (0x1C)' packet from a connection into a Response struct. Details on the packet structure can be found: https://github.com/NiclasOlofsson/MiNET/blob/5bcfbfd94cff943f31208eb8614b3ff16269fdc7/src/MiNET/MiNET/Net/MCPE%20Protocol.cs#L1154

func WriteUnconnectedPing

func WriteUnconnectedPing(writer io.Writer, timestamp uint64) error

WriteUnconnectedPing writes the 'Unconnected Ping (0x01)' packet to a writer. Details on the packet structure can be found: https://github.com/NiclasOlofsson/MiNET/blob/5bcfbfd94cff943f31208eb8614b3ff16269fdc7/src/MiNET/MiNET/Net/MCPE%20Protocol.cs#L1003

func WriteUnconnectedPingPacket

func WriteUnconnectedPingPacket(conn net.Conn, timestamp uint64) error

WriteUnconnectedPingPacket writes the 'Unconnected Ping (0x01)' as a single packet to a connection.

Types

type Response

type Response struct {
	Timestamp       uint64   `json:"timestamp"`
	ServerID        uint64   `json:"serverId"`
	GameID          string   `json:"gameId"`
	ServerName      string   `json:"serverName"`
	ProtocolVersion int      `json:"protocolVersion"`
	MCPEVersion     string   `json:"mcpeVersion"`
	PlayerCount     int      `json:"playerCount"`
	MaxPlayers      int      `json:"maxPlayers"`
	Extra           []string `json:"extra"`
}

Response data returned from ReadUnconnectedPong.

func Query

func Query(network string, address string, timeout time.Duration, resend time.Duration) (Response, error)

Query makes a query to the specified address via the Minecraft Bedrock protocol, if successful it returns a Response containing data from the pong packet. resend is the interval that the ping packet is sent in case there is packet loss.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL