most-box 0.1.2 → 0.1.4

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.
Files changed (172) hide show
  1. package/README.md +18 -5
  2. package/electron/afterPack.cjs +87 -0
  3. package/electron/main.js +85 -1
  4. package/electron/updateChecker.js +97 -0
  5. package/electron/updateChecker.test.js +147 -0
  6. package/out/404/index.html +2 -2
  7. package/out/404.html +2 -2
  8. package/out/__next.__PAGE__.txt +5 -5
  9. package/out/__next._full.txt +13 -13
  10. package/out/__next._head.txt +3 -3
  11. package/out/__next._index.txt +6 -6
  12. package/out/__next._tree.txt +2 -2
  13. package/out/_next/static/chunks/02zzxfop_k6tl.css +1 -0
  14. package/out/_next/static/chunks/03gsbg0fr00ey.js +1 -0
  15. package/out/_next/static/chunks/06lttvu7563zo.css +1 -0
  16. package/out/_next/static/chunks/0fo9-h4knidcz.js +1 -0
  17. package/out/_next/static/chunks/0hyds~bp.auvh.js +1 -0
  18. package/out/_next/static/chunks/0i9sfdypwuw8~.js +1 -0
  19. package/out/_next/static/chunks/0olqjomda37-e.js +1 -0
  20. package/out/_next/static/chunks/{0aq.rc9woa2nz.js → 0puk.7e.tr2zy.js} +1 -1
  21. package/out/_next/static/chunks/0s1k6rlwy02c2.js +1 -0
  22. package/out/_next/static/chunks/0sgltmtk_9s8p.css +1 -0
  23. package/out/_next/static/chunks/0snehvtvu1n4q.js +1 -0
  24. package/out/_next/static/chunks/{16xls5tt_68lx.js → 0s~g.l~x049o2.js} +1 -1
  25. package/out/_next/static/chunks/{12nr19.nnn6s3.js → 0t_3xxx4zkerp.js} +2 -2
  26. package/out/_next/static/chunks/0u38kke9vhobe.js +1 -0
  27. package/out/_next/static/chunks/0vd4_a5x-wpdh.js +1 -0
  28. package/out/_next/static/chunks/0xx_10jns1.s7.css +1 -0
  29. package/out/_next/static/chunks/{0etes81d_cihn.js → 10f-t2n4y1zx8.js} +1 -1
  30. package/out/_next/static/chunks/{0l5_.uqb-uqb8.js → 13jdyag9a-~kk.js} +1 -1
  31. package/out/_next/static/chunks/{0q0ksgxg98xgd.js → 17cwkb2yn_akx.js} +1 -1
  32. package/out/_not-found/__next._full.txt +11 -11
  33. package/out/_not-found/__next._head.txt +3 -3
  34. package/out/_not-found/__next._index.txt +6 -6
  35. package/out/_not-found/__next._not-found.__PAGE__.txt +4 -4
  36. package/out/_not-found/__next._not-found.txt +3 -3
  37. package/out/_not-found/__next._tree.txt +1 -1
  38. package/out/_not-found/index.html +2 -2
  39. package/out/_not-found/index.txt +11 -11
  40. package/out/admin/__next._full.txt +12 -12
  41. package/out/admin/__next._head.txt +3 -3
  42. package/out/admin/__next._index.txt +6 -6
  43. package/out/admin/__next._tree.txt +1 -1
  44. package/out/admin/__next.admin.__PAGE__.txt +4 -4
  45. package/out/admin/__next.admin.txt +3 -3
  46. package/out/admin/index.html +2 -2
  47. package/out/admin/index.txt +12 -12
  48. package/out/app/__next._full.txt +12 -12
  49. package/out/app/__next._head.txt +3 -3
  50. package/out/app/__next._index.txt +6 -6
  51. package/out/app/__next._tree.txt +1 -1
  52. package/out/app/__next.app.__PAGE__.txt +4 -4
  53. package/out/app/__next.app.txt +3 -3
  54. package/out/app/index.html +2 -2
  55. package/out/app/index.txt +12 -12
  56. package/out/chat/__next._full.txt +12 -12
  57. package/out/chat/__next._head.txt +3 -3
  58. package/out/chat/__next._index.txt +6 -6
  59. package/out/chat/__next._tree.txt +1 -1
  60. package/out/chat/__next.chat.__PAGE__.txt +4 -4
  61. package/out/chat/__next.chat.txt +3 -3
  62. package/out/chat/index.html +2 -2
  63. package/out/chat/index.txt +12 -12
  64. package/out/chat/join/__next._full.txt +12 -12
  65. package/out/chat/join/__next._head.txt +3 -3
  66. package/out/chat/join/__next._index.txt +6 -6
  67. package/out/chat/join/__next._tree.txt +1 -1
  68. package/out/chat/join/__next.chat.join.__PAGE__.txt +4 -4
  69. package/out/chat/join/__next.chat.join.txt +3 -3
  70. package/out/chat/join/__next.chat.txt +3 -3
  71. package/out/chat/join/index.html +2 -2
  72. package/out/chat/join/index.txt +12 -12
  73. package/out/download/__next._full.txt +34 -30
  74. package/out/download/__next._head.txt +3 -3
  75. package/out/download/__next._index.txt +6 -6
  76. package/out/download/__next._tree.txt +2 -2
  77. package/out/download/__next.download.__PAGE__.txt +8 -13
  78. package/out/download/__next.download.txt +3 -3
  79. package/out/download/index.html +2 -2
  80. package/out/download/index.txt +34 -30
  81. package/out/favicon.ico +0 -0
  82. package/out/game/__next._full.txt +20 -0
  83. package/out/game/__next._head.txt +5 -0
  84. package/out/game/__next._index.txt +9 -0
  85. package/out/game/__next._tree.txt +5 -0
  86. package/out/game/__next.game.__PAGE__.txt +6 -0
  87. package/out/game/__next.game.txt +5 -0
  88. package/out/game/gandengyan/__next._full.txt +26 -0
  89. package/out/game/gandengyan/__next._head.txt +5 -0
  90. package/out/game/gandengyan/__next._index.txt +9 -0
  91. package/out/game/gandengyan/__next._tree.txt +6 -0
  92. package/out/game/gandengyan/__next.game.gandengyan.__PAGE__.txt +10 -0
  93. package/out/game/gandengyan/__next.game.gandengyan.txt +5 -0
  94. package/out/game/gandengyan/__next.game.txt +5 -0
  95. package/out/game/gandengyan/index.html +15 -0
  96. package/out/game/gandengyan/index.txt +26 -0
  97. package/out/game/index.html +1 -0
  98. package/out/game/index.txt +20 -0
  99. package/out/game/zhajinhua/__next._full.txt +25 -0
  100. package/out/game/zhajinhua/__next._head.txt +5 -0
  101. package/out/game/zhajinhua/__next._index.txt +9 -0
  102. package/out/game/zhajinhua/__next._tree.txt +5 -0
  103. package/out/game/zhajinhua/__next.game.txt +5 -0
  104. package/out/game/zhajinhua/__next.game.zhajinhua.__PAGE__.txt +9 -0
  105. package/out/game/zhajinhua/__next.game.zhajinhua.txt +5 -0
  106. package/out/game/zhajinhua/index.html +15 -0
  107. package/out/game/zhajinhua/index.txt +25 -0
  108. package/out/index.html +2 -2
  109. package/out/index.txt +13 -13
  110. package/out/note/__next._full.txt +12 -12
  111. package/out/note/__next._head.txt +3 -3
  112. package/out/note/__next._index.txt +6 -6
  113. package/out/note/__next._tree.txt +1 -1
  114. package/out/note/__next.note.__PAGE__.txt +4 -4
  115. package/out/note/__next.note.txt +3 -3
  116. package/out/note/index.html +2 -2
  117. package/out/note/index.txt +12 -12
  118. package/out/ping/__next._full.txt +12 -12
  119. package/out/ping/__next._head.txt +3 -3
  120. package/out/ping/__next._index.txt +6 -6
  121. package/out/ping/__next._tree.txt +1 -1
  122. package/out/ping/__next.ping.__PAGE__.txt +4 -4
  123. package/out/ping/__next.ping.txt +3 -3
  124. package/out/ping/index.html +2 -2
  125. package/out/ping/index.txt +12 -12
  126. package/out/web3/__next._full.txt +12 -12
  127. package/out/web3/__next._head.txt +3 -3
  128. package/out/web3/__next._index.txt +6 -6
  129. package/out/web3/__next._tree.txt +1 -1
  130. package/out/web3/__next.web3.__PAGE__.txt +4 -4
  131. package/out/web3/__next.web3.txt +3 -3
  132. package/out/web3/ed25519/__next._full.txt +10 -10
  133. package/out/web3/ed25519/__next._head.txt +3 -3
  134. package/out/web3/ed25519/__next._index.txt +6 -6
  135. package/out/web3/ed25519/__next._tree.txt +1 -1
  136. package/out/web3/ed25519/__next.web3.ed25519.__PAGE__.txt +2 -2
  137. package/out/web3/ed25519/__next.web3.ed25519.txt +3 -3
  138. package/out/web3/ed25519/__next.web3.txt +3 -3
  139. package/out/web3/ed25519/index.html +1 -1
  140. package/out/web3/ed25519/index.txt +10 -10
  141. package/out/web3/index.html +2 -2
  142. package/out/web3/index.txt +12 -12
  143. package/out/web3/tools/__next._full.txt +10 -10
  144. package/out/web3/tools/__next._head.txt +3 -3
  145. package/out/web3/tools/__next._index.txt +6 -6
  146. package/out/web3/tools/__next._tree.txt +1 -1
  147. package/out/web3/tools/__next.web3.tools.__PAGE__.txt +2 -2
  148. package/out/web3/tools/__next.web3.tools.txt +3 -3
  149. package/out/web3/tools/__next.web3.txt +3 -3
  150. package/out/web3/tools/index.html +1 -1
  151. package/out/web3/tools/index.txt +10 -10
  152. package/package.json +29 -29
  153. package/public/favicon.ico +0 -0
  154. package/server/src/config.js +1 -1
  155. package/server/src/core/gameRoom.js +222 -0
  156. package/server/src/core/zhajinhua.js +563 -0
  157. package/server/src/games/gandengyan.js +612 -0
  158. package/server/src/http/access.js +4 -0
  159. package/server/src/http/app.js +14 -1
  160. package/server/src/index.js +9 -1
  161. package/server/src/utils/api.js +19 -1
  162. package/out/_next/static/chunks/0.e2avjgna_b2.js +0 -1
  163. package/out/_next/static/chunks/03h~nhgj0hv3p.css +0 -1
  164. package/out/_next/static/chunks/07td.jq7xff84.css +0 -1
  165. package/out/_next/static/chunks/0gwian.hp3-92.js +0 -1
  166. package/out/_next/static/chunks/0mex8svsiv-2l.js +0 -1
  167. package/out/_next/static/chunks/0myq9gs8szydh.js +0 -1
  168. package/out/_next/static/chunks/0p0sv~fuddvgr.js +0 -1
  169. package/out/_next/static/chunks/0wtf0xsiicxx6.js +0 -1
  170. /package/out/_next/static/{t7ZIeQpVvjz4a7-5Tt-VK → sSvbBrwXZY-4lBmcHshga}/_buildManifest.js +0 -0
  171. /package/out/_next/static/{t7ZIeQpVvjz4a7-5Tt-VK → sSvbBrwXZY-4lBmcHshga}/_clientMiddlewareManifest.js +0 -0
  172. /package/out/_next/static/{t7ZIeQpVvjz4a7-5Tt-VK → sSvbBrwXZY-4lBmcHshga}/_ssgManifest.js +0 -0
