Skip to content

Commit

Permalink
Potential fix for kicking a player when another one tries to log in w…
Browse files Browse the repository at this point in the history
…ith the same name
  • Loading branch information
Iru21 committed Sep 18, 2022
1 parent 64f8145 commit de0c5c9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
9 changes: 6 additions & 3 deletions src/main/kotlin/me/iru/events/LoginEvents.kt
Expand Up @@ -14,9 +14,12 @@ class LoginEvents : Listener {

@EventHandler
fun onJoin(e : PlayerJoinEvent) {
if(DuplicateProtection.check(e.player)) {
JoinProcess(e.player).run()
}
JoinProcess(e.player).run()
}

@EventHandler
fun onInitialLogin(e : PlayerLoginEvent) {
DuplicateProtection.check(e)
}

@EventHandler
Expand Down
19 changes: 12 additions & 7 deletions src/main/kotlin/me/iru/process/DuplicateProtection.kt
Expand Up @@ -3,16 +3,23 @@ package me.iru.process
import me.iru.Authy
import me.iru.PrefixType
import org.bukkit.entity.Player
import org.bukkit.event.player.PlayerLoginEvent

object DuplicateProtection {

val playerData = Authy.playerData
val config = Authy.instance.config
val translations = Authy.translations
val authy = Authy.instance
val config = authy.config

fun check(e: PlayerLoginEvent) {
val p = e.player
if(authy.server.getPlayer(p.name) != null) {
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, "")
}

fun check(p: Player): Boolean {
val protLevel = config.getInt("duplicateIpProtection.protectionLevel")
if(protLevel == 0) return true
if(protLevel == 0) return
val max = config.getInt("duplicateIpProtection.maxPerIp")
val shouldNotify = config.getBoolean("duplicateIpProtection.notifyOnDuplicateIp")
val duplicates = getDuplicatesForIpOf(p)
Expand All @@ -28,11 +35,9 @@ object DuplicateProtection {
}
}
}
return if(duplicates.size > max && !p.hasPermission("authy.ipbypass")) {
p.kickPlayer(translations.get("duplicateprotection_max_reached").format(max.toString()))
false
if(duplicates.size > max && !p.hasPermission("authy.ipbypass")) {
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, translations.get("duplicateprotection_max_reached").format(max.toString()))
}
else true
}

private fun getDuplicatesForIpOf(p: Player): HashSet<String> {
Expand Down

0 comments on commit de0c5c9

Please sign in to comment.