Skip to content

Commit

Permalink
chore: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ultraviolet-jordan committed Feb 4, 2024
1 parent 1284219 commit 890449e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ Click [here](https://github.com/2004scape/Client2/tree/gh-pages) to view the cur

### Client

Try out the client hosted on Github Pages!
Try out the client hosted on Github!

https://2004scape.github.io/Client2/
| World | High Detail | Low Detail |
|-----------------|--------------------------------------------------------------------------------|-------------------------------------------------------------------------------|
| 1 (Central USA) | [Play Now!](https://2004scape.github.io/Client2/?world=1&detail=high&method=0) | [Play Now!](https://2004scape.github.io/Client2/?world=1&detail=low&method=0) |
| 2 (Germany) | [Play Now!](https://2004scape.github.io/Client2/?world=2&detail=high&method=0) | [Play Now!](https://2004scape.github.io/Client2/?world=2&detail=low&method=0) |
| 3 (Central USA) | [Play Now!](https://2004scape.github.io/Client2/?world=3&detail=high&method=0) | [Play Now!](https://2004scape.github.io/Client2/?world=3&detail=low&method=0) |
| 4 (Germany) | [Play Now!](https://2004scape.github.io/Client2/?world=4&detail=high&method=0) | [Play Now!](https://2004scape.github.io/Client2/?world=4&detail=low&method=0) |

### Playground

Expand All @@ -24,6 +29,10 @@ Cache viewer.

https://2004scape.github.io/Client2/viewer

### Items Viewer

https://2004scape.github.io/Client2/items

## First Time Installation

```shell
Expand All @@ -38,6 +47,16 @@ chmod ug+x .husky/*
chmod ug+x .git/hooks/*
```

## Development
## Local

Local development should be done with: `npm run dev`

The client will automatically launch connecting to World 1.
Local world is hosted on World 0.
You have the ability to connect to live servers from the local client by changing the param.

http://localhost:8080/?world=0&detail=high&method=0

This is not to be confused with the Java TeaVM client which is hosted here if the local server is running:

http://localhost/client?world=0&detail=high&method=0
14 changes: 8 additions & 6 deletions src/js/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10517,7 +10517,7 @@ if (GameShell.getParameter('method').length === 0) {
if (hostname === 'localhost' && GameShell.getParameter('world') === '0') {
localConfiguration();
} else {
await liveConfiguration();
await liveConfiguration(secured);
}

if (GameShell.getParameter('detail') === 'low') {
Expand All @@ -10534,9 +10534,9 @@ function localConfiguration(): void {
Client.portOffset = 0;
}

async function liveConfiguration(): Promise<void> {
async function liveConfiguration(secured: boolean): Promise<void> {
// noinspection HttpUrlsUsage
const world: WorldList = await getWorldInfo(parseInt(GameShell.getParameter('world'), 10));
const world: WorldList = await getWorldInfo(secured, parseInt(GameShell.getParameter('world'), 10));

Client.nodeId = 10 + world.id - 1;
// noinspection HttpUrlsUsage
Expand All @@ -10548,15 +10548,17 @@ async function liveConfiguration(): Promise<void> {
Client.members = world?.members === true;
}

async function getWorldInfo(id: number, retries: number = 0): Promise<WorldList> {
async function getWorldInfo(secured: boolean, id: number, retries: number = 0): Promise<WorldList> {
if (retries >= 10) {
throw new Error('could not find world to connect!');
}
const worldlist: WorldList[] = JSON.parse(await downloadText('http://2004scape.org/api/v1/worldlist'));
// github host is secured for example.
const url: string = secured ? 'https://2004scape.org/api/v1/worldlist' : 'http://2004scape.org/api/v1/worldlist';
const worldlist: WorldList[] = JSON.parse(await downloadText(url));
const world: WorldList | undefined = worldlist.find((x): boolean => x.id === id);
if (!world) {
await sleep(1000);
return getWorldInfo(id, ++retries);
return getWorldInfo(secured, id, ++retries);
}
return world;
}

0 comments on commit 890449e

Please sign in to comment.