xivnet

package module
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2019 License: MIT Imports: 12 Imported by: 0

README

xivnet

FFXIV Network Handling Library

A golang parser for incoming or outgoing unencrypted FFXIV network traffic.

Documentation: https://godoc.org/github.com/ff14wed/xivnet

Documentation

Index

Constants

View Source
const FFXIV_PATCH_VERSION = "4.5"

FFXIV_PATCH_VERSION defines the exact patch version of FFXIV that this library supports. We tie xivnet to this version since the network opcodes usually only change on minor patch version updates and not smaller updates like hotfixes.

Variables

This section is empty.

Functions

func MarshalBlockBytes

func MarshalBlockBytes(block BlockData) ([]byte, error)

MarshalBlockBytes returns the byte representation of the block data

Types

type Block

type Block struct {
	Length uint32
	Header BlockHeader
	Data   BlockData
}

Block defines the structure of a block in an FFXIV frame

func (*Block) CorrectLength

func (b *Block) CorrectLength()

CorrectLength computes the true length of the block and sets its Length field

func (*Block) Encode

func (b *Block) Encode(w io.Writer) error

Encode writes the byte representation of the block to the output writer

type BlockData

type BlockData interface {
	IsBlockData()
}

BlockData defines the interface for the XIVWS representation of FFXIV block data

type BlockHeader

type BlockHeader struct {
	SubjectID uint32
	CurrentID uint32
	U1        uint32
	U2        uint16
	Opcode    uint16
	Route     uint32
	Time      time.Time
	U4        uint32
}

BlockHeader defines the type for a 28 byte array

type Decoder

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

Decoder implements an FFXIV frame decoder

func NewDecoder

func NewDecoder(bufSize int) *Decoder

NewDecoder creates a new instance of a decoder

func (*Decoder) CheckHeader

func (d *Decoder) CheckHeader(buf *bufio.Reader) ([]byte, error)

CheckHeader checks to see whether or not the data in the buffer has a valid header

func (*Decoder) Decode

func (d *Decoder) Decode(buf *bufio.Reader) (*Frame, error)

Decode returns a single decoded FFXIV frame from the packet data stored in buf

func (*Decoder) DiscardDataUntilValid

func (d *Decoder) DiscardDataUntilValid(buf *bufio.Reader)

DiscardDataUntilValid will trim off invalid data on the buffered input until it reaches a header that is valid or the buffer has insufficient data. This is useful for when the input stream has been corrupted with some invalid bytes.

type DecodingError

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

DecodingError is returned whenenever some error occurs while decoding the frame or some block within the frame.

func (DecodingError) Error

func (e DecodingError) Error() string

type EOFError

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

EOFError is an error that is returned when there is not enough data to process the packet

func (EOFError) Error

func (e EOFError) Error() string

type Frame

type Frame struct {
	Header      Header
	Time        time.Time
	Length      uint32
	Reserved1   uint16
	NumBlocks   uint16
	Compression uint16
	Reserved2   uint32
	Reserved3   uint16
	Blocks      []*Block
	// contains filtered or unexported fields
}

Frame defines the structure for an FFXIV Frame

func (*Frame) CompressBlocks

func (f *Frame) CompressBlocks() error

CompressBlocks prepares the frame for writing by saving an internal representation of the compressed block bytes

func (*Frame) CorrectLength

func (f *Frame) CorrectLength()

CorrectLength corrects the length in the FFXIV frame header. This method assumes all the block header lengths are correct.

func (*Frame) CorrectTimestamps

func (f *Frame) CorrectTimestamps(timestamp time.Time)

CorrectTimestamps corrects the timestamps in the FFXIV frame header and its blocks

func (*Frame) Encode

func (f *Frame) Encode(w io.Writer, timestamp time.Time, compress bool) error

Encode writes the byte representation of the frame to the output writer with the given timestamp

type GenericBlockData

type GenericBlockData []byte

GenericBlockData defines the type for a variable length byte slice

func GenericBlockDataFromBytes

func GenericBlockDataFromBytes(blockData []byte) *GenericBlockData

GenericBlockDataFromBytes is a helper that creates a GenericBlockData from raw bytes

func (GenericBlockData) IsBlockData

func (GenericBlockData) IsBlockData()

func (*GenericBlockData) Length

func (b *GenericBlockData) Length() uint32

Length returns the length of the block data

func (*GenericBlockData) MarshalBytes

func (b *GenericBlockData) MarshalBytes() ([]byte, error)

MarshalBytes returns the byte representation of the block data

func (*GenericBlockData) MarshalJSON

func (b *GenericBlockData) MarshalJSON() ([]byte, error)

MarshalJSON returns the marshaled version of the BlockHeader

func (*GenericBlockData) UnmarshalBytes

func (b *GenericBlockData) UnmarshalBytes(data []byte) error

UnmarshalBytes sets the block data to the provided raw bytes

func (*GenericBlockData) UnmarshalJSON

func (b *GenericBlockData) UnmarshalJSON(data []byte) error

UnmarshalJSON returns the unmarshaled version of the BlockHeader

type Header [16]byte

Header defines the type for a 16 byte array

func (*Header) MarshalJSON

func (h *Header) MarshalJSON() ([]byte, error)

MarshalJSON returns the marshaled version of the frame header

func (*Header) UnmarshalJSON

func (h *Header) UnmarshalJSON(data []byte) error

UnmarshalJSON returns the unmarshaled version of the frame header

type InvalidFrameLengthError

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

InvalidFrameLength is an error that is returned when the frame specifies a length that is too large. This error guards against the case when garbage or malicious data is read as part of decoding.

func (InvalidFrameLengthError) Error

func (e InvalidFrameLengthError) Error() string

type InvalidHeaderError

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

InvalidHeaderError is an error that is returned when the frame header is not something that is recognized by the decoder. It uses a string as a field to guarantee that the header is copied, so that changes to the original buffer don't affect the error.

func (InvalidHeaderError) Error

func (e InvalidHeaderError) Error() string

type MismatchedReadLengthsError

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

MismatchedReadError is returned when somehow the amount of bytes read doesn't match the requested length. We don't expect this error to happen because we have previously already peeked the required amount of data.

func (MismatchedReadLengthsError) Error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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