Exemple #1
0
func (p *Pill) Decrypt(buf []byte, player *entitie.Player) ([]int, error) {
	var (
		header Header          = Header{}
		netes  *network.Parser = network.NewParser(buf)
	)

	netes.SetEndian(network.LittleEndian).ReadUint16(&header.Len)
	netes.SetEndian(network.BigEndian).ReadUint32(&header.UniqueId)
	netes.SetEndian(network.LittleEndian).ReadUint16(&header.Opcode)

	pill := p.GetPill(int(header.Opcode))
	if pill == nil {
		return nil, errors.New("Pill is not found")
	}

	process := pill.Handler(netes).Process(player)
	if process.Error() != nil {
		return nil, process.Error()
	}

	err := netes.Error()
	if err != nil {
		return nil, err
	}

	return process.Opcodes(), nil
}
Exemple #2
0
func (p *Packet) Decode(buf []byte) ([]int, error) {
	var (
		header PacketHeader    = PacketHeader{}
		netes  *network.Parser = network.NewParser(buf)
	)

	netes.SetEndian(network.LittleEndian).ReadUint16(&header.Len)
	netes.SetEndian(network.BigEndian).ReadUint32(&header.UniqueId)
	netes.SetEndian(network.LittleEndian).ReadUint16(&header.Opcode)

	pck, err := p.GetPck(int(header.Opcode))
	if err != nil {
		return nil, err
	}

	handler, process := pck.Packet(p.Database)

	handler(netes)
	err = netes.Error()
	if err != nil {
		return nil, err
	}

	opcodes := process(p.Player)

	return opcodes, nil
}
Exemple #3
0
func (p *Pill) Decrypt(buf []byte, player entitie.Player) ([]int, error) {
	var (
		header Header          = Header{}
		netes  *network.Parser = network.NewParser(buf)
	)

	netes.SetEndian(network.LittleEndian).ReadUint16(&header.Len)
	netes.SetEndian(network.BigEndian).ReadUint32(&header.UniqueId)
	netes.SetEndian(network.LittleEndian).ReadUint16(&header.Opcode)

	crumb := p.SetOpcode(int(header.Opcode)).GetIncomingCrumb()
	if crumb == nil {
		return nil, errors.New("Crumb is not found")
	}

	crumbProcess, err := crumb.PreHandler(netes).Process(player)
	if err != nil {
		return nil, err
	}

	err = netes.Error()
	if err != nil {
		return nil, err
	}

	return crumbProcess, nil
}