Skip to content

Commit 529b465

Browse files
committed
sync for changes between forks
fix: sometimes autlogin save prompt is not displayed fix: add connect server only ui add some other components for future usage fix: make some fields custommization in main menu from config.json fix: adjust logic on player disconnect in some rare cases
1 parent 1582e16 commit 529b465

17 files changed

+246
-35
lines changed

config.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
"description": "Very nice a polite server. Must try for everyone!"
2626
}
2727
],
28+
"rightSideText": "A Minecraft client clone in the browser!",
29+
"splashText": "Gen is cooking!",
2830
"pauseLinks": [
2931
[
3032
{

src/appConfig.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ export type AppConfig = {
1515
mapsProvider?: string
1616

1717
appParams?: Record<string, any> // query string params
18+
rightSideText?: string
1819

1920
defaultSettings?: Record<string, any>
2021
forceSettings?: Record<string, boolean>
2122
// hideSettings?: Record<string, boolean>
2223
allowAutoConnect?: boolean
24+
splashText?: string
2325
pauseLinks?: Array<Array<Record<string, any>>>
2426
}
2527

src/appParams.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export type AppQsParams = {
4242
suggest_save?: string
4343
noPacketsValidation?: string
4444
testCrashApp?: string
45+
onlyConnect?: string
46+
connectText?: string
4547
freezeSettings?: string
4648

4749
// Replay params

src/cameraRotationControls.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,8 @@ export const onControInit = () => {
7474
}
7575

7676
function pointerLockChangeCallback () {
77-
if (notificationProxy.id === 'pointerlockchange') {
78-
hideNotification()
79-
}
77+
hideNotification('pointerlockchange')
78+
8079
if (appViewer.rendererState.preventEscapeMenu) return
8180
if (!pointerLock.hasPointerLock && activeModalStack.length === 0 && miscUiState.gameLoaded) {
8281
showModal({ reactType: 'pause-screen' })

src/controls.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,36 +41,43 @@ const controlOptions = {
4141
export const contro = new ControMax({
4242
commands: {
4343
general: {
44+
// movement
4445
jump: ['Space', 'A'],
4546
inventory: ['KeyE', 'X'],
4647
drop: ['KeyQ', 'B'],
4748
sneak: ['ShiftLeft'],
4849
toggleSneakOrDown: [null, 'Right Stick'],
4950
sprint: ['ControlLeft', 'Left Stick'],
51+
// game interactions
5052
nextHotbarSlot: [null, 'Right Bumper'],
5153
prevHotbarSlot: [null, 'Left Bumper'],
5254
attackDestroy: [null, 'Right Trigger'],
5355
interactPlace: [null, 'Left Trigger'],
54-
chat: [['KeyT', 'Enter']],
55-
command: ['Slash'],
5656
swapHands: ['KeyF'],
57-
zoom: ['KeyC'],
5857
selectItem: ['KeyH'], // default will be removed
5958
rotateCameraLeft: [null],
6059
rotateCameraRight: [null],
6160
rotateCameraUp: [null],
6261
rotateCameraDown: [null],
63-
viewerConsole: ['Backquote']
62+
// ui?
63+
chat: [['KeyT', 'Enter']],
64+
command: ['Slash'],
65+
// client side
66+
zoom: ['KeyC'],
67+
viewerConsole: ['Backquote'],
6468
},
6569
ui: {
6670
toggleFullscreen: ['F11'],
6771
back: [null/* 'Escape' */, 'B'],
68-
toggleMap: ['KeyM'],
72+
toggleMap: ['KeyJ'],
6973
leftClick: [null, 'A'],
7074
rightClick: [null, 'Y'],
7175
speedupCursor: [null, 'Left Stick'],
7276
pauseMenu: [null, 'Start']
7377
},
78+
communication: {
79+
toggleMicrophone: ['KeyK'],
80+
},
7481
advanced: {
7582
lockUrl: ['KeyY'],
7683
},
@@ -550,6 +557,10 @@ contro.on('trigger', ({ command }) => {
550557
}
551558
}
552559

560+
if (command === 'communication.toggleMicrophone') {
561+
// toggleMicrophoneMuted()
562+
}
563+
553564
if (command === 'ui.pauseMenu') {
554565
showModal({ reactType: 'pause-screen' })
555566
}

src/core/progressReporter.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,16 @@ export const createFullScreenProgressReporter = (): ProgressReporter => {
163163
}
164164

165165
export const createNotificationProgressReporter = (endMessage?: string): ProgressReporter => {
166+
const id = `progress-reporter-${Math.random().toString(36).slice(2)}`
166167
return createProgressReporter({
167168
setMessage (message: string) {
168-
showNotification(`${message}...`, '', false, '', undefined, true)
169+
showNotification(`${message}...`, '', false, '', undefined, true, id)
169170
},
170171
end () {
171172
if (endMessage) {
172173
showNotification(endMessage, '', false, '', undefined, true)
173174
} else {
174-
hideNotification()
175+
hideNotification(id)
175176
}
176177
},
177178

src/customChannels.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,6 @@ const registerMediaChannels = () => {
218218
{ name: 'z', type: 'f32' },
219219
{ name: 'width', type: 'f32' },
220220
{ name: 'height', type: 'f32' },
221-
// N, 0
222-
// W, 3
223-
// S, 2
224-
// E, 1
225221
{ name: 'rotation', type: 'i16' }, // 0: 0° - towards positive z, 1: 90° - positive x, 2: 180° - negative z, 3: 270° - negative x (3-6 is same but double side)
226222
{ name: 'source', type: ['pstring', { countType: 'i16' }] },
227223
{ name: 'loop', type: 'bool' },

src/globalState.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import { AppConfig } from './appConfig'
88

99
// todo: refactor structure with support of hideNext=false
1010

11-
export const notHideableModalsWithoutForce = new Set(['app-status'])
11+
export const notHideableModalsWithoutForce = new Set([
12+
'app-status',
13+
'divkit:nonclosable',
14+
'only-connect-server',
15+
])
1216

1317
type Modal = ({ elem?: HTMLElement & Record<string, any> } & { reactType: string })
1418

@@ -35,10 +39,10 @@ const showModalInner = (modal: Modal) => {
3539
return true
3640
}
3741

38-
export const showModal = (elem: /* (HTMLElement & Record<string, any>) | */{ reactType: string }) => {
39-
const resolved = elem
42+
export const showModal = (elem: /* (HTMLElement & Record<string, any>) | */{ reactType: string } | string) => {
43+
const resolved = typeof elem === 'string' ? { reactType: elem } : elem
4044
const curModal = activeModalStack.at(-1)
41-
if (/* elem === curModal?.elem || */(elem.reactType && elem.reactType === curModal?.reactType) || !showModalInner(resolved)) return
45+
if ((resolved.reactType && resolved.reactType === curModal?.reactType) || !showModalInner(resolved)) return
4246
activeModalStack.push(resolved)
4347
}
4448

@@ -49,7 +53,7 @@ export const showModal = (elem: /* (HTMLElement & Record<string, any>) | */{ re
4953
export const hideModal = (modal = activeModalStack.at(-1), data: any = undefined, options: { force?: boolean; restorePrevious?: boolean } = {}) => {
5054
const { force = false, restorePrevious = true } = options
5155
if (!modal) return
52-
let cancel = notHideableModalsWithoutForce.has(modal.reactType) ? !force : undefined
56+
let cancel = [...notHideableModalsWithoutForce].some(m => modal.reactType.startsWith(m)) ? !force : undefined
5357
if (force) {
5458
cancel = undefined
5559
}

src/index.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ import { createConsoleLogProgressReporter, createFullScreenProgressReporter, Pro
9797
import { appViewer } from './appViewer'
9898
import './appViewerLoad'
9999
import { registerOpenBenchmarkListener } from './benchmark'
100+
import { tryHandleBuiltinCommand } from './builtinCommands'
100101

101102
window.debug = debug
102103
window.beforeRenderFrame = []
@@ -208,8 +209,12 @@ export async function connect (connectOptions: ConnectOptions) {
208209

209210
let ended = false
210211
let bot!: typeof __type_bot
211-
const destroyAll = () => {
212+
const destroyAll = (wasKicked = false) => {
212213
if (ended) return
214+
const hadConnected = !!bot
215+
if (!wasKicked && miscUiState.appConfig?.allowAutoConnect && appQueryParams.autoConnect && hadConnected) {
216+
location.reload()
217+
}
213218
errorAbortController.abort()
214219
ended = true
215220
progress.end()
@@ -251,6 +256,10 @@ export async function connect (connectOptions: ConnectOptions) {
251256
if (isCypress()) throw err
252257
miscUiState.hasErrors = true
253258
if (miscUiState.gameLoaded) return
259+
// close all modals
260+
for (const modal of activeModalStack) {
261+
hideModal(modal)
262+
}
254263

255264
setLoadingScreenStatus(`Error encountered. ${err}`, true)
256265
appStatusState.showReconnect = true
@@ -280,7 +289,7 @@ export async function connect (connectOptions: ConnectOptions) {
280289

281290
if (connectOptions.server && !connectOptions.viewerWsConnect && !parsedServer.isWebSocket) {
282291
console.log(`using proxy ${proxy.host}:${proxy.port || location.port}`)
283-
net['setProxy']({ hostname: proxy.host, port: proxy.port })
292+
net['setProxy']({ hostname: proxy.host, port: proxy.port, headers: { Authorization: `Bearer ${new URLSearchParams(location.search).get('token') ?? ''}` } })
284293
}
285294

286295
const renderDistance = singleplayer ? renderDistanceSingleplayer : multiplayerRenderDistance
@@ -622,9 +631,13 @@ export async function connect (connectOptions: ConnectOptions) {
622631
bot.on('kicked', (kickReason) => {
623632
console.log('You were kicked!', kickReason)
624633
const { formatted: kickReasonFormatted, plain: kickReasonString } = parseFormattedMessagePacket(kickReason)
634+
// close all modals
635+
for (const modal of activeModalStack) {
636+
hideModal(modal)
637+
}
625638
setLoadingScreenStatus(`The Minecraft server kicked you. Kick reason: ${kickReasonString}`, true, undefined, undefined, kickReasonFormatted)
626639
appStatusState.showReconnect = true
627-
destroyAll()
640+
destroyAll(true)
628641
})
629642

630643
const packetBeforePlay = (_, __, ___, fullBuffer) => {
@@ -644,6 +657,10 @@ export async function connect (connectOptions: ConnectOptions) {
644657
if (endReason === 'socketClosed') {
645658
endReason = lastKnownKickReason ?? 'Connection with proxy server lost'
646659
}
660+
// close all modals
661+
for (const modal of activeModalStack) {
662+
hideModal(modal)
663+
}
647664
setLoadingScreenStatus(`You have been disconnected from the server. End reason:\n${endReason}`, true)
648665
appStatusState.showReconnect = true
649666
onPossibleErrorDisconnect()
@@ -799,7 +816,10 @@ export async function connect (connectOptions: ConnectOptions) {
799816
const commands = appQueryParamsArray.command ?? []
800817
for (let command of commands) {
801818
if (!command.startsWith('/')) command = `/${command}`
802-
bot.chat(command)
819+
const builtinHandled = tryHandleBuiltinCommand(command)
820+
if (!builtinHandled) {
821+
bot.chat(command)
822+
}
803823
}
804824
})
805825
}
@@ -888,7 +908,11 @@ if (!reconnectOptions) {
888908
const waitAppConfigLoad = !appQueryParams.proxy
889909
const openServerEditor = () => {
890910
hideModal()
891-
showModal({ reactType: 'editServer' })
911+
if (appQueryParams.onlyConnect) {
912+
showModal({ reactType: 'only-connect-server' })
913+
} else {
914+
showModal({ reactType: 'editServer' })
915+
}
892916
}
893917
showModal({ reactType: 'empty' })
894918
if (waitAppConfigLoad) {

src/react/Chat.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,8 @@ export default ({
283283
const message = chatInput.current.value
284284
if (message) {
285285
setSendHistory([...sendHistoryRef.current, message])
286-
const result = sendMessage?.(message)
287-
if (result !== false) {
288-
onClose?.()
289-
}
286+
onClose?.()
287+
sendMessage?.(message)
290288
// Always scroll to bottom after sending a message
291289
scrollToBottom()
292290
}

0 commit comments

Comments
 (0)