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

@ -170,7 +170,7 @@ namespace CoopClient
catch (Exception ex) catch (Exception ex)
{ {
GTA.UI.Notification.Show(ex.Message); GTA.UI.Notification.Show(ex.Message);
Client.Disconnect(ex.Message); Client.Disconnect($"Packet Type:{packetType} Error:{ex.Message}");
} }
} }
break; break;
@ -189,7 +189,7 @@ namespace CoopClient
catch (Exception ex) catch (Exception ex)
{ {
GTA.UI.Notification.Show(ex.Message); GTA.UI.Notification.Show(ex.Message);
Client.Disconnect(ex.Message); Client.Disconnect($"Packet Type:{packetType} Error:{ex.Message}");
} }
} }
break; break;
@ -208,7 +208,7 @@ namespace CoopClient
catch (Exception ex) catch (Exception ex)
{ {
GTA.UI.Notification.Show(ex.Message); GTA.UI.Notification.Show(ex.Message);
Client.Disconnect(ex.Message); Client.Disconnect($"Packet Type:{packetType} Error:{ex.Message}");
} }
} }
break; break;
@ -227,7 +227,7 @@ namespace CoopClient
catch (Exception ex) catch (Exception ex)
{ {
GTA.UI.Notification.Show(ex.Message); GTA.UI.Notification.Show(ex.Message);
Client.Disconnect(ex.Message); Client.Disconnect($"Packet Type:{packetType} Error:{ex.Message}");
} }
} }
break; break;
@ -246,7 +246,7 @@ namespace CoopClient
catch (Exception ex) catch (Exception ex)
{ {
GTA.UI.Notification.Show(ex.Message); GTA.UI.Notification.Show(ex.Message);
Client.Disconnect(ex.Message); Client.Disconnect($"Packet Type:{packetType} Error:{ex.Message}");
} }
} }
break; break;
@ -265,7 +265,7 @@ namespace CoopClient
catch (Exception ex) catch (Exception ex)
{ {
GTA.UI.Notification.Show(ex.Message); GTA.UI.Notification.Show(ex.Message);
Client.Disconnect(ex.Message); Client.Disconnect($"Packet Type:{packetType} Error:{ex.Message}");
} }
} }
break; break;
@ -284,7 +284,7 @@ namespace CoopClient
catch (Exception ex) catch (Exception ex)
{ {
GTA.UI.Notification.Show(ex.Message); GTA.UI.Notification.Show(ex.Message);
Client.Disconnect(ex.Message); Client.Disconnect($"Packet Type:{packetType} Error:{ex.Message}");
} }
} }
break; break;
@ -309,7 +309,7 @@ namespace CoopClient
catch (Exception ex) catch (Exception ex)
{ {
GTA.UI.Notification.Show(ex.Message); GTA.UI.Notification.Show(ex.Message);
Client.Disconnect(ex.Message); Client.Disconnect($"Packet Type:{packetType} Error:{ex.Message}");
} }
} }
break; break;
@ -328,7 +328,7 @@ namespace CoopClient
catch (Exception ex) catch (Exception ex)
{ {
GTA.UI.Notification.Show(ex.Message); GTA.UI.Notification.Show(ex.Message);
Client.Disconnect(ex.Message); Client.Disconnect($"Packet Type:{packetType} Error:{ex.Message}");
} }
} }
break; break;
@ -347,7 +347,7 @@ namespace CoopClient
catch (Exception ex) catch (Exception ex)
{ {
GTA.UI.Notification.Show(ex.Message); GTA.UI.Notification.Show(ex.Message);
Client.Disconnect(ex.Message); Client.Disconnect($"Packet Type:{packetType} Error:{ex.Message}");
} }
} }
break; break;
@ -369,7 +369,7 @@ namespace CoopClient
catch (Exception ex) catch (Exception ex)
{ {
GTA.UI.Notification.Show(ex.Message); GTA.UI.Notification.Show(ex.Message);
Client.Disconnect(ex.Message); Client.Disconnect($"Packet Type:{packetType} Error:{ex.Message}");
} }
} }
break; break;
@ -388,7 +388,7 @@ namespace CoopClient
catch (Exception ex) catch (Exception ex)
{ {
GTA.UI.Notification.Show(ex.Message); GTA.UI.Notification.Show(ex.Message);
Client.Disconnect(ex.Message); Client.Disconnect($"Packet Type:{packetType} Error:{ex.Message}");
} }
} }
break; break;
@ -407,7 +407,7 @@ namespace CoopClient
catch (Exception ex) catch (Exception ex)
{ {
GTA.UI.Notification.Show(ex.Message); GTA.UI.Notification.Show(ex.Message);
Client.Disconnect(ex.Message); Client.Disconnect($"Packet Type:{packetType} Error:{ex.Message}");
} }
} }
break; break;
@ -417,16 +417,14 @@ namespace CoopClient
{ {
int len = message.ReadInt32(); int len = message.ReadInt32();
byte[] data = message.ReadBytes(len); byte[] data = message.ReadBytes(len);
Packets.Mod packet = new Packets.Mod(); Packets.Mod packet = new Packets.Mod();
packet.NetIncomingMessageToPacket(data); packet.NetIncomingMessageToPacket(data);
COOPAPI.ModPacketReceived(packet.NetHandle, packet.Name, packet.CustomPacketID, packet.Bytes); COOPAPI.ModPacketReceived(packet.NetHandle, packet.Name, packet.CustomPacketID, packet.Bytes);
} }
catch (Exception ex) catch (Exception ex)
{ {
GTA.UI.Notification.Show(ex.Message); GTA.UI.Notification.Show(ex.Message);
Client.Disconnect(ex.Message); Client.Disconnect($"Packet Type:{packetType} Error:{ex.Message}");
} }
} }
break; break;

