trucoshi 8.0.0 → 8.1.0
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/events.d.ts +7 -6
- package/dist/events.js +1 -1
- package/dist/lib/classes/Random.d.ts +1 -0
- package/dist/lib/classes/Random.js +16 -9
- package/dist/lib/constants.js +1 -1
- package/dist/types.d.ts +5 -2
- package/dist/types.js +1 -0
- package/package.json +1 -1
package/dist/events.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { EMatchState } from "@trucoshi/prisma";
|
|
2
2
|
import { SocketError } from "./server";
|
|
3
3
|
import { IAccountDetails, IChatMessage, ILobbyOptions, IMatchDetails, IPlayerRanking, IPublicChatRoom, IPublicMatch, IPublicMatchInfo, IUserData, IWaitingPlayData, IWaitingSayData } from "./types";
|
|
4
|
-
import { User } from "lightning-accounts";
|
|
5
4
|
export type IEventCallback<T = {}> = (args: {
|
|
6
5
|
success: boolean;
|
|
7
6
|
error?: SocketError;
|
|
@@ -17,10 +16,16 @@ export declare enum EServerEvent {
|
|
|
17
16
|
KICK_PLAYER = "PLAYER_KICKED",
|
|
18
17
|
UPDATE_ACTIVE_MATCHES = "UPDATE_ACTIVE_MATCHES",
|
|
19
18
|
WAITING_POSSIBLE_SAY = "WAITING_POSSIBLE_SAY",
|
|
20
|
-
UPDATE_CHAT = "UPDAET_CHAT"
|
|
19
|
+
UPDATE_CHAT = "UPDAET_CHAT",
|
|
20
|
+
ERROR = "ERROR"
|
|
21
21
|
}
|
|
22
22
|
export interface ServerToClientEvents {
|
|
23
23
|
[EServerEvent.PONG]: (serverTime: number, clientTime: number) => void;
|
|
24
|
+
[EServerEvent.ERROR]: (error: {
|
|
25
|
+
code: string;
|
|
26
|
+
message: string;
|
|
27
|
+
action: string;
|
|
28
|
+
}) => void;
|
|
24
29
|
[EServerEvent.UPDATE_CHAT]: (room: IPublicChatRoom) => void;
|
|
25
30
|
[EServerEvent.NEW_MESSAGE]: (roomId: string, message?: IChatMessage) => void;
|
|
26
31
|
[EServerEvent.UPDATE_ACTIVE_MATCHES]: (activeMatches: IPublicMatchInfo[]) => void;
|
|
@@ -33,7 +38,6 @@ export interface ServerToClientEvents {
|
|
|
33
38
|
[EServerEvent.REFRESH_IDENTITY]: (userId: number, callback: (identityJwt: string | null) => void) => void;
|
|
34
39
|
}
|
|
35
40
|
export declare enum EClientEvent {
|
|
36
|
-
LOGIN = "LOGIN",
|
|
37
41
|
LOGOUT = "LOGOUT",
|
|
38
42
|
LEAVE_MATCH = "LEAVE_MATCH",
|
|
39
43
|
CREATE_MATCH = "CREATE_MATCH",
|
|
@@ -96,7 +100,4 @@ export interface ClientToServerEvents {
|
|
|
96
100
|
[EClientEvent.LIST_RANKING]: (filters: {}, callback: IEventCallback<{
|
|
97
101
|
ranking: Array<IPlayerRanking>;
|
|
98
102
|
}>) => void;
|
|
99
|
-
[EClientEvent.LOGIN]: (user: User, identityToken: string, callback: IEventCallback<{
|
|
100
|
-
activeMatches?: IPublicMatchInfo[];
|
|
101
|
-
}>) => void;
|
|
102
103
|
}
|
package/dist/events.js
CHANGED
|
@@ -11,10 +11,10 @@ export var EServerEvent;
|
|
|
11
11
|
EServerEvent["UPDATE_ACTIVE_MATCHES"] = "UPDATE_ACTIVE_MATCHES";
|
|
12
12
|
EServerEvent["WAITING_POSSIBLE_SAY"] = "WAITING_POSSIBLE_SAY";
|
|
13
13
|
EServerEvent["UPDATE_CHAT"] = "UPDAET_CHAT";
|
|
14
|
+
EServerEvent["ERROR"] = "ERROR";
|
|
14
15
|
})(EServerEvent || (EServerEvent = {}));
|
|
15
16
|
export var EClientEvent;
|
|
16
17
|
(function (EClientEvent) {
|
|
17
|
-
EClientEvent["LOGIN"] = "LOGIN";
|
|
18
18
|
EClientEvent["LOGOUT"] = "LOGOUT";
|
|
19
19
|
EClientEvent["LEAVE_MATCH"] = "LEAVE_MATCH";
|
|
20
20
|
EClientEvent["CREATE_MATCH"] = "CREATE_MATCH";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { RequestParams } from "lightning-accounts";
|
|
2
2
|
import { IRandom } from "../../types";
|
|
3
3
|
import { AxiosResponse } from "axios";
|
|
4
|
+
export declare const rng: IRng;
|
|
4
5
|
export declare const Random: () => IRandom;
|
|
5
6
|
export interface IRng {
|
|
6
7
|
combine(client: string, server: string, bitcoinHash: string, nonce: number): string;
|
|
@@ -8,23 +8,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import forge from "node-forge";
|
|
11
|
-
const
|
|
11
|
+
export const rng = Rng();
|
|
12
12
|
export const Random = () => {
|
|
13
13
|
const random = {
|
|
14
|
-
secret:
|
|
14
|
+
secret: rng.generateServerSeed(),
|
|
15
15
|
clients: [],
|
|
16
16
|
bitcoinHash: "",
|
|
17
17
|
bitcoinHeight: 0,
|
|
18
18
|
nonce: 0,
|
|
19
19
|
getLatestBitcoinBlock(fn) {
|
|
20
20
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
-
const { hash, height } = yield
|
|
21
|
+
const { hash, height } = yield rng.getBitcoinLatestBlockHash(fn);
|
|
22
22
|
random.bitcoinHash = hash;
|
|
23
23
|
random.bitcoinHeight = height;
|
|
24
24
|
});
|
|
25
25
|
},
|
|
26
26
|
pick(key, max) {
|
|
27
|
-
return
|
|
27
|
+
return rng.generateInteger(random.clients[key], random.secret, random.bitcoinHash, random.nonce, 0, max);
|
|
28
28
|
},
|
|
29
29
|
next() {
|
|
30
30
|
random.nonce++;
|
|
@@ -111,11 +111,18 @@ function Rng() {
|
|
|
111
111
|
* @param {number} max - The maximum value of the range.
|
|
112
112
|
* @returns {number} A random integer between min and max (inclusive).
|
|
113
113
|
*/
|
|
114
|
-
generateInteger
|
|
115
|
-
const
|
|
116
|
-
const
|
|
117
|
-
const
|
|
118
|
-
|
|
114
|
+
generateInteger(clientSeed, serverSeed, bitcoinHash, nonce, min, max) {
|
|
115
|
+
const range = BigInt(max - min + 1);
|
|
116
|
+
const maxHash = BigInt("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); // 128-bit max (32 hex chars)
|
|
117
|
+
const threshold = maxHash - (maxHash % range); // Ensure divisibility
|
|
118
|
+
let localNonce = nonce;
|
|
119
|
+
let hash;
|
|
120
|
+
do {
|
|
121
|
+
const preHash = this.combine(clientSeed, serverSeed, bitcoinHash, localNonce);
|
|
122
|
+
hash = BigInt(`0x${this.sha512(preHash).slice(0, 32)}`); // Use 128 bits
|
|
123
|
+
localNonce++;
|
|
124
|
+
} while (hash >= threshold);
|
|
125
|
+
return Number(hash % range) + min;
|
|
119
126
|
},
|
|
120
127
|
/**
|
|
121
128
|
* Generates a random float between 0 and 1 using the fairjs library.
|
package/dist/lib/constants.js
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { IHand, IPlayInstance } from "./truco";
|
|
|
6
6
|
import { CARDS, ITable } from "./lib";
|
|
7
7
|
import { AxiosResponse } from "axios";
|
|
8
8
|
import { ITrucoshi } from "./server";
|
|
9
|
+
import { BotProfile } from "./truco/Bot";
|
|
9
10
|
export declare enum EMatchState {
|
|
10
11
|
UNREADY = "UNREADY",
|
|
11
12
|
READY = "READY",
|
|
@@ -196,7 +197,8 @@ export declare enum GAME_ERROR {
|
|
|
196
197
|
INVALID_COMAND = "INVALID_COMAND",
|
|
197
198
|
INSUFFICIENT_BALANCE = "INSUFFICIENT_BALANCE",
|
|
198
199
|
GAME_REQUIRES_ACCOUNT = "GAME_REQUIRES_ACCOUNT",
|
|
199
|
-
NO_FLOR = "NO_FLOR"
|
|
200
|
+
NO_FLOR = "NO_FLOR",
|
|
201
|
+
INVALID_SESSION = "INVALID_SESSION"
|
|
200
202
|
}
|
|
201
203
|
export interface EnvidoState {
|
|
202
204
|
accept: number;
|
|
@@ -283,7 +285,7 @@ export interface IPlayer {
|
|
|
283
285
|
avatarUrl: string | undefined | null;
|
|
284
286
|
name: string;
|
|
285
287
|
key: string;
|
|
286
|
-
bot:
|
|
288
|
+
bot: BotProfile | null;
|
|
287
289
|
session: string;
|
|
288
290
|
payRequestId?: number;
|
|
289
291
|
abandonedTime: number;
|
|
@@ -315,6 +317,7 @@ export interface IPlayer {
|
|
|
315
317
|
ready: boolean;
|
|
316
318
|
getRandomCard(): [number, ICard];
|
|
317
319
|
getHighestCard(): [number, ICard];
|
|
320
|
+
getLowestCard(): [number, ICard];
|
|
318
321
|
getHighestEnvido(): number;
|
|
319
322
|
saidEnvidoPoints(): void;
|
|
320
323
|
saidFlor(): void;
|
package/dist/types.js
CHANGED
|
@@ -73,6 +73,7 @@ export var GAME_ERROR;
|
|
|
73
73
|
GAME_ERROR["INSUFFICIENT_BALANCE"] = "INSUFFICIENT_BALANCE";
|
|
74
74
|
GAME_ERROR["GAME_REQUIRES_ACCOUNT"] = "GAME_REQUIRES_ACCOUNT";
|
|
75
75
|
GAME_ERROR["NO_FLOR"] = "NO_FLOR";
|
|
76
|
+
GAME_ERROR["INVALID_SESSION"] = "INVALID_SESSION";
|
|
76
77
|
})(GAME_ERROR || (GAME_ERROR = {}));
|
|
77
78
|
export const DANGEROUS_COMMANDS = [
|
|
78
79
|
ESayCommand.MAZO,
|