Skip to content

Commit

Permalink
Add system/disconnected event
Browse files Browse the repository at this point in the history
  • Loading branch information
geekingfrog committed Nov 24, 2024
1 parent 6d80303 commit c9438f7
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 3 deletions.
101 changes: 98 additions & 3 deletions docs/schema/system.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,26 @@

# System

System commands to manage the connection itself and get updates from the server.

* [disconnect](#disconnect) is the event to send to the server before
stopping the connection. If the client closes the connection without first
sending this event, it will be considered as a client crash by the server.

* [disconnected](#disconnected) is the dual of `disconnect` where the server
is terminating the connection and disconnecting the user. This can happen
if the server detects a timeout, either because no activity on the connection
or the server is expecting a response to a request and hasn't received it (and
all potential retries have been exhausted). `server_error` is sent when the
server encountered a fatal error for the user and the only way to recover is
to reconnect.

* [serverStats](#serverStats) can be used to request generic, user facing data
about the server like number of connecting players.

---
- [disconnect](#disconnect)
- [disconnected](#disconnected)
- [serverStats](#serverstats)
---

Expand Down Expand Up @@ -150,6 +169,82 @@ Possible Failed Reasons: `internal_error`, `unauthorized`, `invalid_request`, `c

---

## Disconnected

The server is terminating the connection.

- Endpoint Type: **Event**
- Source: **Server**
- Target: **User**
- Required Scopes: `tachyon.lobby`

### Event

<details>
<summary>JSONSchema</summary>

```json
{
"title": "SystemDisconnectedEvent",
"tachyon": {
"source": "server",
"target": "user",
"scopes": ["tachyon.lobby"]
},
"type": "object",
"properties": {
"type": { "const": "event" },
"messageId": { "type": "string" },
"commandId": { "const": "system/disconnected" },
"data": {
"title": "SystemDisconnectedEventData",
"type": "object",
"properties": {
"reason": {
"enum": ["protocol_violation", "server_error", "timeout"]
},
"details": { "type": "string" }
},
"required": ["reason"]
}
},
"required": ["type", "messageId", "commandId"]
}

```
</details>

<details>
<summary>Example</summary>

```json
{
"type": "event",
"messageId": "commodo Lorem",
"commandId": "system/disconnected",
"data": {
"reason": "server_error",
"details": "commodo Lorem"
}
}
```
</details>

#### TypeScript Definition
```ts
export interface SystemDisconnectedEvent {
type: "event";
messageId: string;
commandId: "system/disconnected";
data?: SystemDisconnectedEventData;
}
export interface SystemDisconnectedEventData {
reason: "protocol_violation" | "server_error" | "timeout";
details?: string;
}
```
---

## ServerStats

Get server stats such as user count.
Expand Down Expand Up @@ -190,7 +285,7 @@ Get server stats such as user count.
```json
{
"type": "request",
"messageId": "commodo Lorem",
"messageId": "ut Lorem",
"commandId": "system/serverStats"
}
```
Expand Down Expand Up @@ -267,11 +362,11 @@ export interface SystemServerStatsRequest {
```json
{
"type": "response",
"messageId": "ut Lorem",
"messageId": "occaecat Lorem in",
"commandId": "system/serverStats",
"status": "success",
"data": {
"userCount": -22000000
"userCount": -20000000
}
}
```
Expand Down
30 changes: 30 additions & 0 deletions schema/compiled.json
Original file line number Diff line number Diff line change
Expand Up @@ -1758,6 +1758,36 @@
}
]
},
{
"title": "SystemDisconnectedEvent",
"tachyon": {
"source": "server",
"target": "user",
"scopes": ["tachyon.lobby"]
},
"type": "object",
"properties": {
"type": { "const": "event" },
"messageId": { "type": "string" },
"commandId": { "const": "system/disconnected" },
"data": {
"title": "SystemDisconnectedEventData",
"type": "object",
"properties": {
"reason": {
"enum": [
"protocol_violation",
"server_error",
"timeout"
]
},
"details": { "type": "string" }
},
"required": ["reason"]
}
},
"required": ["type", "messageId", "commandId"]
},
{
"title": "SystemServerStatsRequest",
"tachyon": {
Expand Down
28 changes: 28 additions & 0 deletions schema/system/disconnected/event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"$id": "https://schema.beyondallreason.dev/tachyon/system/disconnected/event.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "SystemDisconnectedEvent",
"tachyon": {
"source": "server",
"target": "user",
"scopes": ["tachyon.lobby"]
},
"type": "object",
"properties": {
"type": { "const": "event" },
"messageId": { "type": "string" },
"commandId": { "const": "system/disconnected" },
"data": {
"title": "SystemDisconnectedEventData",
"type": "object",
"properties": {
"reason": {
"enum": ["protocol_violation", "server_error", "timeout"]
},
"details": { "type": "string" }
},
"required": ["reason"]
}
},
"required": ["type", "messageId", "commandId"]
}
16 changes: 16 additions & 0 deletions src/schema/system/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
System commands to manage the connection itself and get updates from the server.

* [disconnect](#disconnect) is the event to send to the server before
stopping the connection. If the client closes the connection without first
sending this event, it will be considered as a client crash by the server.

* [disconnected](#disconnected) is the dual of `disconnect` where the server
is terminating the connection and disconnecting the user. This can happen
if the server detects a timeout, either because no activity on the connection
or the server is expecting a response to a request and hasn't received it (and
all potential retries have been exhausted). `server_error` is sent when the
server encountered a fatal error for the user and the only way to recover is
to reconnect.

* [serverStats](#serverStats) can be used to request generic, user facing data
about the server like number of connecting players.

0 comments on commit c9438f7

Please sign in to comment.