|
1 | | -# Session Service |
| 1 | +# API Server |
2 | 2 |
|
3 | | -The session service is responsible for keeping track of all players currently online (network wide in the future, but |
4 | | -for now just mapmaker). |
| 3 | +The backend service for [Hollow Cube](https://hollowcube.net) — a Minecraft server for creative map building. |
| 4 | +This accompanies the [mapmaker](https://github.com/hollow-cube/mapmaker) game server repo. |
5 | 5 |
|
6 | | -## Session Tracking |
7 | | -The session service needs to keep a record (in redis for now) of every online player, and remove them when they |
8 | | -disconnect. |
| 6 | +## Project Structure |
9 | 7 |
|
10 | | -The Java server (proxy in the future) handles this by sending requests to the create and delete session endpoints: |
11 | | -- `POST /session/{playerId}` (on join) |
12 | | -- `DELETE /session/{playerId}` (on leave) |
| 8 | +- `api/` |
| 9 | + - `v1Public/` - Current-version public API for game data |
| 10 | + - `v4Internal/` - Current-version API for the game servers |
| 11 | + - `external/` - Incoming webhook endpoints for external services (eg Discord, Tebex) |
| 12 | + - `posthog/` - Caching PostHog feature flag proxy |
| 13 | + - `mapsV3/` - (deprecated) `map-service` api, in-progress migration to `v4Internal` |
| 14 | + - `v2/` - (deprecated) `player-service` api, in-progress migration to `v4Internal` |
| 15 | + - `v3/` - (deprecated) `session-service` api, in-progress migration to `v4Internal` |
| 16 | + - `auth/` - (deprecated) Envoy auth middleware |
13 | 17 |
|
14 | | -This works fine in the happy case, but we need to handle a case where the Minecraft server crashes unexpectedly, |
15 | | -it would be problematic if the session service still thought the player was online. This is handled by the session |
16 | | -service server tracking, see below. |
| 18 | +*Note: Historically this project was made up of 3 distinct services (`map-service`, `player-service`, |
| 19 | +`session-service`) so you may see references to those. They have since been merged but there remains |
| 20 | +some legacy separation.* |
17 | 21 |
|
18 | | -## Server Tracking |
19 | | -The session service needs to keep a record (in redis for now) of every running backend server to be able to route |
20 | | -players to the correct server, as well as know when a server goes down (incl. unexpected crashes). To accomplish this, |
21 | | -the session service uses the Kubernetes client API to watch for changes to the server state. There is a single instance |
22 | | -of the session service selected at any given moment to track the server state. This is done using the Kubernetes client |
23 | | -leadership election API. |
| 22 | +## Getting Started |
24 | 23 |
|
25 | | -The leader instance of the session service will watch for changes and update the server state in redis. Any service |
26 | | -instance (including the leader) may query the server state when assigning players. |
| 24 | +See [Development Setup](https://github.com/hollow-cube/map-maker/blob/main/.github/DEVELOPMENT_SETUP.md) for |
| 25 | +instructions on running the project locally. |
27 | 26 |
|
28 | | -## Chat |
29 | | -Chat is handled by the session service also. Chat is done over Kafka. TODO write more |
| 27 | +## Contributing |
30 | 28 |
|
31 | | -## Local Development |
32 | | -You must have the following installed: |
33 | | -- goimports: `go install golang.org/x/tools/cmd/goimports@latest` |
34 | | -- [openapi-go](https://github.com/mworzala/openapi-go): `go install github.com/mworzala/openapi-go@latest` |
| 29 | +Please read [CONTRIBUTING.md](.github/CONTRIBUTING.md) before opening a pull request. |
35 | 30 |
|
36 | | -You should use our Tilt setup to run the service locally, see [here](https://github.com/hollow-cube/development). |
| 31 | +All contributors must sign our |
| 32 | +[Contributor License Agreement](https://hollowcube.net/legal/individual-contributor-license-agreement). |
| 33 | +You'll be prompted automatically on your first PR. |
37 | 34 |
|
38 | | -## DB Schema Evolution |
39 | | -We use [golang-migrate/migrate](https://github.com/golang-migrate/migrate) to handle postgres schema upgrades. |
| 35 | +## Community |
40 | 36 |
|
41 | | -To create a new migration, run the following command (**make sure to replace <migration_name> with a reasonable name**): |
| 37 | +We have a dedicated `#general-dev` channel in our [Discord](https://discord.hollowcube.net) for related questions. |
42 | 38 |
|
43 | | -```shell |
44 | | -go tool migrate create -ext sql -dir internal/pkg/storage/migrate -seq <migration_name> |
45 | | -``` |
| 39 | +## License |
46 | 40 |
|
47 | | -Before writing any migrations, make sure to read through the best practices in the |
48 | | -[migrate documentation](https://github.com/golang-migrate/migrate/blob/master/MIGRATIONS.md). In |
49 | | -particular, migrations should always be idempotent, transactional and reversible. It is almost never |
50 | | -valid to edit an existing migration after it has been deployed. |
51 | | - |
52 | | -DB changes must always be (at least) single version backwards compatible to allow for rolling updates. |
53 | | - |
54 | | -> **Note on using Tilt:** |
55 | | -> |
56 | | -> If you are using Tilt then the service will autorestart when you run `migrate` commands, which will |
57 | | -> result in the migration being automatically applied. You should disable the tilt resource while editing |
58 | | -> then reenable it after the migration is written. |
| 41 | +The code in this repository is licensed under the [MIT License](LICENSE). |
0 commit comments