@crowdedkingdomstudios/crowdyjs 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +23 -8
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # CrowdyJS SDK
2
2
 
3
3
  Client SDK for the Crowded Kingdoms GraphQL API with UDP proxy support.
4
- Handles authentication, real-time subscriptions, and all game-server
5
- communication through a single `CrowdyClient` instance.
4
+ Handles authentication, real-time subscriptions, and all repilcation-server
5
+ communication through a single `CrowdyClient` instance. Users should still
6
+ directly access the CK GraphQL API for other functions beyond replication.
6
7
 
7
8
  ## Installation
8
9
 
@@ -95,11 +96,25 @@ When all handlers are removed the WebSocket is closed automatically.
95
96
 
96
97
  Before other clients can see you, send an initial actor update so the game
97
98
  server knows which chunk you occupy. Use a minimal base64 payload (the
98
- server requires a non-empty `state`):
99
+ server requires a non-empty `state`).
100
+
101
+ #### Generating a UUID
102
+
103
+ Every client must create its own UUID as a **random 32-byte UTF-8 string**.
104
+ This ensures each client produces a globally unique identifier without
105
+ relying on a central registry.
99
106
 
100
107
  ```javascript
101
- const MY_UUID = 'aaaaaaaabbbbccccddddeeeeeeeeeeee'; // exactly 32 bytes UTF-8
108
+ // Node.js
109
+ const MY_UUID = crypto.randomBytes(32).toString('hex').slice(0, 32);
102
110
 
111
+ // Browser
112
+ const MY_UUID = Array.from(crypto.getRandomValues(new Uint8Array(16)))
113
+ .map((b) => b.toString(16).padStart(2, '0'))
114
+ .join('');
115
+ ```
116
+
117
+ ```javascript
103
118
  await client.sendActorUpdate({
104
119
  mapId: 0,
105
120
  chunk: { x: 0, y: 0, z: 0 },
@@ -110,7 +125,7 @@ await client.sendActorUpdate({
110
125
  });
111
126
  ```
112
127
 
113
- Every client in the same chunk must do this. After registration, the game
128
+ Every actor in every client must do this. After registration, the game
114
129
  server fans out subsequent updates to all registered clients in range.
115
130
 
116
131
  ### 4. Send Actor Updates
@@ -160,7 +175,7 @@ All spatial notification types share a uniform header:
160
175
  | `chunkZ` | `string` | Chunk Z coordinate |
161
176
  | `distance` | `number` | Replication distance (0-8) |
162
177
  | `decayRate` | `number` | Delivery decay (0-5) |
163
- | `uuid` | `string` | 32-byte sender UUID |
178
+ | `uuid` | `string` | Random 32-byte UTF-8 sender UUID |
164
179
  | `sequenceNumber` | `number` | uint8 (0-255), wraps |
165
180
  | `epochMillis` | `string` | Server UTC timestamp in ms |
166
181
 
@@ -191,7 +206,7 @@ All mutation inputs share these fields:
191
206
  |-------|------|----------|---------|-------------|
192
207
  | `mapId` | `number` | yes | -- | Map / chunk-W coordinate |
193
208
  | `chunk` | `{ x, y, z }` | yes | -- | Chunk coordinates (numbers) |
194
- | `uuid` | `string` | yes | -- | Your 32-byte UUID |
209
+ | `uuid` | `string` | yes | -- | Random 32-byte UTF-8 string (see [Generating a UUID](#generating-a-uuid)) |
195
210
  | `distance` | `number` | no | `8` | Replication range (0-8 chunks, Chebyshev) |
196
211
  | `decayRate` | `number` | no | `0` | Delivery decay (see table below) |
197
212
  | `sequenceNumber` | `number` | no | `0` | uint8 (0-255) for correlation |
@@ -253,7 +268,7 @@ const client = new CrowdyClient({
253
268
  wsEndpoint: 'wss://your-server.com/graphql',
254
269
  });
255
270
 
256
- const MY_UUID = 'aaaaaaaabbbbccccddddeeeeeeeeeeee';
271
+ const MY_UUID = crypto.randomBytes(32).toString('hex').slice(0, 32);
257
272
 
258
273
  // 1. Login
259
274
  await client.login('user@example.com', 'password');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdedkingdomstudios/crowdyjs",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "Client SDK for Crowded Kingdoms GraphQL API with UDP proxy support",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",