Skip to content

Commit

Permalink
Fix double accept mods screen + disallow mixing mods
Browse files Browse the repository at this point in the history
Signed-off-by: Seppe Volkaerts <[email protected]>
  • Loading branch information
Cybermaxke committed Oct 19, 2024
1 parent 34f0566 commit af766a5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 26 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
kotlin("jvm") version "2.0.20"
kotlin("plugin.serialization") version "2.0.0"
kotlin("plugin.serialization") version "2.0.20"
id("org.cadixdev.licenser") version "0.6.1"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import org.lanternpowered.terre.impl.event.TerreEventBus
import org.lanternpowered.terre.impl.network.Connection
import org.lanternpowered.terre.impl.network.ConnectionHandler
import org.lanternpowered.terre.impl.network.Packet
import org.lanternpowered.terre.impl.network.Protocol274
import org.lanternpowered.terre.impl.network.ProtocolRegistry
import org.lanternpowered.terre.impl.network.ProtocolTModLoader
import org.lanternpowered.terre.impl.network.ProtocolVersions
Expand All @@ -35,10 +34,7 @@ import org.lanternpowered.terre.impl.network.packet.PasswordResponsePacket
import org.lanternpowered.terre.impl.network.packet.PlayerInfoPacket
import org.lanternpowered.terre.impl.network.packet.WorldInfoRequestPacket
import org.lanternpowered.terre.impl.network.packet.init.InitDisconnectClientPacket
import org.lanternpowered.terre.impl.network.packet.tmodloader.SyncModsDonePacket
import org.lanternpowered.terre.impl.network.packet.tmodloader.SyncModsPacket
import org.lanternpowered.terre.impl.player.PlayerImpl
import org.lanternpowered.terre.text.localizedTextOf
import org.lanternpowered.terre.text.text
import org.lanternpowered.terre.text.textOf
import java.util.UUID
Expand All @@ -53,7 +49,6 @@ internal class ClientInitConnectionHandler(

private enum class State {
Init,
SyncMods,
Handshake,
RequestClientInfo,
DetectClientPlayerLimit,
Expand Down Expand Up @@ -150,23 +145,13 @@ internal class ClientInitConnectionHandler(
if (result is ClientConnectEvent.Result.Denied) {
connection.close(result.reason)
} else {
startLogin()
checkState(State.Handshake)
approveConnection()
}
}, connection.eventLoop)
return true
}

private fun startLogin() {
checkState(State.Handshake)
if (connection.protocolVersion is ProtocolVersion.TModLoader) {
state = State.SyncMods
connection.send(SyncModsPacket(listOf()))
debug { "P -> C [${connection.remoteAddress}] Sync mods" }
} else {
approveConnection()
}
}

private fun approveConnection() {
state = State.RequestClientInfo
// Send the approved packet, we just do this with a fixed id for now to receive information
Expand Down Expand Up @@ -209,13 +194,6 @@ internal class ClientInitConnectionHandler(
}, connection.eventLoop)
}

override fun handle(packet: SyncModsDonePacket): Boolean {
debug { "P <- C [${connection.remoteAddress}] Finished syncing mods" }
checkState(State.SyncMods)
approveConnection()
return true
}

override fun handle(packet: PasswordResponsePacket): Boolean {
debug { "P <- C [${connection.remoteAddress},$name] Password response" }
checkState(State.RequestPassword)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ internal class PlayerImpl(
}
}

private fun disconnectAndForget(reason: Text) {
fun disconnectAndForget(reason: Text) {
clientConnection.close(reason)
serverConnection?.connection?.close()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ internal class ServerConnectionImpl(
}
syncMods = mods.isNotEmpty() || previousMods.isNotEmpty()
}
if (previousServer != null && syncMods) {
// TODO: Is currently not supported because the tModLoader screen to accept new mods
// isn't showing up after you're already in the world
Terre.logger.error("It is currently not supported to mix mods on the backing servers.")
player.disconnectAndForget(textOf("Mixing mods on backing servers is currently not supported."))
return
}
}
if (syncMods) {
if (modsPacket == null) {
Expand Down

0 comments on commit af766a5

Please sign in to comment.