Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- final Player player = RSChannelHandler.get(channel);
- if(player != null) {
- switch(loginState) {
- case OPCODE:
- if(buffer.readableBytes() >= 2) {
- final int opcode = buffer.readByte() & 0xFF;
- if(opcode != 14) {
- player.disconnect();
- throw new IllegalStateException("Invalid request '" + opcode + "', 14 was expected.");
- }
- @SuppressWarnings("unused")
- final int hash = buffer.readByte() & 0xFF;
- player.write(new MessageBuilder().put(INITIAL_RESPONSE).putByte(0).putLong(random.nextLong()));
- checkpoint(LoginState.DETAILS);
- }
- break;
- case DETAILS:
- final int opcode = buffer.readByte();
- if (opcode != 16 && opcode != 18) {
- player.disconnect();
- throw new IllegalStateException("Invalid logintype '" + opcode + "', 16 or 18 was expected.");
- }
- final int loginPacketSize = buffer.readByte();
- final int loginEncryptPacketSize = loginPacketSize - 41;
- if (loginEncryptPacketSize <= 0) {
- player.disconnect();
- throw new IllegalStateException("Invalid RSA packet size '" + loginEncryptPacketSize + "'");
- }
- final int magicId = buffer.readByte() & 0xFF;
- if (magicId != 255) {
- player.disconnect();
- throw new IllegalStateException("Invalid magic id '" + magicId + "', 255 was expected.");
- }
- final int versionId = buffer.readShort();
- if(versionId != 317) {
- player.disconnect();
- throw new IllegalStateException("Invalid client version '" + versionId + "', 289 was expected.");
- }
- @SuppressWarnings("unused")
- final int lowMemoryVersion = buffer.readByte();
- for (int i = 0; i < 9; i++) {
- Integer.toHexString(buffer.readInt());
- }
- final int length = buffer.readByte() & 0xFF;
- if(length < loginEncryptPacketSize) {
- player.disconnect();
- throw new IllegalStateException("Invalid login encrypted '" + length + "', " + loginEncryptPacketSize + " was expected.");
- }
- int tmp = buffer.readByte();
- if (tmp != 10) {
- player.disconnect();
- throw new IllegalStateException("Invalid login opcode '" + tmp + "', 10 was expected.");
- }
- final long clientSessionKey = buffer.readLong();
- final long serverSessionKey = buffer.readLong();
- @SuppressWarnings("unused")
- final int uid = buffer.readInt();
- final String username = ChannelBufferUtils.readRS2String(buffer);
- final String password = ChannelBufferUtils.readRS2String(buffer);
- if(username == null || username.length() == 0) {
- player.debug("Invalid username, dropping connection.");
- player.disconnect();
- throw new IllegalStateException("Invalid username '" + username + "'.");
- }
- player.setUsername(username);
- player.setPassword(password);
- final int sessionKey[] = new int[4];
- sessionKey[0] = (int) (clientSessionKey >> 32);
- sessionKey[1] = (int) clientSessionKey;
- sessionKey[2] = (int) (serverSessionKey >> 32);
- sessionKey[3] = (int) serverSessionKey;
Add Comment
Please, Sign In to add comment