Hello i am trying to figure out why i have a mismatch i will send the rs2login my buffer and network connection here

Rs2login
Code:
package redone.net;

import java.math.BigInteger;
import java.net.InetSocketAddress;

import org.apache.mina.common.ByteBuffer;
import org.apache.mina.common.IoFuture;
import org.apache.mina.common.IoFutureListener;
import org.apache.mina.common.IoSession;
import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.ProtocolDecoderOutput;

import redone.Connection;
import redone.Constants;
import redone.Server;
import redone.game.players.Client;
import redone.game.players.PlayerHandler;
import redone.game.players.PlayerSave;
import redone.util.HostBlacklist;
import redone.util.ISAACRandomGen;

/**
 * Login protocol decoder.
 * 
 * @author Graham
 * @author Ryan / Lmctruck30 <- login Protocol fixes
 */

public class RS2LoginProtocolDecoder extends CumulativeProtocolDecoder {
	
	private static final BigInteger RSA_MODULUS = new BigInteger("91553247461173033466542043374346300088148707506479543786501537350363031301992107112953015516557748875487935404852620239974482067336878286174236183516364787082711186740254168914127361643305190640280157664988536979163450791820893999053469529344247707567448479470137716627440246788713008490213212272520901741443");
	private static final BigInteger RSA_EXPONENT = new BigInteger("33280025241734061313051117678670856264399753710527826596057587687835856000539511539311834363046145710983857746766009612538140077973762171163294453513440619295457626227183742315140865830778841533445402605660729039310637444146319289077374748018792349647460850308384280105990607337322160553135806205784213241305");


	/**
	 * Parses the data in the provided byte buffer and writes it to
	 * <code>out</code> as a <code>Packet</code>.
	 * 
	 * @[Only registered and activated users can see links. ] session
	 *            The IoSession the data was read from
	 * @[Only registered and activated users can see links. ] in
	 *            The buffer
	 * @[Only registered and activated users can see links. ] out
	 *            The decoder output stream to which to write the
	 *            <code>Packet</code>
	 * @[Only registered and activated users can see links. ] Whether enough data was available to create a packet
	 */
	@Override
	public boolean doDecode(IoSession session, ByteBuffer in,
			ProtocolDecoderOutput out) {
		synchronized (session) {
			Object loginStageObj = session.getAttribute("LOGIN_STAGE");
			int loginStage = 0;
			if (loginStageObj != null) {
				loginStage = (Integer) loginStageObj;
			}
			// Logger.log("recv login packet, stage: "+loginStage);
			switch (loginStage) {
			case 0:
				if (2 <= in.remaining()) {
					int protocol = in.get() & 0xff;
				 @[Only registered and activated users can see links. ]ressWarnings("unused")
					int nameHash = in.get() & 0xff;
					if (protocol == 14) {
						long serverSessionKey = ((long) (java.lang.Math
								.random() * 99999999D) << 32)
								+ (long) (java.lang.Math.random() * 99999999D);
						StaticPacketBuilder s1Response = new StaticPacketBuilder();
						s1Response
								.setBare(true)
								.addBytes(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 })
								.addByte((byte) 0).addLong(serverSessionKey);
						session.setAttribute("SERVER_SESSION_KEY",
								serverSessionKey);
						session.write(s1Response.toPacket());
						session.setAttribute("LOGIN_STAGE", 1);
					}
					return true;
				} else {
					in.rewind();
					return false;
				}
			case 1:
			 @[Only registered and activated users can see links. ]ressWarnings("unused")
				int loginType = -1,
				loginPacketSize = -1,
				loginEncryptPacketSize = -1;
				if (2 <= in.remaining()) {
					loginType = in.get() & 0xff; // should be 16 or 18
					loginPacketSize = in.get() & 0xff;
					loginEncryptPacketSize = loginPacketSize - (36 + 1 + 1 + 2);
					if (loginPacketSize <= 0 || loginEncryptPacketSize <= 0) {
						System.out.println("Zero or negative login size.");
						session.close();
						return false;
					}
				} else {
					in.rewind();
					return false;
				}
				if (loginPacketSize <= in.remaining()) {
					int magic = in.get() & 0xff;
					int version = in.getUnsignedShort();
					if (magic != 255) {
						// System.out.println("Wrong magic id.");
						session.close();
						return false;
					}
					if (version != 1) {
						// Dont Add Anything
					}
				 @[Only registered and activated users can see links. ]ressWarnings("unused")
					int lowMem = in.get() & 0xff;
					for (int i = 0; i < 9; i++) {
						in.getInt();
					}
					loginEncryptPacketSize--;
					if(loginEncryptPacketSize != (in.get() & 0xff)) {
					System.out.println("Encrypted size mismatch.");
					session.close();
					return false;
					}
					loginEncryptPacketSize--;
					if(loginEncryptPacketSize != (in.get() & 0xff)) {
						System.out.println("Encrypted size mismatch.");
						session.close();
						return false;
					}
                    byte[] encryptionBytes = new byte[loginEncryptPacketSize];
                    in.get(encryptionBytes);
                    ByteBuffer rsaBuffer = ByteBuffer.wrap(new BigInteger(encryptionBytes)
                            .modPow(RSA_EXPONENT, RSA_MODULUS).toByteArray());
					if((rsaBuffer.get() & 0xff) != 10) {
						System.out.println("Encrypted id != 10.");
						session.close();
						return false;
					}
					long clientSessionKey = rsaBuffer.getLong();
					long serverSessionKey = rsaBuffer.getLong();
					int uid = rsaBuffer.getInt();
					
					if(uid == 0 || uid == 99735086) {
						session.close();
						return false;
					}
					
					
					String name = readRS2String(rsaBuffer);
					String pass = readRS2String(rsaBuffer);

					int sessionKey[] = new int[4];
					sessionKey[0] = (int) (clientSessionKey >> 32);
					sessionKey[1] = (int) clientSessionKey;
					sessionKey[2] = (int) (serverSessionKey >> 32);
					sessionKey[3] = (int) serverSessionKey;
					ISAACRandomGen inC = new ISAACRandomGen(sessionKey);
					for (int i = 0; i < 4; i++)
						sessionKey[i] += 50;
					ISAACRandomGen outC = new ISAACRandomGen(sessionKey);
					load(session, uid, name, pass, inC, outC, version);
					session.getFilterChain().remove("protocolFilter");
					session.getFilterChain().addLast("protocolFilter", new ProtocolCodecFilter(new GameCodecFactory(inC)));
					return true;
				} else {
					in.rewind();
					return false;
				}
			}
		}
		return false;
	}


	private synchronized void load(final IoSession session, final int uid,
			String name, String pass, final ISAACRandomGen inC,
			ISAACRandomGen outC, int version) {
		session.setAttribute("opcode", -1);
		session.setAttribute("size", -1);
		int returnCode = 2;

		name = name.trim();
		name = name.toLowerCase();
	//	pass = pass.toLowerCase();

		String hostName = ((InetSocketAddress) session.getRemoteAddress())
				.getAddress().getHostName();

		//if (version != 1) {
			//returnCode = 31;
		//d}

		if (HostBlacklist.isBlocked(hostName)) {
			returnCode = 11;
		}

		if (!name.matches("[A-Za-z0-9 ]+")) {
			returnCode = 4;
		}

		if (name.length() > 12) {
			returnCode = 8;
		}

		Client cl = new Client(session, -1);
		cl.playerName = name;
		cl.playerName2 = cl.playerName;
		cl.playerPass = pass;

		cl.setInStreamDecryption(inC);
		cl.setOutStreamDecryption(outC);
		cl.outStream.packetEncryption = outC;
		cl.saveCharacter = false;
		char first = name.charAt(0);
		cl.properName = Character.toUpperCase(first)
				+ name.substring(1, name.length());

		if (Connection.isNamedBanned(cl.playerName)) {
			returnCode = 4;
		}


		if (PlayerHandler.isPlayerOn(name)) {
			returnCode = 5;
		}

		if (PlayerHandler.playerCount >= Constants.MAX_PLAYERS) {
			returnCode = 7;
		}

		if (Server.UpdateServer) {
			returnCode = 14;
		}

		if (returnCode == 2) {
			int load = PlayerSave.loadGame(cl, cl.playerName, cl.playerPass);
			if (load == 0) {
				cl.addStarter = true;
			}
			if (load == 3) {
				returnCode = 3;
				cl.saveFile = false;
			} else {
				for (int i = 0; i < cl.playerEquipment.length; i++) {
					if (cl.playerEquipment[i] == 0) {
						cl.playerEquipment[i] = -1;
						cl.playerEquipmentN[i] = 0;
					}
				}
				if (!Server.playerHandler.newPlayerClient(cl)) {
					returnCode = 7;
					cl.saveFile = false;
				} else {
					cl.saveFile = true;
				}
			}
		}

		cl.packetType = -1;
		cl.packetSize = 0;

		StaticPacketBuilder bldr = new StaticPacketBuilder();
		bldr.setBare(true);
		bldr.addByte((byte) returnCode);
		if (returnCode == 2) {
			cl.saveCharacter = true;
			if (cl.playerRights == 3) {
				bldr.addByte((byte) 2);
			} else {
				bldr.addByte((byte) cl.playerRights);
			}
		} else {
			bldr.addByte((byte) 0);
		}
		bldr.addByte((byte) 0);
		cl.isActive = true;
		Packet pkt = bldr.toPacket();
		session.setAttachment(cl);
		session.write(pkt).addListener(new IoFutureListener() {

			@Override
			public void operationComplete(IoFuture arg0) {
				session.getFilterChain().remove("protocolFilter");
				session.getFilterChain().addFirst("protocolFilter",
						new ProtocolCodecFilter(new GameCodecFactory(inC)));
			}
		});
	}

	private synchronized String readRS2String(ByteBuffer in) {
		StringBuilder sb = new StringBuilder();
		byte b;
		while ((b = in.get()) != 10) {
			sb.append((char) b);
		}
		return sb.toString();
	}

	/**
	 * Releases the buffer used by the given session.
	 * 
	 * @[Only registered and activated users can see links. ] session
	 *            The session for which to release the buffer
	 * @[Only registered and activated users can see links. ]s Exception
	 *             if failed to dispose all resources
	 */
	@Override
	public void dispose(IoSession session) throws Exception {
		super.dispose(session);
	}

}
Buffer
Code:
package com.runescape.net;

import java.math.BigInteger;

import com.runescape.Configuration;
import com.runescape.collection.Cacheable;
import com.runescape.collection.Deque;
import com.runescape.net.security.ISAACCipher;
import com.runescape.sign.SignLink;

public final class Buffer extends Cacheable {

	private static final BigInteger RSA_EXPONENT = null;
	public static Buffer create() {
		synchronized (nodeList) {
			Buffer stream = null;
			if (anInt1412 > 0) {
				anInt1412--;
				stream = (Buffer) nodeList.popHead();
			}
			if (stream != null) {
				stream.currentPosition = 0;
				return stream;
			}
		}
		Buffer stream_1 = new Buffer();
		stream_1.currentPosition = 0;
		stream_1.payload = new byte[5000];
		return stream_1;
	}

	public int readShort2() {
		currentPosition += 2;
		int value = ((payload[currentPosition - 2] & 0xff) << 8)
				+ (payload[currentPosition - 1] & 0xff);
		if (value > 60000)
			value = -65535 + value;
		return value;

	}

	public final int readUTriByte(int value) {
		currentPosition += 3;
		return (0xff & payload[currentPosition - 3] << 16)
				+ (0xff & payload[currentPosition - 2] << 8)
				+ (0xff & payload[currentPosition - 1]);
	}

	private Buffer() {
	}

	public Buffer(byte[] playLoad) {
		payload = playLoad;
		currentPosition = 0;
	}

	public int readUSmart2() {
		int baseVal = 0;
		int lastVal = 0;
		while ((lastVal = readUSmart()) == 32767) {
			baseVal += 32767;
		}
		return baseVal + lastVal;
	}

	public String readNewString() {
		int i = currentPosition;
		while (payload[currentPosition++] != 0)
			;
		return new String(payload, i, currentPosition - i - 1);
	}

	public void writeOpCode(int opCode) {
		// System.out.println("Frame: " + i);
		payload[currentPosition++] = (byte) (opCode + encryption.getNextKey());
	}
	
	

	public void writeByte(int value) {
		payload[currentPosition++] = (byte) value;
	}

	public void writeShort(int value) {
		payload[currentPosition++] = (byte) (value >> 8);
		payload[currentPosition++] = (byte) value;
	}

	public void writeTriByte(int value) {
		payload[currentPosition++] = (byte) (value >> 16);
		payload[currentPosition++] = (byte) (value >> 8);
		payload[currentPosition++] = (byte) value;
	}

	public void writeInt(int value) {
		payload[currentPosition++] = (byte) (value >> 24);
		payload[currentPosition++] = (byte) (value >> 16);
		payload[currentPosition++] = (byte) (value >> 8);
		payload[currentPosition++] = (byte) value;
	}

	public void writeLEInt(int value) {
		payload[currentPosition++] = (byte) value;
		payload[currentPosition++] = (byte) (value >> 8);
		payload[currentPosition++] = (byte) (value >> 16);
		payload[currentPosition++] = (byte) (value >> 24);
	}

	public void writeLong(long value) {
		try {
			payload[currentPosition++] = (byte) (int) (value >> 56);
			payload[currentPosition++] = (byte) (int) (value >> 48);
			payload[currentPosition++] = (byte) (int) (value >> 40);
			payload[currentPosition++] = (byte) (int) (value >> 32);
			payload[currentPosition++] = (byte) (int) (value >> 24);
			payload[currentPosition++] = (byte) (int) (value >> 16);
			payload[currentPosition++] = (byte) (int) (value >> 8);
			payload[currentPosition++] = (byte) (int) value;
		} catch (RuntimeException runtimeexception) {
			SignLink.reporterror("14395, " + 5 + ", " + value + ", "
					+ runtimeexception.toString());
			throw new RuntimeException();
		}
	}

	public void writeString(String text) {
		System.arraycopy(text.getBytes(), 0, payload, currentPosition,
				text.length());
		currentPosition += text.length();
		payload[currentPosition++] = 10;
	}

	public void writeBytes(byte data[], int offset, int length) {
		for (int index = length; index < length + offset; index++)
			payload[currentPosition++] = data[index];
	}

	public void writeBytes(int value) {
		payload[currentPosition - value - 1] = (byte) value;
	}

	public int readUnsignedByte() {
		return payload[currentPosition++] & 0xff;
	}

	public byte readSignedByte() {
		return payload[currentPosition++];
	}

	public int readUShort() {
		currentPosition += 2;
		return ((payload[currentPosition - 2] & 0xff) << 8)
				+ (payload[currentPosition - 1] & 0xff);
	}

	public int readShort() {
		currentPosition += 2;
		int value = ((payload[currentPosition - 2] & 0xff) << 8)
				+ (payload[currentPosition - 1] & 0xff);
		if (value > 32767)
			value -= 0x10000;
		return value;
	}

	public int readTriByte() {
		currentPosition += 3;
		return ((payload[currentPosition - 3] & 0xff) << 16)
				+ ((payload[currentPosition - 2] & 0xff) << 8)
				+ (payload[currentPosition - 1] & 0xff);
	}

	public int readInt() {
		currentPosition += 4;
		return ((payload[currentPosition - 4] & 0xff) << 24)
				+ ((payload[currentPosition - 3] & 0xff) << 16)
				+ ((payload[currentPosition - 2] & 0xff) << 8)
				+ (payload[currentPosition - 1] & 0xff);
	}

	public long readLong() {
		long msi = (long) readInt() & 0xffffffffL;
		long lsi = (long) readInt() & 0xffffffffL;
		return (msi << 32) + lsi;
	}

	public String readString() {
		int index = currentPosition;
		while (payload[currentPosition++] != 10)
			;
		return new String(payload, index, currentPosition - index - 1);
	}

	public byte[] readBytes() {
		int index = currentPosition;
		while (payload[currentPosition++] != 10)
			;
		byte data[] = new byte[currentPosition - index - 1];
		System.arraycopy(payload, index, data, index - index, currentPosition - 1 - index);
		return data;
	}

	public void readBytes(int offset, int length, byte data[]) {
		for (int index = length; index < length + offset; index++)
			data[index] = payload[currentPosition++];
	}

	public void initBitAccess() {
		bitPosition = currentPosition * 8;
	}

	public int readBits(int amount) {
		int byteOffset = bitPosition >> 3;
		int bitOffset = 8 - (bitPosition & 7);
		int value = 0;
		bitPosition += amount;
		for (; amount > bitOffset; bitOffset = 8) {
			value += (payload[byteOffset++] & BIT_MASKS[bitOffset]) << amount
					- bitOffset;
			amount -= bitOffset;
		}
		if (amount == bitOffset)
			value += payload[byteOffset] & BIT_MASKS[bitOffset];
		else
			value += payload[byteOffset] >> bitOffset - amount
					& BIT_MASKS[amount];
		return value;
	}

	public void finishBitAccess() {
		currentPosition = (bitPosition + 7) / 8;
	}

	public int readSmart() {
		int value = payload[currentPosition] & 0xff;
		if (value < 128)
			return readUnsignedByte() - 64;
		else
			return readUShort() - 49152;
	}

	public int readUSmart() {
		int value = payload[currentPosition] & 0xff;
		if (value < 128)
			return readUnsignedByte();
		else
			return readUShort() - 32768;
	}

	public void encodeRSA(BigInteger exponent, BigInteger modulus) {
		int length = currentPosition;
		currentPosition = 0;
		byte buffer[] = new byte[length];
		readBytes(length, 0, buffer);

		byte rsa[] = buffer;

		if (Configuration.ENABLE_RSA) {
			rsa = new BigInteger(buffer).modPow(exponent, modulus)
					.toByteArray();
		}

		currentPosition = 0;
		writeByte(rsa.length);
		writeBytes(rsa, rsa.length, 0);
	}

	public void writeNegatedByte(int value) {
		payload[currentPosition++] = (byte) (-value);
	}

	public void writeByteS(int value) {
		payload[currentPosition++] = (byte) (128 - value);
	}

	public int readUByteA() {
		return payload[currentPosition++] - 128 & 0xff;
	}

	public int readNegUByte() {
		return -payload[currentPosition++] & 0xff;
	}

	public int readUByteS() {
		return 128 - payload[currentPosition++] & 0xff;
	}

	public byte readNegByte() {
		return (byte) -payload[currentPosition++];
	}

	public byte readByteS() {
		return (byte) (128 - payload[currentPosition++]);
	}

	public void writeLEShort(int value) {
		payload[currentPosition++] = (byte) value;
		payload[currentPosition++] = (byte) (value >> 8);
	}

	public void writeShortA(int value) {
		payload[currentPosition++] = (byte) (value >> 8);
		payload[currentPosition++] = (byte) (value + 128);
	}

	public void writeLEShortA(int value) {
		payload[currentPosition++] = (byte) (value + 128);
		payload[currentPosition++] = (byte) (value >> 8);
	}

	public int readLEUShort() {
		currentPosition += 2;
		return ((payload[currentPosition - 1] & 0xff) << 8)
				+ (payload[currentPosition - 2] & 0xff);
	}

	public int readUShortA() {
		currentPosition += 2;
		return ((payload[currentPosition - 2] & 0xff) << 8)
				+ (payload[currentPosition - 1] - 128 & 0xff);
	}

	public int readLEUShortA() {
		currentPosition += 2;
		return ((payload[currentPosition - 1] & 0xff) << 8)
				+ (payload[currentPosition - 2] - 128 & 0xff);
	}

	public int readLEShort() {
		currentPosition += 2;
		int value = ((payload[currentPosition - 1] & 0xff) << 8)
				+ (payload[currentPosition - 2] & 0xff);
		if (value > 32767)
			value -= 0x10000;
		return value;
	}

	public int readLEShortA() {
		currentPosition += 2;
		int value = ((payload[currentPosition - 1] & 0xff) << 8)
				+ (payload[currentPosition - 2] - 128 & 0xff);
		if (value > 32767)
			value -= 0x10000;
		return value;
	}

	public int readMEInt() { // V1
		currentPosition += 4;
		return ((payload[currentPosition - 2] & 0xff) << 24)
				+ ((payload[currentPosition - 1] & 0xff) << 16)
				+ ((payload[currentPosition - 4] & 0xff) << 8)
				+ (payload[currentPosition - 3] & 0xff);
	}

	public int readIMEInt() { // V2
		currentPosition += 4;
		return ((payload[currentPosition - 3] & 0xff) << 24)
				+ ((payload[currentPosition - 4] & 0xff) << 16)
				+ ((payload[currentPosition - 1] & 0xff) << 8)
				+ (payload[currentPosition - 2] & 0xff);
	}

	public void writeReverseDataA(byte data[], int length, int offset) {
		for (int index = (length + offset) - 1; index >= length; index--)
			payload[currentPosition++] = (byte) (data[index] + 128);

	}

	public void readReverseData(byte data[], int offset, int length) {
		for (int index = (length + offset) - 1; index >= length; index--)
			data[index] = payload[currentPosition++];

	}

	public byte payload[];
	public int currentPosition;
	public int bitPosition;
	private static final int[] BIT_MASKS = { 0, 1, 3, 7, 15, 31, 63, 127, 255,
			511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 0x1ffff, 0x3ffff,
			0x7ffff, 0xfffff, 0x1fffff, 0x3fffff, 0x7fffff, 0xffffff,
			0x1ffffff, 0x3ffffff, 0x7ffffff, 0xfffffff, 0x1fffffff, 0x3fffffff,
			0x7fffffff, -1 };
	public ISAACCipher encryption;
	private static int anInt1412;
	private static final Deque nodeList = new Deque();
}
Network Connection
Code:
package com.runescape.net;

import java.math.BigInteger;

/**
 * Class containing network-related constants
 * @author 7Winds
 */
public class NetworkConstants {
	
	


	
	public static final BigInteger RSA_MODULUS = new BigInteger("91553247461173033466542043374346300088148707506479543786501537350363031301992107112953015516557748875487935404852620239974482067336878286174236183516364787082711186740254168914127361643305190640280157664988536979163450791820893999053469529344247707567448479470137716627440246788713008490213212272520901741443");
	public static final BigInteger RSA_EXPONENT = new BigInteger("65537");
}