Skip to content

Commit

Permalink
Add toggle to disable 1.19 chat signing, fix crash
Browse files Browse the repository at this point in the history
  • Loading branch information
retrixe committed Jul 20, 2022
1 parent 040341a commit 1f7cd8e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 15 deletions.
8 changes: 5 additions & 3 deletions src/context/settingsContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,23 @@ export interface Settings {
webLinks: boolean
linkPrompt: boolean
disableAutoCorrect: boolean
enableChatSigning: boolean
darkMode: boolean | null
}

export const defaultSettings: Settings = {
// TODO: Better defaults and settings.
// TODO: Better defaults and settings. webLinks and linkPrompt are questionable.
joinMessage:
"I'm using EnderChat, a well-built, ad-free ChatCraft alternative! Even this message can be disabled!",
sendJoinMessage: true,
sendSpawnCommand: true,
chatTheme: 'Colorless',
fontSize: 16,
webLinks: true,
darkMode: null,
webLinks: true,
linkPrompt: true,
disableAutoCorrect: false
disableAutoCorrect: false,
enableChatSigning: true
}

export interface SettingsContext {
Expand Down
10 changes: 7 additions & 3 deletions src/minecraft/chatToJsx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export interface PlainTextChat extends BaseChat {

export interface TranslatedChat {
translate: string
with: PlainTextChat[]
with: string | PlainTextChat[]
}

export type MinecraftChat = PlainTextChat | TranslatedChat | string
Expand Down Expand Up @@ -175,12 +175,16 @@ const parseChatToJsx = (
componentProps?: {},
trim = false
) => {
if (typeof chat !== 'string' && (chat as TranslatedChat).translate) {
if (chat && typeof chat !== 'string' && (chat as TranslatedChat).translate) {
const translatedChat = chat as TranslatedChat
if (!translatedChat.with) translatedChat.with = []
const translation = translations[translatedChat.translate]
?.split('%s')
?.map((text, index) => [{ text }, translatedChat.with[index]])
?.map((text, index) => {
let insert = translatedChat.with[index]
if (typeof insert === 'string') insert = { text: insert }
return [{ text }, insert]
})
?.flat()
?.filter(component => !!component)
chat = {
Expand Down
9 changes: 6 additions & 3 deletions src/minecraft/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,18 @@ const initiateConnection = async (opts: ConnectionOptions) => {
const encryptedVerifyToken = publicEncrypt(ePrms, verifyToken)
// Send encryption response packet.
// From this point forward, everything is encrypted, including the Login Success packet.
const encryptionResponse = concatPacketData([
const response: PacketDataTypes[] = [
writeVarInt(encryptedSharedSecret.byteLength),
encryptedSharedSecret,
writeVarInt(encryptedVerifyToken.byteLength),
encryptedVerifyToken
])
]
if (opts.protocolVersion >= protocolMap[1.19]) {
response.splice(2, 0, true)
}
const AES_ALG = 'aes-128-cfb8'
conn.aesDecipher = createDecipheriv(AES_ALG, secret, secret)
await conn.writePacket(0x01, encryptionResponse)
await conn.writePacket(0x01, concatPacketData(response))
conn.aesCipher = createCipheriv(AES_ALG, secret, secret)
})().catch(e => {
console.error(e)
Expand Down
9 changes: 7 additions & 2 deletions src/screens/ServerScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import Dialog, { dialogStyles } from '../components/Dialog'
import Text from '../components/Text'
import TextField from '../components/TextField'
import ElevatedView from '../components/ElevatedView'
import useDarkMode from '../context/useDarkMode'
import ServersContext from '../context/serversContext'
import SettingsContext from '../context/settingsContext'
import AccountsContext from '../context/accountsContext'
import ConnectionContext from '../context/connectionContext'
import { resolveHostname, protocolMap } from '../minecraft/utils'
Expand All @@ -43,7 +45,6 @@ import {
mojangColorMap,
parseValidJson
} from '../minecraft/chatToJsx'
import useDarkMode from '../context/useDarkMode'
import config from '../../config.json'

const parseIp = (ipAddress: string): [string, number] => {
Expand All @@ -64,6 +65,7 @@ interface Session {

const ServerScreen = () => {
const darkMode = useDarkMode()
const { settings } = useContext(SettingsContext)
const { servers, setServers } = useContext(ServersContext)
const { accounts, setAccounts } = useContext(AccountsContext)
const { connection, setConnection, setDisconnectReason } =
Expand Down Expand Up @@ -181,6 +183,7 @@ const ServerScreen = () => {
if (protocolVersion === -1) {
const ping = pingResponses[servers[server].address]
// Try the latest.
// TODO: Make 1.19 the default.
if (!ping) protocolVersion = protocolMap['1.18.2']
else if (typeof ping.version === 'object') {
protocolVersion = ping.version.protocol
Expand Down Expand Up @@ -258,7 +261,9 @@ const ServerScreen = () => {
protocolVersion,
selectedProfile: uuid,
accessToken: session?.accessToken,
certificate: session?.certificate // TODO: Chat Signing toggle?
certificate: settings.enableChatSigning
? session?.certificate
: undefined
})
const onCloseOrError = () => {
setConnection(undefined)
Expand Down
13 changes: 9 additions & 4 deletions src/screens/settings/SettingScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const SettingScreen = (props: { button?: JSX.Element }) => {
</View>
<ScrollView>
{/* <Text>Hermes in use: {(global as any).HermesInternal ? 'true' : 'false'}</Text> */}
<DarkModeSetting
value={settings.darkMode}
setValue={darkMode => setSettings({ darkMode })}
/>
<Setting
multiline
maxLength={256}
Expand Down Expand Up @@ -49,15 +53,16 @@ const SettingScreen = (props: { button?: JSX.Element }) => {
value={settings.linkPrompt}
setValue={linkPrompt => setSettings({ linkPrompt })}
/>
<Setting
name='Enable 1.19 chat signing'
value={settings.enableChatSigning}
setValue={enableChatSigning => setSettings({ enableChatSigning })}
/>
<Setting
name='Disable auto-correct in chat'
value={settings.disableAutoCorrect}
setValue={disableAutoCorrect => setSettings({ disableAutoCorrect })}
/>
<DarkModeSetting
value={settings.darkMode}
setValue={darkMode => setSettings({ darkMode })}
/>
{/* TODO: Text Font, Font Size, Chat Theme, Feedback/Support */}
<Setting name='Version' value={version} />
<Setting
Expand Down

0 comments on commit 1f7cd8e

Please sign in to comment.