mirror of
https://gitlab.com/2009scape/2009scape.git
synced 2025-12-09 16:45:44 -07:00
Implemented configurable daily account limit per world, defaults to 3 (daily_accounts_per_ip in worldprops)
This commit is contained in:
parent
4930740b6f
commit
c3250acce1
5 changed files with 52 additions and 13 deletions
|
|
@ -13,6 +13,9 @@ import java.math.BigInteger
|
||||||
class ServerConstants {
|
class ServerConstants {
|
||||||
companion object {
|
companion object {
|
||||||
@JvmField
|
@JvmField
|
||||||
|
var DAILY_ACCOUNT_LIMIT = 3
|
||||||
|
|
||||||
|
@JvmField
|
||||||
var REVENANT_POPULATION: Int = 30
|
var REVENANT_POPULATION: Int = 30
|
||||||
|
|
||||||
@JvmField
|
@JvmField
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import core.game.node.entity.player.Player
|
||||||
import org.json.simple.JSONArray
|
import org.json.simple.JSONArray
|
||||||
import org.json.simple.JSONObject
|
import org.json.simple.JSONObject
|
||||||
import org.json.simple.parser.JSONParser
|
import org.json.simple.parser.JSONParser
|
||||||
|
import rs09.ServerStore.Companion.addToList
|
||||||
import rs09.game.system.SystemLogger
|
import rs09.game.system.SystemLogger
|
||||||
import rs09.game.system.SystemLogger.logShutdown
|
import rs09.game.system.SystemLogger.logShutdown
|
||||||
import rs09.game.system.SystemLogger.logStartup
|
import rs09.game.system.SystemLogger.logStartup
|
||||||
|
|
@ -135,6 +136,18 @@ class ServerStore : PersistWorld {
|
||||||
return jArray
|
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
|
/** NPCItemMemory
|
||||||
* These next methods handle the NPCItemMemory database. these are server-stored JSON objects,
|
* These next methods handle the NPCItemMemory database. these are server-stored JSON objects,
|
||||||
* which are based on an npc and an item.
|
* which are based on an npc and an item.
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,7 @@ object ServerConfigParser {
|
||||||
ServerConstants.I_AM_A_CHEATER = data.getBoolean("world.i_want_to_cheat", false)
|
ServerConstants.I_AM_A_CHEATER = data.getBoolean("world.i_want_to_cheat", false)
|
||||||
ServerConstants.USE_AUTH = data.getBoolean("server.use_auth", true)
|
ServerConstants.USE_AUTH = data.getBoolean("server.use_auth", true)
|
||||||
ServerConstants.PERSIST_ACCOUNTS = data.getBoolean("server.persist_accounts", true)
|
ServerConstants.PERSIST_ACCOUNTS = data.getBoolean("server.persist_accounts", true)
|
||||||
|
ServerConstants.DAILY_ACCOUNT_LIMIT = data.getLong("server.daily_accounts_per_ip", 3L).toInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,9 @@ import proto.management.JoinClanRequest
|
||||||
import proto.management.PlayerStatusUpdate
|
import proto.management.PlayerStatusUpdate
|
||||||
import proto.management.RequestContactInfo
|
import proto.management.RequestContactInfo
|
||||||
import rs09.ServerConstants
|
import rs09.ServerConstants
|
||||||
|
import rs09.ServerStore
|
||||||
|
import rs09.ServerStore.Companion.addToList
|
||||||
|
import rs09.ServerStore.Companion.getList
|
||||||
import rs09.auth.AuthResponse
|
import rs09.auth.AuthResponse
|
||||||
import rs09.game.node.entity.player.info.login.LoginParser
|
import rs09.game.node.entity.player.info.login.LoginParser
|
||||||
import rs09.game.system.SystemLogger
|
import rs09.game.system.SystemLogger
|
||||||
|
|
@ -120,22 +123,39 @@ object Login {
|
||||||
Repository.LOGGED_IN_PLAYERS.add(details.username)
|
Repository.LOGGED_IN_PLAYERS.add(details.username)
|
||||||
details.session = session
|
details.session = session
|
||||||
details.info.translate(UIDInfo(details.ipAddress, "DEPRECATED", "DEPRECATED", "DEPRECATED"))
|
details.info.translate(UIDInfo(details.ipAddress, "DEPRECATED", "DEPRECATED", "DEPRECATED"))
|
||||||
val player = Player(details)
|
|
||||||
if (Repository.getPlayerByName(player.name) == null) {
|
if (checkAccountLimit(details.ipAddress, details.username)) {
|
||||||
Repository.addPlayer(player)
|
val player = Player(details)
|
||||||
}
|
if (Repository.getPlayerByName(player.name) == null) {
|
||||||
session.lastPing = System.currentTimeMillis()
|
Repository.addPlayer(player)
|
||||||
try {
|
}
|
||||||
LoginParser(details, LoginType.fromType(opcode)).initialize(player, opcode == RECONNECT_LOGIN_OP)
|
session.lastPing = System.currentTimeMillis()
|
||||||
sendMSEvents(details)
|
try {
|
||||||
} catch (e: Exception) {
|
LoginParser(details, LoginType.fromType(opcode)).initialize(player, opcode == RECONNECT_LOGIN_OP)
|
||||||
e.printStackTrace()
|
sendMSEvents(details)
|
||||||
session.disconnect()
|
} catch (e: Exception) {
|
||||||
Repository.removePlayer(player)
|
e.printStackTrace()
|
||||||
player.clear(true)
|
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) {
|
private fun sendMSEvents(details: PlayerDetails) {
|
||||||
val statusEvent = PlayerStatusUpdate.newBuilder()
|
val statusEvent = PlayerStatusUpdate.newBuilder()
|
||||||
statusEvent.username = details.username
|
statusEvent.username = details.username
|
||||||
|
|
|
||||||
|
|
@ -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.
|
#NOTE: this does not affect actual save data, like stats, inventory, etc.
|
||||||
persist_accounts = false #NOTE: THIS MUST BE SET TO TRUE IN PRODUCTION!
|
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]
|
||||||
database_name = "global"
|
database_name = "global"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue