mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-19 04:06:43 -04:00
gzipping clipboard text, putting it on a cooldown (1ms / char), increased char limit to 64k
This commit is contained in:
parent
f10ba0ed31
commit
67fd960c54
@ -1,12 +1,14 @@
|
|||||||
package li.cil.oc.client
|
package li.cil.oc.client
|
||||||
|
|
||||||
import li.cil.oc.common.PacketBuilder
|
import li.cil.oc.common.{CompressedPacketBuilder, PacketBuilder, PacketType, component}
|
||||||
import li.cil.oc.common.PacketType
|
|
||||||
import li.cil.oc.common.component
|
|
||||||
import li.cil.oc.common.tileentity._
|
import li.cil.oc.common.tileentity._
|
||||||
import net.minecraftforge.common.ForgeDirection
|
import net.minecraftforge.common.ForgeDirection
|
||||||
|
|
||||||
object PacketSender {
|
object PacketSender {
|
||||||
|
// Timestamp after which the next clipboard message may be sent. Used to
|
||||||
|
// avoid spamming large packets on key repeat.
|
||||||
|
protected var clipboardCooldown = 0L
|
||||||
|
|
||||||
def sendComputerPower(t: Computer, power: Boolean) {
|
def sendComputerPower(t: Computer, power: Boolean) {
|
||||||
val pb = new PacketBuilder(PacketType.ComputerPower)
|
val pb = new PacketBuilder(PacketType.ComputerPower)
|
||||||
|
|
||||||
@ -51,8 +53,9 @@ object PacketSender {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def sendClipboard(b: component.Buffer, value: String) {
|
def sendClipboard(b: component.Buffer, value: String) {
|
||||||
if (value != null && !value.isEmpty) {
|
if (value != null && !value.isEmpty && System.currentTimeMillis() > clipboardCooldown) {
|
||||||
val pb = new PacketBuilder(PacketType.Clipboard)
|
clipboardCooldown = System.currentTimeMillis() + value.length
|
||||||
|
val pb = new CompressedPacketBuilder(PacketType.Clipboard)
|
||||||
|
|
||||||
b.owner match {
|
b.owner match {
|
||||||
case t: Buffer if t.hasKeyboard =>
|
case t: Buffer if t.hasKeyboard =>
|
||||||
@ -62,7 +65,7 @@ object PacketSender {
|
|||||||
pb.writeInt(t.number)
|
pb.writeInt(t.number)
|
||||||
case _ => return
|
case _ => return
|
||||||
}
|
}
|
||||||
pb.writeUTF(value.substring(0, math.min(value.length, 1024)))
|
pb.writeUTF(value.substring(0, math.min(value.length, 64 * 1024)))
|
||||||
|
|
||||||
pb.sendToServer()
|
pb.sendToServer()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user