Skip to content

Commit

Permalink
feat: Use WS for Jerry data
Browse files Browse the repository at this point in the history
  • Loading branch information
My-Name-Is-Jeff committed Feb 4, 2025
1 parent 391785b commit 7e697af
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import gg.skytils.skytilsmod.core.SoundQueue
import gg.skytils.skytilsmod.core.tickTimer
import gg.skytils.skytilsmod.events.impl.GuiContainerEvent
import gg.skytils.skytilsmod.utils.*
import gg.skytils.skytilsws.client.WSClient
import gg.skytils.skytilsws.shared.packet.C2SPacketJerryVote
import io.ktor.client.call.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
Expand Down Expand Up @@ -154,33 +156,15 @@ object MayorInfo {
}
}

fun fetchJerryData() = Skytils.IO.launch {
val res = client.get("https://${Skytils.domain}/api/mayor/jerry").body<JerrySession>()
tickTimer(1) {
newJerryPerks = res.nextSwitch
jerryMayor = res.mayor
}
}
fun fetchJerryData() = {} // no-op

fun sendJerryData(mayor: Mayor?, nextSwitch: Long) = Skytils.IO.launch {
if (mayor == null || nextSwitch <= System.currentTimeMillis()) return@launch
if (!Skytils.trustClientTime) {
println("Client's time isn't trusted, skip sending jerry data.")
return@launch
}
try {
val serverId = UUID.randomUUID().toString().replace("-".toRegex(), "")
val commentForDecompilers =
"This sends a request to Mojang's auth server, used for verification. This is how we verify you are the real user without your session details. This is the exact same system Optifine uses."
mc.sessionService.joinServer(mc.session.profile, mc.session.token, serverId)
val url =
"https://${Skytils.domain}/api/mayor/jerry/perks?username=${mc.session.username}&serverId=${serverId}&nextPerks=${nextSwitch}&mayor=${mayor.name}&currTime=${System.currentTimeMillis()}"
println(client.get(url).bodyAsText())
} catch (e: AuthenticationException) {
e.printStackTrace()
} catch (e: IOException) {
e.printStackTrace()
}
WSClient.sendPacket(C2SPacketJerryVote(mayor.name, nextSwitch, System.currentTimeMillis()))
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/main/kotlin/gg/skytils/skytilsws/client/PacketHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import gg.skytils.skytilsmod.features.impl.dungeons.catlas.core.map.Room
import gg.skytils.skytilsmod.features.impl.dungeons.catlas.core.map.Unknown
import gg.skytils.skytilsmod.features.impl.dungeons.catlas.handlers.DungeonInfo
import gg.skytils.skytilsmod.features.impl.dungeons.catlas.utils.ScanUtils
import gg.skytils.skytilsmod.features.impl.handlers.MayorInfo
import gg.skytils.skytilsmod.features.impl.mining.CHWaypoints
import gg.skytils.skytilsmod.features.impl.mining.CHWaypoints.CHInstance
import gg.skytils.skytilsmod.features.impl.mining.CHWaypoints.chWaypointsList
Expand Down Expand Up @@ -101,6 +102,13 @@ object PacketHandler : IPacketHandler {
instance.waypoints[packet.type] = BlockPos(packet.x, packet.y, packet.z)
}
}
is S2CPacketJerryMayor -> {
MayorInfo.jerryMayor = MayorInfo.mayorData.find { it.name == packet.mayor }
MayorInfo.newJerryPerks = packet.endTime
if (MayorInfo.currentMayor != "Jerry") {
MayorInfo.fetchMayorData()
}
}
else -> {
session.close(CloseReason(CloseReason.Codes.CANNOT_ACCEPT, "Unknown packet type"))
}
Expand Down

0 comments on commit 7e697af

Please sign in to comment.