@colyseus/core
Advanced tools
Comparing version 0.15.44 to 0.15.45-preview.0
@@ -80,3 +80,3 @@ /// <reference types="node" /> | ||
protected reservedSeats: { | ||
[sessionId: string]: [any, any]; | ||
[sessionId: string]: [any, any, boolean?, boolean?]; | ||
}; | ||
@@ -83,0 +83,0 @@ protected reservedSeatTimeouts: { |
@@ -132,13 +132,16 @@ var __create = Object.create; | ||
hasReservedSeat(sessionId, reconnectionToken) { | ||
if (reconnectionToken) { | ||
const reconnection = this._reconnections[reconnectionToken]; | ||
return reconnection && reconnection[0] === sessionId && this.reservedSeats[sessionId] !== void 0 && this._reconnectingSessionId.has(sessionId); | ||
const reservedSeat = this.reservedSeats[sessionId]; | ||
if (reservedSeat === void 0) { | ||
return false; | ||
} | ||
if (reservedSeat[3]) { | ||
return reconnectionToken && this._reconnections[reconnectionToken]?.[0] === sessionId && this._reconnectingSessionId.has(sessionId); | ||
} else { | ||
return this.reservedSeats[sessionId] !== void 0 && (!this._reconnectingSessionId.has(sessionId) || this._reconnectingSessionId.get(sessionId) === sessionId); | ||
return reservedSeat[2] === false; | ||
} | ||
} | ||
checkReconnectionToken(reconnectionToken) { | ||
const reconnection = this._reconnections[reconnectionToken]; | ||
const sessionId = reconnection && reconnection[0]; | ||
if (this.hasReservedSeat(sessionId)) { | ||
const sessionId = this._reconnections[reconnectionToken]?.[0]; | ||
const reservedSeat = this.reservedSeats[sessionId]; | ||
if (reservedSeat && reservedSeat[3]) { | ||
this._reconnectingSessionId.set(sessionId, reconnectionToken); | ||
@@ -303,14 +306,19 @@ return sessionId; | ||
} | ||
const [joinOptions, authData] = this.reservedSeats[sessionId]; | ||
if (this.reservedSeats[sessionId].length > 2) { | ||
const [joinOptions, authData, isConsumed, isWaitingReconnection] = this.reservedSeats[sessionId]; | ||
if (isConsumed) { | ||
throw new import_ServerError.ServerError(import_Protocol.ErrorCode.MATCHMAKE_EXPIRED, "already consumed"); | ||
} | ||
this.reservedSeats[sessionId].push(true); | ||
this.reservedSeats[sessionId][2] = true; | ||
client._afterNextPatchQueue = this._afterNextPatchQueue; | ||
client.ref["onleave"] = (_) => client.state = import_Transport.ClientState.LEAVING; | ||
client.ref.once("close", client.ref["onleave"]); | ||
const previousReconnectionToken = this._reconnectingSessionId.get(sessionId); | ||
if (previousReconnectionToken) { | ||
this.clients.push(client); | ||
this._reconnections[previousReconnectionToken]?.[1].resolve(client); | ||
if (isWaitingReconnection) { | ||
const previousReconnectionToken = this._reconnectingSessionId.get(sessionId); | ||
if (previousReconnectionToken) { | ||
this.clients.push(client); | ||
this._reconnections[previousReconnectionToken]?.[1].resolve(client); | ||
} else { | ||
const errorMessage = process.env.NODE_ENV === "production" ? "already consumed" : "bad reconnection token"; | ||
throw new import_ServerError.ServerError(import_Protocol.ErrorCode.MATCHMAKE_EXPIRED, errorMessage); | ||
} | ||
} else { | ||
@@ -461,3 +469,3 @@ try { | ||
} | ||
this.reservedSeats[sessionId] = [joinOptions, authData]; | ||
this.reservedSeats[sessionId] = [joinOptions, authData, false, allowReconnection]; | ||
if (!allowReconnection) { | ||
@@ -464,0 +472,0 @@ await this._incrementClientCount(); |
{ | ||
"name": "@colyseus/core", | ||
"version": "0.15.44", | ||
"version": "0.15.45-preview.0", | ||
"description": "Multiplayer Framework for Node.js.", | ||
@@ -5,0 +5,0 @@ "input": "./src/index.ts", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
661292
7352
12