Skip to content

Commit

Permalink
Fix unban
Browse files Browse the repository at this point in the history
  • Loading branch information
Kieaer committed Apr 8, 2024
1 parent 39ebfa0 commit 34dda17
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
19 changes: 6 additions & 13 deletions src/main/kotlin/essentials/Commands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -904,28 +904,21 @@ class Commands(var handler: CommandHandler, isClient: Boolean) {
val name = data.name
val ip = netServer.admins.getInfo(data.uuid).lastIP

if (!netServer.admins.unbanPlayerID(arg[0])) {
if (!netServer.admins.unbanPlayerIP(arg[0])) {
if (!netServer.admins.unbanPlayerID(data.uuid)) {
if (!netServer.admins.unbanPlayerIP(ip)) {
err("player.not.found")
} else {
send("command.unban.ip", arg[0])
send("command.unban.ip", ip)
}
} else {
send("command.unban.id", arg[0])
send("command.unban.id", data.uuid)
}

val json = JsonArray.readHjson(Fi(Config.banList).readString()).asArray()
json.forEachIndexed { index, jsonValue ->
if (jsonValue.asObject().get("ip").asArray().contains(JsonValue.valueOf(ip))) {
json.remove(index)
}
json.removeAll {
it.asObject().get("ip").asArray().contains(JsonValue.valueOf(ip)) || it.asObject().get("id").asString() == data.uuid
}

json.forEachIndexed { index, jsonValue ->
if (jsonValue.asObject().get("id").asString() == data.uuid) {
json.remove(index)
}
}
Fi(Config.banList).writeString(json.toString(Stringify.HJSON))

Event.log(Event.LogType.Player, Bundle()["log.player.banned", name, ip])
Expand Down
11 changes: 5 additions & 6 deletions src/main/kotlin/essentials/Event.kt
Original file line number Diff line number Diff line change
Expand Up @@ -691,21 +691,20 @@ object Event {
}

Events.on(PlayerUnbanEvent::class.java) {
val ip = if (it.player != null) it.player.ip() else netServer.admins.getInfo(it.uuid).lastIP

if (Config.blockIP) {
val os = System.getProperty("os.name").lowercase(Locale.getDefault())
if (os.contains("nix") || os.contains("nux") || os.contains("aix")) {
val ip = if (it.player != null) it.player.ip() else netServer.admins.getInfo(it.uuid).lastIP
Runtime.getRuntime().exec(arrayOf("/bin/bash", "-c", "echo ${PluginData.sudoPassword} | sudo -S iptables -D INPUT -s $ip -j DROP"))
}
}

val json = JsonArray.readHjson(Fi(Config.banList).readString()).asArray()
json.forEachIndexed { index, jsonValue ->
if (jsonValue.asObject().get("id").asString() == it.uuid) {
json.remove(index)
return@forEachIndexed
}
json.removeAll { js ->
js.asObject().get("ip").asArray().contains(JsonValue.valueOf(ip)) || js.asObject().get("id").asString() == it.uuid
}

Fi(Config.banList).writeString(json.toString(Stringify.HJSON))

Events.fire(PlayerUnbanned(netServer.admins.getInfo(it.uuid).lastName, currentTime()))
Expand Down

0 comments on commit 34dda17

Please sign in to comment.