Exemple #1
0
// DropPacket is a simple hook which will "skip" dropped packets included in the
// server's drop list (including dropped CPE extensions).
func DropPacket(p *Player, dir packets.PacketDirection, packet packets.Packet) (drop bool) {
	if Ku == nil || Ku.Config == nil {
		drop = false
		return
	}
	for _, id := range Ku.Config.Drop {
		if id != packet.Id() {
			continue
		}
		drop = true
		break
	}
	if ep, ok := packet.(cpe.ExtPacket); !drop && ok {
		for _, ext := range Ku.Config.DropExts {
			if ext != ep.String() {
				continue
			}
			drop = true
			break
		}
	}
	if drop {
		Debugf("(%s) %s dropped packet %#.2x", p.Id, p.Name, packet.Id())
	}
	return
}
Exemple #2
0
func (p *Parser) Register(packet packets.Packet, hook Hook) (string, error) {
	if _, ok := p.hooks[packet.Id()]; !ok {
		p.hooks[packet.Id()] = []hookInfo{}
	}
	id := uniuri.NewLen(8)
	info := hookInfo{Id: id, F: hook}
	p.hooks[packet.Id()] = append(p.hooks[packet.Id()], info)
	return id, nil
}