ScratchSrvV2 Protocol ===================== Cloud variables --------------- - CloudSync1 through CloudSync9 - ACK/SDP/STS Server responses are written to ACK/SDP/STS. Client packet layout -------------------- Client packets are numeric strings sent through CloudSync variables. Header length: 31 digits Digits 01-08: user hash Digits 09-12: time, UTC HHMM Digits 13-18: session id Digits 19-22: total vars/chunks Digits 23-24: request type Digits 25-27: lock TTL Digits 28-31: current chunk index Digits 32-end: encoded payload data Request types: 07: register or ping 01: data transfer Payload encoding ---------------- Payload text is encoded as: LenMap + "0" + RawData For each character: 1. Convert the character to its Unicode code point. 2. Append the digit length of that code point to LenMap. 3. Append the code point digits to RawData. Example: Text: hi Code points: 104, 105 LenMap: 33 RawData: 104105 Encoded: 330104105 Type 07: register and ping -------------------------- Type 07 payload is decoded first, then interpreted as a control string. Control strings: hi Ping. If the session is already known, the server uses the stored username and user hash for that session. hi,<username> Register. The server hashes the username, records the session, and stores the username with that session. Current server response for both register and ping: STS, response type 3 Type 01: data transfer ---------------------- Type 01 payload chunks are buffered by session, user hash, and request type. The server stores each chunk by its current chunk index. Payload text is decoded only after every chunk from 1 through total vars has arrived. While chunks are missing, the decoded message is treated as incomplete. Response behavior: - Normal incomplete chunk: STS, response type 3 - Incomplete chunk where index % 9 == 0: ACK-STS, response type 5 - Complete message: STS, response type 3 ACK/SDP/STS response layout --------------------------- Server response packets are numeric strings written to ACK/SDP/STS. Digits 01-04: total vars Digits 05-12: user hash Digit 13: response type Digits 14-19: session id Digits 20-25: time, UTC HHMMSS Digits 26-end: encoded payload data Response types: 1: PBK, ping back 2: SDP, sent data packet 3: STS, safe to send 4: ACK, acknowledge 5: ACK-STS, acknowledge and safe to send Username hash ------------- Hash input is the lowercase username. Sequence: 1qaz2wsx3edc4rfv5tgb6yhn7ujm8ki90opl Algorithm: h = 10 for each character: value = 1-based position in sequence, or 0 if not found h = (h * 33 + value) mod 99999999 result = h padded to 8 digits