Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/gfngfn/game_tianjiupai

A Tian Jiu Pai (天九牌) game server written in Sesterl & Elm
https://github.com/gfngfn/game_tianjiupai

cloudformation elm erlang game sesterl

Last synced: 2 months ago
JSON representation

A Tian Jiu Pai (天九牌) game server written in Sesterl & Elm

Awesome Lists containing this project

README

        

# A Tian Jiu Pai Game Server

![title image](https://github.com/gfngfn/game_tianjiupai/blob/master/assets_client/top.png)

A *Tian Jiu Pai* (*Tien Gow Pai*, 天九牌) game server written in [Sesterl](https://github.com/gfngfn/Sesterl), Erlang, and Elm.

The following is a capture video of playing the game:

- https://twitter.com/bd_gfngfn/status/1404112257517195268?s=20

## Memos for development

### Build dependencies

* make
* Sass
* Erlang/OTP
* Rebar3
* Elm
* [APBuf](https://github.com/gfngfn/apbuf)
- Used for generating a JSON encoder/decoder from `model.apbuf`.
- Can be installed via OPAM pin:
```console
$ git clone [email protected]:gfngfn/apbuf
$ cd apbuf
$ opam pin add apbuf .
```
* [Sesterl](https://github.com/gfngfn/Sesterl)
- A statically-typed Erlang.
- Can be installed via OPAM pin.
```console
$ git clone [email protected]:gfngfn/Sesterl
$ cd Sesterl
$ opam pin add sesterl .
```

### How to build

Just invoke `make`.

### How to run tests

Invoke `make test`.

### How to launch locally

Invoke `make run`.

### Sequence Diagrams

See `model.apbuf` for the definition of the formats of request/response bodies.

#### Login

```
Client Server
| POST /users |
| |
|--------------------------------->|
| |
| 201 |
|<---------------------------------|
| |
| /websocket/users/ |
|--------------------------------->|
| |
| 100 |
|<---------------------------------|
| |
| GET /rooms |
|--------------------------------->|
| |
| 200 |
|<---------------------------------|
```

#### Entering a room

```
Client Server
| |
| PATCH /rooms |
| RoomRequestToEnterRoom() |
|------------------------------------------------->|
| |
| 200 |
|<-------------------------------------------------|
```

#### Card submission

```
Client 1 Server Client 2, 3, and 4
| | | | |
| PATCH /rooms | | | |
| RoomRequestToSubmitCards() | | | |
|----------------------------------------------------->| | | |
| | NotifySubmission() | | |
| |---------------------------------->| | |
| |--------------------------------------->| |
| 200 |-------------------------------------------->|
|<-----------------------------------------------------| | | |
| | | | |
| | CommandAck() | | |
| |<----------------------------------| | |
| | CommandAck() | | |
| CommandAck() |<--------------------------------------------|
|----------------------------------------------------->| | | |
| | CommandAck() | | |
| NotifyNextStep |<---------------------------------------| |
|<-----------------------------------------------------| NotifyNextStep | | |
| |---------------------------------->| | |
| |--------------------------------------->| |
| |-------------------------------------------->|
| | | | |
```

### How to deploy the game server on an EC2 instance

1. Make branch `temp-deploy` which contains the build targets generated by APBuf, Elm, and Sesterl.

- This step shall be removed in the future; the pipeline scripts for building programs written in APBuf, Elm, and Sesterl will be needed.

2. Generate your key pair (the name of which is written as `〈NameOfYourKey〉` hereafter).

3. Create an IAM role `CloudWatchAgentServerRole` to which `CloudWatchAgentServerPolicy` is assigned.

4. Invoke the following command to deploy on an EC2 instance (this step takes approximately 10 minutes):

```console
$ cd 〈RootOfThisRepository〉
$ aws cloudformation deploy --stack-name "〈NameOfYourStack〉" --template-file aws/cloud-formation.template.yaml --parameter-overrides "KeyName=〈NameOfYourKey〉"
```

- Then you can access the instance by using SSH like the following:

```console
$ ssh -i ~/.ssh/〈NameOfYourKey〉.pem ubuntu@〈AssignedIPAddress〉
```

5. Get the IP address `〈AssignedIPAddress〉` assigned to the instance and visit the address by using a browser.

### Acknowledgement

* The cloudFormation template in the following repository has been largely used as a reference:
- [thiagoesteves/erlgame: Snake Game webserver written in Erlang using cowboy as webserver. there is an aws cloud formation to deploy the game at aws amazon](https://github.com/thiagoesteves/erlgame)