Version: v0.0.2 Latest Latest

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

Go to latest
Published: Oct 6, 2020 License: GPL-2.0 Imports: 11 Imported by: 0



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.



This section is empty.


View Source
var ErrDecryption = rsa.ErrDecryption


func RSA___decrypt

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

type Message struct {
	// 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

func NewMessage() *Message

NewMessage creates a new blank message primitive.

func ReadMessage

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

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

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

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

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

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

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

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

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

func (*Message) ReadTibiaString

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

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

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

func (*Message) WriteTibiaString

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

type Position struct {
	X, Y  uint16
	Floor uint8

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

Jump to

Keyboard shortcuts

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