Skip to content

Commit 5322c8a

Browse files
committed
Add zustand and create an unused sessionStore.
1 parent 18b0681 commit 5322c8a

10 files changed

Lines changed: 86 additions & 23 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Publishing to the Google Play Store is eventually planned for the betas and fina
2525

2626
**Note:** iOS support is currently untested and may have bugs and/or performance issues, since I don't have a Mac to properly support iOS as a target platform. Contributions to improve iOS support are welcome though!
2727

28-
Currently, you must build EnderChat yourself from source. However, IPA files are planned to be uploaded in the future for each EnderChat release (similar to Android), which can then be sideloaded using techniques like AltStore.
28+
IPAs are available to download for each EnderChat release [here.](https://github.com/retrixe/EnderChat/releases) These can be sideloaded on your iPhone using techniques like AltStore.
2929

3030
There are no plans to publish EnderChat to the iOS App Store for now. ***While the license allows redistribution, I request people not to abuse this privilege and publish EnderChat to the App Store without my permission (for now).***
3131

package-lock.json

Lines changed: 33 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"react-native-vector-icons": "^9.2.0",
3737
"react-native-webview": "^11.18.2",
3838
"semaphore-async-await": "^1.5.1",
39-
"stream-browserify": "^3.0.0"
39+
"stream-browserify": "^3.0.0",
40+
"zustand": "^4.0.0-rc.3"
4041
},
4142
"devDependencies": {
4243
"@babel/core": "^7.13.10",

src/context/accountsContext.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// Consider using Recoil instead of Context?
21
import React from 'react'
32

43
export interface Account {

src/context/connectionContext.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// Consider using Recoil instead of Context?
21
import React from 'react'
32
import { MinecraftChat } from '../minecraft/chatToJsx'
43
import { ServerConnection } from '../minecraft/connection'

src/context/serversContext.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// Consider using Recoil instead of Context?
21
import React from 'react'
32
import { protocolMap } from '../minecraft/utils'
43

src/context/sessionStore.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import create from 'zustand'
2+
import { Certificate } from '../minecraft/api/mojang'
3+
4+
export interface Session {
5+
certificate?: Certificate
6+
accessToken: string
7+
}
8+
9+
export interface Sessions {
10+
[uuid: string]: Session
11+
}
12+
13+
export type SetSession = (uuid: string, session: Session) => void
14+
15+
const useSessionStore = create<{
16+
sessions: Sessions
17+
setSession: SetSession
18+
}>(set => ({
19+
sessions: {},
20+
setSession: (uuid: string, session: Session) =>
21+
set(state => ({ sessions: { ...state.sessions, [uuid]: session } }))
22+
}))
23+
24+
export default useSessionStore

src/context/settingsContext.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// Consider using Recoil instead of Context?
21
import React from 'react'
32

43
export interface Settings {

src/screens/chat/packetHandler.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@ import { ServerConnection } from '../../minecraft/connection'
44
import { concatPacketData, Packet } from '../../minecraft/packet'
55
import { protocolMap, readVarInt, writeVarInt } from '../../minecraft/utils'
66

7-
const enderChatPrefix = '\u00A74[\u00A7cEnderChat\u00A74] \u00A7c'
8-
const parseMessageErr = 'An error occurred when parsing chat.'
9-
const inventoryCloseErr = 'An error occurred when closing an inventory window.'
10-
const respawnErr = 'An error occurred when trying to respawn after death.'
11-
const deathRespawnMessage = enderChatPrefix + 'You died! Respawning...'
12-
const sendMessageErr = 'Failed to send message to server!'
13-
const healthMessage =
7+
export const enderChatPrefix = '\u00A74[\u00A7cEnderChat\u00A74] \u00A7c'
8+
export const parseMessageError = 'An error occurred when parsing chat.'
9+
export const inventoryCloseError =
10+
'An error occurred when closing an inventory window.'
11+
export const respawnError =
12+
'An error occurred when trying to respawn after death.'
13+
export const deathRespawnMessage = enderChatPrefix + 'You died! Respawning...'
14+
export const sendMessageError = 'Failed to send message to server!'
15+
export const healthMessage =
1416
enderChatPrefix + "You're losing health! \u00A7b%prev \u00A7f-> \u00A7c%new"
1517

16-
export default (
18+
export const packetHandler =
19+
(
1720
healthRef: React.MutableRefObject<number | null>,
1821
loggedInRef: React.MutableRefObject<boolean>,
1922
setLoggedIn: React.Dispatch<React.SetStateAction<boolean>>,
@@ -38,12 +41,12 @@ export default (
3841
0x03,
3942
concatPacketData([joinMessage.substring(0, charLimit)])
4043
)
41-
.catch(handleError(addMessage, sendMessageErr))
44+
.catch(handleError(addMessage, sendMessageError))
4245
}
4346
if (sendSpawnCommand) {
4447
connection
4548
.writePacket(0x03, concatPacketData(['/spawn']))
46-
.catch(handleError(addMessage, sendMessageErr))
49+
.catch(handleError(addMessage, sendMessageError))
4750
}
4851
}
4952

@@ -60,7 +63,7 @@ export default (
6063
addMessage(parseValidJson(chatJson))
6164
}
6265
} catch (e) {
63-
handleError(addMessage, parseMessageErr)(e)
66+
handleError(addMessage, parseMessageError)(e)
6467
}
6568
} else if (
6669
packet.id === 0x30 /* Player Chat Message (clientbound) */ &&
@@ -82,7 +85,7 @@ export default (
8285
addMessage(parseValidJson(chatJson))
8386
}
8487
} catch (e) {
85-
handleError(addMessage, parseMessageErr)(e)
88+
handleError(addMessage, parseMessageError)(e)
8689
}
8790
} else if (packet.id === 0x2e /* Open Window */) {
8891
// Just close the window.
@@ -91,7 +94,7 @@ export default (
9194
buf.writeUInt8(windowId)
9295
connection // Close Window (serverbound)
9396
.writePacket(0x09, buf)
94-
.catch(handleError(addMessage, inventoryCloseErr))
97+
.catch(handleError(addMessage, inventoryCloseError))
9598
} else if (packet.id === 0x35 /* Death Combat Event */) {
9699
const [, playerIdLen] = readVarInt(packet.data)
97100
const offset = playerIdLen + 4 // Entity ID
@@ -106,7 +109,7 @@ export default (
106109
// LOW-TODO: Should this be manual, or a dialog, like MC?
107110
connection // Client Status
108111
.writePacket(0x04, writeVarInt(0))
109-
.catch(handleError(addMessage, respawnErr))
112+
.catch(handleError(addMessage, respawnError))
110113
} else if (packet.id === 0x52 /* Update Health */) {
111114
const newHealth = packet.data.readFloatBE(0)
112115
if (healthRef.current != null && healthRef.current > newHealth) {

yarn.lock

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7129,7 +7129,7 @@
71297129
"react-shallow-renderer" "^16.13.1"
71307130
"scheduler" "^0.21.0"
71317131

7132-
"react@*", "react@^16.0.0 || ^17.0.0", "react@^16.8.0 || ^17.0.0 || ^18.0.0", "react@^17.0.0", "react@^18.0.0", "react@16 || 17", "react@18.0.0":
7132+
"react@*", "react@^16.0.0 || ^17.0.0", "react@^16.8.0 || ^17.0.0 || ^18.0.0", "react@^17.0.0", "react@^18.0.0", "react@>=16.8", "react@16 || 17", "react@18.0.0":
71337133
"integrity" "sha512-x+VL6wbT4JRVPm7EGxXhZ8w8LTROaxPXOqhlGyVSrv0sB1jkyFGgXxJ8LVoPRLvPR6/CIZGFmfzqUa2NYeMr2A=="
71347134
"resolved" "https://registry.npmjs.org/react/-/react-18.0.0.tgz"
71357135
"version" "18.0.0"
@@ -8365,7 +8365,7 @@
83658365
"resolved" "https://registry.npmjs.org/urix/-/urix-0.1.0.tgz"
83668366
"version" "0.1.0"
83678367

8368-
"use-sync-external-store@^1.0.0":
8368+
"use-sync-external-store@^1.0.0", "use-sync-external-store@1.2.0":
83698369
"integrity" "sha512-eEgnFxGQ1Ife9bzYs6VLi8/4X6CObHMw9Qr9tPY43iKwsPw8xE8+EFsf/2cFZ5S3esXgpWgtSCtLNS41F+sKPA=="
83708370
"resolved" "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.2.0.tgz"
83718371
"version" "1.2.0"
@@ -8719,3 +8719,10 @@
87198719
"string-width" "^4.2.0"
87208720
"y18n" "^5.0.5"
87218721
"yargs-parser" "^20.2.2"
8722+
8723+
"zustand@^4.0.0-rc.3":
8724+
"integrity" "sha512-vc7TKQJC6T8lx5EupnuUTWXahuRLYjrK9oWLvY+u65ZkLDjocgxDGMrl5VBuxyjXCXyJ3kquN3l/Y2yUj5ZDEg=="
8725+
"resolved" "https://registry.npmjs.org/zustand/-/zustand-4.0.0-rc.3.tgz"
8726+
"version" "4.0.0-rc.3"
8727+
dependencies:
8728+
"use-sync-external-store" "1.2.0"

0 commit comments

Comments
 (0)