mcpackets

package module
v0.0.0-...-349c2c3 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2020 License: MIT Imports: 3 Imported by: 0

README

MCPACKETS

For more information on varints see: https://wiki.vg/Protocol#VarInt_and_VarLong

Installation

Install this package by running go get -u github.com/Sascha-T/mcpackets

Packet

type Packet struct {
	Bytes  []byte
	Size   int
	Offset int
}

Can be created using:

  • func NewPacket_A(arr []byte)
    Creates a new packet from a byte array
  • func NewPacket_S(size int)
    Creates a new packet with a byte array of size size filled with 0s

Methods:

  • func (p *Packet) WriteByte(r byte)
    Writes one byte and increments offset

  • func (p *Packet) ReadByte() byte
    Reads one byte and increments offset

  • func (p *Packet) WriteShort(r uint16)
    Writes two bytes (uint16) and increments offset

  • func (p *Packet) ReadShort() uint16
    Reads two bytes (uint16) and increments offset

  • func (p *Packet) WriteInt(r uint32)
    Writes four byte (uint32) and increments offset

  • func (p *Packet) ReadInt() uint32
    Reads four byte (uint32) and increments offset

  • func (p *Packet) WriteLong(r uint64)
    Writes eight bytes (uint64) and increments offset

  • func (p *Packet) ReadLong() uint64
    Reads eight bytes (uint64) and increments offset

  • func (p *Packet) WriteVarInt(r uint)
    Writes a varint and increments offset

  • func (p *Packet) ReadVarInt() uint
    Reads a varint and increments offset

  • func (p *Packet) WriteString(str string)
    Writes a varint with the size of the string and the string and increments offset

  • func (p *Packet) ReadString() string
    Reads a varint then reads a string with size being the read varint

EncryptionHolder

type EncryptionHolder struct {
	LocalBoundCryptoStream cipher.Stream
	RemoteBoundCryptoStream cipher.Stream
}

Can be created using:

  • func NewEncryptionHolder(sharedSecret []byte) EncryptionHolder
    Shared secret is the byte array sent by the server encrypted using the client's public key

Methods:

  • func (c EncryptionHolder) EncryptPacket(p Packet) []byte
    Encrypts packet p with the outbound AES stream into a byte array

  • func (c EncryptionHolder) DecryptPacket(p []byte) Packet
    Decrypts byte array p with the inbound AES stream into a packet

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCFB8

func NewCFB8(block cipher.Block, iv []byte, decrypt bool) cipher.Stream

Types

type Cfb8

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

CFB stream with 8 bit segment size See http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf

func (*Cfb8) XORKeyStream

func (x *Cfb8) XORKeyStream(dst, src []byte)

type EncryptionHolder

type EncryptionHolder struct {
	LocalBoundCryptoStream  cipher.Stream
	RemoteBoundCryptoStream cipher.Stream
}

func NewEncryptionHolder

func NewEncryptionHolder(sharedSecret []byte) EncryptionHolder

func (EncryptionHolder) DecryptPacket

func (c EncryptionHolder) DecryptPacket(p []byte) Packet

func (EncryptionHolder) EncryptPacket

func (c EncryptionHolder) EncryptPacket(p Packet) []byte

type Packet

type Packet struct {
	Bytes  []byte
	Size   int
	Offset int
}

func NewPacket_A

func NewPacket_A(arr []byte) Packet

Create Packet from Array

func NewPacket_S

func NewPacket_S(size int) Packet

Create empty Packet from size

func (*Packet) ReadByte

func (p *Packet) ReadByte() byte

func (*Packet) ReadInt

func (p *Packet) ReadInt() uint32

func (*Packet) ReadLong

func (p *Packet) ReadLong() uint64

func (*Packet) ReadShort

func (p *Packet) ReadShort() uint16

func (*Packet) ReadString

func (p *Packet) ReadString() string

func (*Packet) ReadVarInt

func (p *Packet) ReadVarInt() uint

Use for VarLong aswell

func (*Packet) WriteByte

func (p *Packet) WriteByte(r byte)

func (*Packet) WriteInt

func (p *Packet) WriteInt(r uint32)

func (*Packet) WriteLong

func (p *Packet) WriteLong(r uint64)

func (*Packet) WriteShort

func (p *Packet) WriteShort(r uint16)

func (*Packet) WriteString

func (p *Packet) WriteString(str string)

func (*Packet) WriteVarInt

func (p *Packet) WriteVarInt(r uint)

Use for VarLong aswell

Jump to

Keyboard shortcuts

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