Implemented configurable daily account limit per world, defaults to 3 (daily_accounts_per_ip in worldprops)

This commit is contained in:
Ceikry 2022-08-21 05:18:03 +00:00 committed by Ryan
parent 4930740b6f
commit c3250acce1
5 changed files with 52 additions and 13 deletions

View file

@ -13,6 +13,9 @@ import java.math.BigInteger
class ServerConstants {
companion object {
@JvmField
var DAILY_ACCOUNT_LIMIT = 3
@JvmField
var REVENANT_POPULATION: Int = 30
@JvmField

View file

@ -9,6 +9,7 @@ import core.game.node.entity.player.Player
import org.json.simple.JSONArray
import org.json.simple.JSONObject
import org.json.simple.parser.JSONParser
import rs09.ServerStore.Companion.addToList
import rs09.game.system.SystemLogger
import rs09.game.system.SystemLogger.logShutdown
import rs09.game.system.SystemLogger.logStartup
@ -135,6 +136,18 @@ class ServerStore : PersistWorld {
return jArray
}
inline fun <reified T> JSONObject.getList(key: String) : List<T> {
val array = this[key] as? JSONArray ?: JSONArray()
val list = ArrayList<T>()
for(element in array) list.add(element as T)
return list
}
fun JSONObject.addToList(key: String, value: Any) {
val array = this.getOrPut(key) {JSONArray()} as JSONArray
array.add(value)
}
/** NPCItemMemory
* These next methods handle the NPCItemMemory database. these are server-stored JSON objects,
* which are based on an npc and an item.

View file

@ -123,6 +123,7 @@ object ServerConfigParser {
ServerConstants.I_AM_A_CHEATER = data.getBoolean("world.i_want_to_cheat", false)
ServerConstants.USE_AUTH = data.getBoolean("server.use_auth", true)
ServerConstants.PERSIST_ACCOUNTS = data.getBoolean("server.persist_accounts", true)
ServerConstants.DAILY_ACCOUNT_LIMIT = data.getLong("server.daily_accounts_per_ip", 3L).toInt()
}

View file

@ -14,6 +14,9 @@ import proto.management.JoinClanRequest
import proto.management.PlayerStatusUpdate
import proto.management.RequestContactInfo
import rs09.ServerConstants
import rs09.ServerStore
import rs09.ServerStore.Companion.addToList
import rs09.ServerStore.Companion.getList
import rs09.auth.AuthResponse
import rs09.game.node.entity.player.info.login.LoginParser
import rs09.game.system.SystemLogger
@ -120,22 +123,39 @@ object Login {
Repository.LOGGED_IN_PLAYERS.add(details.username)
details.session = session
details.info.translate(UIDInfo(details.ipAddress, "DEPRECATED", "DEPRECATED", "DEPRECATED"))
val player = Player(details)
if (Repository.getPlayerByName(player.name) == null) {
Repository.addPlayer(player)
}
session.lastPing = System.currentTimeMillis()
try {
LoginParser(details, LoginType.fromType(opcode)).initialize(player, opcode == RECONNECT_LOGIN_OP)
sendMSEvents(details)
} catch (e: Exception) {
e.printStackTrace()
session.disconnect()
Repository.removePlayer(player)
player.clear(true)
if (checkAccountLimit(details.ipAddress, details.username)) {
val player = Player(details)
if (Repository.getPlayerByName(player.name) == null) {
Repository.addPlayer(player)
}
session.lastPing = System.currentTimeMillis()
try {
LoginParser(details, LoginType.fromType(opcode)).initialize(player, opcode == RECONNECT_LOGIN_OP)
sendMSEvents(details)
} catch (e: Exception) {
e.printStackTrace()
session.disconnect()
Repository.removePlayer(player)
player.clear(true)
}
} else {
session.write(AuthResponse.LoginLimitExceeded)
}
}
private fun checkAccountLimit(ipAddress: String, username: String): Boolean {
val archive = ServerStore.getArchive("daily-accounts")
val accounts = archive.getList<String>(ipAddress)
if (username in accounts) return true
if (accounts.size >= ServerConstants.DAILY_ACCOUNT_LIMIT)
return false
archive.addToList(ipAddress, username)
return true
}
private fun sendMSEvents(details: PlayerDetails) {
val statusEvent = PlayerStatusUpdate.newBuilder()
statusEvent.username = details.username

View file

@ -13,6 +13,8 @@ use_auth = false #NOTE: THIS MUST BE SET TO TRUE IN PRODUCTION!
#NOTE: this does not affect actual save data, like stats, inventory, etc.
persist_accounts = false #NOTE: THIS MUST BE SET TO TRUE IN PRODUCTION!
#------------------------------------------------------------------------------------------------------
#The limit on how many different accounts a player can log into per day.
daily_accounts_per_ip = 3
[database]
database_name = "global"