trucoshi 7.1.0 → 7.2.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  import { EMatchState } from "@trucoshi/prisma";
2
2
  import { SocketError } from "./server";
3
- import { IAccountDetails, IChatMessage, ILobbyOptions, IMatchDetails, IMatchPreviousHand, IPublicChatRoom, IPublicMatch, IPublicMatchInfo, IUserData, IWaitingPlayData, IWaitingSayData } from "./types";
3
+ import { IAccountDetails, IChatMessage, ILobbyOptions, IMatchDetails, IMatchPreviousHand, IPlayerRanking, IPublicChatRoom, IPublicMatch, IPublicMatchInfo, IUserData, IWaitingPlayData, IWaitingSayData } from "./types";
4
4
  import { User } from "lightning-accounts";
5
5
  export type IEventCallback<T = {}> = (args: {
6
6
  success: boolean;
@@ -43,6 +43,7 @@ export declare enum EClientEvent {
43
43
  FETCH_MATCH_DETAILS = "FETCH_MATCH_DETAILS",
44
44
  SET_MATCH_OPTIONS = "SET_MATCH_OPTIONS",
45
45
  LIST_MATCHES = "LIST_MATCHES",
46
+ LIST_RANKING = "LIST_RANKING",
46
47
  JOIN_MATCH = "JOIN_MATCH",
47
48
  START_MATCH = "START_MATCH",
48
49
  SET_PLAYER_READY = "SET_PLAYER_READY",
@@ -90,6 +91,9 @@ export interface ClientToServerEvents {
90
91
  }, callback: IEventCallback<{
91
92
  matches: Array<IPublicMatchInfo>;
92
93
  }>) => void;
94
+ [EClientEvent.LIST_RANKING]: (filters: {}, callback: IEventCallback<{
95
+ ranking: Array<IPlayerRanking>;
96
+ }>) => void;
93
97
  [EClientEvent.LOGIN]: (user: User, identityToken: string, callback: IEventCallback<{
94
98
  activeMatches?: IPublicMatchInfo[];
95
99
  }>) => void;
package/dist/events.js CHANGED
@@ -23,6 +23,7 @@ export var EClientEvent;
23
23
  EClientEvent["FETCH_MATCH_DETAILS"] = "FETCH_MATCH_DETAILS";
24
24
  EClientEvent["SET_MATCH_OPTIONS"] = "SET_MATCH_OPTIONS";
25
25
  EClientEvent["LIST_MATCHES"] = "LIST_MATCHES";
26
+ EClientEvent["LIST_RANKING"] = "LIST_RANKING";
26
27
  EClientEvent["JOIN_MATCH"] = "JOIN_MATCH";
27
28
  EClientEvent["START_MATCH"] = "START_MATCH";
28
29
  EClientEvent["SET_PLAYER_READY"] = "SET_PLAYER_READY";
@@ -1,10 +1,15 @@
1
+ import { RequestParams } from "lightning-accounts";
1
2
  import { IRandom } from "../../types";
3
+ import { AxiosResponse } from "axios";
2
4
  export declare const Random: () => IRandom;
3
5
  export interface IRng {
4
6
  combine(client: string, server: string, bitcoinHash: string, nonce: number): string;
5
7
  sha512(string: string): string;
6
8
  generateServerSeed(): string;
7
- getBitcoinLatestBlockHash(): Promise<{
9
+ getBitcoinLatestBlockHash(fn: (params?: RequestParams) => Promise<AxiosResponse<{
10
+ hash: string;
11
+ height: number;
12
+ }, any>>): Promise<{
8
13
  hash: string;
9
14
  height: number;
10
15
  }>;
@@ -7,7 +7,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { accountsApi } from "../../accounts/client";
11
10
  import forge from "node-forge";
12
11
  const rnd = Rng();
13
12
  export const Random = () => {
@@ -17,9 +16,9 @@ export const Random = () => {
17
16
  bitcoinHash: "",
18
17
  bitcoinHeight: 0,
19
18
  nonce: 0,
20
- getLatestBitcoinBlock() {
19
+ getLatestBitcoinBlock(fn) {
21
20
  return __awaiter(this, void 0, void 0, function* () {
22
- const { hash, height } = yield rnd.getBitcoinLatestBlockHash();
21
+ const { hash, height } = yield rnd.getBitcoinLatestBlockHash(fn);
23
22
  random.bitcoinHash = hash;
24
23
  random.bitcoinHeight = height;
25
24
  });
@@ -172,13 +171,10 @@ function Rng() {
172
171
  *
173
172
  * @returns {Promise<string>} The latest Bitcoin block hash
174
173
  */
175
- getBitcoinLatestBlockHash: function () {
174
+ getBitcoinLatestBlockHash: function (fn) {
176
175
  return __awaiter(this, void 0, void 0, function* () {
177
176
  try {
178
- if (!accountsApi.instance.defaults.baseURL) {
179
- return { hash: "", height: 0 };
180
- }
181
- return (yield accountsApi.wallet.getLatestBitcoinBlock()).data || { hash: "", height: 0 };
177
+ return (yield fn()).data || { hash: "", height: 0 };
182
178
  }
183
179
  catch (error) {
184
180
  return { hash: "", height: 0 };
package/dist/types.d.ts CHANGED
@@ -1,15 +1,17 @@
1
1
  export * from "./events";
2
2
  export { CARDS, CARDS_HUMAN_READABLE, BURNT_CARD } from "./lib/constants";
3
- import { User } from "lightning-accounts";
3
+ import { RequestParams, User } from "lightning-accounts";
4
4
  import { Match, MatchPlayer, MatchHand, UserStats } from "@trucoshi/prisma";
5
5
  import { IHand } from "./truco";
6
6
  import { CARDS } from "./lib";
7
+ import { AxiosResponse } from "axios";
7
8
  export declare enum EMatchState {
8
9
  UNREADY = "UNREADY",
9
10
  READY = "READY",
10
11
  STARTED = "STARTED",
11
12
  FINISHED = "FINISHED"
12
13
  }
14
+ export type IPlayerRanking = Omit<UserStats, "id" | "satsBet" | "satsWon" | "satsLost"> & Pick<User, "name" | "avatarUrl">;
13
15
  export interface IMatchDetails extends Match {
14
16
  players: Array<Pick<MatchPlayer, "id" | "accountId" | "teamIdx" | "name" | "idx">>;
15
17
  hands: Array<MatchHand>;
@@ -240,7 +242,10 @@ export interface IRandom {
240
242
  bitcoinHash: string;
241
243
  bitcoinHeight: number;
242
244
  nonce: number;
243
- getLatestBitcoinBlock(): Promise<void>;
245
+ getLatestBitcoinBlock(fn: (params?: RequestParams) => Promise<AxiosResponse<{
246
+ hash: string;
247
+ height: number;
248
+ }, any>>): Promise<void>;
244
249
  next(): void;
245
250
  pick(idx: number, max: number): number;
246
251
  reveal(): {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trucoshi",
3
- "version": "7.1.0",
3
+ "version": "7.2.0",
4
4
  "description": "Lightning Truco Server",
5
5
  "main": "dist/types.js",
6
6
  "license": "GPL-3.0",