Dropped packet crypt listeners and related cleanup.
This commit is contained in:
parent
c52d596d79
commit
47786d53d4
@ -125,8 +125,6 @@ import org.l2jmobius.gameserver.model.events.impl.item.OnItemBypassEvent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemCreate;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemTalk;
|
||||
import org.l2jmobius.gameserver.model.events.impl.olympiad.OnOlympiadMatchResult;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeFinish;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeOwnerChange;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeStart;
|
||||
@ -282,9 +280,6 @@ public enum EventType
|
||||
|
||||
ON_DAY_NIGHT_CHANGE(OnDayNightChange.class, void.class),
|
||||
|
||||
ON_PACKET_RECEIVED(OnPacketReceived.class, void.class),
|
||||
ON_PACKET_SENT(OnPacketSent.class, void.class),
|
||||
|
||||
// Instance events
|
||||
ON_INSTANCE_CREATED(OnInstanceCreated.class, void.class),
|
||||
ON_INSTANCE_DESTROY(OnInstanceDestroy.class, void.class),
|
||||
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketReceived implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketReceived(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_RECEIVED;
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketSent implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketSent(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_SENT;
|
||||
}
|
||||
}
|
@ -17,26 +17,16 @@
|
||||
package org.l2jmobius.gameserver.network;
|
||||
|
||||
import org.l2jmobius.commons.network.ICrypt;
|
||||
import org.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
|
||||
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)
|
||||
{
|
||||
@ -44,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)
|
||||
int a = 0;
|
||||
while (buf.isReadable())
|
||||
{
|
||||
final byte[] data = new byte[buf.writerIndex()];
|
||||
buf.getBytes(0, data);
|
||||
EventDispatcher.getInstance().notifyEvent(new OnPacketReceived(_client, data));
|
||||
final int b = buf.readByte() & 0xff;
|
||||
a = b ^ _outKey[(buf.readerIndex() - 1) & 15] ^ a;
|
||||
buf.setByte(buf.readerIndex() - 1, a);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ public class GameClient extends ChannelInboundHandler<GameClient>
|
||||
|
||||
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 int[][] _trace;
|
||||
|
||||
public GameClient()
|
||||
{
|
||||
_crypt = new Crypt(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx)
|
||||
{
|
||||
|
@ -125,8 +125,6 @@ import org.l2jmobius.gameserver.model.events.impl.item.OnItemBypassEvent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemCreate;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemTalk;
|
||||
import org.l2jmobius.gameserver.model.events.impl.olympiad.OnOlympiadMatchResult;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeFinish;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeOwnerChange;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeStart;
|
||||
@ -282,9 +280,6 @@ public enum EventType
|
||||
|
||||
ON_DAY_NIGHT_CHANGE(OnDayNightChange.class, void.class),
|
||||
|
||||
ON_PACKET_RECEIVED(OnPacketReceived.class, void.class),
|
||||
ON_PACKET_SENT(OnPacketSent.class, void.class),
|
||||
|
||||
// Instance events
|
||||
ON_INSTANCE_CREATED(OnInstanceCreated.class, void.class),
|
||||
ON_INSTANCE_DESTROY(OnInstanceDestroy.class, void.class),
|
||||
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketReceived implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketReceived(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_RECEIVED;
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketSent implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketSent(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_SENT;
|
||||
}
|
||||
}
|
@ -17,26 +17,16 @@
|
||||
package org.l2jmobius.gameserver.network;
|
||||
|
||||
import org.l2jmobius.commons.network.ICrypt;
|
||||
import org.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
|
||||
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)
|
||||
{
|
||||
@ -44,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)
|
||||
int a = 0;
|
||||
while (buf.isReadable())
|
||||
{
|
||||
final byte[] data = new byte[buf.writerIndex()];
|
||||
buf.getBytes(0, data);
|
||||
EventDispatcher.getInstance().notifyEvent(new OnPacketReceived(_client, data));
|
||||
final int b = buf.readByte() & 0xff;
|
||||
a = b ^ _outKey[(buf.readerIndex() - 1) & 15] ^ a;
|
||||
buf.setByte(buf.readerIndex() - 1, a);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ public class GameClient extends ChannelInboundHandler<GameClient>
|
||||
|
||||
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 int[][] _trace;
|
||||
|
||||
public GameClient()
|
||||
{
|
||||
_crypt = new Crypt(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx)
|
||||
{
|
||||
|
@ -125,8 +125,6 @@ import org.l2jmobius.gameserver.model.events.impl.item.OnItemBypassEvent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemCreate;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemTalk;
|
||||
import org.l2jmobius.gameserver.model.events.impl.olympiad.OnOlympiadMatchResult;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeFinish;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeOwnerChange;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeStart;
|
||||
@ -282,9 +280,6 @@ public enum EventType
|
||||
|
||||
ON_DAY_NIGHT_CHANGE(OnDayNightChange.class, void.class),
|
||||
|
||||
ON_PACKET_RECEIVED(OnPacketReceived.class, void.class),
|
||||
ON_PACKET_SENT(OnPacketSent.class, void.class),
|
||||
|
||||
// Instance events
|
||||
ON_INSTANCE_CREATED(OnInstanceCreated.class, void.class),
|
||||
ON_INSTANCE_DESTROY(OnInstanceDestroy.class, void.class),
|
||||
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketReceived implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketReceived(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_RECEIVED;
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketSent implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketSent(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_SENT;
|
||||
}
|
||||
}
|
@ -17,26 +17,16 @@
|
||||
package org.l2jmobius.gameserver.network;
|
||||
|
||||
import org.l2jmobius.commons.network.ICrypt;
|
||||
import org.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
|
||||
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)
|
||||
{
|
||||
@ -44,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)
|
||||
int a = 0;
|
||||
while (buf.isReadable())
|
||||
{
|
||||
final byte[] data = new byte[buf.writerIndex()];
|
||||
buf.getBytes(0, data);
|
||||
EventDispatcher.getInstance().notifyEvent(new OnPacketReceived(_client, data));
|
||||
final int b = buf.readByte() & 0xff;
|
||||
a = b ^ _outKey[(buf.readerIndex() - 1) & 15] ^ a;
|
||||
buf.setByte(buf.readerIndex() - 1, a);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ public class GameClient extends ChannelInboundHandler<GameClient>
|
||||
|
||||
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 int[][] _trace;
|
||||
|
||||
public GameClient()
|
||||
{
|
||||
_crypt = new Crypt(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx)
|
||||
{
|
||||
|
@ -125,8 +125,6 @@ import org.l2jmobius.gameserver.model.events.impl.item.OnItemBypassEvent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemCreate;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemTalk;
|
||||
import org.l2jmobius.gameserver.model.events.impl.olympiad.OnOlympiadMatchResult;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeFinish;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeOwnerChange;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeStart;
|
||||
@ -282,9 +280,6 @@ public enum EventType
|
||||
|
||||
ON_DAY_NIGHT_CHANGE(OnDayNightChange.class, void.class),
|
||||
|
||||
ON_PACKET_RECEIVED(OnPacketReceived.class, void.class),
|
||||
ON_PACKET_SENT(OnPacketSent.class, void.class),
|
||||
|
||||
// Instance events
|
||||
ON_INSTANCE_CREATED(OnInstanceCreated.class, void.class),
|
||||
ON_INSTANCE_DESTROY(OnInstanceDestroy.class, void.class),
|
||||
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketReceived implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketReceived(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_RECEIVED;
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketSent implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketSent(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_SENT;
|
||||
}
|
||||
}
|
@ -17,26 +17,16 @@
|
||||
package org.l2jmobius.gameserver.network;
|
||||
|
||||
import org.l2jmobius.commons.network.ICrypt;
|
||||
import org.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
|
||||
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)
|
||||
{
|
||||
@ -44,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)
|
||||
int a = 0;
|
||||
while (buf.isReadable())
|
||||
{
|
||||
final byte[] data = new byte[buf.writerIndex()];
|
||||
buf.getBytes(0, data);
|
||||
EventDispatcher.getInstance().notifyEvent(new OnPacketReceived(_client, data));
|
||||
final int b = buf.readByte() & 0xff;
|
||||
a = b ^ _outKey[(buf.readerIndex() - 1) & 15] ^ a;
|
||||
buf.setByte(buf.readerIndex() - 1, a);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ public class GameClient extends ChannelInboundHandler<GameClient>
|
||||
|
||||
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 int[][] _trace;
|
||||
|
||||
public GameClient()
|
||||
{
|
||||
_crypt = new Crypt(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx)
|
||||
{
|
||||
|
@ -128,8 +128,6 @@ import org.l2jmobius.gameserver.model.events.impl.item.OnItemEnchantAdd;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemSoulCrystalAdd;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemTalk;
|
||||
import org.l2jmobius.gameserver.model.events.impl.olympiad.OnOlympiadMatchResult;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeFinish;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeOwnerChange;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeStart;
|
||||
@ -288,9 +286,6 @@ public enum EventType
|
||||
|
||||
ON_DAY_NIGHT_CHANGE(OnDayNightChange.class, void.class),
|
||||
|
||||
ON_PACKET_RECEIVED(OnPacketReceived.class, void.class),
|
||||
ON_PACKET_SENT(OnPacketSent.class, void.class),
|
||||
|
||||
// Instance events
|
||||
ON_INSTANCE_CREATED(OnInstanceCreated.class, void.class),
|
||||
ON_INSTANCE_DESTROY(OnInstanceDestroy.class, void.class),
|
||||
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketReceived implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketReceived(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_RECEIVED;
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketSent implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketSent(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_SENT;
|
||||
}
|
||||
}
|
@ -17,26 +17,16 @@
|
||||
package org.l2jmobius.gameserver.network;
|
||||
|
||||
import org.l2jmobius.commons.network.ICrypt;
|
||||
import org.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
|
||||
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)
|
||||
{
|
||||
@ -44,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)
|
||||
int a = 0;
|
||||
while (buf.isReadable())
|
||||
{
|
||||
final byte[] data = new byte[buf.writerIndex()];
|
||||
buf.getBytes(0, data);
|
||||
EventDispatcher.getInstance().notifyEvent(new OnPacketReceived(_client, data));
|
||||
final int b = buf.readByte() & 0xff;
|
||||
a = b ^ _outKey[(buf.readerIndex() - 1) & 15] ^ a;
|
||||
buf.setByte(buf.readerIndex() - 1, a);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ public class GameClient extends ChannelInboundHandler<GameClient>
|
||||
|
||||
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 int[][] _trace;
|
||||
|
||||
public GameClient()
|
||||
{
|
||||
_crypt = new Crypt(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx)
|
||||
{
|
||||
|
@ -128,8 +128,6 @@ import org.l2jmobius.gameserver.model.events.impl.item.OnItemEnchantAdd;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemSoulCrystalAdd;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemTalk;
|
||||
import org.l2jmobius.gameserver.model.events.impl.olympiad.OnOlympiadMatchResult;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeFinish;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeOwnerChange;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeStart;
|
||||
@ -288,9 +286,6 @@ public enum EventType
|
||||
|
||||
ON_DAY_NIGHT_CHANGE(OnDayNightChange.class, void.class),
|
||||
|
||||
ON_PACKET_RECEIVED(OnPacketReceived.class, void.class),
|
||||
ON_PACKET_SENT(OnPacketSent.class, void.class),
|
||||
|
||||
// Instance events
|
||||
ON_INSTANCE_CREATED(OnInstanceCreated.class, void.class),
|
||||
ON_INSTANCE_DESTROY(OnInstanceDestroy.class, void.class),
|
||||
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketReceived implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketReceived(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_RECEIVED;
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketSent implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketSent(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_SENT;
|
||||
}
|
||||
}
|
@ -17,26 +17,16 @@
|
||||
package org.l2jmobius.gameserver.network;
|
||||
|
||||
import org.l2jmobius.commons.network.ICrypt;
|
||||
import org.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
|
||||
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)
|
||||
{
|
||||
@ -44,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)
|
||||
int a = 0;
|
||||
while (buf.isReadable())
|
||||
{
|
||||
final byte[] data = new byte[buf.writerIndex()];
|
||||
buf.getBytes(0, data);
|
||||
EventDispatcher.getInstance().notifyEvent(new OnPacketReceived(_client, data));
|
||||
final int b = buf.readByte() & 0xff;
|
||||
a = b ^ _outKey[(buf.readerIndex() - 1) & 15] ^ a;
|
||||
buf.setByte(buf.readerIndex() - 1, a);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ public class GameClient extends ChannelInboundHandler<GameClient>
|
||||
|
||||
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 int[][] _trace;
|
||||
|
||||
public GameClient()
|
||||
{
|
||||
_crypt = new Crypt(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx)
|
||||
{
|
||||
|
@ -128,8 +128,6 @@ import org.l2jmobius.gameserver.model.events.impl.item.OnItemEnchantAdd;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemSoulCrystalAdd;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemTalk;
|
||||
import org.l2jmobius.gameserver.model.events.impl.olympiad.OnOlympiadMatchResult;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeFinish;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeOwnerChange;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeStart;
|
||||
@ -288,9 +286,6 @@ public enum EventType
|
||||
|
||||
ON_DAY_NIGHT_CHANGE(OnDayNightChange.class, void.class),
|
||||
|
||||
ON_PACKET_RECEIVED(OnPacketReceived.class, void.class),
|
||||
ON_PACKET_SENT(OnPacketSent.class, void.class),
|
||||
|
||||
// Instance events
|
||||
ON_INSTANCE_CREATED(OnInstanceCreated.class, void.class),
|
||||
ON_INSTANCE_DESTROY(OnInstanceDestroy.class, void.class),
|
||||
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketReceived implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketReceived(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_RECEIVED;
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketSent implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketSent(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_SENT;
|
||||
}
|
||||
}
|
@ -17,26 +17,16 @@
|
||||
package org.l2jmobius.gameserver.network;
|
||||
|
||||
import org.l2jmobius.commons.network.ICrypt;
|
||||
import org.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
|
||||
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)
|
||||
{
|
||||
@ -44,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)
|
||||
int a = 0;
|
||||
while (buf.isReadable())
|
||||
{
|
||||
final byte[] data = new byte[buf.writerIndex()];
|
||||
buf.getBytes(0, data);
|
||||
EventDispatcher.getInstance().notifyEvent(new OnPacketReceived(_client, data));
|
||||
final int b = buf.readByte() & 0xff;
|
||||
a = b ^ _outKey[(buf.readerIndex() - 1) & 15] ^ a;
|
||||
buf.setByte(buf.readerIndex() - 1, a);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ public class GameClient extends ChannelInboundHandler<GameClient>
|
||||
|
||||
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 int[][] _trace;
|
||||
|
||||
public GameClient()
|
||||
{
|
||||
_crypt = new Crypt(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx)
|
||||
{
|
||||
|
@ -128,8 +128,6 @@ import org.l2jmobius.gameserver.model.events.impl.item.OnItemEnchantAdd;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemSoulCrystalAdd;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemTalk;
|
||||
import org.l2jmobius.gameserver.model.events.impl.olympiad.OnOlympiadMatchResult;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeFinish;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeOwnerChange;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeStart;
|
||||
@ -288,9 +286,6 @@ public enum EventType
|
||||
|
||||
ON_DAY_NIGHT_CHANGE(OnDayNightChange.class, void.class),
|
||||
|
||||
ON_PACKET_RECEIVED(OnPacketReceived.class, void.class),
|
||||
ON_PACKET_SENT(OnPacketSent.class, void.class),
|
||||
|
||||
// Instance events
|
||||
ON_INSTANCE_CREATED(OnInstanceCreated.class, void.class),
|
||||
ON_INSTANCE_DESTROY(OnInstanceDestroy.class, void.class),
|
||||
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketReceived implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketReceived(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_RECEIVED;
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketSent implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketSent(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_SENT;
|
||||
}
|
||||
}
|
@ -17,26 +17,16 @@
|
||||
package org.l2jmobius.gameserver.network;
|
||||
|
||||
import org.l2jmobius.commons.network.ICrypt;
|
||||
import org.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
|
||||
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)
|
||||
{
|
||||
@ -44,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)
|
||||
int a = 0;
|
||||
while (buf.isReadable())
|
||||
{
|
||||
final byte[] data = new byte[buf.writerIndex()];
|
||||
buf.getBytes(0, data);
|
||||
EventDispatcher.getInstance().notifyEvent(new OnPacketReceived(_client, data));
|
||||
final int b = buf.readByte() & 0xff;
|
||||
a = b ^ _outKey[(buf.readerIndex() - 1) & 15] ^ a;
|
||||
buf.setByte(buf.readerIndex() - 1, a);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ public class GameClient extends ChannelInboundHandler<GameClient>
|
||||
|
||||
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 int[][] _trace;
|
||||
|
||||
public GameClient()
|
||||
{
|
||||
_crypt = new Crypt(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx)
|
||||
{
|
||||
|
@ -128,8 +128,6 @@ import org.l2jmobius.gameserver.model.events.impl.item.OnItemEnchantAdd;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemSoulCrystalAdd;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemTalk;
|
||||
import org.l2jmobius.gameserver.model.events.impl.olympiad.OnOlympiadMatchResult;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeFinish;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeOwnerChange;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeStart;
|
||||
@ -288,9 +286,6 @@ public enum EventType
|
||||
|
||||
ON_DAY_NIGHT_CHANGE(OnDayNightChange.class, void.class),
|
||||
|
||||
ON_PACKET_RECEIVED(OnPacketReceived.class, void.class),
|
||||
ON_PACKET_SENT(OnPacketSent.class, void.class),
|
||||
|
||||
// Instance events
|
||||
ON_INSTANCE_CREATED(OnInstanceCreated.class, void.class),
|
||||
ON_INSTANCE_DESTROY(OnInstanceDestroy.class, void.class),
|
||||
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketReceived implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketReceived(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_RECEIVED;
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketSent implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketSent(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_SENT;
|
||||
}
|
||||
}
|
@ -17,26 +17,16 @@
|
||||
package org.l2jmobius.gameserver.network;
|
||||
|
||||
import org.l2jmobius.commons.network.ICrypt;
|
||||
import org.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
|
||||
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)
|
||||
{
|
||||
@ -44,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)
|
||||
int a = 0;
|
||||
while (buf.isReadable())
|
||||
{
|
||||
final byte[] data = new byte[buf.writerIndex()];
|
||||
buf.getBytes(0, data);
|
||||
EventDispatcher.getInstance().notifyEvent(new OnPacketReceived(_client, data));
|
||||
final int b = buf.readByte() & 0xff;
|
||||
a = b ^ _outKey[(buf.readerIndex() - 1) & 15] ^ a;
|
||||
buf.setByte(buf.readerIndex() - 1, a);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ public class GameClient extends ChannelInboundHandler<GameClient>
|
||||
|
||||
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 int[][] _trace;
|
||||
|
||||
public GameClient()
|
||||
{
|
||||
_crypt = new Crypt(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx)
|
||||
{
|
||||
|
@ -128,8 +128,6 @@ import org.l2jmobius.gameserver.model.events.impl.item.OnItemEnchantAdd;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemSoulCrystalAdd;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemTalk;
|
||||
import org.l2jmobius.gameserver.model.events.impl.olympiad.OnOlympiadMatchResult;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeFinish;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeOwnerChange;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeStart;
|
||||
@ -288,9 +286,6 @@ public enum EventType
|
||||
|
||||
ON_DAY_NIGHT_CHANGE(OnDayNightChange.class, void.class),
|
||||
|
||||
ON_PACKET_RECEIVED(OnPacketReceived.class, void.class),
|
||||
ON_PACKET_SENT(OnPacketSent.class, void.class),
|
||||
|
||||
// Instance events
|
||||
ON_INSTANCE_CREATED(OnInstanceCreated.class, void.class),
|
||||
ON_INSTANCE_DESTROY(OnInstanceDestroy.class, void.class),
|
||||
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketReceived implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketReceived(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_RECEIVED;
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketSent implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketSent(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_SENT;
|
||||
}
|
||||
}
|
@ -17,26 +17,16 @@
|
||||
package org.l2jmobius.gameserver.network;
|
||||
|
||||
import org.l2jmobius.commons.network.ICrypt;
|
||||
import org.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
|
||||
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)
|
||||
{
|
||||
@ -44,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)
|
||||
int a = 0;
|
||||
while (buf.isReadable())
|
||||
{
|
||||
final byte[] data = new byte[buf.writerIndex()];
|
||||
buf.getBytes(0, data);
|
||||
EventDispatcher.getInstance().notifyEvent(new OnPacketReceived(_client, data));
|
||||
final int b = buf.readByte() & 0xff;
|
||||
a = b ^ _outKey[(buf.readerIndex() - 1) & 15] ^ a;
|
||||
buf.setByte(buf.readerIndex() - 1, a);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ public class GameClient extends ChannelInboundHandler<GameClient>
|
||||
|
||||
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 int[][] _trace;
|
||||
|
||||
public GameClient()
|
||||
{
|
||||
_crypt = new Crypt(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx)
|
||||
{
|
||||
|
@ -17,28 +17,35 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.network;
|
||||
|
||||
/**
|
||||
* @author KenM
|
||||
*/
|
||||
public class Crypt
|
||||
{
|
||||
byte[] _key;
|
||||
private byte[] _inKey;
|
||||
private byte[] _outKey;
|
||||
|
||||
public void setKey(byte[] key)
|
||||
{
|
||||
_key = new byte[key.length];
|
||||
System.arraycopy(key, 0, _key, 0, key.length);
|
||||
_inKey = new byte[key.length];
|
||||
_outKey = new byte[key.length];
|
||||
System.arraycopy(key, 0, _inKey, 0, key.length);
|
||||
System.arraycopy(key, 0, _outKey, 0, key.length);
|
||||
}
|
||||
|
||||
public long decrypt(byte[] raw)
|
||||
public void decrypt(byte[] raw)
|
||||
{
|
||||
if (_key == null)
|
||||
if (_inKey == null)
|
||||
{
|
||||
return 0L;
|
||||
return;
|
||||
}
|
||||
|
||||
int temp = 0;
|
||||
int j = 0;
|
||||
for (int i = 0; i < raw.length; ++i)
|
||||
{
|
||||
final int temp2 = raw[i] & 0xFF;
|
||||
raw[i] = (byte) (temp2 ^ (_key[j++] & 0xFF) ^ temp);
|
||||
final int temp2 = raw[i] & 0xff;
|
||||
raw[i] = (byte) (temp2 ^ (_inKey[j++] & 0xff) ^ temp);
|
||||
temp = temp2;
|
||||
if (j <= 7)
|
||||
{
|
||||
@ -46,29 +53,32 @@ public class Crypt
|
||||
}
|
||||
j = 0;
|
||||
}
|
||||
long old = _key[0] & 0xFF;
|
||||
old |= (_key[1] << 8) & 0xFF00;
|
||||
old |= (_key[2] << 16) & 0xFF0000;
|
||||
old |= (_key[3] << 24) & 0xFF000000;
|
||||
_key[0] = (byte) ((old += raw.length) & 0xFFL);
|
||||
_key[1] = (byte) ((old >> 8) & 0xFFL);
|
||||
_key[2] = (byte) ((old >> 16) & 0xFFL);
|
||||
_key[3] = (byte) ((old >> 24) & 0xFFL);
|
||||
return old;
|
||||
|
||||
// Shift key.
|
||||
int old = _inKey[0] & 0xff;
|
||||
old |= (_inKey[1] << 8) & 0xff00;
|
||||
old |= (_inKey[2] << 16) & 0xff0000;
|
||||
old |= (_inKey[3] << 24) & 0xff000000;
|
||||
old += raw.length;
|
||||
_inKey[0] = (byte) (old & 0xff);
|
||||
_inKey[1] = (byte) ((old >> 8) & 0xff);
|
||||
_inKey[2] = (byte) ((old >> 16) & 0xff);
|
||||
_inKey[3] = (byte) ((old >> 24) & 0xff);
|
||||
}
|
||||
|
||||
public long encrypt(byte[] raw)
|
||||
public void encrypt(byte[] raw)
|
||||
{
|
||||
if (_key == null)
|
||||
if (_outKey == null)
|
||||
{
|
||||
return 0L;
|
||||
return;
|
||||
}
|
||||
|
||||
int temp = 0;
|
||||
int j = 0;
|
||||
for (int i = 0; i < raw.length; ++i)
|
||||
{
|
||||
final int temp2 = raw[i] & 0xFF;
|
||||
raw[i] = (byte) (temp2 ^ (_key[j++] & 0xFF) ^ temp);
|
||||
final int temp2 = raw[i] & 0xff;
|
||||
raw[i] = (byte) (temp2 ^ (_outKey[j++] & 0xff) ^ temp);
|
||||
temp = raw[i];
|
||||
if (j <= 7)
|
||||
{
|
||||
@ -76,14 +86,16 @@ public class Crypt
|
||||
}
|
||||
j = 0;
|
||||
}
|
||||
long old = _key[0] & 0xFF;
|
||||
old |= (_key[1] << 8) & 0xFF00;
|
||||
old |= (_key[2] << 16) & 0xFF0000;
|
||||
old |= (_key[3] << 24) & 0xFF000000;
|
||||
_key[0] = (byte) ((old += raw.length) & 0xFFL);
|
||||
_key[1] = (byte) ((old >> 8) & 0xFFL);
|
||||
_key[2] = (byte) ((old >> 16) & 0xFFL);
|
||||
_key[3] = (byte) ((old >> 24) & 0xFFL);
|
||||
return old;
|
||||
|
||||
// Shift key.
|
||||
int old = _outKey[0] & 0xff;
|
||||
old |= (_outKey[1] << 8) & 0xff00;
|
||||
old |= (_outKey[2] << 16) & 0xff0000;
|
||||
old |= (_outKey[3] << 24) & 0xff000000;
|
||||
old += raw.length;
|
||||
_outKey[0] = (byte) (old & 0xff);
|
||||
_outKey[1] = (byte) ((old >> 8) & 0xff);
|
||||
_outKey[2] = (byte) ((old >> 16) & 0xff);
|
||||
_outKey[3] = (byte) ((old >> 24) & 0xff);
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
int a = 0;
|
||||
while (buf.isReadable())
|
||||
{
|
||||
final byte[] data = new byte[buf.writerIndex()];
|
||||
buf.getBytes(0, data);
|
||||
// EventDispatcher.getInstance().notifyEvent(new OnPacketReceived(_client, data));
|
||||
final int b = buf.readByte() & 0xff;
|
||||
a = b ^ _outKey[(buf.readerIndex() - 1) & 7] ^ a;
|
||||
buf.setByte(buf.readerIndex() - 1, a);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -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)
|
||||
int a = 0;
|
||||
while (buf.isReadable())
|
||||
{
|
||||
final byte[] data = new byte[buf.writerIndex()];
|
||||
buf.getBytes(0, data);
|
||||
// EventDispatcher.getInstance().notifyEvent(new OnPacketReceived(_client, data));
|
||||
final int b = buf.readByte() & 0xff;
|
||||
a = b ^ _outKey[(buf.readerIndex() - 1) & 15] ^ a;
|
||||
buf.setByte(buf.readerIndex() - 1, a);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -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)
|
||||
int a = 0;
|
||||
while (buf.isReadable())
|
||||
{
|
||||
final byte[] data = new byte[buf.writerIndex()];
|
||||
buf.getBytes(0, data);
|
||||
// EventDispatcher.getInstance().notifyEvent(new OnPacketReceived(_client, data));
|
||||
final int b = buf.readByte() & 0xff;
|
||||
a = b ^ _outKey[(buf.readerIndex() - 1) & 15] ^ a;
|
||||
buf.setByte(buf.readerIndex() - 1, a);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ public class GameClient extends ChannelInboundHandler<GameClient>
|
||||
|
||||
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;
|
||||
@ -79,11 +79,6 @@ public class GameClient extends ChannelInboundHandler<GameClient>
|
||||
private int _protocolVersion;
|
||||
private int[][] _trace;
|
||||
|
||||
public GameClient()
|
||||
{
|
||||
_crypt = new Crypt(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx)
|
||||
{
|
||||
|
@ -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)
|
||||
int a = 0;
|
||||
while (buf.isReadable())
|
||||
{
|
||||
final byte[] data = new byte[buf.writerIndex()];
|
||||
buf.getBytes(0, data);
|
||||
// EventDispatcher.getInstance().notifyEvent(new OnPacketReceived(_client, data));
|
||||
final int b = buf.readByte() & 0xff;
|
||||
a = b ^ _outKey[(buf.readerIndex() - 1) & 15] ^ a;
|
||||
buf.setByte(buf.readerIndex() - 1, a);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ public class GameClient extends ChannelInboundHandler<GameClient>
|
||||
|
||||
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;
|
||||
@ -82,11 +82,6 @@ public class GameClient extends ChannelInboundHandler<GameClient>
|
||||
private int _protocolVersion;
|
||||
private int[][] _trace;
|
||||
|
||||
public GameClient()
|
||||
{
|
||||
_crypt = new Crypt(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx)
|
||||
{
|
||||
|
@ -126,8 +126,6 @@ import org.l2jmobius.gameserver.model.events.impl.item.OnItemBypassEvent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemCreate;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemTalk;
|
||||
import org.l2jmobius.gameserver.model.events.impl.olympiad.OnOlympiadMatchResult;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeFinish;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeOwnerChange;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeStart;
|
||||
@ -284,9 +282,6 @@ public enum EventType
|
||||
|
||||
ON_DAY_NIGHT_CHANGE(OnDayNightChange.class, void.class),
|
||||
|
||||
ON_PACKET_RECEIVED(OnPacketReceived.class, void.class),
|
||||
ON_PACKET_SENT(OnPacketSent.class, void.class),
|
||||
|
||||
// Instance events
|
||||
ON_INSTANCE_CREATED(OnInstanceCreated.class, void.class),
|
||||
ON_INSTANCE_DESTROY(OnInstanceDestroy.class, void.class),
|
||||
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketReceived implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketReceived(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_RECEIVED;
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketSent implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketSent(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_SENT;
|
||||
}
|
||||
}
|
@ -17,26 +17,16 @@
|
||||
package org.l2jmobius.gameserver.network;
|
||||
|
||||
import org.l2jmobius.commons.network.ICrypt;
|
||||
import org.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
|
||||
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)
|
||||
{
|
||||
@ -44,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)
|
||||
int a = 0;
|
||||
while (buf.isReadable())
|
||||
{
|
||||
final byte[] data = new byte[buf.writerIndex()];
|
||||
buf.getBytes(0, data);
|
||||
EventDispatcher.getInstance().notifyEvent(new OnPacketReceived(_client, data));
|
||||
final int b = buf.readByte() & 0xff;
|
||||
a = b ^ _outKey[(buf.readerIndex() - 1) & 15] ^ a;
|
||||
buf.setByte(buf.readerIndex() - 1, a);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ public class GameClient extends ChannelInboundHandler<GameClient>
|
||||
|
||||
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 int[][] _trace;
|
||||
|
||||
public GameClient()
|
||||
{
|
||||
_crypt = new Crypt(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx)
|
||||
{
|
||||
|
@ -126,8 +126,6 @@ import org.l2jmobius.gameserver.model.events.impl.item.OnItemBypassEvent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemCreate;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemTalk;
|
||||
import org.l2jmobius.gameserver.model.events.impl.olympiad.OnOlympiadMatchResult;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeFinish;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeOwnerChange;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeStart;
|
||||
@ -284,9 +282,6 @@ public enum EventType
|
||||
|
||||
ON_DAY_NIGHT_CHANGE(OnDayNightChange.class, void.class),
|
||||
|
||||
ON_PACKET_RECEIVED(OnPacketReceived.class, void.class),
|
||||
ON_PACKET_SENT(OnPacketSent.class, void.class),
|
||||
|
||||
// Instance events
|
||||
ON_INSTANCE_CREATED(OnInstanceCreated.class, void.class),
|
||||
ON_INSTANCE_DESTROY(OnInstanceDestroy.class, void.class),
|
||||
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketReceived implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketReceived(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_RECEIVED;
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketSent implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketSent(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_SENT;
|
||||
}
|
||||
}
|
@ -17,26 +17,16 @@
|
||||
package org.l2jmobius.gameserver.network;
|
||||
|
||||
import org.l2jmobius.commons.network.ICrypt;
|
||||
import org.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
|
||||
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)
|
||||
{
|
||||
@ -44,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)
|
||||
int a = 0;
|
||||
while (buf.isReadable())
|
||||
{
|
||||
final byte[] data = new byte[buf.writerIndex()];
|
||||
buf.getBytes(0, data);
|
||||
EventDispatcher.getInstance().notifyEvent(new OnPacketReceived(_client, data));
|
||||
final int b = buf.readByte() & 0xff;
|
||||
a = b ^ _outKey[(buf.readerIndex() - 1) & 15] ^ a;
|
||||
buf.setByte(buf.readerIndex() - 1, a);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ public class GameClient extends ChannelInboundHandler<GameClient>
|
||||
|
||||
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 int[][] _trace;
|
||||
|
||||
public GameClient()
|
||||
{
|
||||
_crypt = new Crypt(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx)
|
||||
{
|
||||
|
@ -126,8 +126,6 @@ import org.l2jmobius.gameserver.model.events.impl.item.OnItemBypassEvent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemCreate;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemTalk;
|
||||
import org.l2jmobius.gameserver.model.events.impl.olympiad.OnOlympiadMatchResult;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeFinish;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeOwnerChange;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeStart;
|
||||
@ -284,9 +282,6 @@ public enum EventType
|
||||
|
||||
ON_DAY_NIGHT_CHANGE(OnDayNightChange.class, void.class),
|
||||
|
||||
ON_PACKET_RECEIVED(OnPacketReceived.class, void.class),
|
||||
ON_PACKET_SENT(OnPacketSent.class, void.class),
|
||||
|
||||
// Instance events
|
||||
ON_INSTANCE_CREATED(OnInstanceCreated.class, void.class),
|
||||
ON_INSTANCE_DESTROY(OnInstanceDestroy.class, void.class),
|
||||
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketReceived implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketReceived(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_RECEIVED;
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketSent implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketSent(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_SENT;
|
||||
}
|
||||
}
|
@ -17,26 +17,16 @@
|
||||
package org.l2jmobius.gameserver.network;
|
||||
|
||||
import org.l2jmobius.commons.network.ICrypt;
|
||||
import org.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
|
||||
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)
|
||||
{
|
||||
@ -44,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)
|
||||
int a = 0;
|
||||
while (buf.isReadable())
|
||||
{
|
||||
final byte[] data = new byte[buf.writerIndex()];
|
||||
buf.getBytes(0, data);
|
||||
EventDispatcher.getInstance().notifyEvent(new OnPacketReceived(_client, data));
|
||||
final int b = buf.readByte() & 0xff;
|
||||
a = b ^ _outKey[(buf.readerIndex() - 1) & 15] ^ a;
|
||||
buf.setByte(buf.readerIndex() - 1, a);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ public class GameClient extends ChannelInboundHandler<GameClient>
|
||||
|
||||
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 int[][] _trace;
|
||||
|
||||
public GameClient()
|
||||
{
|
||||
_crypt = new Crypt(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx)
|
||||
{
|
||||
|
@ -128,8 +128,6 @@ import org.l2jmobius.gameserver.model.events.impl.item.OnItemBypassEvent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemCreate;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemTalk;
|
||||
import org.l2jmobius.gameserver.model.events.impl.olympiad.OnOlympiadMatchResult;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeFinish;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeOwnerChange;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeStart;
|
||||
@ -286,9 +284,6 @@ public enum EventType
|
||||
|
||||
ON_DAY_NIGHT_CHANGE(OnDayNightChange.class, void.class),
|
||||
|
||||
ON_PACKET_RECEIVED(OnPacketReceived.class, void.class),
|
||||
ON_PACKET_SENT(OnPacketSent.class, void.class),
|
||||
|
||||
// Instance events
|
||||
ON_INSTANCE_CREATED(OnInstanceCreated.class, void.class),
|
||||
ON_INSTANCE_DESTROY(OnInstanceDestroy.class, void.class),
|
||||
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketReceived implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketReceived(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_RECEIVED;
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketSent implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketSent(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_SENT;
|
||||
}
|
||||
}
|
@ -17,26 +17,16 @@
|
||||
package org.l2jmobius.gameserver.network;
|
||||
|
||||
import org.l2jmobius.commons.network.ICrypt;
|
||||
import org.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
|
||||
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)
|
||||
{
|
||||
@ -44,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)
|
||||
int a = 0;
|
||||
while (buf.isReadable())
|
||||
{
|
||||
final byte[] data = new byte[buf.writerIndex()];
|
||||
buf.getBytes(0, data);
|
||||
EventDispatcher.getInstance().notifyEvent(new OnPacketReceived(_client, data));
|
||||
final int b = buf.readByte() & 0xff;
|
||||
a = b ^ _outKey[(buf.readerIndex() - 1) & 15] ^ a;
|
||||
buf.setByte(buf.readerIndex() - 1, a);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ public class GameClient extends ChannelInboundHandler<GameClient>
|
||||
|
||||
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 int[][] _trace;
|
||||
|
||||
public GameClient()
|
||||
{
|
||||
_crypt = new Crypt(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx)
|
||||
{
|
||||
|
@ -128,8 +128,6 @@ import org.l2jmobius.gameserver.model.events.impl.item.OnItemBypassEvent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemCreate;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemTalk;
|
||||
import org.l2jmobius.gameserver.model.events.impl.olympiad.OnOlympiadMatchResult;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeFinish;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeOwnerChange;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeStart;
|
||||
@ -286,9 +284,6 @@ public enum EventType
|
||||
|
||||
ON_DAY_NIGHT_CHANGE(OnDayNightChange.class, void.class),
|
||||
|
||||
ON_PACKET_RECEIVED(OnPacketReceived.class, void.class),
|
||||
ON_PACKET_SENT(OnPacketSent.class, void.class),
|
||||
|
||||
// Instance events
|
||||
ON_INSTANCE_CREATED(OnInstanceCreated.class, void.class),
|
||||
ON_INSTANCE_DESTROY(OnInstanceDestroy.class, void.class),
|
||||
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketReceived implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketReceived(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_RECEIVED;
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketSent implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketSent(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_SENT;
|
||||
}
|
||||
}
|
@ -17,26 +17,16 @@
|
||||
package org.l2jmobius.gameserver.network;
|
||||
|
||||
import org.l2jmobius.commons.network.ICrypt;
|
||||
import org.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
|
||||
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)
|
||||
{
|
||||
@ -44,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)
|
||||
int a = 0;
|
||||
while (buf.isReadable())
|
||||
{
|
||||
final byte[] data = new byte[buf.writerIndex()];
|
||||
buf.getBytes(0, data);
|
||||
EventDispatcher.getInstance().notifyEvent(new OnPacketReceived(_client, data));
|
||||
final int b = buf.readByte() & 0xff;
|
||||
a = b ^ _outKey[(buf.readerIndex() - 1) & 15] ^ a;
|
||||
buf.setByte(buf.readerIndex() - 1, a);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ public class GameClient extends ChannelInboundHandler<GameClient>
|
||||
|
||||
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 int[][] _trace;
|
||||
|
||||
public GameClient()
|
||||
{
|
||||
_crypt = new Crypt(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx)
|
||||
{
|
||||
|
@ -128,8 +128,6 @@ import org.l2jmobius.gameserver.model.events.impl.item.OnItemBypassEvent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemCreate;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemTalk;
|
||||
import org.l2jmobius.gameserver.model.events.impl.olympiad.OnOlympiadMatchResult;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeFinish;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeOwnerChange;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeStart;
|
||||
@ -286,9 +284,6 @@ public enum EventType
|
||||
|
||||
ON_DAY_NIGHT_CHANGE(OnDayNightChange.class, void.class),
|
||||
|
||||
ON_PACKET_RECEIVED(OnPacketReceived.class, void.class),
|
||||
ON_PACKET_SENT(OnPacketSent.class, void.class),
|
||||
|
||||
// Instance events
|
||||
ON_INSTANCE_CREATED(OnInstanceCreated.class, void.class),
|
||||
ON_INSTANCE_DESTROY(OnInstanceDestroy.class, void.class),
|
||||
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketReceived implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketReceived(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_RECEIVED;
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketSent implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketSent(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_SENT;
|
||||
}
|
||||
}
|
@ -17,26 +17,16 @@
|
||||
package org.l2jmobius.gameserver.network;
|
||||
|
||||
import org.l2jmobius.commons.network.ICrypt;
|
||||
import org.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
|
||||
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)
|
||||
{
|
||||
@ -44,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)
|
||||
int a = 0;
|
||||
while (buf.isReadable())
|
||||
{
|
||||
final byte[] data = new byte[buf.writerIndex()];
|
||||
buf.getBytes(0, data);
|
||||
EventDispatcher.getInstance().notifyEvent(new OnPacketReceived(_client, data));
|
||||
final int b = buf.readByte() & 0xff;
|
||||
a = b ^ _outKey[(buf.readerIndex() - 1) & 15] ^ a;
|
||||
buf.setByte(buf.readerIndex() - 1, a);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ public class GameClient extends ChannelInboundHandler<GameClient>
|
||||
|
||||
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 int[][] _trace;
|
||||
|
||||
public GameClient()
|
||||
{
|
||||
_crypt = new Crypt(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx)
|
||||
{
|
||||
|
@ -125,8 +125,6 @@ import org.l2jmobius.gameserver.model.events.impl.item.OnItemBypassEvent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemCreate;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemTalk;
|
||||
import org.l2jmobius.gameserver.model.events.impl.olympiad.OnOlympiadMatchResult;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeFinish;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeOwnerChange;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeStart;
|
||||
@ -282,9 +280,6 @@ public enum EventType
|
||||
|
||||
ON_DAY_NIGHT_CHANGE(OnDayNightChange.class, void.class),
|
||||
|
||||
ON_PACKET_RECEIVED(OnPacketReceived.class, void.class),
|
||||
ON_PACKET_SENT(OnPacketSent.class, void.class),
|
||||
|
||||
// Instance events
|
||||
ON_INSTANCE_CREATED(OnInstanceCreated.class, void.class),
|
||||
ON_INSTANCE_DESTROY(OnInstanceDestroy.class, void.class),
|
||||
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketReceived implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketReceived(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_RECEIVED;
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketSent implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketSent(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_SENT;
|
||||
}
|
||||
}
|
@ -17,26 +17,16 @@
|
||||
package org.l2jmobius.gameserver.network;
|
||||
|
||||
import org.l2jmobius.commons.network.ICrypt;
|
||||
import org.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
|
||||
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)
|
||||
{
|
||||
@ -44,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)
|
||||
int a = 0;
|
||||
while (buf.isReadable())
|
||||
{
|
||||
final byte[] data = new byte[buf.writerIndex()];
|
||||
buf.getBytes(0, data);
|
||||
EventDispatcher.getInstance().notifyEvent(new OnPacketReceived(_client, data));
|
||||
final int b = buf.readByte() & 0xff;
|
||||
a = b ^ _outKey[(buf.readerIndex() - 1) & 15] ^ a;
|
||||
buf.setByte(buf.readerIndex() - 1, a);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ public class GameClient extends ChannelInboundHandler<GameClient>
|
||||
|
||||
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 int[][] _trace;
|
||||
|
||||
public GameClient()
|
||||
{
|
||||
_crypt = new Crypt(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx)
|
||||
{
|
||||
|
@ -128,8 +128,6 @@ import org.l2jmobius.gameserver.model.events.impl.item.OnItemBypassEvent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemCreate;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemTalk;
|
||||
import org.l2jmobius.gameserver.model.events.impl.olympiad.OnOlympiadMatchResult;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeFinish;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeOwnerChange;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeStart;
|
||||
@ -286,9 +284,6 @@ public enum EventType
|
||||
|
||||
ON_DAY_NIGHT_CHANGE(OnDayNightChange.class, void.class),
|
||||
|
||||
ON_PACKET_RECEIVED(OnPacketReceived.class, void.class),
|
||||
ON_PACKET_SENT(OnPacketSent.class, void.class),
|
||||
|
||||
// Instance events
|
||||
ON_INSTANCE_CREATED(OnInstanceCreated.class, void.class),
|
||||
ON_INSTANCE_DESTROY(OnInstanceDestroy.class, void.class),
|
||||
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketReceived implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketReceived(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_RECEIVED;
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.server;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnPacketSent implements IBaseEvent
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final byte[] _data;
|
||||
|
||||
public OnPacketSent(GameClient client, byte[] data)
|
||||
{
|
||||
_client = client;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public PlayerInstance getActiveChar()
|
||||
{
|
||||
return _client.getPlayer();
|
||||
}
|
||||
|
||||
public GameClient getClient()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_PACKET_SENT;
|
||||
}
|
||||
}
|
@ -17,26 +17,16 @@
|
||||
package org.l2jmobius.gameserver.network;
|
||||
|
||||
import org.l2jmobius.commons.network.ICrypt;
|
||||
import org.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
|
||||
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)
|
||||
{
|
||||
@ -44,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)
|
||||
int a = 0;
|
||||
while (buf.isReadable())
|
||||
{
|
||||
final byte[] data = new byte[buf.writerIndex()];
|
||||
buf.getBytes(0, data);
|
||||
EventDispatcher.getInstance().notifyEvent(new OnPacketReceived(_client, data));
|
||||
final int b = buf.readByte() & 0xff;
|
||||
a = b ^ _outKey[(buf.readerIndex() - 1) & 15] ^ a;
|
||||
buf.setByte(buf.readerIndex() - 1, a);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ public class GameClient extends ChannelInboundHandler<GameClient>
|
||||
|
||||
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 int[][] _trace;
|
||||
|
||||
public GameClient()
|
||||
{
|
||||
_crypt = new Crypt(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx)
|
||||
{
|
||||
|
@ -128,8 +128,6 @@ import org.l2jmobius.gameserver.model.events.impl.item.OnItemBypassEvent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemCreate;
|
||||
import org.l2jmobius.gameserver.model.events.impl.item.OnItemTalk;
|
||||
import org.l2jmobius.gameserver.model.events.impl.olympiad.OnOlympiadMatchResult;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketReceived;
|
||||
import org.l2jmobius.gameserver.model.events.impl.server.OnPacketSent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeFinish;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeOwnerChange;
|
||||
import org.l2jmobius.gameserver.model.events.impl.sieges.OnCastleSiegeStart;
|
||||
@ -286,9 +284,6 @@ public enum EventType
|
||||
|
||||
ON_DAY_NIGHT_CHANGE(OnDayNightChange.class, void.class),
|
||||
|
||||
ON_PACKET_RECEIVED(OnPacketReceived.class, void.class),
|
||||
ON_PACKET_SENT(OnPacketSent.class, void.class),
|
||||
|
||||
// Instance events
|
||||
ON_INSTANCE_CREATED(OnInstanceCreated.class, void.class),
|
||||
ON_INSTANCE_DESTROY(OnInstanceDestroy.class, void.class),
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user