001/*
002 * Trident - A Multithreaded Server Alternative
003 * Copyright 2014 The TridentSDK Team
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *    http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018package net.tridentsdk.server.netty.packet;
019
020import io.netty.buffer.ByteBuf;
021import net.tridentsdk.server.netty.ClientConnection;
022import net.tridentsdk.util.TridentLogger;
023
024import javax.annotation.concurrent.ThreadSafe;
025
026/**
027 * Used to represent any erroneous inPackets received
028 *
029 * @author The TridentSDK Team
030 */
031@ThreadSafe
032public class UnknownPacket implements Packet {
033    @Override
034    public Packet decode(ByteBuf buf) {
035        return this;
036    }
037
038    /**
039     * {@inheritDoc}
040     *
041     * <p>Cannot be encoded. Throws UnsupportedOperationException</p>
042     */
043    @Override
044    public void encode(ByteBuf buf) {
045        TridentLogger.get().error(new UnsupportedOperationException("Cannot serialize unknown packet"));
046    }
047
048    @Override
049    public int id() {
050        return -1;
051    }
052
053    /**
054     * {@inheritDoc}
055     *
056     * <p>Returns {@code null}, since we don't know where the packet came from</p>
057     */
058    @Override
059    public PacketDirection direction() {
060        return null;
061    }
062
063    /**
064     * {@inheritDoc}
065     *
066     * <p>Does not do anything</p>
067     */
068    @Override
069    public void handleReceived(ClientConnection connection) {
070    }
071}