diff --git a/Server/data/configs/account_limit_exceptions.conf b/Server/data/configs/account_limit_exceptions.conf new file mode 100644 index 000000000..c412ca256 --- /dev/null +++ b/Server/data/configs/account_limit_exceptions.conf @@ -0,0 +1,2 @@ +[exceptions] +"127.0.0.1" = 5 \ No newline at end of file diff --git a/Server/src/main/core/net/packet/in/Login.kt b/Server/src/main/core/net/packet/in/Login.kt index 0a413f269..15b9d526a 100644 --- a/Server/src/main/core/net/packet/in/Login.kt +++ b/Server/src/main/core/net/packet/in/Login.kt @@ -1,5 +1,6 @@ package core.net.packet.`in` +import com.moandjiezana.toml.Toml import core.cache.crypto.ISAACCipher import core.cache.crypto.ISAACPair import core.cache.misc.buffer.ByteBufferUtils @@ -24,6 +25,7 @@ import core.game.world.GameWorld import core.game.world.repository.Repository import core.tools.Log import core.worker.ManagementEvents.publish +import java.io.File import java.math.BigInteger import java.nio.BufferUnderflowException import java.nio.ByteBuffer @@ -34,6 +36,9 @@ object Login { private const val RECONNECT_LOGIN_OP = 18 const val CACHE_INDEX_COUNT = 29 + private var exceptionData: Toml? = null + private var lastModifiedData = 0L + fun decodeFromBuffer(buffer: ByteBuffer) : Pair { try { val info = LoginInfo.createDefault() @@ -164,11 +169,29 @@ object Login { } private fun checkAccountLimit(ipAddress: String, username: String): Boolean { + var accountLimit = ServerConstants.DAILY_ACCOUNT_LIMIT + + if (File(ServerConstants.CONFIG_PATH + "account_limit_exceptions.conf").exists()) { + try { + val f = File(ServerConstants.CONFIG_PATH + "account_limit_exceptions.conf") + if (f.lastModified() != lastModifiedData) { + exceptionData = Toml().read(f) + lastModifiedData = f.lastModified() + } + + if (exceptionData?.contains("exceptions.\"${ipAddress}\"") == true) { + accountLimit = exceptionData?.getLong("exceptions.\"${ipAddress}\"", 0L)?.toInt() ?: accountLimit + } + } catch (e: Exception) { + e.printStackTrace() + } + } + val archive = ServerStore.getArchive("daily-accounts") val accounts = archive.getList(ipAddress) if (username in accounts) return true - if (accounts.size >= ServerConstants.DAILY_ACCOUNT_LIMIT) + if (accounts.size >= accountLimit) return false archive.addToList(ipAddress, username)