public static ToffeeClientPacketReadResult Read <T>(ToffeeParticipant receiver, byte[] packet, out T output) where T : new() { // Default the output output = new T(); // Read the packet ToffeeClientPacketReadResult result = Read(receiver, packet); if (result.Success) { // Create a new iterator for the decompressed/decrypted packet data ToffeePacketIterator iterator = new ToffeePacketIterator(receiver, result.Data); output = (T)iterator.Read(typeof(T)); } // Return the read result return(result); }
/// <summary> /// Handles the decryption, decompression and basic decoding of received client packets. /// </summary> /// <param name="packet">The received packet.</param> sealed protected override void HandlePacket(byte[] packet) { // Read the packet ToffeeClientPacketReadResult result = ToffeeClientPacket.Read(this, packet); if (!result.Success) { // This packet was malformed.. // TODO return; } // If we have encryption, set the last timestamp we received if (UseEncryption) { Encryption.LastServerTimestamp = result.Header.Timestamp; } // Handle the packet! HandlePacket(result.Header.OpCode, result.Data); }