Fixed many issues with login
Reconnecting to an existing session can no longer cause an account wipe Player saves can no longer be saved unless they've already been parsed Sessions now have their most recent ping properly set Sessions can now recover from a hypothetical scenario where the session's player reference becomes null but the player is still in-game Players now disconnected properly if no packets have been received from the client in the last 20 seconds
This commit is contained in:
@@ -25,6 +25,9 @@ import java.util.function.Consumer
|
||||
* Parses the login of a player.
|
||||
*/
|
||||
class LoginParser(val details: PlayerDetails, private val type: LoginType) {
|
||||
companion object {
|
||||
var monkeywrench = true
|
||||
}
|
||||
/**
|
||||
* The player in the game, used for reconnect login type.
|
||||
*/
|
||||
@@ -39,10 +42,6 @@ class LoginParser(val details: PlayerDetails, private val type: LoginType) {
|
||||
*/
|
||||
fun initialize(player: Player, reconnect: Boolean) {
|
||||
if(!validateRequest()) return
|
||||
if (reconnect) {
|
||||
reconnect(player)
|
||||
return
|
||||
}
|
||||
lateinit var parser: PlayerSaveParser
|
||||
try {
|
||||
parser = PlayerParser.parse(player)
|
||||
@@ -65,8 +64,12 @@ class LoginParser(val details: PlayerDetails, private val type: LoginType) {
|
||||
loginListeners.forEach(Consumer { listener: LoginListener -> listener.login(player) }) //Run our login hooks
|
||||
parser.runContentHooks() //Run our saved-content-parsing hooks
|
||||
player.details.session.setObject(player)
|
||||
flag(AuthResponse.Success)
|
||||
player.init()
|
||||
if (reconnect) {
|
||||
reconnect(player)
|
||||
} else {
|
||||
flag(AuthResponse.Success)
|
||||
player.init()
|
||||
}
|
||||
player.monitor.log(player.details.ipAddress, PlayerMonitor.ADDRESS_LOG)
|
||||
player.monitor.log(player.details.serial, PlayerMonitor.ADDRESS_LOG)
|
||||
player.monitor.log(player.details.macAddress, PlayerMonitor.ADDRESS_LOG)
|
||||
|
||||
@@ -86,6 +86,7 @@ class PlayerSaveParser(val player: Player) {
|
||||
{
|
||||
if(read)
|
||||
contentHooks.forEach{it.parsePlayer(player, saveFile!!)}
|
||||
player.details.saveParsed = true
|
||||
}
|
||||
|
||||
fun parseVarps(){
|
||||
|
||||
@@ -61,6 +61,7 @@ class PlayerSaver (val player: Player){
|
||||
return saveFile
|
||||
}
|
||||
fun save() = runBlocking {
|
||||
if (!player.details.saveParsed) return@runBlocking
|
||||
val manager = ScriptEngineManager()
|
||||
val scriptEngine = manager.getEngineByName("JavaScript")
|
||||
scriptEngine.put("jsonString", populate().toJSONString())
|
||||
|
||||
@@ -7,6 +7,7 @@ import core.game.world.map.Location
|
||||
import core.game.world.map.RegionManager
|
||||
import core.game.world.repository.NodeList
|
||||
import rs09.ServerConstants
|
||||
import rs09.game.world.update.UpdateSequence
|
||||
import java.util.*
|
||||
import java.util.concurrent.CopyOnWriteArrayList
|
||||
|
||||
@@ -146,6 +147,7 @@ object Repository {
|
||||
players.remove(player)
|
||||
uid_map.remove(player.details.usernameHashcode)
|
||||
playerNames.remove(player.name)
|
||||
UpdateSequence.renderablePlayers.remove(player)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,6 +33,7 @@ class LoginReadEvent(session: IoSession?, buffer: ByteBuffer?) : IoReadEvent(ses
|
||||
details.communication.parse(accountInfo)
|
||||
session.clientInfo = ClientInfo(info.displayMode, info.windowMode, info.screenWidth, info.screenHeight)
|
||||
session.isaacPair = info.isaacPair
|
||||
session.associatedUsername = info.username
|
||||
Login.proceedWith(session, details, info.opcode)
|
||||
}
|
||||
}
|
||||
@@ -121,11 +121,19 @@ object Login {
|
||||
details.session = session
|
||||
details.info.translate(UIDInfo(details.ipAddress, "DEPRECATED", "DEPRECATED", "DEPRECATED"))
|
||||
val player = Player(details)
|
||||
if (!Repository.players.contains(player)) {
|
||||
if (Repository.getPlayerByName(player.name) == null) {
|
||||
Repository.addPlayer(player)
|
||||
}
|
||||
LoginParser(details, LoginType.fromType(opcode)).initialize(player, opcode == RECONNECT_LOGIN_OP)
|
||||
sendMSEvents(details)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
private fun sendMSEvents(details: PlayerDetails) {
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
package rs09.worker
|
||||
|
||||
import api.submitWorldPulse
|
||||
import core.game.system.SystemManager
|
||||
import core.game.system.SystemState
|
||||
import core.game.system.task.Pulse
|
||||
import core.plugin.CorePluginTypes.Managers
|
||||
import gui.GuiEvent
|
||||
import gui.ServerMonitor
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import rs09.Server
|
||||
import rs09.ServerConstants
|
||||
import rs09.ServerStore
|
||||
@@ -18,13 +11,10 @@ import rs09.game.system.SystemLogger
|
||||
import rs09.game.world.GameWorld
|
||||
import rs09.game.world.repository.Repository
|
||||
import rs09.game.world.update.UpdateSequence
|
||||
import rs09.net.packet.PacketWriteQueue
|
||||
import rs09.tools.stringtools.colorize
|
||||
import java.lang.Long.max
|
||||
import java.lang.Long.min
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
/**
|
||||
@@ -46,6 +36,15 @@ class MajorUpdateWorker {
|
||||
|
||||
handleTickActions()
|
||||
|
||||
for (player in Repository.players.filter {!it.isArtificial}) {
|
||||
if (System.currentTimeMillis() - player.session.lastPing > 20000L) {
|
||||
player?.details?.session?.disconnect()
|
||||
player?.session?.lastPing = Long.MAX_VALUE
|
||||
player?.clear(true)
|
||||
Repository.removePlayer(player)
|
||||
}
|
||||
}
|
||||
|
||||
//Handle daily restart if enabled
|
||||
if(sdf.format(Date()).toInt() == 0){
|
||||
|
||||
|
||||
Reference in New Issue
Block a user