mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
MessagePacker.MessageHandler refactored for consistency with DOTSNET
This commit is contained in:
parent
3cb928fb30
commit
99b3d95484
@ -102,30 +102,32 @@ internal static NetworkMessageDelegate MessageHandler<T, C>(Action<C, T> handler
|
||||
//
|
||||
// let's catch them all and then disconnect that connection to avoid
|
||||
// further attacks.
|
||||
T message = default;
|
||||
try
|
||||
{
|
||||
if (requireAuthenication && !conn.isAuthenticated)
|
||||
// check authentication
|
||||
// -> either we don't need it
|
||||
// -> or if we need it, connection needs to be authenticated
|
||||
if (!requireAuthenication || conn.isAuthenticated)
|
||||
{
|
||||
// deserialize
|
||||
T message = default;
|
||||
message.Deserialize(reader);
|
||||
|
||||
// call it
|
||||
handler((C)conn, message);
|
||||
}
|
||||
else
|
||||
{
|
||||
// message requires authentication, but the connection was not authenticated
|
||||
Debug.LogWarning($"Closing connection: {conn}. Received message {typeof(T)} that required authentication, but the user has not authenticated yet");
|
||||
conn.Disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
// if it is a value type, just use defult(T)
|
||||
// otherwise allocate a new instance
|
||||
message = default(T);
|
||||
message.Deserialize(reader);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Debug.LogError("Closed connection: " + conn + ". This can happen if the other side accidentally (or an attacker intentionally) sent invalid data. Reason: " + exception);
|
||||
conn.Disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
handler((C)conn, message);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user