xivnet

package module
v3.51.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2023 License: MIT Imports: 10 Imported by: 11

README

xivnet

Test

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 (
	BlockTypeSessionInit = 1
	BlockTypeSessionRecv = 2
	BlockTypeIPC         = 3
	BlockTypePing        = 7
	BlockTypePong        = 8
	BlockTypeEncryptInit = 9
	BlockTypeEncryptRecv = 10
)

These constants indicate the type of block.

View Source
const FFXIV_PATCH_VERSION = "6.38"

FFXIV_PATCH_VERSION defines the exact patch version of FFXIV that this library supports.

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 // [0:4] - Total block size, including the header
	SubjectID uint32 // [4:8] - The session ID that this block describes
	CurrentID uint32 // [8:12] - The session ID of the sender/receiver of this block
	Type      uint16 // [12:14] - The segment type
	Pad1      uint16 // [14:16]
	IPCHeader        // [16:32] if Type == BlockTypeIPC
	Data      BlockData
}

Block defines the structure of a block in an FFXIV frame. More details in Sapphire's `Network/CommonNetwork.h`.

func (Block) CorrectLength

func (b Block) CorrectLength() uint32

CorrectLength returns the true length of the block

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 Decoder

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

Decoder implements an FFXIV frame decoder. It is not thread-safe, so consumers need to be sure not to use it concurrently.

func NewDecoder

func NewDecoder(r io.Reader, bufSize int) *Decoder

NewDecoder creates a new instance of a frame decoder. bufSize controls the total size of the buffer used to store a single frame. It's recommended to keep this value at least 8192, since this value generally works for all frames (as far as I can tell).

func NewDecoderWithOodle added in v3.35.0

func NewDecoderWithOodle(r io.Reader, bufSize int, oodleImpl OodleImpl) *Decoder

func (*Decoder) CheckHeader

func (d *Decoder) CheckHeader() ([]byte, error)

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

func (*Decoder) DiscardDataUntilValid

func (d *Decoder) DiscardDataUntilValid()

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.

func (*Decoder) NextFrame

func (d *Decoder) NextFrame() (*Frame, error)

NextFrame reads data from the underlying buffer and returns a single decoded FFXIV frame from the provided buffer. If there is some sort of decoding error, NextFrame will call DiscardDataUntilValid in order to recover from corrupt data in the byte stream.

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 {
	Preamble           Preamble  // [0:16] - Used to identify the start of a frame
	Time               time.Time // [16:24] - Number of milliseconds since the Unix epoch
	Length             uint32    // [24:28] - Total frame size, including the header
	ConnectionType     uint16    // [28:30] - Connection type (0 lobby, 1 zone, 2 chat)
	Count              uint16    // [30:32] - Number of blocks in this frame
	Reserved1          byte      // [32]    - Usually 1
	Compression        byte      // [33]    - 1 if compressed, 0 if not
	Reserved2          uint16    // [34:36]
	DecompressedLength uint32    // [36:40]
	Blocks             []*Block
}

Frame defines the structure for an FFXIV Frame. More details in Sapphire's `Network/CommonNetwork.h`. The Frame header is encoded as 40 bytes on the wire.

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 generic block data

func (GenericBlockData) MarshalJSON

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

MarshalJSON returns the marshaled version of the generic block data

func (*GenericBlockData) UnmarshalBytes

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

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 generic block data

type IPCHeader

type IPCHeader struct {
	Reserved uint16    // [16:18] - 0x14
	Opcode   uint16    // [18:20] - Type of IPC message
	Pad2     uint16    // [20:22]
	ServerID uint16    // [22:24] - Server ID handling this message
	Time     time.Time // [24:28] - Number of seconds since Unix epoch
	Pad3     uint32    // [28:32]
}

IPCHeader defines the type for the IPC header of an FFXIV block. In cases other than SEGMENTTYPE_IPC, this header will not be present.

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 OodleImpl added in v3.35.0

type OodleImpl interface {
	Decompress(input []byte, outputLength int64) ([]byte, error)
}

type Preamble

type Preamble [16]byte

Preamble defines the type for a 16 byte array

func (*Preamble) MarshalJSON

func (p *Preamble) MarshalJSON() ([]byte, error)

MarshalJSON returns the marshaled version of the frame magic

func (*Preamble) UnmarshalJSON

func (p *Preamble) UnmarshalJSON(data []byte) error

UnmarshalJSON returns the unmarshaled version of the frame magic

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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