go-tibia: badc0de.net/pkg/go-tibia/net Index | Files

package net

import "badc0de.net/pkg/go-tibia/net"

Package net implements network communication primitives for the login and gameworld protocol.

This includes a message (a single communications block sent by client or server) and encryption primitives.

Index

Package Files

doc.go message.go rsa.go

Variables

var ErrDecryption = rsa.ErrDecryption

func RSA___decrypt Uses

func RSA___decrypt(random io.Reader, priv *rsa.PrivateKey, c *big.Int) (m *big.Int, err error)

decrypt performs an RSA decryption, resulting in a plaintext integer. If a random source is given, RSA blinding is used.

type Message Uses

type Message struct {
    bytes.Buffer
    // contains filtered or unexported fields
}

Message implements the network message primitive in the login and gameworld protocols, and provides an io.Reader and io.Writer interface.

It happens to be a bytes.Buffer.

func NewMessage Uses

func NewMessage() *Message

NewMessage creates a new blank message primitive.

func ReadMessage Uses

func ReadMessage(r io.Reader) (*Message, error)

ReadMessage reads the message primitive from the passed reader, and returns it as a new Message.

func (*Message) Decrypt Uses

func (msg *Message) Decrypt(xteaKey [16]byte) (*Message, error)

Decrypt reads through the entire message buffer (moving the read cursor), and returns a new Message containing the decrypted buffer.

func (*Message) Encrypt Uses

func (msg *Message) Encrypt(xteaKey [16]byte) (*Message, error)

Encrypt reads through the entire message buffer (moving the read cursor), and returns a new Message containing the encrypted buffer.

func (*Message) Finalize Uses

func (msg *Message) Finalize(xteaKey [16]byte) (*Message, error)

Finalize correctly adds the message length and checksum, as well as performs the XTEA encryption on the message.

func (*Message) PrependSize Uses

func (msg *Message) PrependSize() (*Message, error)

PrependSize only prepends the size+checksum+innert size to the message. Used only to send initial 0x1F packet.

func (*Message) RSADecryptRemainder Uses

func (msg *Message) RSADecryptRemainder(pk *rsa.PrivateKey) error

RSADecryptRemainder checks if the remaining bytes form 128 bytes of data, and decrypts them using the passed RSA private key.

Once decrypted, the bytes are overwritten in the original buffer, instead of being returned as a new message.

func (*Message) Read Uses

func (msg *Message) Read(b []byte) (int, error)

Read fetches bytes into the passed byte slice, and returns how many bytes were read.

This implements the io.Reader protocol, but happens to be only a thin wrapper around bytes.Buffer. Specific implementation will probably be dropped in favor of fully reusing the bytes.Buffer implementation.

func (*Message) ReadTibiaPosition Uses

func (msg *Message) ReadTibiaPosition() (Position, error)

ReadTibiaPosition is a helper function to decode Tibia-style position on the tiled map.

func (*Message) ReadTibiaString Uses

func (msg *Message) ReadTibiaString() (string, error)

ReadTibiaString is a helper function to decode Tibia-style strings coming up in the buffer: u16+bytes of the message.

func (*Message) WriteTibiaPosition Uses

func (msg *Message) WriteTibiaPosition(pos Position) error

WriteTibiaPosition is a helper function to encode Tibia-style position on the tiled map.

func (*Message) WriteTibiaString Uses

func (msg *Message) WriteTibiaString(s string) error

WriteTibiaString is a helper function to encode Tibia-style string passed, appending it onto the message buffer.

type Position Uses

type Position struct {
    X, Y  uint16
    Floor uint8
}

Position defines the network representation of a character or creature position in the tiled world.

Package net imports 11 packages (graph) and is imported by 4 packages. Updated 2020-10-13. Refresh now. Tools for package owners.