View File

@ -287,7 +287,7 @@ namespace CoopServer
} }
catch (Exception e) catch (Exception e)
{ {
message.SenderConnection.Disconnect(e.Message); DisconnectAndLog(message.SenderConnection, type, e);
} }
} }
break; break;
@ -305,7 +305,7 @@ namespace CoopServer
} }
catch (Exception e) catch (Exception e)
{ {
message.SenderConnection.Disconnect(e.Message); DisconnectAndLog(message.SenderConnection, type, e);
} }
} }
break; break;
@ -323,7 +323,7 @@ namespace CoopServer
} }
catch (Exception e) catch (Exception e)
{ {
message.SenderConnection.Disconnect(e.Message); DisconnectAndLog(message.SenderConnection, type, e);
} }
} }
break; break;
@ -341,7 +341,7 @@ namespace CoopServer
} }
catch (Exception e) catch (Exception e)
{ {
message.SenderConnection.Disconnect(e.Message); DisconnectAndLog(message.SenderConnection, type, e);
} }
} }
break; break;
@ -359,7 +359,7 @@ namespace CoopServer
} }
catch (Exception e) catch (Exception e)
{ {
message.SenderConnection.Disconnect(e.Message); DisconnectAndLog(message.SenderConnection, type, e);
} }
} }
break; break;
@ -379,7 +379,7 @@ namespace CoopServer
} }
catch (Exception e) catch (Exception e)
{ {
message.SenderConnection.Disconnect(e.Message); DisconnectAndLog(message.SenderConnection, type, e);
} }
} }
else else
@ -404,7 +404,7 @@ namespace CoopServer
} }
catch (Exception e) catch (Exception e)
{ {
message.SenderConnection.Disconnect(e.Message); DisconnectAndLog(message.SenderConnection, type, e);
} }
} }
else else
@ -435,7 +435,7 @@ namespace CoopServer
} }
catch (Exception e) catch (Exception e)
{ {
message.SenderConnection.Disconnect(e.Message); DisconnectAndLog(message.SenderConnection, type, e);
} }
} }
break; break;
@ -487,7 +487,7 @@ namespace CoopServer
} }
catch (Exception e) catch (Exception e)
{ {
message.SenderConnection.Disconnect(e.Message); DisconnectAndLog(message.SenderConnection, type, e);
} }
} }
else 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 -- #region -- PLAYER --
// Before we approve the connection, we must shake hands // Before we approve the connection, we must shake hands
private void GetHandshake(NetConnection local, Packets.Handshake packet) private void GetHandshake(NetConnection local, Packets.Handshake packet)