Adds logging to disconnection to help debugging

When the user is disconnected from a malformed or wrong message
it is now logged in the server for debugging purposes.
If the disconnection comes from the client itself, the reason
of disconnection will contain the offending message type.
This commit is contained in:
Makinolo
2022-02-06 09:59:18 -07:00
parent 9373cb3c85
commit 32ea3a0037
2 changed files with 31 additions and 25 deletions

View File

@ -287,7 +287,7 @@ namespace CoopServer
}
catch (Exception e)
{
message.SenderConnection.Disconnect(e.Message);
DisconnectAndLog(message.SenderConnection, type, e);
}
}
break;
@ -305,7 +305,7 @@ namespace CoopServer
}
catch (Exception e)
{
message.SenderConnection.Disconnect(e.Message);
DisconnectAndLog(message.SenderConnection, type, e);
}
}
break;
@ -323,7 +323,7 @@ namespace CoopServer
}
catch (Exception e)
{
message.SenderConnection.Disconnect(e.Message);
DisconnectAndLog(message.SenderConnection, type, e);
}
}
break;
@ -341,7 +341,7 @@ namespace CoopServer
}
catch (Exception e)
{
message.SenderConnection.Disconnect(e.Message);
DisconnectAndLog(message.SenderConnection, type, e);
}
}
break;
@ -359,7 +359,7 @@ namespace CoopServer
}
catch (Exception e)
{
message.SenderConnection.Disconnect(e.Message);
DisconnectAndLog(message.SenderConnection, type, e);
}
}
break;
@ -379,7 +379,7 @@ namespace CoopServer
}
catch (Exception e)
{
message.SenderConnection.Disconnect(e.Message);
DisconnectAndLog(message.SenderConnection, type, e);
}
}
else
@ -404,7 +404,7 @@ namespace CoopServer
}
catch (Exception e)
{
message.SenderConnection.Disconnect(e.Message);
DisconnectAndLog(message.SenderConnection, type, e);
}
}
else
@ -435,7 +435,7 @@ namespace CoopServer
}
catch (Exception e)
{
message.SenderConnection.Disconnect(e.Message);
DisconnectAndLog(message.SenderConnection, type, e);
}
}
break;
@ -487,7 +487,7 @@ namespace CoopServer
}
catch (Exception e)
{
message.SenderConnection.Disconnect(e.Message);
DisconnectAndLog(message.SenderConnection, type, e);
}
}
else
@ -552,6 +552,14 @@ namespace CoopServer
}
}
private void DisconnectAndLog(NetConnection senderConnection, byte type, Exception e)
{
Logging.Error($"Error receiving a packet of type {type}");
Logging.Error(e.Message);
Logging.Error(e.StackTrace);
senderConnection.Disconnect(e.Message);
}
#region -- PLAYER --
// Before we approve the connection, we must shake hands
private void GetHandshake(NetConnection local, Packets.Handshake packet)