package ru.dbotthepony.kstarbound.network.packets.clientbound

import ru.dbotthepony.kommons.io.readUUID
import ru.dbotthepony.kommons.io.readVarInt
import ru.dbotthepony.kommons.io.writeUUID
import ru.dbotthepony.kommons.io.writeVarInt
import ru.dbotthepony.kstarbound.client.ClientConnection
import ru.dbotthepony.kstarbound.defs.world.CelestialBaseInformation
import ru.dbotthepony.kstarbound.network.IClientPacket
import java.io.DataInputStream
import java.io.DataOutputStream
import java.util.UUID

class ConnectSuccessPacket(val connectionID: Int, val serverUUID: UUID, val celestialInformation: CelestialBaseInformation) : IClientPacket {
	constructor(stream: DataInputStream, isLegacy: Boolean) : this(
		stream.readVarInt(),
		stream.readUUID(),
		CelestialBaseInformation(stream, isLegacy)
	)

	override fun write(stream: DataOutputStream, isLegacy: Boolean) {
		stream.writeVarInt(connectionID)
		stream.writeUUID(serverUUID)
		celestialInformation.write(stream, isLegacy)
	}

	override fun play(connection: ClientConnection) {
		connection.connectionID = connectionID
	}
}
