func (this *packetClientJoinGameCodec) Encode(writer io.Writer, util []byte, encode packet.Packet) (err error) {
	packetClientJoinGame := encode.(*PacketClientJoinGame)
	err = packet.WriteInt32(writer, util, packetClientJoinGame.EntityId)
	if err != nil {
		return
	}
	err = packet.WriteInt8(writer, util, packetClientJoinGame.Gamemode)
	if err != nil {
		return
	}
	err = packet.WriteInt8(writer, util, packetClientJoinGame.Dimension)
	if err != nil {
		return
	}
	err = packet.WriteInt8(writer, util, packetClientJoinGame.Difficulty)
	if err != nil {
		return
	}
	err = packet.WriteInt8(writer, util, packetClientJoinGame.MaxPlayers)
	if err != nil {
		return
	}
	err = packet.WriteString(writer, util, packetClientJoinGame.LevelType)
	if err != nil {
		return
	}
	err = packet.WriteBool(writer, util, packetClientJoinGame.ReducedDebugInfo)
	return
}
示例#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 *packetClientJoinGameCodec17) Encode(writer io.Writer, encode packet.Packet) (err error) {
	packetClientJoinGame := encode.(*PacketClientJoinGame)
	err = packet.WriteInt32(writer, packetClientJoinGame.EntityId)
	if err != nil {
		return
	}
	err = packet.WriteInt8(writer, packetClientJoinGame.Gamemode)
	if err != nil {
		return
	}
	err = packet.WriteInt8(writer, packetClientJoinGame.Dimension)
	if err != nil {
		return
	}
	err = packet.WriteInt8(writer, packetClientJoinGame.Difficulty)
	if err != nil {
		return
	}
	err = packet.WriteInt8(writer, packetClientJoinGame.MaxPlayers)
	if err != nil {
		return
	}
	err = packet.WriteString(writer, packetClientJoinGame.LevelType)
	return
}
func (this *packetClientRespawnCodec) Encode(writer io.Writer, util []byte, encode packet.Packet) (err error) {
	packetClientRespawn := encode.(*PacketClientRespawn)
	err = packet.WriteInt32(writer, util, packetClientRespawn.Dimension)
	if err != nil {
		return
	}
	err = packet.WriteInt8(writer, util, packetClientRespawn.Difficulty)
	if err != nil {
		return
	}
	err = packet.WriteInt8(writer, util, packetClientRespawn.Gamemode)
	if err != nil {
		return
	}
	err = packet.WriteString(writer, util, packetClientRespawn.LevelType)
	return
}
示例#5
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
}
func (this *packetKeepaliveCodec) Encode(writer io.Writer, util []byte, encode packet.Packet) (err error) {
	err = packet.WriteInt32(writer, util, encode.(*PacketKeepalive).Random)
	return
}