func (this *packetClientJoinGameCodec) Decode(reader io.Reader, util []byte) (decode packet.Packet, err error) {
	packetClientJoinGame := new(PacketClientJoinGame)
	packetClientJoinGame.EntityId, err = packet.ReadInt32(reader, util)
	if err != nil {
		return
	}
	packetClientJoinGame.Gamemode, err = packet.ReadInt8(reader, util)
	if err != nil {
		return
	}
	packetClientJoinGame.Dimension, err = packet.ReadInt8(reader, util)
	if err != nil {
		return
	}
	packetClientJoinGame.Difficulty, err = packet.ReadInt8(reader, util)
	if err != nil {
		return
	}
	packetClientJoinGame.MaxPlayers, err = packet.ReadInt8(reader, util)
	if err != nil {
		return
	}
	packetClientJoinGame.LevelType, err = packet.ReadString(reader, util)
	if err != nil {
		return
	}
	packetClientJoinGame.ReducedDebugInfo, err = packet.ReadBool(reader, util)
	if err != nil {
		return
	}
	decode = packetClientJoinGame
	return
}
func (this *PacketClientJoinGameCodec) Decode(reader io.Reader, util []byte) (decode packet.Packet, err error) {
	packetClientJoinGame := &PacketClientJoinGame{}
	packetClientJoinGame.EntityId, err = packet.ReadInt32(reader, util)
	if err != nil {
		return
	}
	packetClientJoinGame.Gamemode, err = packet.ReadInt8(reader, util)
	if err != nil {
		return
	}
	packetClientJoinGame.Dimension, err = packet.ReadInt8(reader, util)
	if err != nil {
		return
	}
	packetClientJoinGame.Difficulty, err = packet.ReadInt8(reader, util)
	if err != nil {
		return
	}
	packetClientJoinGame.MaxPlayers, err = packet.ReadInt8(reader, util)
	if err != nil {
		return
	}
	packetClientJoinGame.LevelType, err = packet.ReadString(reader, util)
	if err != nil {
		return
	}
	return packetClientJoinGame, nil
}
Beispiel #3
0
func (this *PacketKeepaliveCodec) Decode(reader io.Reader, util []byte) (decode packet.Packet, err error) {
	packetKeepalive := &PacketKeepalive{}
	packetKeepalive.Random, err = packet.ReadInt32(reader, util)
	if err != nil {
		return
	}
	return packetKeepalive, nil
}
func (this *packetKeepaliveCodec) Decode(reader io.Reader, util []byte) (decode packet.Packet, err error) {
	packetKeepalive := new(PacketKeepalive)
	packetKeepalive.Random, err = packet.ReadInt32(reader, util)
	if err != nil {
		return
	}
	decode = packetKeepalive
	return
}
Beispiel #5
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
}
Beispiel #6
0
func (this *PacketClientRespawnCodec) Decode(reader io.Reader, util []byte) (decode packet.Packet, err error) {
	packetClientRespawn := &PacketClientRespawn{}
	packetClientRespawn.Dimension, err = packet.ReadInt32(reader, util)
	if err != nil {
		return
	}
	packetClientRespawn.Difficulty, err = packet.ReadInt8(reader, util)
	if err != nil {
		return
	}
	packetClientRespawn.Gamemode, err = packet.ReadInt8(reader, util)
	if err != nil {
		return
	}
	packetClientRespawn.LevelType, err = packet.ReadString(reader, util)
	if err != nil {
		return
	}
	return packetClientRespawn, nil
}
func (this *packetClientRespawnCodec) Decode(reader io.Reader) (decode packet.Packet, err error) {
	packetClientRespawn := new(PacketClientRespawn)
	packetClientRespawn.Dimension, err = packet.ReadInt32(reader)
	if err != nil {
		return
	}
	packetClientRespawn.Difficulty, err = packet.ReadInt8(reader)
	if err != nil {
		return
	}
	packetClientRespawn.Gamemode, err = packet.ReadInt8(reader)
	if err != nil {
		return
	}
	packetClientRespawn.LevelType, err = packet.ReadString(reader)
	if err != nil {
		return
	}
	decode = packetClientRespawn
	return
}
Beispiel #8
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
}