Esempio n. 1
0
func NewCharTemplatePacket() []byte {
	buffer := packets.NewBuffer()
	buffer.WriteByte(0x23)   // Packet type: CharTemplate
	buffer.WriteUInt32(0x00) // We don't actually need to send the template to the client

	return buffer.Bytes()
}
Esempio n. 2
0
func NewCharListPacket() []byte {
	buffer := packets.NewBuffer()
	buffer.WriteByte(0x1f)                       // Packet type: CharList
	buffer.Write([]byte{0x00, 0x00, 0x00, 0x00}) // TODO

	return buffer.Bytes()
}
Esempio n. 3
0
func NewCharCreateOkPacket() []byte {
	buffer := packets.NewBuffer()
	buffer.WriteByte(0x25)   // Packet type: CharCreateOk
	buffer.WriteUInt32(0x01) // Everything went like expected

	return buffer.Bytes()
}
Esempio n. 4
0
func NewCryptInitPacket() []byte {
	key := []byte{0x94, 0x35, 0x00, 0x00, 0xa1, 0x6c, 0x54, 0x87}

	buffer := packets.NewBuffer()
	buffer.WriteByte(0x00) // Packet type: CryptInit
	buffer.WriteByte(0x01) // ?
	buffer.Write(key)      // Key

	return buffer.Bytes()
}
Esempio n. 5
0
func (c *Client) Send(data []byte, params ...bool) error {
	var doChecksum, doBlowfish bool = true, true

	// Should we skip the checksum?
	if len(params) >= 1 && params[0] == false {
		doChecksum = false
	}

	// Should we skip the blowfish encryption?
	if len(params) >= 2 && params[1] == false {
		doBlowfish = false
	}

	if doChecksum == true {
		// Add 4 empty bytes for the checksum new( new(
		data = append(data, []byte{0x00, 0x00, 0x00, 0x00}...)

		// Add blowfish padding
		missing := len(data) % 8

		if missing != 0 {
			for i := missing; i < 8; i++ {
				data = append(data, byte(0x00))
			}
		}

		// Finally do the checksum
		crypt.Checksum(data)
	}

	if doBlowfish == true {
		var err error
		data, err = crypt.BlowfishEncrypt(data, []byte("[;'.]94-31==-%&@!^+]\000"))

		if err != nil {
			return err
		}
	}

	// Calculate the packet length
	length := uint16(len(data) + 2)

	// Put everything together
	buffer := packets.NewBuffer()
	buffer.WriteUInt16(length)
	buffer.Write(data)

	_, err := c.Socket.Write(buffer.Bytes())

	if err != nil {
		return errors.New("The packet couldn't be sent.")
	}

	return nil
}
Esempio n. 6
0
func (g *GameServer) Send(data []byte) error {
	// Calculate the packet length
	length := uint16(len(data) + 2)

	// Put everything together
	buffer := packets.NewBuffer()
	buffer.WriteUInt16(length)
	buffer.Write(data)

	_, err := g.loginServerSocket.Write(buffer.Bytes())

	if err != nil {
		return errors.New("The packet couldn't be sent.")
	}

	return nil
}