Merge branch 'packet-write-queue' into 'master'
Packet writeouts are now queued excluding dynamic packets See merge request 2009scape/2009scape!109
This commit is contained in:
@@ -5,12 +5,12 @@ package core.net.packet;
|
|||||||
* @author Emperor
|
* @author Emperor
|
||||||
* @param <T> The context type.
|
* @param <T> The context type.
|
||||||
*/
|
*/
|
||||||
public interface OutgoingPacket<T extends Context> {
|
public interface OutgoingPacket<Context> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends the packet.
|
* Sends the packet.
|
||||||
* @param context The context.
|
* @param context The context.
|
||||||
*/
|
*/
|
||||||
public void send(T context);
|
public void send(Context context);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@ import core.net.packet.in.*;
|
|||||||
import core.net.packet.out.GrandExchangePacket;
|
import core.net.packet.out.GrandExchangePacket;
|
||||||
import core.net.packet.out.*;
|
import core.net.packet.out.*;
|
||||||
import rs09.game.system.SystemLogger;
|
import rs09.game.system.SystemLogger;
|
||||||
|
import rs09.net.packet.PacketWriteQueue;
|
||||||
import rs09.net.packet.in.ItemOnGroundItemPacket;
|
import rs09.net.packet.in.ItemOnGroundItemPacket;
|
||||||
import rs09.net.packet.in.QuickChatPacketHandler;
|
import rs09.net.packet.in.QuickChatPacketHandler;
|
||||||
|
|
||||||
@@ -19,7 +20,7 @@ public final class PacketRepository {
|
|||||||
/**
|
/**
|
||||||
* The outgoing packets mapping.
|
* The outgoing packets mapping.
|
||||||
*/
|
*/
|
||||||
private final static Map<Class<?>, OutgoingPacket<? extends Context>> OUTGOING_PACKETS = new HashMap<>();
|
public final static Map<Class<?>, OutgoingPacket<? extends Context>> OUTGOING_PACKETS = new HashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The incoming packets mapping.
|
* The incoming packets mapping.
|
||||||
@@ -189,8 +190,9 @@ public final class PacketRepository {
|
|||||||
SystemLogger.logErr("Invalid outgoing packet [handler=" + clazz + ", context=" + context + "].");
|
SystemLogger.logErr("Invalid outgoing packet [handler=" + clazz + ", context=" + context + "].");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(!context.getPlayer().isArtificial())
|
if(!context.getPlayer().isArtificial()) {
|
||||||
p.send(context);
|
PacketWriteQueue.handle(p, context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -25,12 +25,7 @@ class EquipHandler : InteractionListener() {
|
|||||||
override fun defineListeners() {
|
override fun defineListeners() {
|
||||||
|
|
||||||
on(ITEM,"equip","wield","wear"){player,node ->
|
on(ITEM,"equip","wield","wear"){player,node ->
|
||||||
GameWorld.Pulser.submit(object : Pulse(){
|
|
||||||
override fun pulse(): Boolean {
|
|
||||||
handleEquip(player,node)
|
handleEquip(player,node)
|
||||||
return true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return@on true
|
return@on true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package rs09.net.packet
|
||||||
|
|
||||||
|
import core.net.packet.OutgoingPacket
|
||||||
|
import core.net.packet.out.*
|
||||||
|
import rs09.game.system.SystemLogger
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
object PacketWriteQueue {
|
||||||
|
private val PacketsToWrite: Queue<QueuedPacket<*>> = LinkedList<QueuedPacket<*>>()
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun <T> handle(packet: OutgoingPacket<T>, context: T){
|
||||||
|
when(packet){
|
||||||
|
is UpdateSceneGraph,
|
||||||
|
is BuildDynamicScene,
|
||||||
|
is InstancedLocationUpdate -> packet.send(context)
|
||||||
|
else -> queue(packet,context)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun <T> queue(packet: OutgoingPacket<T>, context: T){
|
||||||
|
PacketsToWrite.add(QueuedPacket(packet,context))
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun flush(){
|
||||||
|
while(!PacketsToWrite.isEmpty()){
|
||||||
|
val p = PacketsToWrite.poll()
|
||||||
|
write(p.out,p.context)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
fun <T> write(out: OutgoingPacket<*>, context: T){
|
||||||
|
val pack = out as? OutgoingPacket<T>
|
||||||
|
val ctx = context as? T
|
||||||
|
if(pack == null || ctx == null){
|
||||||
|
SystemLogger.logWarn("Failed packet casting")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
pack.send(ctx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class QueuedPacket<T>(val out: OutgoingPacket<T>, val context: T)
|
||||||
@@ -13,6 +13,7 @@ import rs09.ServerConstants
|
|||||||
import rs09.game.world.GameWorld
|
import rs09.game.world.GameWorld
|
||||||
import rs09.game.world.repository.Repository
|
import rs09.game.world.repository.Repository
|
||||||
import rs09.game.world.update.UpdateSequence
|
import rs09.game.world.update.UpdateSequence
|
||||||
|
import rs09.net.packet.PacketWriteQueue
|
||||||
import rs09.tools.stringtools.colorize
|
import rs09.tools.stringtools.colorize
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@@ -48,6 +49,7 @@ class MajorUpdateWorker {
|
|||||||
sequence.start()
|
sequence.start()
|
||||||
sequence.run()
|
sequence.run()
|
||||||
sequence.end()
|
sequence.end()
|
||||||
|
PacketWriteQueue.flush()
|
||||||
//increment global ticks variable
|
//increment global ticks variable
|
||||||
GameWorld.pulse()
|
GameWorld.pulse()
|
||||||
//disconnect all players waiting to be disconnected
|
//disconnect all players waiting to be disconnected
|
||||||
|
|||||||
Reference in New Issue
Block a user