func (this *packetServerClientSettingsCodec17) Encode(writer io.Writer, util []byte, encode packet.Packet) (err error) {
	packetServerClientSettings := encode.(*PacketServerClientSettings)
	err = packet.WriteString(writer, util, packetServerClientSettings.Locale)
	if err != nil {
		return
	}
	err = packet.WriteUint8(writer, util, packetServerClientSettings.ViewDistance)
	if err != nil {
		return
	}
	err = packet.WriteUint8(writer, util, packetServerClientSettings.ChatFlags)
	if err != nil {
		return
	}
	err = packet.WriteBool(writer, util, packetServerClientSettings.ChatColours)
	if err != nil {
		return
	}
	err = packet.WriteUint8(writer, util, packetServerClientSettings.difficulty17)
	if err != nil {
		return
	}
	err = packet.WriteBool(writer, util, packetServerClientSettings.ShowCape)
	return
}
Exemplo n.º 2
0
func (this *PacketResultCodec) Encode(writer io.Writer, util []byte, encode packet.Packet) (err error) {
	packetResult := encode.(*PacketResult)
	err = packet.WriteInt32(writer, util, packetResult.SequenceId)
	if err != nil {
		return
	}
	err = packet.WriteUint8(writer, util, packetResult.StatusCode)
	if packetResult.StatusCode == STATUS_SUCCESS {
		if packetResult.Result.Id() < 0 {
			err = errors.New(fmt.Sprintf("Encode, Request Id is below zero: %d", packetResult.Result.Id()))
			return
		}
		if packetResult.Result.Id() >= len(requestCodecs) {
			err = errors.New(fmt.Sprintf("Encode, Request Id is above maximum: %d", packetResult.Result.Id()))
			return
		}
		buffer := &bytes.Buffer{}
		codec := resultCodecs[packetResult.Result.Id()]
		if codec == nil {
			err = errors.New(fmt.Sprintf("Encode, Request Id does not have a codec: %d", packetResult.Result.Id()))
			return
		}
		err = codec.Encode(buffer, util, packetResult.Result)
		if err != nil {
			return
		}
		payload := buffer.Bytes()
		err = packet.WriteUint16(writer, util, uint16(len(payload)))
		if err != nil {
			return
		}
		_, err = writer.Write(payload)
	}
	return
}
func (this *packetServerClientSettingsCodec) Encode(writer io.Writer, encode packet.Packet) (err error) {
	packetServerClientSettings := encode.(*PacketServerClientSettings)
	err = packet.WriteString(writer, packetServerClientSettings.Locale)
	if err != nil {
		return
	}
	err = packet.WriteUint8(writer, packetServerClientSettings.ViewDistance)
	if err != nil {
		return
	}
	err = packet.WriteUint8(writer, packetServerClientSettings.ChatFlags)
	if err != nil {
		return
	}
	err = packet.WriteBool(writer, packetServerClientSettings.ChatColours)
	if err != nil {
		return
	}
	err = packet.WriteUint8(writer, packetServerClientSettings.SkinParts)
	return
}
Exemplo n.º 4
0
func (this *packetRequestCodec) Encode(writer io.Writer, encode packet.Packet) (err error) {
	packetRequest := encode.(*PacketRequest)
	err = packet.WriteInt32(writer, packetRequest.SequenceId)
	if err != nil {
		return
	}
	err = packet.WriteUint8(writer, uint8(packetRequest.Request.Id()))
	if err != nil {
		return
	}
	if packetRequest.Request.Id() < 0 {
		err = errors.New(fmt.Sprintf("Encode, Request Id is below zero: %d", packetRequest.Request.Id()))
		return
	}
	if packetRequest.Request.Id() >= len(requestCodecs) {
		err = errors.New(fmt.Sprintf("Encode, Request Id is above maximum: %d", packetRequest.Request.Id()))
		return
	}
	buffer := new(bytes.Buffer)
	codec := requestCodecs[packetRequest.Request.Id()]
	if codec == nil {
		err = errors.New(fmt.Sprintf("Encode, Request Id does not have a codec: %d", packetRequest.Request.Id()))
		return
	}
	err = codec.Encode(buffer, packetRequest.Request)
	if err != nil {
		return
	}
	payload := buffer.Bytes()
	err = packet.WriteUint16(writer, uint16(len(payload)))
	if err != nil {
		return
	}
	_, err = writer.Write(payload)
	return
}