/** @param con */ public L2LoginClient(MMOConnection<L2LoginClient> con) { super(con); _state = LoginClientState.CONNECTED; _scrambledPair = LoginController.getInstance().getScrambledRSAKeyPair(); _blowfishKey = LoginController.getInstance().getBlowfishKey(); _sessionId = Rnd.nextInt(); _connectionStartTime = System.currentTimeMillis(); _loginCrypt = new LoginCrypt(); _loginCrypt.setKey(_blowfishKey); }
/** @see org.mmocore.network.MMOClient#encrypt(java.nio.ByteBuffer, int) */ @Override public boolean encrypt(ByteBuffer buf, int size) { final int offset = buf.position(); try { size = _loginCrypt.encrypt(buf.array(), offset, size); } catch (IOException e) { e.printStackTrace(); return false; } buf.position(offset + size); return true; }
/** @see org.mmocore.network.MMOClient#decrypt(java.nio.ByteBuffer, int) */ @Override public boolean decrypt(ByteBuffer buf, int size) { boolean ret = false; try { ret = _loginCrypt.decrypt(buf.array(), buf.position(), size); } catch (IOException e) { e.printStackTrace(); super.getConnection().close((SendablePacket<L2LoginClient>) null); return false; } if (!ret) { byte[] dump = new byte[size]; System.arraycopy(buf.array(), buf.position(), dump, 0, size); _log.warning("Wrong checksum from client: " + toString()); super.getConnection().close((SendablePacket<L2LoginClient>) null); } return ret; }