Potential overall stability improvements
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package core.net;
|
package core.net;
|
||||||
|
|
||||||
|
import rs09.game.system.SystemLogger;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.*;
|
import java.nio.channels.*;
|
||||||
@@ -58,8 +60,14 @@ public class IoEventHandler {
|
|||||||
ByteBuffer buffer = ByteBuffer.allocate(100_000);
|
ByteBuffer buffer = ByteBuffer.allocate(100_000);
|
||||||
IoSession session = (IoSession) key.attachment();
|
IoSession session = (IoSession) key.attachment();
|
||||||
if (channel.read(buffer) == -1) {
|
if (channel.read(buffer) == -1) {
|
||||||
//just when a client closes their client, nothing to worry about.
|
if(session != null){
|
||||||
throw new IOException("An existing connection was disconnected!");
|
if(session.getPlayer() != null){
|
||||||
|
SystemLogger.logInfo("Connection closed - disconnecting player.");
|
||||||
|
session.getPlayer().clear();
|
||||||
|
}
|
||||||
|
//key.cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
buffer.flip();
|
buffer.flip();
|
||||||
if (session == null) {
|
if (session == null) {
|
||||||
|
|||||||
@@ -29,8 +29,10 @@ object SystemLogger {
|
|||||||
|
|
||||||
@JvmStatic()
|
@JvmStatic()
|
||||||
fun flushLogs() {
|
fun flushLogs() {
|
||||||
|
try {
|
||||||
tradeLogWriter?.flush()
|
tradeLogWriter?.flush()
|
||||||
tradeLogWriter?.close()
|
tradeLogWriter?.close()
|
||||||
|
} catch(ignored: Exception) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getTime(): String{
|
fun getTime(): String{
|
||||||
@@ -76,10 +78,12 @@ object SystemLogger {
|
|||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun logTrade(message: String){
|
fun logTrade(message: String){
|
||||||
if(message.isNotBlank()){
|
try {
|
||||||
if(tradeLogWriter == null) logWarn("Trade Logger is null!")
|
if (message.isNotBlank()) {
|
||||||
|
if (tradeLogWriter == null) logWarn("Trade Logger is null!")
|
||||||
tradeLogWriter?.write("${getTime()}: $message")
|
tradeLogWriter?.write("${getTime()}: $message")
|
||||||
tradeLogWriter?.newLine()
|
tradeLogWriter?.newLine()
|
||||||
}
|
}
|
||||||
|
} catch(ignored: Exception){}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,7 +23,6 @@ object PacketWriteQueue {
|
|||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun <T> queue(packet: OutgoingPacket<T>, context: T){
|
fun <T> queue(packet: OutgoingPacket<T>, context: T){
|
||||||
SystemLogger.logInfo(packet.javaClass.simpleName)
|
|
||||||
PacketsToWrite.add(QueuedPacket(packet,context))
|
PacketsToWrite.add(QueuedPacket(packet,context))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user