func (this *packetServerClientSettingsCodec) Decode(reader io.Reader) (decode packet.Packet, err error) {
	packetServerClientSettings := new(PacketServerClientSettings)
	packetServerClientSettings.Locale, err = packet.ReadString(reader)
	if err != nil {
		return
	}
	packetServerClientSettings.ViewDistance, err = packet.ReadUint8(reader)
	if err != nil {
		return
	}
	packetServerClientSettings.ChatFlags, err = packet.ReadUint8(reader)
	if err != nil {
		return
	}
	packetServerClientSettings.ChatColours, err = packet.ReadBool(reader)
	if err != nil {
		return
	}
	packetServerClientSettings.SkinParts, err = packet.ReadUint8(reader)
	if err != nil {
		return
	}
	decode = packetServerClientSettings
	return
}
func (this *PacketServerClientSettingsCodec) Decode(reader io.Reader, util []byte) (decode packet.Packet, err error) {
	packetServerClientSettings := &PacketServerClientSettings{}
	packetServerClientSettings.Locale, err = packet.ReadString(reader, util)
	if err != nil {
		return
	}
	packetServerClientSettings.ViewDistance, err = packet.ReadUint8(reader, util)
	if err != nil {
		return
	}
	packetServerClientSettings.ChatFlags, err = packet.ReadUint8(reader, util)
	if err != nil {
		return
	}
	packetServerClientSettings.Unused, err = packet.ReadBool(reader, util)
	if err != nil {
		return
	}
	packetServerClientSettings.Difficulty, err = packet.ReadUint8(reader, util)
	if err != nil {
		return
	}
	packetServerClientSettings.ShowCape, err = packet.ReadBool(reader, util)
	if err != nil {
		return
	}
	return packetServerClientSettings, nil
}
func (this *packetServerClientSettingsCodec17) Decode(reader io.Reader, util []byte) (decode packet.Packet, err error) {
	packetServerClientSettings := new(PacketServerClientSettings)
	packetServerClientSettings.Locale, err = packet.ReadString(reader, util)
	if err != nil {
		return
	}
	packetServerClientSettings.ViewDistance, err = packet.ReadUint8(reader, util)
	if err != nil {
		return
	}
	packetServerClientSettings.ChatFlags, err = packet.ReadUint8(reader, util)
	if err != nil {
		return
	}
	packetServerClientSettings.ChatColours, err = packet.ReadBool(reader, util)
	if err != nil {
		return
	}
	packetServerClientSettings.difficulty17, err = packet.ReadUint8(reader, util)
	if err != nil {
		return
	}
	packetServerClientSettings.ShowCape, err = packet.ReadBool(reader, util)
	if err != nil {
		return
	}
	decode = packetServerClientSettings
	return
}
Example #4
0
func (this *packetResultCodec) Decode(reader io.Reader) (decode packet.Packet, err error) {
	if this.Sequencer == nil {
		err = errors.New("No sequencer to decode PacketResult")
		return
	}
	packetResult := new(PacketResult)
	packetResult.SequenceId, err = packet.ReadInt32(reader)
	if err != nil {
		return
	}
	packetResult.StatusCode, err = packet.ReadUint8(reader)
	if err != nil {
		return
	}
	if packetResult.StatusCode == STATUS_SUCCESS {
		var payloadSize uint16
		payloadSize, err = packet.ReadUint16(reader)
		if err != nil {
			return
		}
		payload := make([]byte, payloadSize)
		_, err = reader.Read(payload)
		if err != nil {
			return
		}
		buffer := bytes.NewBuffer(payload)
		requestId := this.Sequencer.RequestIdBySequenceId(packetResult.SequenceId)
		if requestId < 0 {
			err = errors.New(fmt.Sprintf("Decode, Request Id is below zero: %d", requestId))
			return
		}
		if int(requestId) >= len(requestCodecs) {
			err = errors.New(fmt.Sprintf("Decode, Request Id is above maximum: %d", requestId))
			return
		}
		codec := resultCodecs[requestId]
		if codec == nil {
			err = errors.New(fmt.Sprintf("Decode, Request Id does not have a codec: %d", requestId))
			return
		}
		packetResult.Result, err = codec.Decode(buffer)
		if err != nil {
			return
		}
	}
	decode = packetResult
	return
}
Example #5
0
func (this *packetRequestCodec) Decode(reader io.Reader) (decode packet.Packet, err error) {
	packetRequest := new(PacketRequest)
	packetRequest.SequenceId, err = packet.ReadInt32(reader)
	if err != nil {
		return
	}
	requestId, err := packet.ReadUint8(reader)
	if err != nil {
		return
	}
	if requestId < 0 {
		err = errors.New(fmt.Sprintf("Decode, Request Id is below zero: %d", requestId))
		return
	}
	if int(requestId) >= len(requestCodecs) {
		err = errors.New(fmt.Sprintf("Decode, Request Id is above maximum: %d", requestId))
		return
	}
	payloadSize, err := packet.ReadUint16(reader)
	if err != nil {
		return
	}
	payload := make([]byte, payloadSize)
	_, err = reader.Read(payload)
	if err != nil {
		return
	}
	buffer := bytes.NewBuffer(payload)
	codec := requestCodecs[requestId]
	if codec == nil {
		err = errors.New(fmt.Sprintf("Decode, Request Id does not have a codec: %d", requestId))
		return
	}
	packetRequest.Request, err = codec.Decode(buffer)
	if err != nil {
		return
	}
	decode = packetRequest
	return
}