Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.inferno.net.event;
- import java.math.BigInteger;
- import java.nio.ByteBuffer;
- import java.sql.SQLException;
- import java.util.Arrays;
- import com.inferno.ForumIntegration;
- import com.inferno.NetworkConstants;
- import com.inferno.cache.Cache;
- import com.inferno.cache.crypto.ISAACCipher;
- import com.inferno.cache.crypto.ISAACPair;
- import com.inferno.cache.crypto.XTEACryption;
- import com.inferno.cache.misc.buffer.ByteBufferUtils;
- import com.inferno.game.node.entity.player.info.ClientInfo;
- import com.inferno.game.node.entity.player.info.DisplayMode;
- import com.inferno.game.node.entity.player.info.PlayerDetails;
- import com.inferno.game.node.entity.player.info.UIDInfo;
- import com.inferno.game.node.entity.player.info.login.LoginParser;
- import com.inferno.game.node.entity.player.info.login.LoginType;
- import com.inferno.game.node.entity.player.info.login.Response;
- import com.inferno.game.system.task.TaskExecutor;
- import com.inferno.net.IoReadEvent;
- import com.inferno.net.IoSession;
- import com.inferno.tools.StringUtils;
- /**
- * Handles login reading events.
- *
- * @author Emperor
- */
- public final class LoginReadEvent extends IoReadEvent {
- /**
- * The RSA modulus.
- */
- public static final BigInteger MODULUS = new BigInteger("165865706435016682110653568563251120094278686912987295809145491806194715902716739338411927793058925228087565434562948389222225588420069703784252638483569608159614392485969864899137973999614056797405232846059198315441808544524190866210655169682670028293787208173603935453834899795395794572295868565624049196373");
- /**
- * The RSA exponent.
- */
- public static final BigInteger RSA_KEY = new BigInteger("56600403721755849042871300293705052867669386058593586576677751174965876168398876338011266203274025417717477354449635744336265820214938719432244777866648612856409222657603092909839244312101542583618644127794582316068916809421286289618425813349038287935817476491851970456260849477664967448547154113206350117073");
- /**
- * Constructs a new {@code LoginReadEvent}.
- *
- * @param session The session.
- * @param buffer The buffer with data to read from.
- */
- public LoginReadEvent(IoSession session, ByteBuffer buffer) {
- super(session, buffer);
- }
- @Override
- public void read(IoSession session, ByteBuffer buffer) {
- int opcode = buffer.get() & 0xFF;
- if ((buffer.getShort()) != buffer.remaining()) {
- session.write(Response.BAD_SESSION_ID);
- return;
- }
- if (buffer.getInt() != NetworkConstants.REVISION) {
- session.write(Response.UPDATED);
- return;
- }
- int new1 = buffer.getInt();
- byte new2 = buffer.get();
- switch (opcode) {
- case 16: // Reconnect world login
- case 18: // World login
- decodeWorld(opcode, session, buffer);
- break;
- default:
- System.err.println("[Login] Unhandled login type [opcode=" + opcode + "]!");
- session.disconnect();
- break;
- }
- }
- /**
- * Decodes a world login request.
- *
- * @param session The session.
- * @param rsa_buffer The buffer to read from.
- */
- private static void decodeWorld(final int opcode, final IoSession session, ByteBuffer buffer) {
- ByteBuffer rsa_buffer = getRSABlock(buffer);
- int[] xtea = new int[]{rsa_buffer.getInt(), rsa_buffer.getInt(), rsa_buffer.getInt(), rsa_buffer.getInt()};
- long var1 = rsa_buffer.getLong();
- int auth_type = rsa_buffer.get();
- switch (auth_type) {
- case 0:
- case 3:
- int code = ByteBufferUtils.getTriByte(rsa_buffer);
- rsa_buffer.position(rsa_buffer.position() + 1);
- break;
- case 1:
- rsa_buffer.position(rsa_buffer.position() + 4);
- break;
- case 2:
- rsa_buffer.getInt();
- break;
- }
- int var2 = rsa_buffer.get();
- String password = ByteBufferUtils.getString(rsa_buffer);
- ByteBuffer xtea_buffer = XTEACryption.decrypt(buffer, xtea);
- String username = ByteBufferUtils.getString(xtea_buffer);
- //int info = ForumIntegration.validate(username, password);
- int displaySetting = xtea_buffer.get();
- int windowMode = (displaySetting >> 1);
- boolean lowMem = (displaySetting & 0xFF) == 1;
- int width = xtea_buffer.getShort();
- int height = xtea_buffer.getShort();
- xtea_buffer.position(xtea_buffer.position() + 24);
- String sessionToken1 = ByteBufferUtils.getString(xtea_buffer);
- int affiliateID = xtea_buffer.getInt();
- xtea_buffer.get(); // machine info opcode 6
- xtea_buffer.get(); // os type
- xtea_buffer.get(); // 64 bit
- xtea_buffer.get(); // os version
- xtea_buffer.get(); // vendor
- xtea_buffer.get(); // major
- xtea_buffer.get(); // minor
- xtea_buffer.get(); // patchcant type anything
- xtea_buffer.get(); // some flag
- xtea_buffer.getShort(); // max memory
- xtea_buffer.get();
- xtea_buffer.get();
- xtea_buffer.getShort();
- xtea_buffer.getShort();
- ByteBufferUtils.getJagString(xtea_buffer);
- ByteBufferUtils.getJagString(xtea_buffer);
- ByteBufferUtils.getJagString(xtea_buffer);
- ByteBufferUtils.getJagString(xtea_buffer);
- xtea_buffer.get();
- xtea_buffer.getShort();
- ByteBufferUtils.getJagString(xtea_buffer);
- ByteBufferUtils.getJagString(xtea_buffer);
- xtea_buffer.get();
- xtea_buffer.get();
- xtea_buffer.getInt();
- xtea_buffer.getInt();
- xtea_buffer.getInt();
- xtea_buffer.getInt();
- int sessionToken2 = xtea_buffer.get();
- xtea_buffer.getShort(); //mobile OS
- int crcBlock = xtea_buffer.getInt();
- final int[] clientCRC = new int[18];
- final int[] serverCRC = new int[18];
- for (int i = 0; i < 18; i++) {
- clientCRC[i] = xtea_buffer.getInt();
- serverCRC[i] = Cache.getIndexes()[i] == null ? 0 : Cache.getIndexes()[i].getInformation().getInformationContainer().getCrc();
- }
- ISAACCipher inCipher = new ISAACCipher(xtea);
- for (int i = 0; i < 4; i++) {
- xtea[i] += 50;
- }
- ISAACCipher outCipher = new ISAACCipher(xtea);
- session.setIsaacPair(new ISAACPair(inCipher, outCipher));
- DisplayMode mode = DisplayMode.FIXED_MODE;
- if(windowMode >= 1)
- {
- mode = DisplayMode.values()[windowMode-1];
- }
- final PlayerDetails details = new PlayerDetails(username, null, session, mode);
- details.setClientInfo(new ClientInfo(width, height));
- final ByteBuffer b = xtea_buffer;
- /*if (info != 2) {
- session.write(Response.INVALID_CREDENTIALS, true);
- return;
- } else {
- login(details, username, password, session, b, opcode);
- }*/
- login(details, username, password, session, b, opcode);
- }
- /**
- * Handles the login procedure after we check an acc is registered.
- *
- * @param username the username.
- * @param password the password.
- * @param session the session.
- * @param buffer the byte buffer.
- * @param opcode the opcode.
- */
- private static void login(final PlayerDetails details, String username, String password, IoSession session, ByteBuffer buffer, int opcode) {
- LoginParser parser = new LoginParser(details, password, new UIDInfo(session.getAddress(), "none", "none", "none"), LoginType.fromType(opcode));
- TaskExecutor.execute(parser);
- }
- /**
- * Gets the ISAAC seed from the buffer.
- *
- * @param buffer The buffer to read from.
- * @return The ISAAC seed.
- */
- public static int[] getISAACSeed(ByteBuffer buffer) {
- int[] seed = new int[4];
- for (int i = 0; i < 4; i++) {
- seed[i] = buffer.getInt();
- }
- return seed;
- }
- /**
- * Gets the RSA block buffer.
- *
- * @param buffer The buffer to get the RSA block from.
- * @return The RSA block buffer.
- */
- public static ByteBuffer getRSABlock(ByteBuffer buffer) {
- byte[] rsaData = new byte[buffer.getShort()];
- buffer.get(rsaData);
- ByteBuffer block = ByteBuffer.wrap(new BigInteger(rsaData).modPow(RSA_KEY, MODULUS).toByteArray());
- int num = block.get();
- if (num != 1) {
- throw new IllegalArgumentException("Invalid RSA Magic Number " + num + "!");
- }
- return block;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement