From b8d4ab90f2b1b46fe868a5f0610d4548fa0a8eb4 Mon Sep 17 00:00:00 2001 From: pixtaded Date: Tue, 11 Feb 2025 21:04:18 +0300 Subject: [PATCH] Add RACv2 protocol specification. (I hate it) --- README.md | 26 ++++++++++++++++--- .../java/net/pixtaded/crab/common/PID.java | 1 + 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6ff82ed..aa58369 100644 --- a/README.md +++ b/README.md @@ -51,14 +51,32 @@ Once the server is running, clients can connect to it and send messages accordin 2. Message Transmission - a. To send a message, the client issues a request in the following format: + a. To send a message, the client issues a request in one of the following formats: - `0x01` followed immediately by the message content. + i. Unauthenticated Message: The client sends the byte `0x01` followed immediately by the message content. The server does not send a response. + + ii. Authenticated Message: The client sends the byte `0x02` followed by the username, a newline character (`\n`), the password, a newline character and the message content. The server responds with a single byte: + - `0x01` indicates the user does not exist. + - `0x02` indicates the password is incorrect. + - A successful authentication results in the server accepting the message without sending a response. + +3. User Registration + + a. To register a new user, the client sends a request formatted as: + - The byte `0x03`. + - The username, followed by a newline character (`\n`). + - The password. + + b. The server processes the request and responds with a single byte: + - `0x01` if the username already exists. + - A successful registration is assumed if no error byte (`0x01`) is received. The client should close the connection after handling the response. ### Additional Notes: -- Although the protocol may appear similar to RACv1, it is important to note that RACv1.99 represents the beta development phase of RACv2. Consequently, significant changes and enhancements are anticipated. The current specification is implemented in `lRACd` version 1.99.2 and `clRAC` version 1.99.2. +- The current specification of RACv2 is implemented in `lRACd` version 2.0.0 and `clRAC` version 2.0.0. - When using `0x02` for incremental retrieval, the client must ensure the cached length is synchronized with the server’s total message length (retrieved via `0x00`). The server sends messages from the cached length onward, and the client calculates the read size as `(total_length - cached_length)`. -- After receiving incremental messages, the client must update its cached length to the total length provided in step 1b to maintain consistency in subsequent requests. \ No newline at end of file +- After receiving incremental messages, the client must update its cached length to the total length provided in step 1b to maintain consistency in subsequent requests. + +- For authenticated message transmission (`0x02`) or user registration (`0x03`), the client must follow the specified format precisely. The server validates the structure of the request and responds with error codes only for specific failure conditions (e.g., invalid credentials or duplicate usernames). \ No newline at end of file diff --git a/src/main/java/net/pixtaded/crab/common/PID.java b/src/main/java/net/pixtaded/crab/common/PID.java index 59a91e1..db9292e 100644 --- a/src/main/java/net/pixtaded/crab/common/PID.java +++ b/src/main/java/net/pixtaded/crab/common/PID.java @@ -6,4 +6,5 @@ public class PID { public static final byte MESSAGE = 0x01; public static final byte CACHED_LOGS = 0x02; public static final byte AUTHENTICATED_MESSAGE = 0x02; + public static final byte REGISTER = 0x03; } \ No newline at end of file