minenet

package module
v0.0.0-...-d78c878 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2025 License: GPL-3.0 Imports: 26 Imported by: 0

README

Minecraft Protocol Library for Go

Efficient Minecraft protocol integration in Go. Send, receive, and manipulate packets with its built-in connection class. TCP listener manages status and login states, complete with full encryption and compression support.

Installation

go get github.com/aimjel/minenet
Simple server with PLAY ready connections
package main

import (
	"fmt"
	"github.com/aimjel/minenet"
	"github.com/aimjel/minenet/packet"
)

func main() {
	lc := minenet.ListenConfig{
		OnlineMode:           true,//enables server encryption
		CompressionThreshold: 0, //compresses everything!
		Status:               minenet.NewStatus(minecraft.Version{Protocol: 763}, 10, "someone had todo it"),
	}

	l, err := lc.Listen("localhost:25565")
	if err != nil {
		panic(err)
	}

	for {
		c, err := l.Accept()
		if err != nil {
			fmt.Printf("main thread|server: %v", err)
			return
		}

		if err := c.SendPacket(&packet.JoinGame{
			DimensionNames: []string{"minecraft:overworld"},
			DimensionName:  "minecraft:overworld",
		}); err != nil {
			c.Close(err)
		}

		if err := c.SendPacket(&packet.PlayerPositionLook{}); err != nil {
			c.Close(err)
		}
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	Pool Pool
	// contains filtered or unexported fields
}

func (*Conn) Close

func (c *Conn) Close(err error)

func (*Conn) DecodePacket

func (c *Conn) DecodePacket(pk packet.Packet) error

func (*Conn) FlushPackets

func (c *Conn) FlushPackets() error

func (*Conn) Name

func (c *Conn) Name() string

func (*Conn) Properties

func (c *Conn) Properties() []types.Property

func (*Conn) ReadPacket

func (c *Conn) ReadPacket() (packet.Packet, error)

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

func (*Conn) SendPacket

func (c *Conn) SendPacket(pk packet.Packet) error

SendPacket writes and immediately sends the packet. Use for critical information. overusing can cause more latency and bandwidth to be used.

func (*Conn) UUID

func (c *Conn) UUID() [16]byte

func (*Conn) WritePacket

func (c *Conn) WritePacket(pk packet.Packet) error

WritePacket writes the packet to a buffer. Use for situations where packets don't need to be sent IMMEDIATELY. Chat messages etc. Can also be used to improve bandwidth and client side latency by sending all the data at once. Just make sure it's done in a timely way

type Dialer

type Dialer struct {
	Username string
}

func (*Dialer) Dial

func (d *Dialer) Dial(address string) (*Conn, error)

type ListenConfig

type ListenConfig struct {
	// Status handles the information showed to the client on the server list
	// which includes description, favicon, online/max players and protocol version and name
	Status *Status

	// OnlineMode enables server side encryption.
	// cracked accounts will not be able to connect when online mode is true.
	OnlineMode bool

	// CompressionThreshold compresses packets when they exceed n bytes.
	//-1 disables compression
	// 0 compresses everything
	CompressionThreshold int32

	// If Protocol is not nil the returned boolean determines if the server
	// should proceed with logging in. If the returned value is bool the
	// string value is used as the disconnect reason.
	Protocol func(v int32) (bool, string)
}

func (*ListenConfig) Listen

func (lc *ListenConfig) Listen(address string) (*Listener, error)

type Listener

type Listener struct {
	// contains filtered or unexported fields
}

func (*Listener) Accept

func (l *Listener) Accept() (*Conn, error)

type NopPool

type NopPool struct{}

func (NopPool) Get

func (c NopPool) Get(int32) packet.Packet

type Pool

type Pool interface {
	Get(id int32) packet.Packet
}

type ProxyConfig

type ProxyConfig struct {
	// OnReceive called when a packet is received from the client or server.
	// Returning false will drop the packet.
	OnReceive func(conn *Conn, pk packet.Packet, fromServer bool, state int) bool

	//ErrCh receives errors from the client and server
	ErrCh chan ProxyError
}

func (*ProxyConfig) Listen

func (cfg *ProxyConfig) Listen(addr, targetAddr string) (*ProxyListener, error)

type ProxyError

type ProxyError struct {
	//State is the protocol state the error occurred in
	State int

	Addr net.Addr

	Err error
}

func (ProxyError) Error

func (p ProxyError) Error() string

type ProxyListener

type ProxyListener struct {
	// contains filtered or unexported fields
}

func (*ProxyListener) Close

func (l *ProxyListener) Close() error

type ServerBoundPool

type ServerBoundPool struct{}

ServerBoundPool implements the Pool interface and returns the server bound packets for the play state.

func (ServerBoundPool) Get

func (b ServerBoundPool) Get(id int32) packet.Packet

type Status

type Status struct {
	// contains filtered or unexported fields
}

func NewStatus

func NewStatus(version Version, max int, desc string, enforcesSecureChat, previewsChat bool) *Status

type Version

type Version struct {
	Protocol int
	Text     string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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