Skip to content

Commit

Permalink
docs(readme): update all readmes
Browse files Browse the repository at this point in the history
  • Loading branch information
rallieon committed Aug 19, 2021
1 parent 95aebc6 commit 9f19615
Show file tree
Hide file tree
Showing 9 changed files with 385 additions and 230 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ All new repositories in the haste ecosystem should contain the following:
4. All top level `package.json` should have the following scripts: `test`, `lint`, `build`, `pretty`, `clean`, `prepare`.
5. `.gitignore`
6. Top level `package.json` should use the haste-sdk as a template for how to structure the `package.json`.
7. If using Lerna, you must include a `README` at the top level and in each package.
7. You must include a `README` at the top level and in each package if using a monorepo.

#### Coding Style

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 playhaste
Copyright (c) 2021 hastearcade

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
277 changes: 221 additions & 56 deletions README.md

Large diffs are not rendered by default.

Binary file added docs/assets/gameclientkeys.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/gameserverkeys.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/haste-game-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The haste game server is an example an ILP based game server. It leverages [matt

All game logic and scoring occurs within the haste-game-server. The client is used only to render the latest game state. No logic or scoring should occur on the client.

The haste-game-server also leverages the @hastearcade/haste to integrate with the Haste API. This supports authz, submitting scores, and retrieving information about the latest leaderboard.
The haste-game-server also leverages the `@hastearcade/server` to integrate with the Haste API. This supports authz, submitting scores, and retrieving information about the latest leaderboard.

Information is transferred between the client and server using socket.io.

Expand Down
27 changes: 9 additions & 18 deletions packages/models/README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
# @hastearcade/models

[![npm version](https://badge.fury.io/js/%40hastearcade%2Fmodels.svg)](https://badge.fury.io/js/%40hastearcade%2Fmodels)

## Overview

The @hastearcade/models package includes common domain models and services used in the SDK. Eventually it will also be used to support tooling such as a CLI tool.
The `@hastearcade/models` package includes common domain models and services used in the SDK. Eventually it will also be used to support tooling such as a CLI tool. At the current time this package should not be used on its own. Please use the `@hastearcade/server` and `@hastearcade/web` packages.

See [here](https://github.com/playhaste/haste-sdk/blob/main/README.md) for an overview of the haste-sdk repository.

<Add deploy badge here>

## Table of Contents

- [Background and Use Case](#background)
- [Setup](#setup)
- [Usage](#usage)
- [Deploy](#deploy)
- [Documentation](#documentation)
- [License](#license)
- [Contributing](#contributing)
Expand All @@ -27,27 +25,20 @@ See [here](https://github.com/playhaste/haste-sdk/blob/main/README.md#Background

See [here](https://github.com/playhaste/haste-sdk/blob/main/README.md#Setup) for a detailed setup guide.

## Usage

See [here](https://github.com/playhaste/haste-sdk/blob/main/README.md#Usage) for a detailed usage guide.

### Testing

@hastearcade/models utilizes Jest for running tests. To run all tests in the domain package use the following command

`pnpm run test`

## Documentation

See [here](https://github.com/playhaste/haste-sdk/blob/main/README.md#Documentation) for more documentation.
This `README` and each package's `README` provides high-level documentation. Additionally the code has been reviewed and comments provided to aid future developers in understanding why certain decisions were made.

More comprehensive documentation can be found [here](https://haste-arcade.stoplight.io/).

## License

haste-sdk is currently licensed under [MIT](https://github.com/playhaste/haste-sdk/blob/main/LICENSE)
The haste-sdk repository along with the corresponding npm packages are currently licensed under [MIT](https://github.com/playhaste/haste-sdk/blob/main/LICENSE)

## Contributing

Please read our contribution [policy](https://github.com/playhaste/haste-sdk/blob/main/CONTRIBUTING.md).
If you are a developer looking to contribute to the Haste ecosystem please review our
[Contributing Readme](https://github.com/playhaste/haste-sdk/blob/main/ContributingReadme.md) and our [Contributing Guidelines](https://github.com/playhaste/haste-sdk/blob/main/CONTRIBUTING.md)

## Authors

Expand Down
174 changes: 96 additions & 78 deletions packages/server/README.md
Original file line number Diff line number Diff line change
@@ -1,132 +1,150 @@
# haste-sdk
# @hastearcade/server

## Overview

The SDK to be used to empower developers to leverage the Haste Arcade. The SDK is intended to be used only on the server side. The SDK current supports
[![npm version](https://badge.fury.io/js/%40hastearcade%2Fserver.svg)](https://badge.fury.io/js/%40hastearcade%2Fserver)

- Authz
- Submitting Scores

On the roadmap the Haste team plans to provide
## Overview

- [ ] Real time leaderboard updates
- [ ] Simpler authentication setup and support
- [ ] Access to player information
- [ ] Player cards
The `@hastearcade/server` sdk empowers developers to leverage the Haste Arcade ecosystem to build Instant Leaderboard Payout (ILP) based games. The SDK is intended to be used only on the server side, but it is required to be used in conjunction with `@hastearcade/web`. See details [here](https://github.com/playhaste/haste-sdk/blob/main/packages/web/README.md).

See [here](https://github.com/playhaste/haste-sdk/blob/main/README.md) for an overview of the haste-sdk repository.

<Add deploy badge here>

## Table of Contents

- [Quickstart](#quickstart)
- [Background and Use Case](#background)
- [Setup](#setup)
- [Usage](#usage)
- [Deploy](#deploy)
- [Testing](#testing)
- [Documentation](#documentation)
- [License](#license)
- [Contributing](#contributing)
- [Authors](#authors)

## Background
## Quickstart

See [here](https://github.com/playhaste/haste-sdk/blob/main/README.md#Background) for a detailed background.
The `@hastearcade/server` package is the primary entry point to the Haste ecosystem. The sdk is a wrapper for the Haste API and allows developers to ILP enable a game. The Haste ecosystem provides tools to handle the following components of ILP:

## Setup
1. Authentication
2. Leaderboard management
3. Payouts to the leaderboard
4. Play & Score submission

See [here](https://github.com/playhaste/haste-sdk/blob/main/README.md#Setup) for a detailed setup guide.
#### Initialize Haste

To initialize the Haste sdk for use in your server, you need to perform the following:

```typescript
const haste = await Haste.build(process.env.HASTE_SERVER_CLIENT_ID, process.env.HASTE_SERVER_CLIENT_SECRET);
/// Now do things with the haste object like submit a play or a score.
```

The client id and secret are defined in the developer portal on your game page. See image below for reference:

![](docs\assets\gameserverkeys.png)

NOTE: It is recommneded to create an abstraction (service, lib, etc) around the haste-sdk in your codebase. This will allow you to initialize one haste object.

## Quick Start
#### Authentication

### Initialize the Haste SDK
Integrating the Haste authentication system into your server is one of the first steps needed. This step is important because it allows players in the arcade to receive payment for their skill. If the user is not logged in, then they can not submit and score, and ultimately can not be paid for placing on a leaderboard. The game client (using `@hastearcade/web`) will send the token to the server with each request. The server can use the following code to validate the token:

A game developer can access their game's client id and client secret through the developer portal.
```typescript
import { Haste } from '@hastearcade/server';
const token = receiveTokenFromRequest();
try {
const playerId = await Haste.validatePlayerAccess(token);
console.log(`The player authenticated has an id of ${playerId}`);
} catch (err) {
console.error(`An error occurred while validating the player's token.`);
}
```

Note: the above code does not use the haste object created from `build`. `build` and `validatePlayerAccess` are both static async functions. All other functions (get leaderboards, submit score, etc should utilize the haste object created from `build`)

#### Leaderboard management

The Haste ecosystem currently has multiple leaderboards that can be played for every game. Each tier requires additional funds to play the game (i.e. paying a penny vs paying a quarter). Every game in the arcade must support this concept in game. Thus, most games will display a dropdown UI to allow the player to select what leaderboard they wish to participate in. In order to retrieve the list of leaderboards to show in your dropdown you can use the following:

```typescript
const haste = await Haste.build(process.env.HASTE_CLIENT_ID, process.env.HASTE_CLIENT_SECRET, {
hostProtocol: process.env.HASTE_API_PROTOCOL,
host: process.env.HASTE_API_HOST,
port: parseInt(process.env.HASTE_API_PORT, 10),
});
const haste = await Haste.build(process.env.HASTE_SERVER_CLIENT_ID, process.env.HASTE_SERVER_CLIENT_SECRET);
const leaderBoards = haste.game.leaderboards();
console.log(leaderBoards);

/*
output:
[{
id: "guid",
name: "Beginner",
cost: 2000, // cost to play in this leaderboard in satoshis.
}]
```
### Authenticate a user
#### Submit Play & Score
The example game server and client use socket.io so here is the necessary code to authenticate the user and setup the Haste SDK.
When playing a game in an arcade, in order to play you must first insert your quarter. The `@hastearcade/server` sdk requires a similar flow. Once a player has selected their leaderboard, the developer will need to submit a "play" to the Haste api via the sdk. The following code shows a demonstration of this concept:
```typescript
this.io = new Server(server, {
cors: {
origin: process.env.CORS_URL,
methods: ['GET', 'POST'],
},
});

this.jwtClient = new JwksClient({
jwksUri: 'https://playhaste.us.auth0.com/.well-known/jwks.json',
});

this.io.use(this.jwtMiddleware);

private getKey = (header: JwtHeader, callback: SigningKeyCallback) => {
this.jwtClient.getSigningKey(header.kid, (err: Error, key: SigningKey) => {
const signingKey = key.getPublicKey();
callback(err, signingKey);
});
};

private jwtMiddleware = (socket: Socket, next: (err?: ExtendedError) => void) => {
if (socket.handshake.auth && socket.handshake.auth.token) {
jwt.verify(socket.handshake.auth.token as string, this.getKey, {}, (err, decoded) => {
if (err) return next(new Error('Authentication error'));
if (decoded.iss === process.env.AUTH0_ISSUER && decoded.exp > new Date().getTime() / 1000) {
socket.data = decoded;
return next();
} else {
return next(new Error('Authentication error'));
}
});
} else {
next(new Error('Authentication error'));
const haste = await Haste.build(process.env.HASTE_SERVER_CLIENT_ID, process.env.HASTE_SERVER_CLIENT_SECRET);
const play = await haste.game.play(new Player(playerId), new Leaderboard(leaderboardId));
console.log(play);
/*
output:
{
id: "guid",
gameId: "your game guid",
playerId: "player guid",
leaderboard: {
id: "guid",
name: "Beginner",
cost: 2000, // cost to play in this leaderboard in satoshis.
}
};

}
```
### Submit a score
Once the play submission is you completed you should allow the user the play your game.
This assumes a user is already logged in and the developer has access to the JWT.
_Always maintain the business logic and scoring logic server side for security reasons in your game. Do not keep score or make any important game state decisions on the client._
Upon hitting an end state for your game (i.e. the player gets hit by a bomb and dies) it is time to submit your score. To submit a score, you'll need the original play object. The play object can be maintained however you choose (memory, database, cache, etc). The score sdk method takes the current Play object, the Leaderboard the score is being submitted against, and the score.
```typescript
const metadata = jwt['http://haste/metadata'].playerId;
const player = new Player(metadata.playerId);
const score = 1;
const play = await haste.game.play(player);
await haste.game.score(play, score);
await haste.game.score(currentPlay, leaderboard, score);
```
## Usage
#### Payouts
All payouts are handled internal to the Haste ecosystem and do not require any additional code for the game developer.
See [here](https://github.com/playhaste/haste-sdk/blob/main/README.md#Usage) for a detailed usage guide.
## Background
See [here](https://github.com/playhaste/haste-sdk/blob/main/README.md#Background) for a detailed background.
## Setup
See [here](https://github.com/playhaste/haste-sdk/blob/main/README.md#Setup) for a detailed setup guide.
### Testing
@hastearcade/haste utilizes Jest for running tests. To run all tests in the server package use the following command
`@hastearcade/server` utilizes Jest for running tests. To run all tests in the server package use the following command
`npm run test`
## Documentation
Currently there is no further documentation setup, but please check back in the future.
This `README` and each package's `README` provides high-level documentation. Additionally the code has been reviewed and comments provided to aid future developers in understanding why certain decisions were made.
More comprehensive documentation can be found [here](https://haste-arcade.stoplight.io/).
## License
haste-sdk is currently licensed under [MIT](https://github.com/playhaste/haste-sdk/blob/main/LICENSE)
The haste-sdk repository along with the corresponding npm packages are currently licensed under [MIT](https://github.com/playhaste/haste-sdk/blob/main/LICENSE)
## Contributing
Please read our contribution [policy](https://github.com/playhaste/haste-sdk/blob/main/CONTRIBUTING.md).
If you are a developer looking to contribute to the Haste ecosystem please review our
[Contributing Readme](https://github.com/playhaste/haste-sdk/blob/main/ContributingReadme.md) and our [Contributing Guidelines](https://github.com/playhaste/haste-sdk/blob/main/CONTRIBUTING.md)
## Authors
Expand Down
Loading

0 comments on commit 9f19615

Please sign in to comment.