@@ -0,0 +1,222 @@
1
+ export const GAME_CHANNEL_TYPE = 'game'
2
+ export const GAME_EVENT_KIND = 'mostbox.game.event'
3
+ export const GAME_EVENT_VERSION = 1
4
+
5
+ export const GAME_IDS = ['gandengyan', 'zhajinhua']
6
+
7
+ const ROOM_CODE_ALPHABET = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789'
8
+
9
+ export function normalizeGameId(input) {
10
+ const value = String(input || '').trim().toLowerCase()
11
+ return GAME_IDS.includes(value) ? value : ''
12
+ }
13
+
14
+ export function normalizeGameRoomCode(input) {
15
+ return String(input || '')
16
+ .trim()
17
+ .toUpperCase()
18
+ .replace(/[^A-Z0-9]/g, '')
19
+ .slice(0, 8)
20
+ }
21
+
22
+ export function isValidGameRoomCode(input) {
23
+ return /^[A-Z0-9]{4,8}$/.test(String(input || ''))
24
+ }
25
+
26
+ export function createGameRoomCode() {
27
+ let code = ''
28
+ for (let i = 0; i < 6; i++) {
29
+ code += ROOM_CODE_ALPHABET[randomInt(ROOM_CODE_ALPHABET.length)]
30
+ }
31
+ return code
32
+ }
33
+
34
+ export function gameRoomCodeToChannelName(gameId, roomCode) {
35
+ const normalizedGameId = normalizeGameId(gameId)
36
+ const code = normalizeGameRoomCode(roomCode)
37
+ if (!normalizedGameId || !isValidGameRoomCode(code)) return ''
38
+ return `game-${normalizedGameId}-${code.toLowerCase()}`
39
+ }
40
+
41
+ export function channelNameToGameRoom(input) {
42
+ const value = String(input || '').trim().toLowerCase()
43
+ const match = /^game-([a-z0-9]+)-([a-z0-9]+)$/.exec(value)
44
+ if (!match) return null
45
+ const gameId = normalizeGameId(match[1])
46
+ const roomCode = normalizeGameRoomCode(match[2])
47
+ if (!gameId || !isValidGameRoomCode(roomCode)) return null
48
+ return { gameId, roomCode }
49
+ }
50
+
51
+ export function createGameEvent({ gameId, roomCode, event, payload }) {
52
+ const normalizedGameId = normalizeGameId(gameId)
53
+ const code = normalizeGameRoomCode(roomCode)
54
+ return {
55
+ kind: GAME_EVENT_KIND,
56
+ version: GAME_EVENT_VERSION,
57
+ gameId: normalizedGameId,
58
+ roomCode: code,
59
+ event: String(event || ''),
60
+ eventId: createEventId(normalizedGameId || 'game'),
61
+ payload: payload || {},
62
+ }
63
+ }
64
+
65
+ export function parseGameEvent(content, options = {}) {
66
+ try {
67
+ const event = JSON.parse(String(content || ''))
68
+ if (
69
+ !event ||
70
+ event.kind !== GAME_EVENT_KIND ||
71
+ event.version !== GAME_EVENT_VERSION ||
72
+ typeof event.event !== 'string' ||
73
+ typeof event.eventId !== 'string'
74
+ ) {
75
+ return null
76
+ }
77
+
78
+ const gameId = normalizeGameId(event.gameId)
79
+ const roomCode = normalizeGameRoomCode(event.roomCode)
80
+ if (!gameId || !isValidGameRoomCode(roomCode)) return null
81
+ if (options.gameId && gameId !== normalizeGameId(options.gameId)) return null
82
+ if (
83
+ options.roomCode &&
84
+ roomCode !== normalizeGameRoomCode(options.roomCode)
85
+ ) {
86
+ return null
87
+ }
88
+
89
+ return {
90
+ ...event,
91
+ gameId,
92
+ roomCode,
93
+ payload:
94
+ event.payload && typeof event.payload === 'object'
95
+ ? event.payload
96
+ : {},
97
+ }
98
+ } catch {
99
+ return null
100
+ }
101
+ }
102
+
103
+ export function deriveGameRoomLobby(messages = [], options = {}) {
104
+ const players = []
105
+ const playerMap = new Map()
106
+ let hostAddress = ''
107
+
108
+ for (const message of sortMessages(messages)) {
109
+ const event = parseGameEvent(message.content, options)
110
+ if (!event) continue
111
+
112
+ if (event.event === 'room:create') {
113
+ const player = createPlayerFromPayload(event.payload?.player, message.author)
114
+ if (!player) continue
115
+ if (!hostAddress) hostAddress = player.address
116
+ upsertPlayer(players, playerMap, player)
117
+ continue
118
+ }
119
+
120
+ if (event.event === 'player:join') {
121
+ const player = createPlayerFromPayload(event.payload?.player, message.author)
122
+ if (player) upsertPlayer(players, playerMap, player)
123
+ }
124
+ }
125
+
126
+ return {
127
+ gameId: normalizeGameId(options.gameId),
128
+ roomCode: normalizeGameRoomCode(options.roomCode),
129
+ hostAddress,
130
+ players,
131
+ }
132
+ }
133
+
134
+ export function getLatestGameState(messages = [], options = {}) {
135
+ let latest = null
136
+ for (const message of sortMessages(messages)) {
137
+ const event = parseGameEvent(message.content, options)
138
+ if (!event) continue
139
+ if (event.event !== 'room:state') continue
140
+ const seq = Number(event.payload?.seq || 0)
141
+ if (!latest || seq >= Number(latest.payload?.seq || 0)) {
142
+ latest = event
143
+ }
144
+ }
145
+ return latest
146
+ }
147
+
148
+ export function createPlayerFromPayload(input, author) {
149
+ if (!input || typeof input !== 'object') return null
150
+ const address = normalizeAddress(input.address || author)
151
+ if (!address || normalizeAddress(author) !== address) return null
152
+ const name = String(input.name || '').trim().slice(0, 50) || shortAddress(address)
153
+ const publicKey = String(input.publicKey || '').trim()
154
+ return {
155
+ address,
156
+ name,
157
+ publicKey,
158
+ joinedAt: Number(input.joinedAt || Date.now()),
159
+ }
160
+ }
161
+
162
+ export function normalizeGamePlayer(input) {
163
+ if (!input || typeof input !== 'object') return null
164
+ const address = normalizeAddress(input.address)
165
+ if (!address) return null
166
+ return {
167
+ ...input,
168
+ address,
169
+ name: String(input.name || shortAddress(address)).slice(0, 50),
170
+ publicKey: String(input.publicKey || ''),
171
+ }
172
+ }
173
+
174
+ export function normalizeAddress(value) {
175
+ const address = String(value || '').trim()
176
+ return /^0x[a-fA-F0-9]{40}$/.test(address) ? address.toLowerCase() : ''
177
+ }
178
+
179
+ function upsertPlayer(players, playerMap, player) {
180
+ const existing = playerMap.get(player.address)
181
+ if (existing) {
182
+ Object.assign(existing, player)
183
+ return
184
+ }
185
+ players.push(player)
186
+ playerMap.set(player.address, player)
187
+ }
188
+
189
+ function sortMessages(messages) {
190
+ return [...messages].sort(
191
+ (a, b) => Number(a.timestamp || 0) - Number(b.timestamp || 0)
192
+ )
193
+ }
194
+
195
+ function createEventId(prefix) {
196
+ return `${prefix}_${Date.now()}_${randomHex(4)}`
197
+ }
198
+
199
+ function randomInt(max) {
200
+ if (globalThis.crypto?.getRandomValues) {
201
+ const value = new Uint32Array(1)
202
+ globalThis.crypto.getRandomValues(value)
203
+ return value[0] % max
204
+ }
205
+ return Math.floor(Math.random() * max)
206
+ }
207
+
208
+ function randomHex(byteLength) {
209
+ const bytes = new Uint8Array(byteLength)
210
+ if (globalThis.crypto?.getRandomValues) {
211
+ globalThis.crypto.getRandomValues(bytes)
212
+ } else {
213
+ for (let i = 0; i < bytes.length; i++) {
214
+ bytes[i] = Math.floor(Math.random() * 256)
215
+ }
216
+ }
217
+ return [...bytes].map(byte => byte.toString(16).padStart(2, '0')).join('')
218
+ }
219
+
220
+ function shortAddress(address) {
221
+ return address ? `${address.slice(0, 6)}...${address.slice(-4)}` : ''
222
+ }