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

import ru.dbotthepony.kommons.io.readBinaryString
import ru.dbotthepony.kommons.io.writeBinaryString
import ru.dbotthepony.kstarbound.client.ClientConnection
import ru.dbotthepony.kstarbound.defs.ChatMessage
import ru.dbotthepony.kstarbound.defs.MessageContext
import ru.dbotthepony.kstarbound.network.IClientPacket
import java.io.DataInputStream
import java.io.DataOutputStream

class ChatReceivePacket(val data: ChatMessage) : IClientPacket {
	constructor(stream: DataInputStream, isLegacy: Boolean) : this(ChatMessage(
		MessageContext(stream, isLegacy),
		stream.readUnsignedShort(), // bugger, written as short again
		stream.readBinaryString(),
		stream.readBinaryString(),
		stream.readBinaryString(),
	))

	override fun write(stream: DataOutputStream, isLegacy: Boolean) {
		data.context.write(stream, isLegacy)
		stream.writeShort(data.sender)
		stream.writeBinaryString(data.senderNick)
		stream.writeBinaryString(data.portrait)
		stream.writeBinaryString(data.text)
	}

	override fun play(connection: ClientConnection) {
		TODO("Not yet implemented")
	}
}
