Dropped packet crypt listeners and related cleanup.
This commit is contained in:
@@ -25,15 +25,8 @@ import io.netty.buffer.ByteBuf;
|
||||
*/
|
||||
public class Crypt implements ICrypt
|
||||
{
|
||||
// private final GameClient _client;
|
||||
private final byte[] _inKey = new byte[8];
|
||||
private final byte[] _outKey = new byte[8];
|
||||
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, 8);
|
||||
}
|
||||
|
||||
@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) & 7] ^ 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) & 7] ^ a);
|
||||
a = b;
|
||||
}
|
||||
|
||||
shiftKey(_inKey, buf.writerIndex());
|
||||
|
||||
onPacketReceive(buf);
|
||||
// Shift key.
|
||||
int old = _inKey[0] & 0xff;
|
||||
old |= (_inKey[1] << 8) & 0xff00;
|
||||
old |= (_inKey[2] << 16) & 0xff0000;
|
||||
old |= (_inKey[3] << 24) & 0xff000000;
|
||||
old += buf.writerIndex();
|
||||
_inKey[0] = (byte) (old & 0xff);
|
||||
_inKey[1] = (byte) ((old >> 8) & 0xff);
|
||||
_inKey[2] = (byte) ((old >> 16) & 0xff);
|
||||
_inKey[3] = (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[0] & 0xff;
|
||||
old |= (key[1] << 8) & 0xff00;
|
||||
old |= (key[2] << 0x10) & 0xff0000;
|
||||
old |= (key[3] << 0x18) & 0xff000000;
|
||||
int a = 0;
|
||||
while (buf.isReadable())
|
||||
{
|
||||
final int b = buf.readByte() & 0xff;
|
||||
a = b ^ _outKey[(buf.readerIndex() - 1) & 7] ^ a;
|
||||
buf.setByte(buf.readerIndex() - 1, a);
|
||||
}
|
||||
|
||||
old += size;
|
||||
|
||||
key[0] = (byte) (old & 0xff);
|
||||
key[1] = (byte) ((old >> 0x08) & 0xff);
|
||||
key[2] = (byte) ((old >> 0x10) & 0xff);
|
||||
key[3] = (byte) ((old >> 0x18) & 0xff);
|
||||
// Shift key.
|
||||
int old = _outKey[0] & 0xff;
|
||||
old |= (_outKey[1] << 8) & 0xff00;
|
||||
old |= (_outKey[2] << 16) & 0xff0000;
|
||||
old |= (_outKey[3] << 24) & 0xff000000;
|
||||
old += buf.writerIndex();
|
||||
_outKey[0] = (byte) (old & 0xff);
|
||||
_outKey[1] = (byte) ((old >> 8) & 0xff);
|
||||
_outKey[2] = (byte) ((old >> 16) & 0xff);
|
||||
_outKey[3] = (byte) ((old >> 24) & 0xff);
|
||||
}
|
||||
}
|
||||
|
@@ -87,7 +87,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;
|
||||
@@ -98,11 +98,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