diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/server/StarboundServer.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/server/StarboundServer.kt index 27d29ca2..94a34ada 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/server/StarboundServer.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/server/StarboundServer.kt @@ -25,10 +25,14 @@ import ru.dbotthepony.kstarbound.defs.world.WorldTemplate import ru.dbotthepony.kstarbound.fromJson import ru.dbotthepony.kstarbound.json.readJsonElement import ru.dbotthepony.kstarbound.json.readJsonElementInflated +import ru.dbotthepony.kstarbound.json.readJsonElementZstd import ru.dbotthepony.kstarbound.json.readJsonObject +import ru.dbotthepony.kstarbound.json.readJsonObjectZstd import ru.dbotthepony.kstarbound.json.writeJsonElement import ru.dbotthepony.kstarbound.json.writeJsonElementDeflated +import ru.dbotthepony.kstarbound.json.writeJsonElementZstd import ru.dbotthepony.kstarbound.json.writeJsonObject +import ru.dbotthepony.kstarbound.json.writeJsonObjectZstd import ru.dbotthepony.kstarbound.math.vector.Vector2i import ru.dbotthepony.kstarbound.server.world.LegacyWorldStorage import ru.dbotthepony.kstarbound.server.world.NativeLocalWorldStorage @@ -159,7 +163,7 @@ sealed class StarboundServer(val root: File) : BlockableEventLoop("Server thread lookupClientContext.executeQuery().use { if (it.next()) { - it.getBytes(1).readJsonObject() + it.getBytes(1).readJsonObjectZstd() } else { null } @@ -168,9 +172,10 @@ sealed class StarboundServer(val root: File) : BlockableEventLoop("Server thread } fun writeClientContext(uuid: UUID, context: JsonObject): CompletableFuture<*> { + val compressed = context.writeJsonObjectZstd() return supplyAsync { writeClientContext.setString(1, uuid.toStarboundString()) - writeClientContext.setBytes(2, context.writeJsonObject()) + writeClientContext.setBytes(2, compressed) writeClientContext.execute() } } @@ -241,7 +246,7 @@ sealed class StarboundServer(val root: File) : BlockableEventLoop("Server thread lookupSystemWorld.executeQuery().use { if (it.next()) { - it.getBytes(1).readJsonElementInflated() + it.getBytes(1).readJsonElementZstd() } else { null } @@ -250,11 +255,13 @@ sealed class StarboundServer(val root: File) : BlockableEventLoop("Server thread } fun writeServerWorldData(pos: Vector3i, data: JsonElement) { + val compressed = data.writeJsonElementZstd() + execute { writeSystemWorld.setInt(1, pos.x) writeSystemWorld.setInt(2, pos.y) writeSystemWorld.setInt(3, pos.z) - writeSystemWorld.setBytes(4, data.writeJsonElementDeflated()) + writeSystemWorld.setBytes(4, compressed) writeSystemWorld.execute() }