forked from 2009Scape/Server
Increased server stability
Fixed NPE in IoEventHandler Fixed NPEs in PacketWriteQueue Reworked PacketWriteQueue slightly so that instead of breaking at first null packet we continue past it and pop the whole queue along the way
This commit is contained in:
parent
ee5bc78b62
commit
95414bc02b
2 changed files with 20 additions and 17 deletions
|
|
@ -72,7 +72,8 @@ public class IoEventHandler {
|
|||
} catch (IOException e) {
|
||||
if (e.getMessage().contains("reset by peer")) {
|
||||
session.disconnect();
|
||||
session.getPlayer().clear(true);
|
||||
if (session.getPlayer() != null)
|
||||
session.getPlayer().clear(true);
|
||||
} else e.printStackTrace();
|
||||
}
|
||||
buffer.flip();
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import core.net.packet.out.*
|
|||
import rs09.game.system.SystemLogger
|
||||
import java.util.*
|
||||
import java.util.concurrent.locks.ReentrantLock
|
||||
import kotlin.NoSuchElementException
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
class PacketWriteQueue : TickListener {
|
||||
|
|
@ -15,8 +16,8 @@ class PacketWriteQueue : TickListener {
|
|||
|
||||
companion object {
|
||||
private val queueLock = ReentrantLock()
|
||||
private val packetsToQueue = ArrayList<QueuedPacket<*>>(1000)
|
||||
private val packetsToWrite = LinkedList<QueuedPacket<*>>()
|
||||
private val packetsToQueue = ArrayList<QueuedPacket<*>?>(1000)
|
||||
private val packetsToWrite = LinkedList<QueuedPacket<*>?>()
|
||||
|
||||
@JvmStatic
|
||||
fun <T> handle(packet: OutgoingPacket<T>, context: T) {
|
||||
|
|
@ -39,25 +40,24 @@ class PacketWriteQueue : TickListener {
|
|||
packetsToWrite.add(QueuedPacket(packet, context))
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun pop(): QueuedPacket<*>? {
|
||||
return try {
|
||||
packetsToWrite.pop()
|
||||
} catch (e: NoSuchElementException) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun flush() {
|
||||
queueLock.lock()
|
||||
var packet: QueuedPacket<*>?
|
||||
while (pop().also { packet = it } != null)
|
||||
write(packet?.out ?: break, packet?.context ?: break)
|
||||
|
||||
var hasEnded = false
|
||||
while (!hasEnded) {
|
||||
try {
|
||||
val packet = packetsToWrite.pop()
|
||||
write(packet?.out ?: continue, packet.context ?: continue)
|
||||
} catch (e: NoSuchElementException) {
|
||||
hasEnded = true
|
||||
}
|
||||
}
|
||||
|
||||
if (packetsToWrite.isNotEmpty()) {
|
||||
SystemLogger.logWarn("Packet queue was NOT empty! Remaining packets: ${packetsToWrite.size}")
|
||||
try {
|
||||
for (pkt in packetsToWrite) SystemLogger.logWarn("${pkt.out.javaClass.simpleName} <- ${pkt.context}")
|
||||
for (pkt: QueuedPacket<*>? in packetsToWrite) SystemLogger.logWarn("${pkt?.out?.javaClass?.simpleName ?: "NULL"} <- ${pkt?.context ?: "NULL"}")
|
||||
} catch (e: Exception)
|
||||
{
|
||||
e.printStackTrace()
|
||||
|
|
@ -65,12 +65,14 @@ class PacketWriteQueue : TickListener {
|
|||
packetsToWrite.clear()
|
||||
}
|
||||
}
|
||||
|
||||
queueLock.unlock()
|
||||
|
||||
val queueIter = packetsToQueue.iterator()
|
||||
while (queueIter.hasNext()) {
|
||||
packetsToWrite.add(queueIter.next())
|
||||
queueIter.remove()
|
||||
}
|
||||
queueLock.unlock()
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue