This repository has been archived on 2022-09-04. You can view files and clone it, but cannot push or open issues or pull requests.
api/README.md

148 lines
4.5 KiB
Markdown
Raw Permalink Normal View History

2021-11-12 16:26:16 +00:00
# api.tribalwarshelp.com
2020-08-24 11:33:30 +00:00
2021-06-06 16:53:49 +00:00
A GraphQL API designed for developers who want to create something meaningful for the game [Tribal Wars](https://tribalwars.net).
2021-05-06 13:05:47 +00:00
## Limits
2021-06-06 16:53:49 +00:00
It is possible to fetch in one GraphQL query:
2021-03-21 12:11:28 +00:00
1. 1000 daily player/tribe stats records
2. 200 ennoblements
3. 30 versions
4. 200 players/tribes
5. 1000 villages
6. 100 player/tribe history records
7. 100 servers
2021-03-21 12:11:28 +00:00
8. 60 server stats records
9. 100 tribe changes
## Sample queries
2021-06-06 16:53:49 +00:00
1. Fetch all bonus villages with 10% more population
```graphql
query {
2021-03-21 12:11:28 +00:00
villages(server: "en115", filter: { playerID: [0], bonus: 4 }) {
total
items {
id
name
x
y
points
}
}
}
2021-03-21 12:11:28 +00:00
```
2. Top 30 players without a tribe, ordered by points.
```graphql
query {
2021-03-21 12:11:28 +00:00
players(
server: "pl148"
filter: { tribeID: [0] }
sort: ["points DESC"]
limit: 30
) {
total
items {
id
name
rank
points
totalVillages
rankAtt
rankDef
rankTotal
rankSup
}
}
}
2021-03-21 12:11:28 +00:00
```
3. Search a player by a nickname fragment.
```graphql
query {
2021-03-21 12:11:28 +00:00
players(server: "pl148", filter: { nameIEQ: "%pablo%" }) {
total
items {
id
name
}
}
}
```
2021-06-06 16:53:49 +00:00
More examples [here](https://github.com/tribalwarshelp/scripts).
2021-11-12 16:26:16 +00:00
## Map generator
2021-06-06 16:53:49 +00:00
You can generate a server map with this API. The current endpoint is http(s)://youraddress/map/server (replace "server"
with the server you're interested in, for example, pl151).
### Available query params:
| Param | Default |
| ------------------------------------------------ | ---------------------------------------------------------- |
| showBarbarians | false |
| largerMarkers | false |
| markersOnly | false |
| centerX | 500 |
| centerY | 500 |
| scale | 1 (max 5) |
| showGrid | false |
| showContinentNumbers | false |
| backgroundColor | #000 |
| gridLineColor | #fff |
| continentNumberColor | #fff |
2021-06-06 16:53:49 +00:00
| tribe(this param you can define multiple times) | format: tribeid,hexcolor (for example, tribe=631,#0000ff) |
| player(this param you can define multiple times) | format: playerid,hexcolor (for example, player=631,#0000ff) |
### Example
**pl151**
2021-06-06 16:53:49 +00:00
```
https://api.tribalwarshelp.com/map/pl151?showBarbarian=true&tribe=124,%230000ff&tribe=631,%230000ff&tribe=1675,%230000ff&onlyMarkers=false&scale=1&showGrid=true&showContinentNumbers=true
```
![Map](https://api.tribalwarshelp.com/map/pl151?showBarbarian=true&tribe=124,%230000ff&tribe=631,%230000ff&tribe=1675,%230000ff&onlyMarkers=false&scale=1&showGrid=true&showContinentNumbers=true)
2020-08-24 11:33:30 +00:00
## Development
2021-06-06 16:53:49 +00:00
### Prerequisites
1. Golang
2. PostgreSQL database
3. Configured [cron](https://github.com/tribalwarshelp/cron)
### Installation
2021-05-06 13:05:47 +00:00
**Required ENV variables:**
2020-08-24 11:33:30 +00:00
```
DB_USER=your_pgdb_user
DB_NAME=your_pgdb_name
DB_PORT=your_pgdb_port
DB_HOST=your_pgdb_host
DB_PASSWORD=your_pgdb_password
LIMIT_WHITELIST=127.0.0.1,::1
2021-06-06 16:53:49 +00:00
LOG_DB_QUERIES=true
DISABLE_ACCESS_LOG=false
2020-08-24 11:33:30 +00:00
```
1. Clone this repo - ``git clone git@github.com:tribalwarshelp/api.git``
2021-06-19 15:01:53 +00:00
2. Open the folder with this project in a terminal.
2021-06-06 16:53:49 +00:00
3. Set the required env variables directly in your system or create .env.local file.
4. Run the app - ``go run ./cmd/api/main.go``
2021-06-06 16:53:49 +00:00
## License
Distributed under the MIT License. See ``LICENSE`` for more information.
## Contact
Dawid Wysokiński - [contact@dwysokinski.me](mailto:contact@dwysokinski.me)