Skip to content

Commit

Permalink
Write README, remove Mojang MS client ID.
Browse files Browse the repository at this point in the history
  • Loading branch information
retrixe committed Jul 16, 2022
1 parent 9eaef66 commit 3209317
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/config.json

# OSX
#
.DS_Store
Expand Down
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,48 @@
# EnderChat

A React Native app for Android/iOS to chat on Minecraft servers from your phone.

## Features

- Fully open-source with no ads! Easily report issues through GitHub and get a direct response.
- Supports connecting to Minecraft 1.16.4 through Minecraft 1.18.2 servers. (1.19 being worked on!)
- Supports all Minecraft chat features, which sometimes trip up other chat apps.
- Send join messages and commands on connecting to a server.
- Health change indicator and respawn on death support.
- [Many other features planned!](https://github.com/retrixe/EnderChat/issues)

## Installation

[The latest versions of EnderChat are published to GitHub Releases.](https://github.com/retrixe/EnderChat/releases)

### Android

APKs are available to download for each EnderChat release [here.](https://github.com/retrixe/EnderChat/releases)

Publishing to the Google Play Store is eventually planned for the betas and final release. ***While the license allows redistribution, I request that people do not abuse this privilege and publish EnderChat to the Play Store without my consent (for now).***

### iOS

**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!

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.

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

## Development

Development on this application is similar to any other React Native app. However, you must follow the instructions [here](https://wiki.vg/Microsoft_Authentication_Scheme) to get Microsoft Login working, by obtaining a client ID and placing it in a `config.json` file at the top-level, which must be formatted like so:

```json
{"clientId": "", "scope": "XboxLive.signin offline_access"}
```

## License

```markdown
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
```

The `src/minecraft` folder is independent of the rest of the project, and is licensed under MIT. Refer to the folder's own `README` and `LICENSE.md` files for more information.
20 changes: 12 additions & 8 deletions src/minecraft/api/microsoft.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export const loginUrl =
'https://login.live.com/oauth20_authorize.srf' +
'?client_id=00000000402b5328' +
'?client_id={CLIENT_ID}' +
'&response_type=code' +
'&scope=service%3A%3Auser.auth.xboxlive.com%3A%3AMBI_SSL' +
'&scope={SCOPE}' +
'&redirect_uri=https%3A%2F%2Flogin.live.com%2Foauth20_desktop.srf'
export const redirectUrlPrefix =
'https://login.live.com/oauth20_desktop.srf?code='
Expand All @@ -16,10 +16,12 @@ const mcStoreUrl = 'https://api.minecraftservices.com/entitlements/mcstore'
const mcProfileUrl = 'https://api.minecraftservices.com/minecraft/profile'

export const getMSAuthToken = async (
authorizationCode: string
authorizationCode: string,
clientId: string,
scope: string
): Promise<[string, string]> => {
const body = `client_id=00000000402b5328
&scope=${encodeURIComponent('service::user.auth.xboxlive.com::MBI_SSL')}
const body = `client_id=${clientId}
&scope=${encodeURIComponent(scope)}
&code=${encodeURIComponent(authorizationCode)}
&grant_type=authorization_code
&redirect_uri=${encodeURIComponent(redirectUri)}`
Expand All @@ -35,10 +37,12 @@ export const getMSAuthToken = async (
}

export const refreshMSAuthToken = async (
refreshToken: string
refreshToken: string,
clientId: string,
scope: string
): Promise<[string, string]> => {
const body = `client_id=00000000402b5328
&scope=${encodeURIComponent('service::user.auth.xboxlive.com::MBI_SSL')}
const body = `client_id=${clientId}
&scope=${encodeURIComponent(scope)}
&code=${encodeURIComponent(refreshToken)}
&grant_type=refresh_token
&redirect_uri=${encodeURIComponent(redirectUri)}`
Expand Down
2 changes: 1 addition & 1 deletion src/minecraft/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const resolveHostname = async (
const res = await req.json()
const srvRecords = res.Answer?.filter((r: any) => r.type === 33 && r.data)
if (srvRecords && srvRecords.length) {
// Support SRV priority/weight, maybe?
// FIXME: Support SRV priority/weight, maybe?
const record = srvRecords.map((r: { data: string }) => r.data.split(' '))[0]
return [record[3], +record[2]]
} else return [hostname, port]
Expand Down
14 changes: 11 additions & 3 deletions src/screens/accounts/MicrosoftLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
authenticateWithXsts,
getGameProfile
} from '../../minecraft/api/microsoft'
import config from '../../../config.json'

const MicrosoftLogin = ({ close }: { close: () => void }) => {
const darkMode = useDarkMode()
Expand Down Expand Up @@ -74,7 +75,11 @@ const MicrosoftLogin = ({ close }: { close: () => void }) => {
webview.current.reload()
const suffix = newNavState.url.substring(redirectUrlPrefix.length)
const authCode = suffix.substr(0, suffix.indexOf('&'))
const [msAccessToken, msRefreshToken] = await getMSAuthToken(authCode)
const [msAccessToken, msRefreshToken] = await getMSAuthToken(
authCode,
config.clientId,
config.scope
)
const [xboxLiveToken, xboxUserHash] = await getXboxLiveTokenAndUserHash(
msAccessToken
)
Expand Down Expand Up @@ -114,6 +119,9 @@ const MicrosoftLogin = ({ close }: { close: () => void }) => {
}
}

const uri = loginUrl
.replace('{CLIENT_ID}', config.clientId)
.replace('{SCOPE}', encodeURIComponent(config.scope))
return (
<Modal
animationType='fade'
Expand All @@ -129,11 +137,11 @@ const MicrosoftLogin = ({ close }: { close: () => void }) => {
incognito
ref={webview}
originWhitelist={['*']}
source={html ? { html } : { uri: loginUrl }}
source={html ? { html } : { uri }}
onNavigationStateChange={handleNavigationStateChange}
androidLayerType={
Platform.OS === 'android' && Platform.Version > 30
? 'software' // TODO: Really choppy. Seems to only happen on Google Pixel?
? 'software' // FIXME: Really choppy. Seems to only happen on Google Pixel?
: 'hardware'
}
/>
Expand Down

0 comments on commit 3209317

Please sign in to comment.