blurite / rsprot

RSProt is an all-in-one networking package for RuneScape Private Servers, primarily targeted at the OldSchool scene.
MIT License
28 stars 7 forks source link

Packet Limitations #5

Closed Z-Kris closed 6 months ago

Z-Kris commented 7 months ago

Packet Limitations

The below documentation is based on OldSchool RuneScape, and does not apply to all revisions. RuneScape 3 is known to use different limits.

Socket

It is unclear what the actual underlying limitations of sockets are on the server's end, but a safe bet is to follow what the client is doing, since that is one half of the equation.

public SocketStream(Socket socket, int readerCapacity, int writerCapacity) throws IOException {
    this.socket = socket;
    this.socket.setSoTimeout(30000);
    this.socket.setTcpNoDelay(true);
    this.socket.setReceiveBufferSize(65536);
    this.socket.setSendBufferSize(65536);
    this.reader = new Reader(this.socket.getInputStream(), readerCapacity);
    this.writer = new Writer(this.socket.getOutputStream(), writerCapacity);
}

In the above snippet, the readerCapacity is 40,000 and the writerCapacity is 5,000. This means that each packet going from the client to the server can be up to 5,000 bytes in size, and each packet coming from the server to the client can be 40,000 bytes in size.

[!IMPORTANT] While the writer capacity if 5,000, the server will close the socket if any packet has a size greater than 1,600 bytes. This was tested with the MESSAGE_PRIVATE and the EVENT_KEYBOARD packets, both of which followed the same limitations.

Channel Decoder

This section refers to the server reading/decoding packets sent by the client. All incoming packets[^1] get categorized into two possible categories - client events, and user events. Majority of the packets sent by the client belong in the user events category, which additionally has a cumulative maximum limit of 10 per game cycle. A few other packets (see list below), however, belong in the client events category. These have a cumulative maximum limit of 50 per game cycle. These limits are not cross-shared in any way, it is possible to send 49 client events and 9 user events and have them all process on the same game cycle.

If either category threshold is reached, no more packets are decoded that cycle. This can be seen by sending 10 user events, followed by a corrupt packet. The 'crashing' caused by the corrupt packet does not occur for two cycles (where the first cycle handles the 10 user events, then stops, and the following cycle trying to decode the corrupt packet, which leads to an error and socket closing).

Client Events List

Below is a list of all the packets that are confirmed to belong in the client events category (counting towards the 50 limit):

[!NOTE] A few other packets, such as SEND_PING_REPLY and TIMINGS were tested, however these count towards the user events threshold. The above list should be complete for the Java platform (excluding any C++-only packets).

[^1]: Incoming packets refer to packets sent by the client to the server.