Dropped packet crypt listeners and related cleanup.
This commit is contained in:
		@@ -21,19 +21,12 @@ import org.l2jmobius.commons.network.ICrypt;
 | 
			
		||||
import io.netty.buffer.ByteBuf;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author UnAfraid, Nos
 | 
			
		||||
 * @author KenM
 | 
			
		||||
 */
 | 
			
		||||
public class Crypt implements ICrypt
 | 
			
		||||
{
 | 
			
		||||
	// private final GameClient _client;
 | 
			
		||||
	private final byte[] _inKey = new byte[16];
 | 
			
		||||
	private final byte[] _outKey = new byte[16];
 | 
			
		||||
	private boolean _isEnabled;
 | 
			
		||||
	
 | 
			
		||||
	public Crypt(GameClient client)
 | 
			
		||||
	{
 | 
			
		||||
		// _client = client;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void setKey(byte[] key)
 | 
			
		||||
	{
 | 
			
		||||
@@ -41,77 +34,49 @@ public class Crypt implements ICrypt
 | 
			
		||||
		System.arraycopy(key, 0, _outKey, 0, 16);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public void encrypt(ByteBuf buf)
 | 
			
		||||
	{
 | 
			
		||||
		if (!_isEnabled)
 | 
			
		||||
		{
 | 
			
		||||
			_isEnabled = true;
 | 
			
		||||
			onPacketSent(buf);
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		onPacketSent(buf);
 | 
			
		||||
		
 | 
			
		||||
		int a = 0;
 | 
			
		||||
		while (buf.isReadable())
 | 
			
		||||
		{
 | 
			
		||||
			final int b = buf.readByte() & 0xFF;
 | 
			
		||||
			a = b ^ _outKey[(buf.readerIndex() - 1) & 15] ^ a;
 | 
			
		||||
			buf.setByte(buf.readerIndex() - 1, a);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		shiftKey(_outKey, buf.writerIndex());
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public void decrypt(ByteBuf buf)
 | 
			
		||||
	{
 | 
			
		||||
		if (!_isEnabled)
 | 
			
		||||
		{
 | 
			
		||||
			onPacketReceive(buf);
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		int a = 0;
 | 
			
		||||
		while (buf.isReadable())
 | 
			
		||||
		{
 | 
			
		||||
			final int b = buf.readByte() & 0xFF;
 | 
			
		||||
			final int b = buf.readByte() & 0xff;
 | 
			
		||||
			buf.setByte(buf.readerIndex() - 1, b ^ _inKey[(buf.readerIndex() - 1) & 15] ^ a);
 | 
			
		||||
			a = b;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		shiftKey(_inKey, buf.writerIndex());
 | 
			
		||||
		
 | 
			
		||||
		onPacketReceive(buf);
 | 
			
		||||
		// Shift key.
 | 
			
		||||
		int old = _inKey[8] & 0xff;
 | 
			
		||||
		old |= (_inKey[9] << 8) & 0xff00;
 | 
			
		||||
		old |= (_inKey[10] << 16) & 0xff0000;
 | 
			
		||||
		old |= (_inKey[11] << 24) & 0xff000000;
 | 
			
		||||
		old += buf.writerIndex();
 | 
			
		||||
		_inKey[8] = (byte) (old & 0xff);
 | 
			
		||||
		_inKey[9] = (byte) ((old >> 8) & 0xff);
 | 
			
		||||
		_inKey[10] = (byte) ((old >> 16) & 0xff);
 | 
			
		||||
		_inKey[11] = (byte) ((old >> 24) & 0xff);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	private void onPacketSent(ByteBuf buf)
 | 
			
		||||
	@Override
 | 
			
		||||
	public void encrypt(ByteBuf buf)
 | 
			
		||||
	{
 | 
			
		||||
		final byte[] data = new byte[buf.writerIndex()];
 | 
			
		||||
		buf.getBytes(0, data);
 | 
			
		||||
		// EventDispatcher.getInstance().notifyEvent(new OnPacketSent(_client, data));
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	private void onPacketReceive(ByteBuf buf)
 | 
			
		||||
	{
 | 
			
		||||
		final byte[] data = new byte[buf.writerIndex()];
 | 
			
		||||
		buf.getBytes(0, data);
 | 
			
		||||
		// EventDispatcher.getInstance().notifyEvent(new OnPacketReceived(_client, data));
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	private void shiftKey(byte[] key, int size)
 | 
			
		||||
	{
 | 
			
		||||
		int old = key[8] & 0xff;
 | 
			
		||||
		old |= (key[9] << 8) & 0xff00;
 | 
			
		||||
		old |= (key[10] << 0x10) & 0xff0000;
 | 
			
		||||
		old |= (key[11] << 0x18) & 0xff000000;
 | 
			
		||||
		int a = 0;
 | 
			
		||||
		while (buf.isReadable())
 | 
			
		||||
		{
 | 
			
		||||
			final int b = buf.readByte() & 0xff;
 | 
			
		||||
			a = b ^ _outKey[(buf.readerIndex() - 1) & 15] ^ a;
 | 
			
		||||
			buf.setByte(buf.readerIndex() - 1, a);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		old += size;
 | 
			
		||||
		
 | 
			
		||||
		key[8] = (byte) (old & 0xff);
 | 
			
		||||
		key[9] = (byte) ((old >> 0x08) & 0xff);
 | 
			
		||||
		key[10] = (byte) ((old >> 0x10) & 0xff);
 | 
			
		||||
		key[11] = (byte) ((old >> 0x18) & 0xff);
 | 
			
		||||
		// Shift key.
 | 
			
		||||
		int old = _outKey[8] & 0xff;
 | 
			
		||||
		old |= (_outKey[9] << 8) & 0xff00;
 | 
			
		||||
		old |= (_outKey[10] << 16) & 0xff0000;
 | 
			
		||||
		old |= (_outKey[11] << 24) & 0xff000000;
 | 
			
		||||
		old += buf.writerIndex();
 | 
			
		||||
		_outKey[8] = (byte) (old & 0xff);
 | 
			
		||||
		_outKey[9] = (byte) ((old >> 8) & 0xff);
 | 
			
		||||
		_outKey[10] = (byte) ((old >> 16) & 0xff);
 | 
			
		||||
		_outKey[11] = (byte) ((old >> 24) & 0xff);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -75,7 +75,7 @@ public class GameClient extends ChannelInboundHandler<GameClient>
 | 
			
		||||
	protected PlayerInstance _player;
 | 
			
		||||
	private final FloodProtectors _floodProtectors = new FloodProtectors(this);
 | 
			
		||||
	private final ReentrantLock _playerLock = new ReentrantLock();
 | 
			
		||||
	private final Crypt _crypt;
 | 
			
		||||
	private final Crypt _crypt = new Crypt();
 | 
			
		||||
	private InetAddress _addr;
 | 
			
		||||
	private Channel _channel;
 | 
			
		||||
	private String _accountName;
 | 
			
		||||
@@ -86,11 +86,6 @@ public class GameClient extends ChannelInboundHandler<GameClient>
 | 
			
		||||
	private int _protocolVersion;
 | 
			
		||||
	private ScheduledFuture<?> _cleanupTask = null;
 | 
			
		||||
	
 | 
			
		||||
	public GameClient()
 | 
			
		||||
	{
 | 
			
		||||
		_crypt = new Crypt(this);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public void channelActive(ChannelHandlerContext ctx)
 | 
			
		||||
	{
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user