Skip to content

Commit 6cc2405

Browse files
0.4.11: update ktor, flush when writability is false, cleanup
1 parent 4a3f410 commit 6cc2405

File tree

13 files changed

+42
-40
lines changed

13 files changed

+42
-40
lines changed

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ compileKotlin.kotlinOptions.jvmTarget = "11"
3737
val gitVersion: groovy.lang.Closure<String> by extra
3838

3939
group = "com.github.creeper123123321.viaaas"
40-
version = "0.4.10+" + try {
40+
version = "0.4.11+" + try {
4141
gitVersion()
4242
} catch (e: Exception) {
4343
"unknown"
@@ -86,7 +86,7 @@ dependencies {
8686
implementation("org.jline:jline-terminal-jansi:3.20.0")
8787
implementation("org.slf4j:slf4j-api:$slf4jVer")
8888

89-
val ktorVersion = "1.6.1"
89+
val ktorVersion = "1.6.2"
9090
implementation("io.ktor:ktor-network-tls-certificates:$ktorVersion")
9191
implementation("io.ktor:ktor-websockets:$ktorVersion")
9292
implementation("io.ktor:ktor-server-netty:$ktorVersion")

src/main/kotlin/com/viaversion/aas/AspirinServer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ object AspirinServer {
3838
.getResourceAsStream("viaaas_info.json")!!
3939
.reader(Charsets.UTF_8)
4040
.readText()
41-
).asJsonObject.get("version").asString
41+
).asJsonObject["version"].asString
4242
val cleanedVer get() = version.substringBefore("+")
4343
var viaWebServer = WebDashboardServer()
4444
private var serverFinishing = CompletableFuture<Unit>()
@@ -135,7 +135,7 @@ object AspirinServer {
135135
return try {
136136
val latestData =
137137
httpClient.get<JsonObject>("https://api.github.com/repos/viaversion/viaaas/releases/latest")
138-
val latest = Version(latestData.get("tag_name")!!.asString.removePrefix("v"))
138+
val latest = Version(latestData["tag_name"]!!.asString.removePrefix("v"))
139139
val current = Version(cleanedVer)
140140
when {
141141
latest > current -> "This build is outdated. Latest is $latest"

src/main/kotlin/com/viaversion/aas/handler/ConnectionData.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class ConnectionData(
1212
var frontVer: Int? = null,
1313
var backServerVer: Int? = null,
1414
) {
15-
val frontHandler get() = frontChannel.pipeline().get(MinecraftHandler::class.java)
15+
val frontHandler get() = frontChannel.pipeline()[MinecraftHandler::class.java]
1616
val backHandler get() = backChannel?.pipeline()?.get(MinecraftHandler::class.java)
17-
val frontEncrypted get() = frontChannel.pipeline().get(CryptoCodec::class.java) != null
17+
val frontEncrypted get() = frontChannel.pipeline()[CryptoCodec::class.java] != null
1818
}

src/main/kotlin/com/viaversion/aas/handler/MinecraftHandler.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class MinecraftHandler(
3030
}
3131

3232
override fun channelActive(ctx: ChannelHandlerContext) {
33-
endRemoteAddress = (ctx.channel().pipeline().get("proxy") as? ProxyHandler)?.destinationAddress()
33+
endRemoteAddress = (ctx.pipeline()["proxy"] as? ProxyHandler)?.destinationAddress()
3434
?: ctx.channel().remoteAddress()
3535
}
3636

@@ -46,12 +46,15 @@ class MinecraftHandler(
4646
}
4747

4848
override fun channelWritabilityChanged(ctx: ChannelHandlerContext) {
49+
if (!ctx.channel().isWritable) {
50+
ctx.executor().execute(ctx.channel()::flush) // Flush to write more
51+
}
4952
other?.setAutoRead(ctx.channel().isWritable)
5053
}
5154

5255
private fun failedProxy(ctx: ChannelHandlerContext): Boolean {
5356
// proxy connect future fails are handled in another part
54-
return (ctx.channel().pipeline().get("proxy") as? ProxyHandler)?.connectFuture()?.isSuccess == false
57+
return (ctx.pipeline()["proxy"] as? ProxyHandler)?.connectFuture()?.isSuccess == false
5558
}
5659

5760
override fun exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable) {

src/main/kotlin/com/viaversion/aas/handler/autoprotocol/ProtocolDetectionState.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ class ProtocolDetectionState(val future: CompletableFuture<ProtocolVersion>) : C
2121
handler.data.frontChannel.close()
2222
if (packet !is StatusResponse) throw StacklessException("Unexpected packet")
2323
val ver = JsonParser.parseString(packet.msg).asJsonObject
24-
.getAsJsonObject("version")
25-
.get("protocol").asInt.parseProtocol()
24+
.getAsJsonObject("version")["protocol"].asInt.parseProtocol()
2625
future.complete(ver)
2726
mcLogger.info("A.D.: ${handler.endRemoteAddress} $ver")
2827
}

src/main/kotlin/com/viaversion/aas/handler/state/HandshakeState.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class HandshakeState : ConnectionState {
4040

4141
private fun checkRateLimit(handler: MinecraftHandler, state: State) {
4242
val socketAddress = (handler.endRemoteAddress as InetSocketAddress).address
43-
val limit = RateLimit.rateLimitByIp.get(socketAddress)
43+
val limit = RateLimit.rateLimitByIp[socketAddress]
4444

4545
if (!limit.handshakeLimiter.tryAcquire()
4646
|| (state == State.LOGIN && !limit.loginLimiter.tryAcquire())

src/main/kotlin/com/viaversion/aas/handler/state/LoginState.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ class LoginState : ConnectionState {
7373
private fun handleCompression(handler: MinecraftHandler, setCompression: SetCompression) {
7474
val pipe = handler.data.frontChannel.pipeline()
7575
val threshold = setCompression.threshold
76-
val backPipe = pipe.get(MinecraftHandler::class.java).other!!.pipeline()
76+
val backPipe = pipe[MinecraftHandler::class.java].other!!.pipeline()
7777

78-
if (backPipe.get("compress") != null) {
78+
if (backPipe["compress"] != null) {
7979
backPipe.remove("compress")
8080
}
8181
if (threshold != -1) {
@@ -84,7 +84,7 @@ class LoginState : ConnectionState {
8484

8585
forward(handler, setCompression)
8686

87-
if (pipe.get("compress") != null) {
87+
if (pipe["compress"] != null) {
8888
pipe.remove("compress")
8989
}
9090
if (threshold != -1) {
@@ -189,7 +189,7 @@ class LoginState : ConnectionState {
189189
handler.coroutineScope.launch(Dispatchers.IO) {
190190
try {
191191
val profile = hasJoined(frontName, frontHash)
192-
val id = profile.get("id")!!.asString
192+
val id = profile["id"]!!.asString
193193

194194
callbackPlayerId.complete(parseUndashedId(id))
195195
} catch (e: Exception) {

src/main/kotlin/com/viaversion/aas/handler/state/Util.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private suspend fun createBackChannel(
4545
.connect(socketAddr)
4646
.also { it.suspendAwait() }
4747
.channel()
48-
(channel.pipeline().get("proxy") as? ProxyHandler)?.connectFuture()?.suspendAwait()
48+
(channel.pipeline()["proxy"] as? ProxyHandler)?.connectFuture()?.suspendAwait()
4949

5050
mcLogger.info("+ ${state.name.substring(0, 1)} ${handler.endRemoteAddress} -> $socketAddr")
5151
handler.data.backChannel = channel as SocketChannel

src/main/kotlin/com/viaversion/aas/protocol/id47toid5/packets/EntityPackets.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper
1010
import com.viaversion.viaversion.api.protocol.remapper.TypeRemapper
1111
import com.viaversion.viaversion.api.type.Type
1212
import com.viaversion.viaversion.api.type.types.version.Types1_8
13+
import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8
1314
import com.viaversion.viaversion.protocols.protocol1_8.ServerboundPackets1_8
1415
import de.gerrygames.viarewind.protocol.protocol1_7_6_10to1_8.ClientboundPackets1_7
1516
import de.gerrygames.viarewind.protocol.protocol1_7_6_10to1_8.types.Types1_7_6_10
@@ -31,7 +32,7 @@ fun Protocol1_8To1_7_6.registerEntityPackets() {
3132
val animation = packetWrapper.read(Type.UNSIGNED_BYTE) //Animation
3233
packetWrapper.clearInputBuffer()
3334
if (animation.toInt() == 104 || animation.toInt() == 105) {
34-
packetWrapper.id = 0x1C //Entity Metadata
35+
packetWrapper.packetType = ClientboundPackets1_8.ENTITY_METADATA
3536
packetWrapper.write(Type.VAR_INT, entityId) //Entity Id
3637
packetWrapper.write(Type.UNSIGNED_BYTE, 0.toShort()) //Index
3738
packetWrapper.write(Type.UNSIGNED_BYTE, 0.toShort()) //Type

src/main/kotlin/com/viaversion/aas/protocol/id47toid5/packets/PlayerPackets.kt

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@ import com.viaversion.aas.protocol.id47toid5.storage.Scoreboard
99
import com.viaversion.aas.protocol.id47toid5.storage.Tablist
1010
import com.viaversion.aas.protocol.xyzToPosition
1111
import com.viaversion.aas.protocol.xyzUBytePos
12-
import com.viaversion.viaversion.api.Via
1312
import com.viaversion.viaversion.api.minecraft.entities.Entity1_10Types
1413
import com.viaversion.viaversion.api.minecraft.item.Item
1514
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper
16-
import com.viaversion.viaversion.api.protocol.packet.State
1715
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper
1816
import com.viaversion.viaversion.api.protocol.remapper.TypeRemapper
1917
import com.viaversion.viaversion.api.type.Type
2018
import com.viaversion.viaversion.api.type.types.CustomByteType
2119
import com.viaversion.viaversion.api.type.types.version.Types1_8
2220
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag
2321
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag
22+
import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8
2423
import com.viaversion.viaversion.protocols.protocol1_8.ServerboundPackets1_8
2524
import com.viaversion.viaversion.util.ChatColorUtil
2625
import de.gerrygames.viarewind.protocol.protocol1_7_6_10to1_8.ClientboundPackets1_7
@@ -127,14 +126,15 @@ fun Protocol1_8To1_7_6.registerPlayerPackets() {
127126
val entryByUUID = tablist.getTabListEntry(uuid)
128127
if (entryByName == null || entryByUUID == null) {
129128
if (entryByName != null || entryByUUID != null) {
130-
val remove = PacketWrapper.create(0x38, null, packetWrapper.user())
129+
val remove = PacketWrapper.create(ClientboundPackets1_8.PLAYER_INFO, null, packetWrapper.user())
131130
remove.write(Type.VAR_INT, 4)
132131
remove.write(Type.VAR_INT, 1)
133132
remove.write(Type.UUID, entryByName?.uuid ?: entryByUUID!!.uuid)
134133
tablist.remove(entryByName ?: entryByUUID!!)
135134
remove.send(Protocol1_8To1_7_6::class.java)
136135
}
137-
val packetPlayerListItem = PacketWrapper.create(0x38, null, packetWrapper.user())
136+
val packetPlayerListItem =
137+
PacketWrapper.create(ClientboundPackets1_8.PLAYER_INFO, null, packetWrapper.user())
138138
val newentry = Tablist.TabListEntry(name, uuid)
139139
if (entryByName != null || entryByUUID != null) {
140140
newentry.displayName =
@@ -160,8 +160,10 @@ fun Protocol1_8To1_7_6.registerPlayerPackets() {
160160
packetPlayerListItem.write(Type.STRING, newentry.displayName)
161161
}
162162
packetPlayerListItem.send(Protocol1_8To1_7_6::class.java)
163+
163164
packetWrapper.cancel()
164-
val delayedPacket = PacketWrapper.create(0x0C, null, packetWrapper.user())
165+
val delayedPacket =
166+
PacketWrapper.create(ClientboundPackets1_8.SPAWN_PLAYER, null, packetWrapper.user())
165167
delayedPacket.write(Type.VAR_INT, entityId)
166168
delayedPacket.write(Type.UUID, uuid)
167169
delayedPacket.write(Type.INT, x)
@@ -171,13 +173,8 @@ fun Protocol1_8To1_7_6.registerPlayerPackets() {
171173
delayedPacket.write(Type.BYTE, pitch)
172174
delayedPacket.write(Type.SHORT, item)
173175
delayedPacket.write(Types1_8.METADATA_LIST, metadata)
174-
Via.getPlatform().runSync({
175-
try {
176-
delayedPacket.send(Protocol1_8To1_7_6::class.java)
177-
} catch (ex: Exception) {
178-
ex.printStackTrace()
179-
}
180-
}, 1L)
176+
177+
delayedPacket.send(Protocol1_8To1_7_6::class.java)
181178
} else {
182179
entryByUUID.properties = properties
183180
}
@@ -403,10 +400,11 @@ fun Protocol1_8To1_7_6.registerPlayerPackets() {
403400
packetWrapper.write(Type.ITEM, book)
404401
}
405402
packetWrapper.cancel()
406-
packetWrapper.id = -1
403+
packetWrapper.packetType = null
407404
val newPacketBuf = Unpooled.buffer()
408405
packetWrapper.writeToBuffer(newPacketBuf)
409-
val newWrapper = PacketWrapper.create(0x17, newPacketBuf, packetWrapper.user())
406+
val newWrapper =
407+
PacketWrapper.create(ServerboundPackets1_8.PLUGIN_MESSAGE, newPacketBuf, packetWrapper.user())
410408
newWrapper.passthrough(Type.STRING)
411409
newWrapper.write(Type.SHORT, newPacketBuf.readableBytes().toShort())
412410
newWrapper.sendToServer(Protocol1_8To1_7_6::class.java)

0 commit comments

Comments
 (0)