mcproto

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2021 License: MIT Imports: 9 Imported by: 0

README

go-mcproto ⚒️

Implementation of the Minecraft Protocol in go (still in progress...)

Go Reference

Example ✨

This example initializes the connection between the client and the server, thus switching to the Play state, and listens for keepalive packets to which it responds

package main

import (
	"github.com/BRA1L0R/go-mcproto"
	"github.com/BRA1L0R/go-mcproto/packets/models"
)

func main() {
  client := mcproto.McProto{
    Host: "my.minecraftserver.com",
    Port: 25565,
    ProtocolVersion: 754, // 1.16.5
    Name: "QuickStart",
  }
  
  client.Initialize()
  
  for {
    packet, err := client.ReceivePacket()
    if err != nil {
      panic(err)
    }
    
    if packet.PacketID == 0x1F { // clientbound keepalive packetid
      receivedKeepalive := models.KeepAlivePacket{MinecraftPacket: packet}

      err := receivedKeepalive.DeserializeData(&receivedKeepalive)
      if err != nil {
        panic(err)
      }
      
      serverBoundKeepalive := new(models.KeepAlivePacket)
      serverBoundKeepalive.KeepAliveID = receivedKeepalive.KeepAliveID
      serverBoundKeepalive.PacketID = 0x10 // serverbound keepaliveid

      err = client.WritePacket(serverBoundKeepalive)
    }
  }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type McProto

type McProto struct {
	Host            string
	Port            uint16
	Name            string
	ProtocolVersion int32
	// contains filtered or unexported fields
}

func (*McProto) GetCompressionTreshold

func (mc *McProto) GetCompressionTreshold() int32

func (*McProto) Initialize

func (mc *McProto) Initialize() error

Initializes the connection to the server by sending the handshake packet and the login packet

Server Host, Port and Username are defined in the McProto object

func (*McProto) ReceivePacket

func (mc *McProto) ReceivePacket() (packets.MinecraftPacket, error)

func (*McProto) WritePacket

func (mc *McProto) WritePacket(packet PacketOp) error

type PacketOp

type PacketOp interface {
	SerializeData(inter interface{}) error
	Serialize(compressionTreshold int32) ([]byte, error)
}

PacketOp defines the standard methods that a struct should have in order to be serializable by the library

You can actually create your own methods as long as they respect this standard

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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