package ru.dbotthepony.kstarbound.network.packets.serverbound

import it.unimi.dsi.fastutil.bytes.ByteArrayList
import ru.dbotthepony.kommons.io.readByteArray
import ru.dbotthepony.kommons.io.writeByteArray
import ru.dbotthepony.kstarbound.network.IServerPacket
import ru.dbotthepony.kstarbound.server.ServerConnection
import java.io.DataInputStream
import java.io.DataOutputStream

// general information about client, such as window size and zoom,
// sent as NetworkedElement deltas
class WorldClientStateUpdatePacket(val deltas: ByteArrayList) : IServerPacket {
	constructor(stream: DataInputStream, isLegacy: Boolean) : this(ByteArrayList.wrap(stream.readByteArray()))

	override fun write(stream: DataOutputStream, isLegacy: Boolean) {
		stream.writeByteArray(deltas.elements(), 0, deltas.size)
	}

	override fun play(connection: ServerConnection) {
		connection.client2serverGroup.read(deltas.elements(), 0, deltas.size, isLegacy = connection.isLegacy)
	}
}
