Post your RS2LoginProtocolDecoder and your client its login block (Login function).
|
I tried to follow this tutorial - http://www.rune-server.org/runescape...t-clients.html
When I came across
long clientSessionKey = in.getLong();
long serverSessionKey = in.getLong();
I didn't have that, but I did have
final long clientSessionKey = rsaBuffer.getLong();
final long serverSessionKey = rsaBuffer.getLong();
But I still continued the tutorial. But after I finished it and tried to login, it won't let me login. Why?
Post your RS2LoginProtocolDecoder and your client its login block (Login function).
I have taken out the parts from the tutorial for better representation. What else do you need?
Code:public class RS2LoginProtocolDecoder extends CumulativeProtocolDecoder { private static final BigInteger RSA_MODULUS = new BigInteger( "numbers here"); private static final BigInteger RSA_EXPONENT = new BigInteger( "numbers here"); private synchronized static void load(final IoSession session, final int uid, String name, String pass, final ISAACRandomGen inC, final ISAACRandomGen outC, final int version) { session.setAttribute("opcode", -1); session.setAttribute("size", -1); String hostName = ((InetSocketAddress) session.getRemoteAddress()).getAddress().getHostName(); if(HostBlacklist.isBlocked(hostName)); final int loginDelay = 1; int returnCode = 2; name = name.trim(); name = name.toLowerCase(); pass = pass.toLowerCase(); if (!name.matches("[A-Za-z0-9 ]+")) { returnCode = 4; } if (name.length() > 12) { returnCode = 8; } final Player cl = new Player(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; final 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 (Config.CLIENT_VERSION != version) { // returnCode = 6; // } if (PlayerHandler.playerCount >= Config.MAX_PLAYERS) { returnCode = 7; } // Login Limit Exceeded // if() { // returnCode = 9; // } if (Server.UpdateServer) { returnCode = 14; } /* * if(Connection.isUidBanned(UUID)) { returnCode = 22; } */ // if(Connection.checkLoginList(loginIp)) { // returnCode = 16; // } // Just Left World Login Delay Included // if() { // returnCode = 21; // } if (returnCode == 2) { final 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; final game.net.packets.StaticPacketBuilder bldr = new game.net.packets.StaticPacketBuilder(); bldr.setBare(true); bldr.addByte((byte) returnCode); if (returnCode == 2) { cl.saveCharacter = true; /* * if (cl.playerRights == 1) { bldr.addByte((byte) 1); } else if * (cl.playerRights == 2) { bldr.addByte((byte) 2); } else if * (cl.playerRights == 5) { bldr.addByte((byte) 5); } else if * (cl.playerRights == 6) { bldr.addByte((byte) 6); } else { */ bldr.addByte((byte) cl.playerRights); // } // cl.playerServer = "riotscape.no-ip.info"; } else if (returnCode == 21) { bldr.addByte((byte) loginDelay); } else { bldr.addByte((byte) 0); } cl.isActive = true; bldr.addByte((byte) 0); final Packet pkt = bldr.toPacket(); session.setAttachment(cl); session.write(pkt).addListener(new IoFutureListener() { @Override public void operationComplete(final IoFuture arg0) { session.getFilterChain().remove("protocolFilter"); session.getFilterChain().addFirst("protocolFilter", new ProtocolCodecFilter(new GameCodecFactory(inC))); } }); } private synchronized static String readRS2String(final ByteBuffer in) { final 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. * * @param session * The session for which to release the buffer * @throws Exception * if failed to dispose all resources */ @Override public void dispose(final IoSession session) throws Exception { super.dispose(session); } /** * Parses the data in the provided byte buffer and writes it to * <code>out</code> as a <code>Packet</code>. * * @param session * The IoSession the data was read from * @param in * The buffer * @param out * The decoder output stream to which to write the * <code>Packet</code> * @return Whether enough data was available to create a packet */ @Override public boolean doDecode(final IoSession session, final ByteBuffer in, final ProtocolDecoderOutput out) { synchronized (session) { final 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()) { final int protocol = in.get() & 0xff; @SuppressWarnings("unused") final int nameHash = in.get() & 0xff; if (protocol == 14) { final long serverSessionKey = ((long) (java.lang.Math .random() * 99999999D) << 32) + (long) (java.lang.Math.random() * 99999999D); final game.net.packets.StaticPacketBuilder s1Response = new game.net.packets.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: @SuppressWarnings("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()) { final int magic = in.get() & 0xff; final int version = in.getUnsignedShort(); if (magic != 255) { // System.out.println("Wrong magic id."); session.close(); return false; } if (version != 1) { // Dont Add Anything } @SuppressWarnings("unused") final 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; } 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; } final long clientSessionKey = rsaBuffer.getLong(); final long serverSessionKey = rsaBuffer.getLong(); final int uid = rsaBuffer.getInt(); /* * int uid = in.getInt(); if(uid != numbers here) { * session.close(); return false; } */ // UUID = readRS2String(rsaBuffer); final String name = RS2LoginProtocolDecoder .readRS2String(rsaBuffer); final String pass = RS2LoginProtocolDecoder .readRS2String(rsaBuffer); final int sessionKey[] = new int[4]; sessionKey[0] = (int) (clientSessionKey >> 32); sessionKey[1] = (int) clientSessionKey; sessionKey[2] = (int) (serverSessionKey >> 32); sessionKey[3] = (int) serverSessionKey; final ISAACRandomGen inC = new ISAACRandomGen(sessionKey); for (int i = 0; i < 4; i++) { sessionKey[i] += 50; } final ISAACRandomGen outC = new ISAACRandomGen(sessionKey); RS2LoginProtocolDecoder.load(session, uid, name, pass, inC, outC, version); // WorkerThread.load(session, name, pass, inC, outC); session.getFilterChain().remove("protocolFilter"); session.getFilterChain().addLast("protocolFilter", new ProtocolCodecFilter(new GameCodecFactory(inC))); return true; } else { in.rewind(); return false; } } } return false; } }
Client its login block.
Code:private void login(String s, String s1, boolean flag) { SignLink.errorname = s; try { if (!flag) { loginMessage1 = ""; loginMessage2 = "Connecting to server..."; drawLoginScreen(true); } passwordstrength = false; socketStream = new RSSocket(this, openSocket(Configuration.serverPort + portOff)); long l = TextClass.longForName(s); int i = (int) (l >> 16 & 31L); stream.currentOffset = 0; stream.writeWordBigEndian(14); stream.writeWordBigEndian(i); socketStream.queueBytes(2, stream.buffer); for (int j = 0; j < 8; j++) socketStream.read(); int k = socketStream.read(); int i1 = k; if (k == 0) { socketStream.flushInputStream(inStream.buffer, 8); inStream.currentOffset = 0; aLong1215 = inStream.readQWord(); int ai[] = new int[4]; ai[0] = (int) (Math.random() * 99999999D); ai[1] = (int) (Math.random() * 99999999D); ai[2] = (int) (aLong1215 >> 32); ai[3] = (int) aLong1215; stream.currentOffset = 0; stream.writeWordBigEndian(10); stream.writeDWord(ai[0]); stream.writeDWord(ai[1]); stream.writeDWord(ai[2]); stream.writeDWord(ai[3]); stream.writeDWord(SignLink.uid); stream.writeString(s); stream.writeString(s1); stream.doKeys(); aStream_847.currentOffset = 0; if (flag) aStream_847.writeWordBigEndian(18); else aStream_847.writeWordBigEndian(16); aStream_847.writeWordBigEndian(stream.currentOffset + 36 + 1 + 1 + 2); aStream_847.writeWordBigEndian(255); aStream_847.writeWord(317); aStream_847.writeWordBigEndian(lowMem ? 1 : 0); for (int l1 = 0; l1 < 9; l1++) aStream_847.writeDWord(expectedCRCs[l1]); aStream_847.writeBytes(stream.buffer, stream.currentOffset, 0); stream.encryption = new ISAACRandomGen(ai); for (int j2 = 0; j2 < 4; j2++) ai[j2] += 50; encryption = new ISAACRandomGen(ai); socketStream.queueBytes(aStream_847.currentOffset, aStream_847.buffer); k = socketStream.read(); } if (k == 1) { try { Thread.sleep(2000L); } catch (Exception _ex) { } login(s, s1, flag); return; } if (k == 2) { myPrivilege = socketStream.read(); flagged = socketStream.read() == 1; aLong1220 = 0L; anInt1022 = 0; mouseDetection.coordsIndex = 0; super.awtFocus = true; aBoolean954 = true; loggedIn = true; stream.currentOffset = 0; inStream.currentOffset = 0; pktType = -1; anInt841 = -1; anInt842 = -1; anInt843 = -1; pktSize = 0; anInt1009 = 0; anInt1104 = 0; anInt1011 = 0; anInt855 = 0; menuActionRow = 0; menuOpen = false; super.idleTime = 0; for (int j1 = 0; j1 < 100; j1++) chatMessages[j1] = null; itemSelected = 0; spellSelected = 0; loadingStage = 0; anInt1062 = 0; anInt1278 = (int) (Math.random() * 100D) - 50; anInt1131 = (int) (Math.random() * 110D) - 55; anInt896 = (int) (Math.random() * 80D) - 40; minimapInt2 = (int) (Math.random() * 120D) - 60; minimapInt3 = (int) (Math.random() * 30D) - 20; minimapInt1 = (int) (Math.random() * 20D) - 10 & 0x7ff; anInt1021 = 0; anInt985 = -1; destX = 0; destY = 0; playerCount = 0; npcCount = 0; for (int i2 = 0; i2 < maxPlayers; i2++) { playerArray[i2] = null; aStreamArray895s[i2] = null; } for (int k2 = 0; k2 < 16384; k2++) npcArray[k2] = null; myPlayer = playerArray[myPlayerIndex] = new Player(); aClass19_1013.removeAll(); aClass19_1056.removeAll(); for (int l2 = 0; l2 < 4; l2++) { for (int i3 = 0; i3 < 104; i3++) { for (int k3 = 0; k3 < 104; k3++) groundArray[l2][i3][k3] = null; } } aClass19_1179 = new NodeList(); fullscreenInterfaceID = -1; anInt900 = 0; friendsCount = 0; dialogID = -1; backDialogID = -1; openInterfaceID = -1; invOverlayInterfaceID = -1; anInt1018 = -1; aBoolean1149 = false; tabID = 3; inputDialogState = 0; menuOpen = false; messagePromptRaised = false; aString844 = null; anInt1055 = 0; anInt1054 = -1; aBoolean1047 = true; method45(); for (int j3 = 0; j3 < 5; j3++) anIntArray990[j3] = 0; for (int l3 = 0; l3 < 5; l3++) { atPlayerActions[l3] = null; atPlayerArray[l3] = false; } anInt1175 = 0; anInt1134 = 0; anInt986 = 0; anInt1288 = 0; anInt924 = 0; anInt1188 = 0; anInt1155 = 0; anInt1226 = 0; resetImageProducers2(); return; } if (k == 3) { loginMessage1 = ""; loginMessage2 = "Invalid username or password."; // mp3.play(); return; } if (k == 4) { loginMessage1 = "Your account has been disabled."; loginMessage2 = "Please check your message-center for details."; // mp3.play(); return; } if (k == 5) { loginMessage1 = "Your account is already logged in."; loginMessage2 = "Try again in 60 secs..."; // mp3.play(); return; } if (k == 6) { loginMessage1 = ""+ Configuration.serverName +" has been updated!"; loginMessage2 = "Please reload this page."; // mp3.play(); return; } if (k == 7) { loginMessage1 = "This world is full."; loginMessage2 = "Please use a different world."; // mp3.play(); return; } if (k == 8) { loginMessage1 = "Unable to connect."; loginMessage2 = "Login server offline."; // mp3.play(); return; } if (k == 9) { loginMessage1 = "Login limit exceeded."; loginMessage2 = "Too many connections from your address."; // mp3.play(); return; } if (k == 10) { loginMessage1 = "Unable to connect."; loginMessage2 = "Bad session id."; // mp3.play(); return; } if (k == 11) { loginMessage2 = "Login server rejected session."; loginMessage2 = "Please try again."; // mp3.play(); return; } if (k == 12) { loginMessage1 = "You need a members account to login to this world."; loginMessage2 = "Please subscribe, or use a different world."; // mp3.play(); return; } if (k == 13) { loginMessage1 = "Could not complete login."; loginMessage2 = "Please try using a different world."; // mp3.play(); return; } if (k == 14) { loginMessage1 = "The server is being updated."; loginMessage2 = "Please wait 1 minute and try again."; // mp3.play(); return; } if (k == 15) { // mp3.close(); loggedIn = true; stream.currentOffset = 0; inStream.currentOffset = 0; pktType = -1; anInt841 = -1; anInt842 = -1; anInt843 = -1; pktSize = 0; anInt1009 = 0; anInt1104 = 0; menuActionRow = 0; menuOpen = false; aLong824 = System.currentTimeMillis(); return; } if (k == 16) { loginMessage1 = "Login attempts exceeded."; loginMessage2 = "Please wait 1 minute and try again."; // mp3.play(); return; } if (k == 17) { loginMessage1 = "You are standing in a members-only area."; loginMessage2 = "To play on this world move to a free area first"; // mp3.play(); return; } if (k == 20) { loginMessage1 = "Invalid loginserver requested"; loginMessage2 = "Please try using a different world."; // mp3.play(); return; } if (k == 21) { for (int k1 = socketStream.read(); k1 >= 0; k1--) { loginMessage1 = "You have only just left another world"; loginMessage2 = "Your profile will be transferred in: " + k1 + " seconds"; drawLoginScreen(true); // mp3.play(); try { Thread.sleep(1000L); } catch (Exception _ex) { } } login(s, s1, flag); return; } if (k == 22) { loginMessage1 = "Your account has been disabled!"; loginMessage2 = "Please appeal on the forums."; return; } if (k == -1) { if (i1 == 0) { if (loginFailures < 2) { try { Thread.sleep(2000L); } catch (Exception _ex) { } loginFailures++; login(s, s1, flag); return; } else { loginMessage1 = "No response from loginserver"; loginMessage2 = "Please wait 1 minute and try again."; // mp3.play(); return; } } else { loginMessage1 = "No response from server"; loginMessage2 = "Please try using a different world."; // mp3.play(); return; } } else { System.out.println("response:" + k); loginMessage1 = "Unexpected server response"; loginMessage2 = "Please try using a different world."; // mp3.play(); return; } } catch (IOException _ex) { loginMessage1 = ""; } loginMessage2 = "Error connecting to server."; }
In your client login block move:
to just under 'stream.writeWordBigEndian(10);'Code:stream.writeDWord(SignLink.uid);
Then move:
belowCode:final int uid = rsaBuffer.getInt();
Code:if ((rsaBuffer.get() & 0xff) != 10) { System.out.println("Encrypted id != 10."); session.close(); return false; }
Compile, print it out and check if it works.
What is asking you to rename it? The compiler? Does it give a reason for it? Duplicated maybe because you didnt remove the older one?
The reason your crashing is because the client sends data to the server and the server matches up with that data. So if you start to add new things in the client its login block it needs to match up in the server its decoder else it will take a UID for example as a seed.
I dont understand why it asks you to rename, add it like I said and post your decoder again.
It says that there is a duplicate local variable uid (compiler says that, eclipse)
Also when I mark this out the duplicate goes away.
Code:public boolean doDecode(final IoSession session, final ByteBuffer in, final ProtocolDecoderOutput out) { synchronized (session) { final Object loginStageObj = session.getAttribute("LOGIN_STAGE"); int loginStage = 0; if (loginStageObj != null) { loginStage = (Integer) loginStageObj; } // Logger.log("recv login packet, stage: "+loginStage); switch (loginStage) {
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |