Disconnect - edqx/amongus-protocol GitHub Wiki
A disconnect packet is used to indicate a closing connection. This can be sent by either the client or the server, although the client typically doesn't send a reason with the request., while a server usually does. When a disconnect is received, the server or client responds with a Disconnect packet back.
A disconnect packet is identified with the 0x09 opcode.
A disconnect packet can just be a single byte, although more commonly when sent by the server, it has a reason attached to it.
| Name | Type | Description |
|---|---|---|
| Unkown | unknown |
I've only seen this as 0x01 |
| Length? | uint16 |
The length of the packet starting at the disconnect reason, or the 6th byte. |
| Unknown | unknown |
I've seen this as 0x00 and 0x01 |
| Reason? | uint8 |
The reason for the disconnect, as described in the Disconnect Reasons enum. |
| Message? | string |
A custom message attached to the message if the disconnect reason is Custom (0x08) |
Example parsing code
const opcode = reader.uint8();
if (opcode === Opcode.Disconnect) {
if (reader.size > 1) {
reader.jump(0x01);
const length = reader.uint16LE();
reader.jump(0x01);
const reason = reader.uint8();
if (reason === DisconnectReason.Custom) {
const message = reader.string();
}
}
}
Example compose code
if (reason) {
const disconnect = new BufferWriter;
disconnect.uint8(reason);
if (reason === DisconnectReason.Custom && message) {
disconnect.string(message);
}
writer.uint8(0x01);
writer.uint16LE(disconnect.size);
writer.uint8(0x00);
writer.write(disconnect);
}
Example packet
0000 09 01 2e 00 00 08 2c 54 68 65 20 73 65 72 76 65 ......,The serve
0010 72 20 63 6c 6f 73 65 64 20 74 68 65 20 72 6f 6f r closed the roo
0020 6d 20 64 75 65 20 74 6f 20 69 6e 61 63 74 69 76 m due to inactiv
0030 69 74 79 ity