[[Category RSC]] This page refers to the RSC #135 client revision. == '''Packet structure''' == ? == '''Login''' == (The login protocol documentation is currently a work in progress. Below you will find a partially refactored version of the login method found in the 135 client.)
try {
			username = user;
			user = jagex.Util.formatString(user, 20);
			password = pass;
			pass = jagex.Util.formatString(pass, 20);
			if (user.trim().length() == 0) {
				drawMessage(messageTable[0], messageTable[1]);
				return;
			}
			if (reconnecting)
				d(messageTable[2], messageTable[3]);
			else
				drawMessage(messageTable[6], messageTable[7]);
			if (appletStarted())
				stream = new SocketStream(host, this, port);
			else
				stream = new SocketStream(host, null, port);
			stream.oe = xc;
			int ssk = stream.readInt32();
			serverSessionID = ssk;
			System.out.println("Session id: " + ssk);
			if (reconnecting)
				stream.beginFrame(19);
			else
				stream.beginFrame(0);
			stream.putInt16(wc);
			stream.putInt64(jagex.Util.longForName(user));
			stream.putLineRSA(pass, ssk, pd, qd);
			stream.putInt32(getSessionID());
			stream.flush();
			stream.read();
			int response = stream.read();
			System.out.println("Login response: " + response);
			if (response == 0) {
				ed = 0;
				e_();
				return;
			}
			if (response == 1) {
				ed = 0;
				a();
				return;
			}
			if (reconnecting) {
				user = "";
				pass = "";
				f();
				return;
			}
			if (response == 3) {
				drawMessage(messageTable[10], messageTable[11]);
				return;
			}
			if (response == 4) {
				drawMessage(messageTable[4], messageTable[5]);
				return;
			}
			if (response == 5) {
				drawMessage(messageTable[16], messageTable[17]);
				return;
			}
			if (response == 6) {
				drawMessage(messageTable[18], messageTable[19]);
				return;
			}
			if (response == 7) {
				drawMessage(messageTable[20], messageTable[21]);
				return;
			}
			if (response == 11) {
				drawMessage(messageTable[22], messageTable[23]);
				return;
			}
			if (response == 12) {
				drawMessage(messageTable[24], messageTable[25]);
				return;
			}
			if (response == 13) {
				drawMessage(messageTable[14], messageTable[15]);
				return;
			}
			if (response == 14) {
				drawMessage(messageTable[8], messageTable[9]);
				sd = 1500;
				return;
			}
			if (response == 15) {
				drawMessage(messageTable[26], messageTable[27]);
				return;
			}
			if (response == 16) {
				drawMessage(messageTable[28], messageTable[29]);
				return;
			} else {
				drawMessage(messageTable[12], messageTable[13]);
				return;
			}
		} catch (Exception exception) {
			System.out.println(String.valueOf(exception));
		}
		if (ed > 0) {
			try {
				Thread.sleep(5000L);
			} catch (Exception _ex) {
			}
			ed--;
			login(username, password, reconnecting);
		}
		if (reconnecting) {
			username = "";
			password = "";
			f();
		} else {
			drawMessage(messageTable[12], messageTable[13]);
		}
== '''Reference''' == A lot of times, Util.longForName is referenced in the packets following:
public static long longForName(String arg0) {
		String s = "";
		for (int i = 0; i < arg0.length(); i++) {
			char c = arg0.charAt(i);
			if (c >= 'a' && c <= 'z')
				s = s + c;
			else if (c >= 'A' && c <= 'Z')
				s = s + (char) ((c + 97) - 65);
			else if (c >= '0' && c <= '9')
				s = s + c;
			else
				s = s + ' ';
		}

		s = s.trim();
		if (s.length() > 12)
			s = s.substring(0, 12);
		long l = 0L;
		for (int j = 0; j < s.length(); j++) {
			char c1 = s.charAt(j);
			l *= 37L;
			if (c1 >= 'a' && c1 <= 'z')
				l += (1 + c1) - 97;
			else if (c1 >= '0' && c1 <= '9')
				l += (27 + c1) - 48;
		}

		return l;
	}
