コード例 #1
0
 /// <summary>
 /// Validates an internal packet and returns the matching <see cref="PacketRule"/>.
 /// </summary>
 internal bool ValidatePacket(byte id, CryptoAlgorithm alg, out PacketRule rule)
 {
     rule = RegisteredPackets[id];
     if (!rule.Available)
     {
         parent.ExceptionHandler.CloseConnection("InvalidPacket",
                                                 $"Packet id {id} is no valid internal packet for this instance.",
                                                 nameof(PacketHandler), nameof(ValidatePacket));
         return(false);
     }
     if (!rule.VerifyAlgorithm(alg))
     {
         parent.ExceptionHandler.CloseConnection("WrongAlgorithm",
                                                 $"{rule.Packet} with {alg} is not allowed.",
                                                 nameof(PacketHandler), nameof(ValidatePacket));
         return(false);
     }
     return(true);
 }