playsocketjs 4.3.0 → 4.3.2

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.
package/README.md CHANGED
@@ -293,7 +293,7 @@ const server = new PlaySocketServer({
293
293
  const forwarded = info.req.headers["x-forwarded-for"];
294
294
  const ip = forwarded ? forwarded.split(",")[0].trim() : info.req.socket.remoteAddress;
295
295
  if (isRateLimited(ip)) {
296
- return callback(false, 429, "Too many requests");
296
+ return callback(false, 429, "Too Many Requests");
297
297
  }
298
298
  callback(true);
299
299
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playsocketjs",
3
- "version": "4.3.0",
3
+ "version": "4.3.2",
4
4
  "description": "WebSocket wrapper for creating simple multiplayer systems with ease.",
5
5
  "type": "module",
6
6
  "module": "./src/client/client.js",
@@ -152,7 +152,7 @@ export default class PlaySocketServer {
152
152
  }
153
153
 
154
154
  // Register client ID if provided & check for a duplicate
155
- if (data.id && (this.#clients.get(data.id) || data.id === "server")) {
155
+ if (data.id && (this.#clients.get(data.id) || this.#pendingDisconnects.has(data.id) || data.id === "server")) {
156
156
  ws.send(encode({ type: "registration_failed", reason: "ID is taken" }), { binary: true });
157
157
  return;
158
158
  }
@@ -161,7 +161,7 @@ export default class PlaySocketServer {
161
161
  if (!data.id) {
162
162
  for (let i = 0; i < 50; i++) {
163
163
  const id = this.#generateId();
164
- if (!this.#clients.get(id)) {
164
+ if (!this.#clients.get(id) && !this.#pendingDisconnects.has(id)) {
165
165
  data.id = id;
166
166
  break;
167
167
  }
@@ -9,7 +9,7 @@ export const HEARTBEAT_INTERVAL = 5000;
9
9
  /**
10
10
  * Library version, must match package.json
11
11
  */
12
- export const VERSION = "4.3.0";
12
+ export const VERSION = "4.3.2";
13
13
 
14
14
  /**
15
15
  * Logging prefixes
@@ -114,7 +114,7 @@ export default class CRDTManager {
114
114
  if (this.#debug) console.log(CONSOLE_PREFIX + "Importing update:", update); // Debug
115
115
 
116
116
  // Check key limit to safeguard against too many keys
117
- if (this.#keyOperations.size >= 100 && !this.#keyOperations.has(key)) throw new Error("Key limit exceeded!");
117
+ if (this.#keyOperations.size >= 100 && !this.#keyOperations.has(key)) throw new Error("Key limit exceeded");
118
118
 
119
119
  // Get COPY of current ops (or empty array if none yet)
120
120
  const currentOps = [...(this.#keyOperations.get(key) || [])];
@@ -157,7 +157,7 @@ export default class CRDTManager {
157
157
 
158
158
  const currentOps = this.#keyOperations.get(key);
159
159
  if (!currentOps?.some(op => op.uuid === opUuid)) return; // Operation not found
160
- if (this.#debug) console.log(CONSOLE_PREFIX + `Removing operation ${opUuid} for key ${key} as part of property update reversion.`);
160
+ if (this.#debug) console.log(CONSOLE_PREFIX + `Removing operation ${opUuid} for key ${key} as part of property update reversion`);
161
161
 
162
162
  // The own vector clock entry isn't decremented because later ops may already embed the incremented counter
163
163
  // and reusing a counter value would corrupt operation ordering (while a gap is harmless)
@@ -188,7 +188,7 @@ export default class CRDTManager {
188
188
  secondValue = this.#sanitizeValue(secondValue);
189
189
 
190
190
  // Debug log
191
- if (this.#debug) console.log(CONSOLE_PREFIX + `Updating property with key ${key}, type ${type}, value ${value} and secondValue ${secondValue}.`);
191
+ if (this.#debug) console.log(CONSOLE_PREFIX + `Updating property with key ${key}, type ${type}, value ${value} and secondValue ${secondValue}`);
192
192
 
193
193
  // Increment vector clock
194
194
  const counter = this.#vectorClock.get(this.#replicaId) || 0;
@@ -440,7 +440,7 @@ export default class CRDTManager {
440
440
 
441
441
  // Check total serialized size
442
442
  const jsonString = JSON.stringify(value);
443
- if (jsonString?.length > 50000) throw new Error("Value too large!"); // 50KB limit
443
+ if (jsonString?.length > 50000) throw new Error("Value too large"); // 50KB limit
444
444
 
445
445
  if (typeof value === "string") return (value.includes("<") || value.includes(">")) ? value.replace(/[<>]/g, "") : value;
446
446
  if (Array.isArray(value)) return Array.from(value, item => this.#sanitizeValue(item));
@@ -8,7 +8,7 @@ export declare const HEARTBEAT_INTERVAL = 5000;
8
8
  /**
9
9
  * Library version, must match package.json
10
10
  */
11
- export declare const VERSION = "4.3.0";
11
+ export declare const VERSION = "4.3.2";
12
12
  /**
13
13
  * Logging prefixes
14
14
  */