diff options
author | My-Name-Is-Jeff <37018278+My-Name-Is-Jeff@users.noreply.github.com> | 2022-05-22 17:24:07 -0400 |
---|---|---|
committer | My-Name-Is-Jeff <37018278+My-Name-Is-Jeff@users.noreply.github.com> | 2022-05-22 17:24:07 -0400 |
commit | 295242581162cc74ade1a25819d0f305fec474f3 (patch) | |
tree | a137497094b0a9eba9aff0acd6dfd8b1c97406e9 | |
parent | dc620e6d8dab707a3f07e17f1f71d76a61c343fc (diff) | |
download | SkytilsMod-295242581162cc74ade1a25819d0f305fec474f3.tar.gz SkytilsMod-295242581162cc74ade1a25819d0f305fec474f3.tar.bz2 SkytilsMod-295242581162cc74ade1a25819d0f305fec474f3.zip |
add scam checking capability
4 files changed, 119 insertions, 2 deletions
diff --git a/src/main/kotlin/gg/skytils/skytilsmod/Skytils.kt b/src/main/kotlin/gg/skytils/skytilsmod/Skytils.kt index 1b4fc270..d26464cb 100644 --- a/src/main/kotlin/gg/skytils/skytilsmod/Skytils.kt +++ b/src/main/kotlin/gg/skytils/skytilsmod/Skytils.kt @@ -301,6 +301,7 @@ class Skytils { RainTimer(), RandomStuff, RelicWaypoints, + ScamCheck, ScoreCalculation, SelectAllColorSolver, ShootTheTargetSolver, @@ -348,8 +349,9 @@ class Skytils { cch.registerCommand(CataCommand) cch.registerCommand(CalcXPCommand) - cch.registerCommand(LimboCommand) cch.registerCommand(HollowWaypointCommand) + cch.registerCommand(LimboCommand) + cch.registerCommand(ScamCheckCommand) cch.registerCommand(SlayerCommand) if (!cch.commands.containsKey("armorcolor")) { diff --git a/src/main/kotlin/gg/skytils/skytilsmod/commands/impl/ScamCheckCommand.kt b/src/main/kotlin/gg/skytils/skytilsmod/commands/impl/ScamCheckCommand.kt new file mode 100644 index 00000000..0b1e17ff --- /dev/null +++ b/src/main/kotlin/gg/skytils/skytilsmod/commands/impl/ScamCheckCommand.kt @@ -0,0 +1,29 @@ +/* + * Skytils - Hypixel Skyblock Quality of Life Mod + * Copyright (C) 2022 Skytils + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package gg.skytils.skytilsmod.commands.impl + +import gg.skytils.skytilsmod.commands.stats.StatCommand +import gg.skytils.skytilsmod.features.impl.misc.ScamCheck +import java.util.* + +object ScamCheckCommand : StatCommand("skytilsscamcheck", needApiKey = false, needProfile = false, listOf("stsc")) { + override suspend fun displayStats(username: String, uuid: UUID) { + val check = ScamCheck.checkScammer(uuid).printResult(username) + } +} diff --git a/src/main/kotlin/gg/skytils/skytilsmod/features/impl/misc/Funny.kt b/src/main/kotlin/gg/skytils/skytilsmod/features/impl/misc/Funny.kt index 67c2de2a..20fbf162 100644 --- a/src/main/kotlin/gg/skytils/skytilsmod/features/impl/misc/Funny.kt +++ b/src/main/kotlin/gg/skytils/skytilsmod/features/impl/misc/Funny.kt @@ -36,7 +36,7 @@ object Funny { fun onWorldRender(event: RenderWorldLastEvent) { if (SuperSecretSettings.bennettArthur) { if (++ticks >= 360) ticks = 0 - alphaMult = MathHelper.sin(ticks * 0.0174533f) + alphaMult = MathHelper.sin(ticks * 0.0174533f).coerceAtLeast(0f) } else { ticks = 0 alphaMult = 1f diff --git a/src/main/kotlin/gg/skytils/skytilsmod/features/impl/misc/ScamCheck.kt b/src/main/kotlin/gg/skytils/skytilsmod/features/impl/misc/ScamCheck.kt new file mode 100644 index 00000000..33922a43 --- /dev/null +++ b/src/main/kotlin/gg/skytils/skytilsmod/features/impl/misc/ScamCheck.kt @@ -0,0 +1,86 @@ +/* + * Skytils - Hypixel Skyblock Quality of Life Mod + * Copyright (C) 2022 Skytils + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package gg.skytils.skytilsmod.features.impl.misc + +import gg.essential.universal.UChat +import gg.essential.universal.wrappers.message.UMessage +import gg.skytils.skytilsmod.Skytils +import gg.skytils.skytilsmod.Skytils.Companion.client +import gg.skytils.skytilsmod.Skytils.Companion.mc +import gg.skytils.skytilsmod.events.impl.MainReceivePacketEvent +import gg.skytils.skytilsmod.utils.Utils +import io.ktor.client.call.* +import io.ktor.client.request.* +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext +import kotlinx.serialization.Serializable +import net.minecraft.network.play.server.S2DPacketOpenWindow +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.util.* + +object ScamCheck { + private val tradingRegex = Regex("You {18}(?<otherParty>\\w{1,16})") + + @SubscribeEvent + fun onPacket(event: MainReceivePacketEvent<*, *>) { + if (Utils.inSkyblock && event.packet is S2DPacketOpenWindow) { + val otherParty = + tradingRegex.matchEntire(event.packet.windowTitle.unformattedText)?.groups?.get("otherParty")?.value + ?: return + val uuid = runCatching { + mc.theWorld?.playerEntities?.find { + it.uniqueID.version() == 4 && it.name == otherParty + }?.uniqueID ?: Skytils.hylinAPI.getUUIDSync(otherParty) + }.getOrNull() + ?: return UChat.chat("${Skytils.failPrefix} §cUnable to get the UUID for ${otherParty}! Could they be nicked?") + Skytils.IO.launch { + val result = checkScammer(uuid) + if (result.isScammer) mc.thePlayer?.closeScreen() + result.printResult(otherParty) + }.invokeOnCompletion { + if (it != null) UChat.chat("${Skytils.failPrefix} §cSomething went wrong while checking the scammer status for ${otherParty}!") + } + } + } + + + suspend fun checkScammer(uuid: UUID) = withContext(Skytils.IO.coroutineContext) { + client.get("https://${Skytils.domain}/api/scams/check?uuid=$uuid").body<ScamCheckResponse>() + } +} + +@Serializable +data class ScamCheckResponse( + val isScammer: Boolean, + val reasons: Map<String, String>, + val isAlt: Boolean +) { + fun printResult(username: String) { + if (!isScammer) { + UChat.chat("${Skytils.prefix} §a$username is not a known scammer!") + } else { + UMessage("${Skytils.prefix} §c$username is a known scammer!\n", + "§bDatabases:\n", + reasons.entries.joinToString("\n") { (db, reason) -> + "§b${db}: ${reason}" + } + ).chat() + } + } +}
\ No newline at end of file |