In the 135 client, messages that are to be drawn on the login screen are stored in an array. This makes it a bit tedious to understand what messages are being drawn. Here is the message table:
static {
		messageTable = new String[50];
		messageTable[0] = "You must enter both a username";
		messageTable[1] = "and a password - Please try again";
		messageTable[2] = "Connection lost! Please wait...";
		messageTable[3] = "Attempting to re-establish";
		messageTable[4] = "That username is already in use.";
		messageTable[5] = "Wait 60 seconds then retry";
		messageTable[6] = "Please wait...";
		messageTable[7] = "Connecting to server";
		messageTable[8] = "Sorry! The server is currently full.";
		messageTable[9] = "Please try again later";
		messageTable[10] = "Invalid username or password.";
		messageTable[11] = "Try again, or create a new account";
		messageTable[12] = "Sorry! Unable to connect to server.";
		messageTable[13] = "Check your internet settings";
		messageTable[14] = "Username already taken.";
		messageTable[15] = "Please choose another username";
		messageTable[16] = "The client has been updated.";
		messageTable[17] = "Please reload this page";
		messageTable[18] = "You may only use 1 character at once.";
		messageTable[19] = "Your ip-address is already in use";
		messageTable[20] = "Login attempts exceeded!";
		messageTable[21] = "Please try again in 5 minutes";
		messageTable[22] = "Account has been temporarily disabled";
		messageTable[23] = "for cheating or abuse";
		messageTable[24] = "Account has been permanently disabled";
		messageTable[25] = "for cheating or abuse";
		messageTable[26] = "You need a members account";
		messageTable[27] = "to login to this server";
		messageTable[28] = "Please login to a members server";
		messageTable[29] = "to access member-only features";
	}
== '''Packets''' == Some 135 packets are documented ahead. First you will find the packets' body, then you will find a table (for easier reading) === '''Incoming Data''' === '''TODO:'''


=== '''Outgoing Data''' ===
(ns rsc.rsc135.packets
  (:require [jagex.Util])
  (:use [jagex.client.SocketStream]))

;; Opcode: 1
(defn disconnect [stream]
  (doto stream
    (.begin-packet1)
    (.flush)))

;; Opcode: 2
(defn newplayer [stream]
  (doto stream
    (.begin-packet 2)
    (.put-int16 ???)
    (.put-int64 (Util/long-for-name username))
    (.put-int16 referrerid)
    (.putline-rsa password server-session-id key-a key-b) ; keys for RSA?
    (.flush)
    (.read) ; newplayer response
    (.end-packet)))

;; Opcode: 6
(defn logout [stream]
  (doto stream
    (.begin-packet 6)
    (.end-packet)))

;; Opcode: 7
(defn send-command [stream command] ; sends command to server e.g ::home, command arg is (.substring command 2)
  (doto stream
    (.begin-packet 7)
    (.putline command)
    (.end-packet)))

;; Opcode: 10
(defn report-abuse [stream username]
  (let [name (.substring username 12)
	l5 (Util/long-for-name name)]
    (doto stream
      (.begin-packet 10)
      (.put-int64 l5)
      (.end-packet))))

;; Opcode: 26
(defn add-friend [stream name] ; name is string represenation of username
  (doto stream
    (.begin-packet 26)
    (.put-int64 (Util/long-for-name name)
    (.end-packet)))

;; Opcode: 27
(defn remove-friend [stream name] ; name is long represenation of username (i.e Util/long-for-name username)
  (doto stream
    (.begin-packet 27)
    (.put-int64 name)
    (.end-packet)))

;; Opcode: 28
;; name is long representation of username, message is byte representation of message (.getBytes message), length is length of message (maximum length is 200)
(defn send-message [stream name message length]
  (doto stream
    (.begin-packet 28)
    (.put-int64 username)
    (.read-bytes message 0 length)
    (.end-packet)))

;; Opcode: 29
(defn add-ignore [stream username] ; username is string representation of username
  (let [name (Util/long-for-name username)]
    (doto stream
      (.begin-packet 29)
      (.put-int64 name)
      (.end-packet))))
{| class="wikitable" |+ Outgoing Packets |- ! Name ! Opcode ! Payload ! Description |- ! Disconnect | 1 || * None | Sends the disconnect packet. |- ! Newplayer (Registration) | 2 || * Short - Unknown * Long - Long represenation of username * Short - Referrer ID ** Integer.parseInt(getParameter("referrerid")); * Line-RSA - Password, server session ID, bigintegers | Registers a new user (probably not used in private servers) |- ! Logout | 6 || * None | Sends the logout packet to the server |- ! Execute Command | 7 || * String - The command | Sends a command to the server to be executed |- ! Report Abuse | 10 || * Long - The long representation of the username of the user to report | Sends an abuse report to the server |- ! Add Friend | 26 || * Long - long represenation of username | Adds a user to your friends list |- ! Remove Friend | 27 || * Long - The long representation of the username of the user to report | Removes a user from your friends list |- ! Send Message | 28 || * Long - The long representation of the username of the user to send the message to * Byte[] - A byte array containing the bytes of the message to send to the user | Sends a message to the specified user |- ! Ignore User | 29 || * Long - The long representation of the username of the user to ignore | Adds a user to your ignore list |}