diff --git a/src/minecraft/connection/native.ts b/src/minecraft/connection/native.ts index 660868b..9ef3158 100644 --- a/src/minecraft/connection/native.ts +++ b/src/minecraft/connection/native.ts @@ -133,6 +133,7 @@ export class NativeServerConnection this.eventEmitter.removeAllListeners('ecm:packet') this.eventEmitter.removeAllListeners('ecm:error') this.eventEmitter.removeAllListeners('ecm:close') + this.eventEmitter.removeAllListeners('ecm:log') this.closed = true this.emit('close') }) @@ -150,6 +151,7 @@ export class NativeServerConnection this.eventEmitter.removeAllListeners('ecm:packet') this.eventEmitter.removeAllListeners('ecm:error') this.eventEmitter.removeAllListeners('ecm:close') + this.eventEmitter.removeAllListeners('ecm:log') } } diff --git a/src/minecraft/connection/shared.ts b/src/minecraft/connection/shared.ts index 203d84d..fb60ad7 100644 --- a/src/minecraft/connection/shared.ts +++ b/src/minecraft/connection/shared.ts @@ -30,6 +30,8 @@ export const parseEncryptionRequestPacket = (packet: Packet) => { export const getLoginPacket = (opts: ConnectionOptions) => { const data: PacketDataTypes[] = [opts.username] if (opts.protocolVersion >= protocolMap[1.19]) { + data.push(false) + /* TODO: Support chat signing properly. data.push(!!opts.certificate) if (opts.certificate) { let buf = Buffer.alloc(8) @@ -46,7 +48,7 @@ export const getLoginPacket = (opts: ConnectionOptions) => { buf = Buffer.from(opts.certificate.publicKeySignature, 'base64') data.push(writeVarInt(buf.byteLength)) data.push(buf) - } + } */ if (opts.protocolVersion >= protocolMap['1.19.1']) { if (opts.selectedProfile) { const msb = Buffer.from(opts.selectedProfile.substring(0, 16), 'hex') diff --git a/src/screens/chat/ChatScreen.tsx b/src/screens/chat/ChatScreen.tsx index d62b2b3..c738e5d 100644 --- a/src/screens/chat/ChatScreen.tsx +++ b/src/screens/chat/ChatScreen.tsx @@ -108,6 +108,7 @@ const ChatScreen = ({ navigation, route }: Props) => { const [messages, setMessages] = useState([]) const [loggedIn, setLoggedIn] = useState(false) const [message, setMessage] = useState('') + const messagesBufferRef = useRef([]) const healthRef = useRef(null) const statusRef = useRef(connection ? 'CONNECTING' : 'OPENING') const idRef = useRef(0) @@ -117,16 +118,27 @@ const ChatScreen = ({ navigation, route }: Props) => { ? 256 : 100 const addMessage = (text: MinecraftChat) => - setMessages(m => { - const trunc = m.length > 500 ? m.slice(0, 499) : m - return [{ key: idRef.current++, text }].concat(trunc) - }) + messagesBufferRef.current.unshift({ key: idRef.current++, text }) const closeChatScreen = () => { if (navigation.canGoBack() && statusRef.current !== 'CLOSED') { navigation.goBack() } } + // Chat message buffering function. + useEffect(() => { + const interval = setInterval(() => { + if (messagesBufferRef.current.length) { + setMessages(m => { + const concat = messagesBufferRef.current.concat(m) + messagesBufferRef.current = [] + return concat.length > 500 ? concat.slice(0, 499) : concat + }) + } + }, 50) + return () => clearInterval(interval) + }, []) + // Screen cleanup function. useEffect(() => navigation.addListener('beforeRemove', () => { diff --git a/src/screens/chat/sessionBuilder.ts b/src/screens/chat/sessionBuilder.ts index 058837b..9d561bd 100644 --- a/src/screens/chat/sessionBuilder.ts +++ b/src/screens/chat/sessionBuilder.ts @@ -43,8 +43,8 @@ export const createConnection = async ( // Create an updated "session" containing access tokens and certificates. let session = sessions[activeAccount] const is119 = version >= protocolMap[1.19] + // TODO: We should store session store in a persistent cache. Certificates and access tokens should be updated regularly. if (uuid && (!session || (!session.certificate && is119))) { - // LOW-TODO: Certificates and access tokens should be updated regularly. // We should probably lock access to them via a semaphore. try { // Create a session with the latest access token. @@ -91,6 +91,7 @@ export const createConnection = async ( } } + // TODO: Better connection cancellation support. The session load can take a lot of time. // Connect to server after setting up the session. try { const newConn = await initiateConnection({