@dimcool/mcp 0.1.28 → 0.1.29
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/dist/index.js +45 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -15991,16 +15991,56 @@ async function joinQueue(client, args) {
|
|
|
15991
15991
|
try {
|
|
15992
15992
|
await client.ensureConnected();
|
|
15993
15993
|
const lobby = await client.sdk.lobbies.joinQueue(args.lobbyId);
|
|
15994
|
-
|
|
15994
|
+
let matched = !!(lobby.status === "active" && lobby.gameId);
|
|
15995
|
+
let gameId = lobby.gameId || null;
|
|
15996
|
+
if (!matched) {
|
|
15997
|
+
const lobbyStore = client.sdk.lobbyStore;
|
|
15998
|
+
lobbyStore.joinLobby(args.lobbyId);
|
|
15999
|
+
const timeout = 3e5;
|
|
16000
|
+
const start = Date.now();
|
|
16001
|
+
let lastRefresh = Date.now();
|
|
16002
|
+
while (Date.now() - start < timeout) {
|
|
16003
|
+
const matchedEvent = lobbyStore.store.getState().matchedEvent;
|
|
16004
|
+
if (matchedEvent?.gameId) {
|
|
16005
|
+
gameId = matchedEvent.gameId;
|
|
16006
|
+
matched = true;
|
|
16007
|
+
break;
|
|
16008
|
+
}
|
|
16009
|
+
if (Date.now() - lastRefresh > 2e3) {
|
|
16010
|
+
try {
|
|
16011
|
+
const fresh = await client.sdk.lobbies.getLobby(args.lobbyId);
|
|
16012
|
+
if (fresh.status === "active" && fresh.gameId) {
|
|
16013
|
+
gameId = fresh.gameId;
|
|
16014
|
+
matched = true;
|
|
16015
|
+
break;
|
|
16016
|
+
}
|
|
16017
|
+
} catch {
|
|
16018
|
+
}
|
|
16019
|
+
lastRefresh = Date.now();
|
|
16020
|
+
}
|
|
16021
|
+
await raceTimeout(
|
|
16022
|
+
new Promise((resolve2) => {
|
|
16023
|
+
const unsub = lobbyStore.store.subscribeSelector(
|
|
16024
|
+
(s) => s.matchedEvent,
|
|
16025
|
+
() => {
|
|
16026
|
+
unsub();
|
|
16027
|
+
resolve2();
|
|
16028
|
+
}
|
|
16029
|
+
);
|
|
16030
|
+
}),
|
|
16031
|
+
1e3
|
|
16032
|
+
);
|
|
16033
|
+
}
|
|
16034
|
+
}
|
|
15995
16035
|
const spectateUrl = matched ? await getSpectateUrl(client) : null;
|
|
15996
16036
|
return {
|
|
15997
16037
|
data: {
|
|
15998
16038
|
lobbyId: lobby.id,
|
|
15999
|
-
status: lobby.status,
|
|
16000
|
-
gameId
|
|
16039
|
+
status: matched ? "active" : lobby.status,
|
|
16040
|
+
gameId,
|
|
16001
16041
|
matched: !!matched,
|
|
16002
16042
|
...spectateUrl && { spectateUrl },
|
|
16003
|
-
hint: matched ? `Game started! Call dim_game_loop with gameId "${
|
|
16043
|
+
hint: matched ? `Game started! Call dim_game_loop with gameId "${gameId}" to play.${spectateUrl ? ` Tell the user they can spectate at ${spectateUrl}` : ""}` : "No match found within timeout. Call dim_join_queue again to resume waiting."
|
|
16004
16044
|
}
|
|
16005
16045
|
};
|
|
16006
16046
|
} catch (error) {
|
|
@@ -16141,7 +16181,7 @@ async function gameLoop(client, args) {
|
|
|
16141
16181
|
}),
|
|
16142
16182
|
1e3
|
|
16143
16183
|
);
|
|
16144
|
-
if (Date.now() - lastRefresh >
|
|
16184
|
+
if (Date.now() - lastRefresh > 2e3) {
|
|
16145
16185
|
const fresh = await client.sdk.games.getGameState(gameId);
|
|
16146
16186
|
store.setBaseState(gameId, fresh);
|
|
16147
16187
|
lastRefresh = Date.now();
|