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

import ru.dbotthepony.kommons.io.readBinaryString
import ru.dbotthepony.kommons.io.writeBinaryString
import ru.dbotthepony.kstarbound.defs.ChatSendMode
import ru.dbotthepony.kstarbound.network.IServerPacket
import ru.dbotthepony.kstarbound.server.ServerConnection
import java.io.DataInputStream
import java.io.DataOutputStream

class ChatSendPacket(val text: String, val mode: ChatSendMode) : IServerPacket {
	constructor(stream: DataInputStream, isLegacy: Boolean) : this(stream.readBinaryString(), ChatSendMode.entries[stream.readUnsignedByte()])

	override fun write(stream: DataOutputStream, isLegacy: Boolean) {
		stream.writeBinaryString(text)
		stream.writeByte(mode.ordinal)
	}

	override fun play(connection: ServerConnection) {
		connection.server.chat.handle(connection, this)
	}
}
