mirror of
https://github.com/DaanVandenBosch/phantasmal-world.git
synced 2025-04-08 01:01:36 +08:00
Better disconnection logging in psoserv.
This commit is contained in:
parent
c11b84c950
commit
2a05650ac8
@ -4,6 +4,7 @@ import world.phantasmal.psolib.buffer.Buffer
|
|||||||
import world.phantasmal.psoserv.encryption.Cipher
|
import world.phantasmal.psoserv.encryption.Cipher
|
||||||
import world.phantasmal.psoserv.messages.*
|
import world.phantasmal.psoserv.messages.*
|
||||||
import java.net.Socket
|
import java.net.Socket
|
||||||
|
import java.net.SocketException
|
||||||
|
|
||||||
class ProxyServer(
|
class ProxyServer(
|
||||||
name: String,
|
name: String,
|
||||||
@ -129,5 +130,9 @@ class ProxyServer(
|
|||||||
override fun logMessageReceived(message: Message) {
|
override fun logMessageReceived(message: Message) {
|
||||||
logger.trace { "Sent $message." }
|
logger.trace { "Sent $message." }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun logUnexpectedSocketException(e: SocketException) {
|
||||||
|
// Do nothing, we expect both server and client to close connections.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@ abstract class SocketHandler<MessageType : Message>(
|
|||||||
fun listen() {
|
fun listen() {
|
||||||
logger.info { "Listening to $name ($sockName)." }
|
logger.info { "Listening to $name ($sockName)." }
|
||||||
running = true
|
running = true
|
||||||
|
var clientDisconnected = false
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val readBuffer = Buffer.withCapacity(BUFFER_CAPACITY, Endianness.Little)
|
val readBuffer = Buffer.withCapacity(BUFFER_CAPACITY, Endianness.Little)
|
||||||
@ -49,6 +50,7 @@ abstract class SocketHandler<MessageType : Message>(
|
|||||||
if (readSize == -1) {
|
if (readSize == -1) {
|
||||||
// Close the connection if no more bytes available.
|
// Close the connection if no more bytes available.
|
||||||
logger.debug { "$name ($sockName) end of stream." }
|
logger.debug { "$name ($sockName) end of stream." }
|
||||||
|
clientDisconnected = true
|
||||||
break@readLoop
|
break@readLoop
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,6 +167,7 @@ abstract class SocketHandler<MessageType : Message>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Close the connection.
|
// Close the connection.
|
||||||
|
clientDisconnected = true
|
||||||
break@readLoop
|
break@readLoop
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,9 +201,8 @@ abstract class SocketHandler<MessageType : Message>(
|
|||||||
// Don't log if we're not running anymore because that means this exception was probably
|
// Don't log if we're not running anymore because that means this exception was probably
|
||||||
// generated by a socket.close() call.
|
// generated by a socket.close() call.
|
||||||
if (running) {
|
if (running) {
|
||||||
logger.error(e) {
|
logUnexpectedSocketException(e)
|
||||||
"Error while listening to $name ($sockName), closing connection."
|
clientDisconnected = true
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
logger.error(e) { "Error while listening to $name ($sockName), closing connection." }
|
logger.error(e) { "Error while listening to $name ($sockName), closing connection." }
|
||||||
@ -208,7 +210,7 @@ abstract class SocketHandler<MessageType : Message>(
|
|||||||
running = false
|
running = false
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (socket.isClosed) {
|
if (socket.isClosed || socket.isInputShutdown || clientDisconnected) {
|
||||||
logger.info { "Connection to $name ($sockName) was closed." }
|
logger.info { "Connection to $name ($sockName) was closed." }
|
||||||
} else {
|
} else {
|
||||||
logger.info { "Closing connection to $name ($sockName)." }
|
logger.info { "Closing connection to $name ($sockName)." }
|
||||||
@ -282,6 +284,12 @@ abstract class SocketHandler<MessageType : Message>(
|
|||||||
logger.trace { "Received $message." }
|
logger.trace { "Received $message." }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected open fun logUnexpectedSocketException(e: SocketException) {
|
||||||
|
logger.error(e) {
|
||||||
|
"Error while listening to $name ($sockName), closing connection."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected enum class ProcessResult {
|
protected enum class ProcessResult {
|
||||||
Ok, Changed, Done
|
Ok, Changed, Done
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user