@dimcool/sdk 0.1.30 → 0.1.32
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 +55 -45
- package/dist/index.cjs +229 -50
- package/dist/index.d.cts +62 -20
- package/dist/index.d.ts +62 -20
- package/dist/index.js +229 -50
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -29,7 +29,7 @@ var require_money = __commonJS({
|
|
|
29
29
|
"../utils/dist/money.js"(exports) {
|
|
30
30
|
"use strict";
|
|
31
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
-
exports.SOL_LAMPORTS = exports.MICRO_UNITS = void 0;
|
|
32
|
+
exports.SOL_MINT = exports.SOL_LAMPORTS = exports.MICRO_UNITS = void 0;
|
|
33
33
|
exports.isSolMint = isSolMint;
|
|
34
34
|
exports.formatMoneyMinor = formatMoneyMinor2;
|
|
35
35
|
exports.toMajor = toMajor2;
|
|
@@ -42,12 +42,12 @@ var require_money = __commonJS({
|
|
|
42
42
|
exports.formatMoneyMinorCompact = formatMoneyMinorCompact;
|
|
43
43
|
exports.MICRO_UNITS = 1e6;
|
|
44
44
|
exports.SOL_LAMPORTS = 1e9;
|
|
45
|
-
|
|
45
|
+
exports.SOL_MINT = "SOL";
|
|
46
46
|
var SOL_SYSTEM_PROGRAM = "11111111111111111111111111111111";
|
|
47
47
|
function isSolMint(mint) {
|
|
48
48
|
if (!mint)
|
|
49
49
|
return false;
|
|
50
|
-
return mint ===
|
|
50
|
+
return mint === exports.SOL_MINT || mint === SOL_SYSTEM_PROGRAM;
|
|
51
51
|
}
|
|
52
52
|
function formatMoneyMinor2(amountMinor, fractionDigits = 2) {
|
|
53
53
|
return (amountMinor / exports.MICRO_UNITS).toFixed(fractionDigits);
|
|
@@ -153,7 +153,7 @@ var require_dist = __commonJS({
|
|
|
153
153
|
"../utils/dist/index.js"(exports) {
|
|
154
154
|
"use strict";
|
|
155
155
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
156
|
-
exports.formatMoneyMinorCompact = exports.formatCurrencyPartsForToken = exports.formatCurrencyParts = exports.kformatMoney = exports.kformat = exports.formatSolMinor = exports.toSolMajor = exports.toMajor = exports.formatMoneyMinor = exports.isSolMint = exports.SOL_LAMPORTS = exports.MICRO_UNITS = void 0;
|
|
156
|
+
exports.formatMoneyMinorCompact = exports.formatCurrencyPartsForToken = exports.formatCurrencyParts = exports.kformatMoney = exports.kformat = exports.formatSolMinor = exports.toSolMajor = exports.toMajor = exports.formatMoneyMinor = exports.isSolMint = exports.SOL_MINT = exports.SOL_LAMPORTS = exports.MICRO_UNITS = void 0;
|
|
157
157
|
var money_1 = require_money();
|
|
158
158
|
Object.defineProperty(exports, "MICRO_UNITS", { enumerable: true, get: function() {
|
|
159
159
|
return money_1.MICRO_UNITS;
|
|
@@ -161,6 +161,9 @@ var require_dist = __commonJS({
|
|
|
161
161
|
Object.defineProperty(exports, "SOL_LAMPORTS", { enumerable: true, get: function() {
|
|
162
162
|
return money_1.SOL_LAMPORTS;
|
|
163
163
|
} });
|
|
164
|
+
Object.defineProperty(exports, "SOL_MINT", { enumerable: true, get: function() {
|
|
165
|
+
return money_1.SOL_MINT;
|
|
166
|
+
} });
|
|
164
167
|
Object.defineProperty(exports, "isSolMint", { enumerable: true, get: function() {
|
|
165
168
|
return money_1.isSolMint;
|
|
166
169
|
} });
|
|
@@ -743,6 +746,9 @@ var Admin = class {
|
|
|
743
746
|
this.http = http;
|
|
744
747
|
this.logger = logger2;
|
|
745
748
|
}
|
|
749
|
+
async getInternalBots() {
|
|
750
|
+
return this.http.get("/admin/internal-bots");
|
|
751
|
+
}
|
|
746
752
|
async getUserById(id) {
|
|
747
753
|
return this.http.get(`/admin/users/${id}`);
|
|
748
754
|
}
|
|
@@ -1100,6 +1106,13 @@ var Lobbies = class {
|
|
|
1100
1106
|
setLobbyStore(store) {
|
|
1101
1107
|
this.lobbyStore = store;
|
|
1102
1108
|
}
|
|
1109
|
+
/**
|
|
1110
|
+
* Create a new game lobby.
|
|
1111
|
+
*
|
|
1112
|
+
* **Important:** Creating a lobby automatically closes and refunds any
|
|
1113
|
+
* existing open or queued lobby for this user. You do not need to manually
|
|
1114
|
+
* leave or cancel a previous lobby before calling this.
|
|
1115
|
+
*/
|
|
1103
1116
|
async createLobby(gameType, betAmount) {
|
|
1104
1117
|
return this.http.post("/lobbies", { gameType, betAmount });
|
|
1105
1118
|
}
|
|
@@ -1163,21 +1176,6 @@ var Lobbies = class {
|
|
|
1163
1176
|
async deleteLobby(lobbyId) {
|
|
1164
1177
|
return this.http.delete(`/lobbies/admin/${lobbyId}`);
|
|
1165
1178
|
}
|
|
1166
|
-
/**
|
|
1167
|
-
* Play again: Create a new lobby and prepare deposit in one flow.
|
|
1168
|
-
* Returns the lobby and unsigned transaction that needs to be signed.
|
|
1169
|
-
* @param gameType - The game type to play again
|
|
1170
|
-
* @param betAmount - The bet amount (same as previous game)
|
|
1171
|
-
* @param escrow - The escrow service instance (from sdk.escrow)
|
|
1172
|
-
*/
|
|
1173
|
-
async playAgain(gameType, betAmount, escrow) {
|
|
1174
|
-
const lobby = await this.createLobby(gameType, betAmount);
|
|
1175
|
-
const { transaction } = await escrow.prepareAndStartDeposit(lobby.id);
|
|
1176
|
-
return {
|
|
1177
|
-
lobby,
|
|
1178
|
-
unsignedTransaction: transaction
|
|
1179
|
-
};
|
|
1180
|
-
}
|
|
1181
1179
|
};
|
|
1182
1180
|
|
|
1183
1181
|
// src/games.ts
|
|
@@ -1716,11 +1714,11 @@ var Achievements = class {
|
|
|
1716
1714
|
|
|
1717
1715
|
// src/wallet.ts
|
|
1718
1716
|
import { Transaction as Transaction2 } from "@solana/web3.js";
|
|
1717
|
+
var import_utils = __toESM(require_dist(), 1);
|
|
1719
1718
|
var TRANSFER_FEE_MINOR = 1e4;
|
|
1720
1719
|
var MIN_TRANSFER_AMOUNT = 5e4;
|
|
1721
1720
|
var MIN_SOL_TRANSFER_AMOUNT = 1e6;
|
|
1722
1721
|
var SOL_DECIMALS = 9;
|
|
1723
|
-
var SOL_MINT = "SOL";
|
|
1724
1722
|
var ESTIMATED_SOL_FEE_LAMPORTS = 1e4;
|
|
1725
1723
|
var Wallet = class {
|
|
1726
1724
|
constructor(http, logger2) {
|
|
@@ -3410,6 +3408,19 @@ function createGameStore(transport) {
|
|
|
3410
3408
|
}
|
|
3411
3409
|
|
|
3412
3410
|
// src/stores/game-actions-store.ts
|
|
3411
|
+
function selectGameLifecycleState(gameState) {
|
|
3412
|
+
const s = gameState;
|
|
3413
|
+
if (!s) return null;
|
|
3414
|
+
const raw = s;
|
|
3415
|
+
return {
|
|
3416
|
+
status: raw.status,
|
|
3417
|
+
winnerId: raw.winnerId ?? null,
|
|
3418
|
+
betAmount: raw.betAmount ?? 0,
|
|
3419
|
+
wonAmount: raw.wonAmount ?? null,
|
|
3420
|
+
totalPotMinor: raw.totalPotMinor,
|
|
3421
|
+
currentPlayerId: raw.currentPlayerId ?? null
|
|
3422
|
+
};
|
|
3423
|
+
}
|
|
3413
3424
|
var isRpsCompletionPayload = (payload) => payload.gameType === "rock-paper-scissors";
|
|
3414
3425
|
function createGameActionsStore(transport) {
|
|
3415
3426
|
const store = createSdkStore({
|
|
@@ -3431,8 +3442,21 @@ function createGameActionsStore(transport) {
|
|
|
3431
3442
|
});
|
|
3432
3443
|
};
|
|
3433
3444
|
const isNonRpsState = (state) => Boolean(state && !isRpsState(state));
|
|
3445
|
+
const pendingEvents = /* @__PURE__ */ new Map();
|
|
3446
|
+
function enqueue(gameId, event) {
|
|
3447
|
+
const q = pendingEvents.get(gameId) ?? [];
|
|
3448
|
+
q.push(event);
|
|
3449
|
+
pendingEvents.set(gameId, q);
|
|
3450
|
+
}
|
|
3451
|
+
function drainQueue(gameId) {
|
|
3452
|
+
const q = pendingEvents.get(gameId);
|
|
3453
|
+
if (!q?.length) return;
|
|
3454
|
+
pendingEvents.delete(gameId);
|
|
3455
|
+
for (const ev of q) applyWsEvent(ev);
|
|
3456
|
+
}
|
|
3434
3457
|
const setBaseState = (gameId, state) => {
|
|
3435
3458
|
updateState(gameId, state);
|
|
3459
|
+
drainQueue(gameId);
|
|
3436
3460
|
};
|
|
3437
3461
|
const clearState = (gameId) => {
|
|
3438
3462
|
store.updateState((state) => {
|
|
@@ -3442,6 +3466,7 @@ function createGameActionsStore(transport) {
|
|
|
3442
3466
|
const { [gameId]: _, ...rest } = state.statesByGameId;
|
|
3443
3467
|
return { ...state, statesByGameId: rest };
|
|
3444
3468
|
});
|
|
3469
|
+
pendingEvents.delete(gameId);
|
|
3445
3470
|
};
|
|
3446
3471
|
const applyWsEvent = (event) => {
|
|
3447
3472
|
switch (event.event) {
|
|
@@ -3460,7 +3485,10 @@ function createGameActionsStore(transport) {
|
|
|
3460
3485
|
}
|
|
3461
3486
|
case "game:rps:starting": {
|
|
3462
3487
|
const current = store.getState().statesByGameId[event.payload.gameId];
|
|
3463
|
-
if (!current || !isRpsState(current))
|
|
3488
|
+
if (!current || !isRpsState(current)) {
|
|
3489
|
+
enqueue(event.payload.gameId, event);
|
|
3490
|
+
return;
|
|
3491
|
+
}
|
|
3464
3492
|
const betAmount = typeof event.payload.betAmount === "number" ? event.payload.betAmount : void 0;
|
|
3465
3493
|
const startedAt = typeof event.payload.startedAt === "string" ? event.payload.startedAt : current.roundState.startedAt;
|
|
3466
3494
|
const bufferEndsAt = typeof event.payload.bufferEndsAt === "string" ? event.payload.bufferEndsAt : current.roundState.selectionEndsAt;
|
|
@@ -3481,7 +3509,10 @@ function createGameActionsStore(transport) {
|
|
|
3481
3509
|
}
|
|
3482
3510
|
case "game:rps:round:started": {
|
|
3483
3511
|
const current = store.getState().statesByGameId[event.payload.gameId];
|
|
3484
|
-
if (!current || !isRpsState(current))
|
|
3512
|
+
if (!current || !isRpsState(current)) {
|
|
3513
|
+
enqueue(event.payload.gameId, event);
|
|
3514
|
+
return;
|
|
3515
|
+
}
|
|
3485
3516
|
const actions = {};
|
|
3486
3517
|
const baseUsers = /* @__PURE__ */ new Set();
|
|
3487
3518
|
Object.keys(current.roundState.actions).forEach(
|
|
@@ -3515,7 +3546,10 @@ function createGameActionsStore(transport) {
|
|
|
3515
3546
|
}
|
|
3516
3547
|
case "game:rps:action:received": {
|
|
3517
3548
|
const current = store.getState().statesByGameId[event.payload.gameId];
|
|
3518
|
-
if (!current || !isRpsState(current))
|
|
3549
|
+
if (!current || !isRpsState(current)) {
|
|
3550
|
+
enqueue(event.payload.gameId, event);
|
|
3551
|
+
return;
|
|
3552
|
+
}
|
|
3519
3553
|
const updated = {
|
|
3520
3554
|
...current,
|
|
3521
3555
|
roundState: {
|
|
@@ -3534,7 +3568,10 @@ function createGameActionsStore(transport) {
|
|
|
3534
3568
|
}
|
|
3535
3569
|
case "game:rps:timer:cutoff": {
|
|
3536
3570
|
const current = store.getState().statesByGameId[event.payload.gameId];
|
|
3537
|
-
if (!current || !isRpsState(current))
|
|
3571
|
+
if (!current || !isRpsState(current)) {
|
|
3572
|
+
enqueue(event.payload.gameId, event);
|
|
3573
|
+
return;
|
|
3574
|
+
}
|
|
3538
3575
|
const updated = {
|
|
3539
3576
|
...current,
|
|
3540
3577
|
roundState: {
|
|
@@ -3548,7 +3585,10 @@ function createGameActionsStore(transport) {
|
|
|
3548
3585
|
}
|
|
3549
3586
|
case "game:rps:round:reveal": {
|
|
3550
3587
|
const current = store.getState().statesByGameId[event.payload.gameId];
|
|
3551
|
-
if (!current || !isRpsState(current))
|
|
3588
|
+
if (!current || !isRpsState(current)) {
|
|
3589
|
+
enqueue(event.payload.gameId, event);
|
|
3590
|
+
return;
|
|
3591
|
+
}
|
|
3552
3592
|
const actions = {};
|
|
3553
3593
|
const payloadActions = event.payload.actions;
|
|
3554
3594
|
Object.keys(payloadActions || {}).forEach((userId) => {
|
|
@@ -3572,7 +3612,10 @@ function createGameActionsStore(transport) {
|
|
|
3572
3612
|
}
|
|
3573
3613
|
case "game:rps:round:completed": {
|
|
3574
3614
|
const current = store.getState().statesByGameId[event.payload.gameId];
|
|
3575
|
-
if (!current || !isRpsState(current))
|
|
3615
|
+
if (!current || !isRpsState(current)) {
|
|
3616
|
+
enqueue(event.payload.gameId, event);
|
|
3617
|
+
return;
|
|
3618
|
+
}
|
|
3576
3619
|
const roundHistory = [
|
|
3577
3620
|
...current.roundHistory || [],
|
|
3578
3621
|
{
|
|
@@ -3597,7 +3640,10 @@ function createGameActionsStore(transport) {
|
|
|
3597
3640
|
}
|
|
3598
3641
|
case "game:rps:timeout": {
|
|
3599
3642
|
const current = store.getState().statesByGameId[event.payload.gameId];
|
|
3600
|
-
if (!current || !isRpsState(current))
|
|
3643
|
+
if (!current || !isRpsState(current)) {
|
|
3644
|
+
enqueue(event.payload.gameId, event);
|
|
3645
|
+
return;
|
|
3646
|
+
}
|
|
3601
3647
|
const timedOutUser = event.payload.playerId;
|
|
3602
3648
|
const action = event.payload.action;
|
|
3603
3649
|
const updated = {
|
|
@@ -3622,7 +3668,10 @@ function createGameActionsStore(transport) {
|
|
|
3622
3668
|
const payload = event.payload;
|
|
3623
3669
|
const { gameId } = payload;
|
|
3624
3670
|
const current = store.getState().statesByGameId[gameId];
|
|
3625
|
-
if (!current)
|
|
3671
|
+
if (!current) {
|
|
3672
|
+
enqueue(gameId, event);
|
|
3673
|
+
return;
|
|
3674
|
+
}
|
|
3626
3675
|
const updated = isRpsCompletionPayload(payload) && isRpsState(current) ? {
|
|
3627
3676
|
...current,
|
|
3628
3677
|
status: "completed",
|
|
@@ -3671,11 +3720,15 @@ function createGameActionsStore(transport) {
|
|
|
3671
3720
|
const current = store.getState().statesByGameId[gameId];
|
|
3672
3721
|
const updated = current ? { ...current, ...incoming } : incoming;
|
|
3673
3722
|
updateState(gameId, updated);
|
|
3723
|
+
drainQueue(gameId);
|
|
3674
3724
|
break;
|
|
3675
3725
|
}
|
|
3676
3726
|
case "game:rematch:requested": {
|
|
3677
3727
|
const current = store.getState().statesByGameId[event.payload.gameId];
|
|
3678
|
-
if (!current)
|
|
3728
|
+
if (!current) {
|
|
3729
|
+
enqueue(event.payload.gameId, event);
|
|
3730
|
+
return;
|
|
3731
|
+
}
|
|
3679
3732
|
const requestedBy = event.payload.requestedBy;
|
|
3680
3733
|
const userId = event.payload.userId;
|
|
3681
3734
|
const requested = new Set(
|
|
@@ -3691,7 +3744,10 @@ function createGameActionsStore(transport) {
|
|
|
3691
3744
|
}
|
|
3692
3745
|
case "game:rematch:cancelled": {
|
|
3693
3746
|
const current = store.getState().statesByGameId[event.payload.gameId];
|
|
3694
|
-
if (!current)
|
|
3747
|
+
if (!current) {
|
|
3748
|
+
enqueue(event.payload.gameId, event);
|
|
3749
|
+
return;
|
|
3750
|
+
}
|
|
3695
3751
|
const requestedBy = event.payload.requestedBy ?? [];
|
|
3696
3752
|
const updated = {
|
|
3697
3753
|
...current,
|
|
@@ -3702,7 +3758,10 @@ function createGameActionsStore(transport) {
|
|
|
3702
3758
|
}
|
|
3703
3759
|
case "game:rematch:started": {
|
|
3704
3760
|
const current = store.getState().statesByGameId[event.payload.gameId];
|
|
3705
|
-
if (!current)
|
|
3761
|
+
if (!current) {
|
|
3762
|
+
enqueue(event.payload.gameId, event);
|
|
3763
|
+
return;
|
|
3764
|
+
}
|
|
3706
3765
|
const updated = {
|
|
3707
3766
|
...current,
|
|
3708
3767
|
rematchRequestedBy: event.payload.playerIds ?? []
|
|
@@ -3713,7 +3772,10 @@ function createGameActionsStore(transport) {
|
|
|
3713
3772
|
case "game:pot:updated": {
|
|
3714
3773
|
const { gameId, totalPotMinor } = event.payload;
|
|
3715
3774
|
const current = store.getState().statesByGameId[gameId];
|
|
3716
|
-
if (!current)
|
|
3775
|
+
if (!current) {
|
|
3776
|
+
enqueue(gameId, event);
|
|
3777
|
+
return;
|
|
3778
|
+
}
|
|
3717
3779
|
const updated = {
|
|
3718
3780
|
...current,
|
|
3719
3781
|
totalPotMinor
|
|
@@ -3726,12 +3788,123 @@ function createGameActionsStore(transport) {
|
|
|
3726
3788
|
}
|
|
3727
3789
|
};
|
|
3728
3790
|
const joinGame = (gameId) => transport.joinRoom(`game:${gameId}`);
|
|
3791
|
+
const getCountdownDigit = (gameId, nowMs) => {
|
|
3792
|
+
const state = store.getState().statesByGameId[gameId];
|
|
3793
|
+
if (!state) return null;
|
|
3794
|
+
if (isRpsState(state)) {
|
|
3795
|
+
if (state.roundState.phase !== "starting") return null;
|
|
3796
|
+
const remaining = new Date(state.roundState.selectionEndsAt).getTime() - nowMs;
|
|
3797
|
+
if (remaining <= 0) return null;
|
|
3798
|
+
return Math.ceil(remaining / 1e3);
|
|
3799
|
+
}
|
|
3800
|
+
const bufferEndsAt = state.bufferEndsAt;
|
|
3801
|
+
if (bufferEndsAt) {
|
|
3802
|
+
const remaining = new Date(bufferEndsAt).getTime() - nowMs;
|
|
3803
|
+
if (remaining <= 0) return null;
|
|
3804
|
+
return Math.ceil(remaining / 1e3);
|
|
3805
|
+
}
|
|
3806
|
+
return null;
|
|
3807
|
+
};
|
|
3808
|
+
const getChessClockTimes = (gameId, nowMs) => {
|
|
3809
|
+
const state = store.getState().statesByGameId[gameId];
|
|
3810
|
+
if (!state || state.gameType !== "chess") return null;
|
|
3811
|
+
const s = state;
|
|
3812
|
+
let whiteMs = s.whiteTimeMs ?? 0;
|
|
3813
|
+
let blackMs = s.blackTimeMs ?? 0;
|
|
3814
|
+
if (s.status === "active" && s.currentPlayerId) {
|
|
3815
|
+
const startedAt = Date.parse(s.turnStartedAt);
|
|
3816
|
+
if (!Number.isNaN(startedAt)) {
|
|
3817
|
+
const elapsed = Math.max(0, nowMs - startedAt);
|
|
3818
|
+
if (s.currentPlayerId === s.whitePlayerId) {
|
|
3819
|
+
whiteMs = Math.max(0, whiteMs - elapsed);
|
|
3820
|
+
} else if (s.currentPlayerId === s.blackPlayerId) {
|
|
3821
|
+
blackMs = Math.max(0, blackMs - elapsed);
|
|
3822
|
+
}
|
|
3823
|
+
}
|
|
3824
|
+
}
|
|
3825
|
+
return { whiteTimeMs: whiteMs, blackTimeMs: blackMs };
|
|
3826
|
+
};
|
|
3827
|
+
const getChessCapturedPieces = (gameId) => {
|
|
3828
|
+
const state = store.getState().statesByGameId[gameId];
|
|
3829
|
+
if (!state || state.gameType !== "chess") return null;
|
|
3830
|
+
const fen = state.fen;
|
|
3831
|
+
if (!fen) return { capturedByWhite: [], capturedByBlack: [] };
|
|
3832
|
+
const placement = fen.split(" ")[0];
|
|
3833
|
+
const white = {};
|
|
3834
|
+
const black = {};
|
|
3835
|
+
for (const char of placement) {
|
|
3836
|
+
if (char === "/" || char >= "1" && char <= "8") continue;
|
|
3837
|
+
const lower = char.toLowerCase();
|
|
3838
|
+
if (char === lower) {
|
|
3839
|
+
black[lower] = (black[lower] ?? 0) + 1;
|
|
3840
|
+
} else {
|
|
3841
|
+
white[lower] = (white[lower] ?? 0) + 1;
|
|
3842
|
+
}
|
|
3843
|
+
}
|
|
3844
|
+
const INITIAL = {
|
|
3845
|
+
p: 8,
|
|
3846
|
+
r: 2,
|
|
3847
|
+
n: 2,
|
|
3848
|
+
b: 2,
|
|
3849
|
+
q: 1,
|
|
3850
|
+
k: 1
|
|
3851
|
+
};
|
|
3852
|
+
const capturedByWhite = [];
|
|
3853
|
+
const capturedByBlack = [];
|
|
3854
|
+
for (const [type, initial] of Object.entries(INITIAL)) {
|
|
3855
|
+
const missingBlack = initial - (black[type] ?? 0);
|
|
3856
|
+
for (let i = 0; i < missingBlack; i++) capturedByWhite.push(`b${type}`);
|
|
3857
|
+
const missingWhite = initial - (white[type] ?? 0);
|
|
3858
|
+
for (let i = 0; i < missingWhite; i++) capturedByBlack.push(`w${type}`);
|
|
3859
|
+
}
|
|
3860
|
+
return { capturedByWhite, capturedByBlack };
|
|
3861
|
+
};
|
|
3862
|
+
const getTicTacToeClockTimes = (gameId, nowMs) => {
|
|
3863
|
+
const state = store.getState().statesByGameId[gameId];
|
|
3864
|
+
if (!state || state.gameType !== "tic-tac-toe") return null;
|
|
3865
|
+
const s = state;
|
|
3866
|
+
let xMs = s.xTimeMs ?? 0;
|
|
3867
|
+
let oMs = s.oTimeMs ?? 0;
|
|
3868
|
+
if (s.status === "active" && s.currentPlayerId) {
|
|
3869
|
+
const currentMark = s.playerMarks[s.currentPlayerId];
|
|
3870
|
+
const startedAt = Date.parse(s.turnStartedAt);
|
|
3871
|
+
if (!Number.isNaN(startedAt)) {
|
|
3872
|
+
const elapsed = Math.max(0, nowMs - startedAt);
|
|
3873
|
+
if (currentMark === "X") xMs = Math.max(0, xMs - elapsed);
|
|
3874
|
+
else if (currentMark === "O") oMs = Math.max(0, oMs - elapsed);
|
|
3875
|
+
}
|
|
3876
|
+
}
|
|
3877
|
+
return { xTimeMs: xMs, oTimeMs: oMs };
|
|
3878
|
+
};
|
|
3879
|
+
const getConnect4ClockTimes = (gameId, nowMs) => {
|
|
3880
|
+
const state = store.getState().statesByGameId[gameId];
|
|
3881
|
+
if (!state || state.gameType !== "connect-four") return null;
|
|
3882
|
+
const s = state;
|
|
3883
|
+
let redMs = s.redTimeMs ?? 0;
|
|
3884
|
+
let yellowMs = s.yellowTimeMs ?? 0;
|
|
3885
|
+
if (s.status === "active" && s.currentPlayerId) {
|
|
3886
|
+
const currentColor = s.playerColors[s.currentPlayerId];
|
|
3887
|
+
const startedAt = Date.parse(s.turnStartedAt);
|
|
3888
|
+
if (!Number.isNaN(startedAt)) {
|
|
3889
|
+
const elapsed = Math.max(0, nowMs - startedAt);
|
|
3890
|
+
if (currentColor === "RED") redMs = Math.max(0, redMs - elapsed);
|
|
3891
|
+
else if (currentColor === "YELLOW")
|
|
3892
|
+
yellowMs = Math.max(0, yellowMs - elapsed);
|
|
3893
|
+
}
|
|
3894
|
+
}
|
|
3895
|
+
return { redTimeMs: redMs, yellowTimeMs: yellowMs };
|
|
3896
|
+
};
|
|
3729
3897
|
return {
|
|
3730
3898
|
store,
|
|
3731
3899
|
setBaseState,
|
|
3732
3900
|
clearState,
|
|
3733
3901
|
applyWsEvent,
|
|
3734
|
-
joinGame
|
|
3902
|
+
joinGame,
|
|
3903
|
+
getCountdownDigit,
|
|
3904
|
+
getChessClockTimes,
|
|
3905
|
+
getChessCapturedPieces,
|
|
3906
|
+
getTicTacToeClockTimes,
|
|
3907
|
+
getConnect4ClockTimes
|
|
3735
3908
|
};
|
|
3736
3909
|
}
|
|
3737
3910
|
function isRpsState(state) {
|
|
@@ -4401,12 +4574,14 @@ var WsRouter = class {
|
|
|
4401
4574
|
}
|
|
4402
4575
|
const decoded = decodeWsEvent(eventName, payload);
|
|
4403
4576
|
if (!decoded) return;
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
this.deps.
|
|
4407
|
-
this.deps.
|
|
4408
|
-
this.deps.
|
|
4409
|
-
this.deps.
|
|
4577
|
+
const serverTs = payload !== null && typeof payload === "object" ? payload._serverTs : void 0;
|
|
4578
|
+
const event = serverTs !== void 0 ? { ...decoded, _serverTs: serverTs } : decoded;
|
|
4579
|
+
this.deps.lobbyStore.applyWsEvent(event);
|
|
4580
|
+
this.deps.gameStore.applyWsEvent(event);
|
|
4581
|
+
this.deps.gameActionsStore.applyWsEvent(event);
|
|
4582
|
+
this.deps.chatStore.applyWsEvent(event);
|
|
4583
|
+
this.deps.dmThreadsStore.applyWsEvent(event);
|
|
4584
|
+
this.deps.notificationsStore.applyWsEvent(event);
|
|
4410
4585
|
});
|
|
4411
4586
|
}
|
|
4412
4587
|
stop() {
|
|
@@ -4418,12 +4593,14 @@ var WsRouter = class {
|
|
|
4418
4593
|
this.transport.subscribeEvent(eventName, (payload) => {
|
|
4419
4594
|
const decoded = decodeWsEvent(eventName, payload);
|
|
4420
4595
|
if (!decoded) return;
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
this.deps.
|
|
4424
|
-
this.deps.
|
|
4425
|
-
this.deps.
|
|
4426
|
-
this.deps.
|
|
4596
|
+
const serverTs = payload !== null && typeof payload === "object" ? payload._serverTs : void 0;
|
|
4597
|
+
const event = serverTs !== void 0 ? { ...decoded, _serverTs: serverTs } : decoded;
|
|
4598
|
+
this.deps.lobbyStore.applyWsEvent(event);
|
|
4599
|
+
this.deps.gameStore.applyWsEvent(event);
|
|
4600
|
+
this.deps.gameActionsStore.applyWsEvent(event);
|
|
4601
|
+
this.deps.chatStore.applyWsEvent(event);
|
|
4602
|
+
this.deps.dmThreadsStore.applyWsEvent(event);
|
|
4603
|
+
this.deps.notificationsStore.applyWsEvent(event);
|
|
4427
4604
|
});
|
|
4428
4605
|
}
|
|
4429
4606
|
}
|
|
@@ -4782,10 +4959,11 @@ var SharedWorkerTransport = class extends BaseWsTransport {
|
|
|
4782
4959
|
};
|
|
4783
4960
|
|
|
4784
4961
|
// src/utils/money.ts
|
|
4785
|
-
var
|
|
4786
|
-
var export_MICRO_UNITS =
|
|
4787
|
-
var
|
|
4788
|
-
var
|
|
4962
|
+
var import_utils2 = __toESM(require_dist(), 1);
|
|
4963
|
+
var export_MICRO_UNITS = import_utils2.MICRO_UNITS;
|
|
4964
|
+
var export_SOL_MINT = import_utils.SOL_MINT;
|
|
4965
|
+
var export_formatMoneyMinor = import_utils2.formatMoneyMinor;
|
|
4966
|
+
var export_toMajor = import_utils2.toMajor;
|
|
4789
4967
|
export {
|
|
4790
4968
|
Admin,
|
|
4791
4969
|
BrowserLocalStorage,
|
|
@@ -4804,7 +4982,7 @@ export {
|
|
|
4804
4982
|
SDK,
|
|
4805
4983
|
SDK_VERSION,
|
|
4806
4984
|
SOL_DECIMALS,
|
|
4807
|
-
SOL_MINT,
|
|
4985
|
+
export_SOL_MINT as SOL_MINT,
|
|
4808
4986
|
SharedWorkerTransport,
|
|
4809
4987
|
Spectate,
|
|
4810
4988
|
StandaloneWsTransport,
|
|
@@ -4826,6 +5004,7 @@ export {
|
|
|
4826
5004
|
export_formatMoneyMinor as formatMoneyMinor,
|
|
4827
5005
|
isRetryableError,
|
|
4828
5006
|
logger,
|
|
5007
|
+
selectGameLifecycleState,
|
|
4829
5008
|
export_toMajor as toMajor,
|
|
4830
5009
|
withRetry
|
|
4831
5010
|
};
|