diff --git a/.gitignore b/.gitignore index db1031a..9990885 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,5 @@ Cargo.lock *.http *.csv etc/* -gen_doc.sh website* \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 91678a5..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,210 +0,0 @@ -# Changelog - -All notable changes to this project will be documented in this file. - -## [0.3.1] - 2024-08-11 - -### Bug fixes - -- Unsynchronized leaderboards state - -### Miscellaneous Tasks - -- Update ci.yml - -## [0.3.0] - 2024-08-10 - -### Bug fixes - -- Avoid showing not yet released events -- Not retrieving non-pb records for an event -- Removed escaped names from the api -- Fix doc test errors - -- Fix tiny wrong fmt - -- Return record date in utc format -- Fix non waiting for process kill - -- Fix wrong lib name import - - -### Documentation - -- Enhanced the overall documentation -- Api source file for bash - -### Features - -- Fields `authors` and `end_date` for edition -- Enhanced internal documentation -- Allow save of non-event records to event -- Record saving in non-event ctx -- Add transitive save flag -- Try count on record -- Return old rank on player finish -- Allow many articles for the website - -### Miscellaneous Tasks - -- Create ci.yml -- Update ci.yml -- Merge pull request #19 from Obstacle-Reborn/test-ci - - -- Merge pull request #20 from Obstacle-Reborn/docs-ci - -Create docs.yml - -### Refactor - -- Remove reversed leaderboards feature -- Better mappack/events scores management -- Using new opt event type -- Mpdefault module and default consts - -## [0.2.7] - 2024-05-11 - -### Features - -- /player/ac route -- Using `mkenv` crate for env init -- Ttl for events -- Populate event with mappack mx id -- Sort event maps records -- Staggered requests - -## [0.2.6] - 2024-04-15 - -### Bug fixes - -- Db returning null for events without category -- Usernames not escaped -- Add ttl for mappack related keys -- Fix updating wrong event editions scores - -- Wrong last/worst rank when calculating scores -- Map last rank set at 0 on empty records -- Persist event mappack in redis after populate -- Temporary hardcode for benchmark 2 -- Using wrong mappack id for events -- Overflow when calculating remaining time - -### Features - -- Returning medal times for each map for `/event//` route -- Filling rest of response with empty categories -- Allowing retrieving mappack from event -- Retrieve event edition admins -- Add relations between maps and events -- Info of leaderboard row in event player info -- Unfinished maps for player in event -- `latestnews_image` route -- Next update of mappack scores in graphql -- Next opponent in campaign page - -### Refactor - -- Refactor code - - -## [0.2.5] - 2023-11-10 - -### Bug fixes - -- Overview query -- Including storm map pack -- Avoiding cloning maps name and uids -- Moved `last_rank` field to `MappackMap` struct -- Avoiding hashmap usage for map pack scores calculations - -### Features - -- Using sql transaction for `/player/finished` route -- Returning request id for graphql errors -- Mappack branch for graphql -- Added `/info` route - -## [0.2.4] - 2023-11-04 - -### Bug fixes - -- Fix wrong version for ladder_score package - -- Wrong latest records shown for a player on the website -- Logging wrong message in console -- Not using transaction for `/player/finished` route -- Avoiding retrieving object from redis pool in loop - -### Features - -- Added `/player/report_error` route -- Returning request id on error - -### Refactor - -- Grouped arguments of some util functions -- Using sql transaction for a record insert - -## [0.2.3] - 2023-10-25 - -### Bug fixes - -- Fix weird issue triggered on server - -- Fix missing auth guard on /player/finished route - -- Temporary system for benchmark -- /player/pb routes returning wrong cps times -- Optimized sql queries for graphql route -- Benchmark maps leaderboard not showing - -### Miscellaneous Tasks - -- Upgrading dependencies - - -### Refactor - -- Refactored update_or_insert function body - - -## [0.2.1] - 2023-07-30 - -### Bug fixes - -- Full update after missing rank -- Redis leaderboard updating incorrectly - -## [0.2.0] - 2023-07-24 - -### Bug fixes - -- Avoided sql syntax error with wrong map id -- Permanent ban not retrieved -- Auth state not shared across server -- Not compiling without feature - -### Documentation - -- Documented part of the API and server deployment - -- Documented auth system and other stuff - - -### Features - -- Logging info when client token deleted -- Added times route - -### Miscellaneous Tasks - -- Using explicit flow for MP oauth system - - -### Testing - -- Test v0 - - - diff --git a/api.md b/api.md deleted file mode 100644 index 382610a..0000000 --- a/api.md +++ /dev/null @@ -1,305 +0,0 @@ -# Obstacle API - -Note: This API is mainly used by the Obstacle Titlepack. -It has only access to GET and POST request methods. Thus, it may not respect the conventions of a REST API. In addition, it may change in the future, even drastically. - -This file does not necessarily list all the endpoints correctly defined in the source code, as it may become cumbersome to keep synchronized both versions. - -- [Obstacle API](#obstacle-api) - - [GET `/overview`](#get-overview) - - [GET `/graphql`](#get-graphql) - - [POST `/graphql`](#post-graphql) - - [POST `/player/update`](#post-playerupdate) - - [POST `/player/finished`](#post-playerfinished) - - [Authentication](#authentication) - - [POST `/player/get_token`](#post-playerget_token) - - [POST `/player/give_token`](#post-playergive_token) - - [GET `/player/give_token`](#get-playergive_token) - - [GET `/player/info`](#get-playerinfo) - - [POST `/map/insert`](#post-mapinsert) - - [GET `/event`](#get-event) - - [GET `/event/:event_handle`](#get-eventevent_handle) - - [GET `/event/:event_handle/:edition_id`](#get-eventevent_handleedition_id) - -## GET `/overview` - -Retrieves the leaderboard centered on a player in a map. - -Query parameter | Type | Description ---------------------|--------|-------------------------------- -`playerId` | string | The login of the player (it has this name for compatibility reasons). -`mapId` | string | The UID of the map. - -An invalid `playerId` or `mapId` will result in a `400 Bad Request` error. - -Example response: - -```json -{ - "response": [ - { - "rank": 1, - "login": "wazas", - "nickname": "...", - "time": 39483 - }, - // ... - ] -} -``` - -## GET `/graphql` - -This is the entrypoint for the GraphQL playground. - -## POST `/graphql` - -This is the entrypoint for a GraphQL request. Use the playground to see the schema. - -## POST `/player/update` - -*This method requires [authentication](#authentication)* - -Updates the information about a player, e.g. its nickname and its zone path. - -Body: - -```json -{ - "login": "Player's login", - "nickname": "Player's nickname", - "zone_path": "Player's zone path" -} -``` - -An invalid login will result in a `400 Bad Request` error. - -Response: `200 OK` if everything went normal. - -## POST `/player/finished` - -*This method requires [authentication](#authentication)* - -Registers the record of a player on a map. - -Body: - -```json -{ - "time": 34335, // in microseconds - "respawn_count": 3, - "login": "Player's login", - "map_uid": "Map's UID", - "flags": 0, // determines if ALT key was pressed or not for example - "cps": [ - 11445, - 11445, - 11445 - ] -} -``` - -An invalid `login` or `map_uid`, or the `cps` array length being greater than the cps number of the map, -or the sum of the `cps` times being different than the `time` provided, will result to a `400 Bad Request` error. - -Example response: - -```json -{ - "has_improved": true, - "login": "Player's login", - "old": 34312, - "new": 34335 -} -``` - -## Authentication - -For all endpoints that require an authentication, you must provide an `Authorization` header, -with the Obstacle token of the player. - -### POST `/player/get_token` - -Requests a new token for a player. This request must be given with a `state` string, a randomly generated string, -that will be the same as the `` in this link when you open it to the player: - -`https://prod.live.maniaplanet.com/login/oauth2/authorize?response_type=code&client_id=de1ce3ba8e&redirect_uri=https://obstacle.titlepack.io/give_token&state=&scope=basic` - -Body: - -```json -{ - "login": "Player's login", - "state": "The randomly generated string", - "redirect_uri": "https://obstacle.titlepack.io/give_token" -} -``` - -Note that this works even if the player doesn't yet exist in the database. - -Response: - -```json -{ - "token": "..." -} -``` - -### POST `/player/give_token` - -This endpoint is used in the [GET `/player/give_token`] page to connect with -the [POST `/player/get_token`] endpoint, to give it the access token. -You usually don't need to use it directly. - -### GET `/player/give_token` - -This endpoint is the redirection page used by the ManiaPlanet OAuth2 system after -the user logged in. -You usually don't need to use it directly. - -## GET `/player/info` - -Retrieves the information about a player. - -Body: - -```json -{ - "login": "Player's login" -} -``` - -An invalid `login` will result in a `400 Bad Request` error. - -Example response: - -```json -{ - "id": 1056, - "login": "ahmad3", - "name": "ahmad", - "join_date": "...", - "zone_path": "World|Middle East|Lebanon", - "role_name": "admin" -} -``` - -## POST `/map/insert` - -Inserts a new map in the database, or does nothing if it already exists. -Note that if the author does not yet exist in the database, it is inserted on the fly. - -Body: - -```json -{ - "name": "Map's name", - "map_uid": "Map's UID", - "cps_number": 3, - "author": { - "login": "Author's login", - "nickname": "Author's nickname", - "zone_path": "Author's zone path" - } -} -``` - -Response: `200 OK` if everything went normal. - -## GET `/event` - -Returns the all the list of the events, with the id of their last edition, or `null` if not yet registered. - -Example response: - -```json -[ - { - "handle": "benchmark", - "last_edition_id": 1 - }, - { - "handle": "storm_runners", - "last_edition_id": 2 - }, - { - "handle": "atria_coop", - "last_edition_id": null - }, - // ... -] -``` - -## GET `/event/:event_handle` - -Returns all the editions of an event from its handle, reverse-ordered by their ID. - -Example response for `/event/storm_runners`: - -```json -[ - { - "id": 1, - "start_date": "..." - }, - { - "id": 2, - "start_date": "..." - } -] -``` - -## GET `/event/:event_handle/:edition_id` - -Returns the details of an edition of an event from its ID and the event handle. - -Example response for `/event/storm_runners/2`: - -```json -{ - "id": 2, - "name": "Storm Runners #2", - "start_date": "...", - "banner_img_url": "...", - "content": { - "type": "Maps", - "maps": [ - { - "main_author": { - "login": "aurelamck", - "name": "$L[www.twitch.tv/aurelsm]$fffGrandp'Aurel$i$09F", - "zone_path": null - }, - "other_authors": [ - "Lyyras", - "Triss", - "rustydead", - "Lagaffe", - "artyoh" - ], - "name": "$o$nStorm Runners #2 - $F00The $A06Spirit $50CWorld", - "map_uid": "LPOsdLqT5NKvefQT6y_vzZXsf23", - "mx_id": 42418 - }, - // ... - ] - } -} -``` - -Note that the field `content.type` may be `"Maps"` or `"Categories"`. - -For `"Maps"`, the next field will be `maps`, an array of the objects mentioned above. - -For `"Categories"`, the next field will be `categories`, an array of these objets: - -```json -{ - "handle": "The category's handle (for example: white)", - "name": "The category's name (for example: White)", - "banner_img_url": "...", - "maps": [ - // ...same as above - ] -} -``` \ No newline at end of file diff --git a/apisource.sh b/apisource.sh deleted file mode 100644 index cce0942..0000000 --- a/apisource.sh +++ /dev/null @@ -1,102 +0,0 @@ -#!/bin/bash - -__wd=$(pwd) -__dir=$(dirname $0) - -# Returns 0 if the PID $1 is not running, 1 otherwise -__is_pid_stopped() { - if ps -p $1 >/dev/null 2>&1; then return 1; fi - return 0 -} - -# Waits for the PID $1 makes a fork, then returns its PID -__wait_for_fork() { - # Avoids waiting forever - if __is_pid_stopped $1; then return; fi - local cpid=$(pgrep -P $1) - until [[ -n $cpid ]]; do - if __is_pid_stopped $1; then return; fi - cpid=$(pgrep -P $1) - done - echo $cpid -} - -startwebsite() { - local firstwd=$(pwd) - local dir="$__wd/$__dir" - cd $dir - - cd website - yarn dev > ../etc/web_out 2>&1 & - - cd $firstwd -} - -startapi() { - local firstwd=$(pwd) - local dir="$__wd/$__dir" - cd $dir - - trap 'cd $firstwd' 2 - - if [[ $1 == "gql" ]]; then - local output_gql_arg="-F gql_schema" - fi - cargo run --bin game-api $output_gql_arg > ./etc/api_out 2>&1 & - - if [[ $1 == "gql" ]]; then - until [[ -f ./etc/api_last_gql_schema ]]; do - sleep 1 - done - - local last_schema=$(cat ./etc/api_last_gql_schema) - local schema_file="schemas/$last_schema" - cp $schema_file website/schema.graphql - rm $schema_file - rm ./etc/api_last_gql_schema - cd website - yarn compile - cd .. - fi - - cd $firstwd -} - -attachobs() { - local firstwd=$(pwd) - local dir="$__wd/$__dir" - cd $dir - - trap 'cd $firstwd; return 2' 2 - - local code=0 - - local arg=$1 - if [[ -z $arg ]]; then arg=api; fi - - case $arg in - api) - if [[ ! -f ./etc/api_out ]]; then - echo "Error: Obstacle API is not running." - code=1 - else - tail -f ./etc/api_out - fi - ;; - website) - if [[ ! -f ./etc/web_out ]]; then - echo "Error: Obstacle website is not running." - code=1 - else - tail -f ./etc/web_out - fi - ;; - *) - echo "Error: either attach to \`api\` (default) or \`website\`." - code=1 - ;; - esac - - cd $firstwd - return $code -} \ No newline at end of file diff --git a/cliff.toml b/cliff.toml deleted file mode 100644 index eb4afd0..0000000 --- a/cliff.toml +++ /dev/null @@ -1,82 +0,0 @@ -# git-cliff ~ default configuration file -# https://git-cliff.org/docs/configuration -# -# Lines starting with "#" are comments. -# Configuration options are organized into tables and keys. -# See documentation for more information on available options. - -[changelog] -# changelog header -header = """ -# Changelog\n -All notable changes to this project will be documented in this file.\n -""" -# template for the changelog body -# https://keats.github.io/tera/docs/#introduction -body = """ -{% if version %}\ - ## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }} -{% else %}\ - ## [unreleased] -{% endif %}\ -{% for group, commits in commits | group_by(attribute="group") %} - ### {{ group | upper_first }} - {% for commit in commits %} - - {% if commit.breaking %}[**breaking**] {% endif %}{{ commit.message | upper_first }}\ - {% endfor %} -{% endfor %}\n -""" -# remove the leading and trailing whitespace from the template -trim = true -# changelog footer -footer = """ - -""" -# postprocessors -postprocessors = [ - # { pattern = '', replace = "https://github.com/orhun/git-cliff" }, # replace repository URL -] -[git] -# parse the commits based on https://www.conventionalcommits.org -conventional_commits = true -# filter out the commits that are not conventional -filter_unconventional = false -# process each line of a commit as an individual commit -split_commits = false -# regex for preprocessing the commit messages -commit_preprocessors = [ - # { pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](/issues/${2}))"}, # replace issue numbers -] -# regex for parsing and grouping commits -commit_parsers = [ - { message = "^feat", group = "Features" }, - { message = "^fix", group = "Bug fixes" }, - { message = "^doc", group = "Documentation" }, - { message = "^perf", group = "Performance" }, - { message = "^refactor", group = "Refactor" }, - { message = "^style", group = "Styling" }, - { message = "^test", group = "Testing" }, - { message = "^chore\\(release\\): prepare for", skip = true }, - { message = "^chore\\(deps\\)", skip = true }, - { message = "^chore\\(pr\\)", skip = true }, - { message = "^chore\\(pull\\)", skip = true }, - { message = "^chore|ci", group = "Miscellaneous Tasks" }, - { body = ".*security", group = "Security" }, - { message = "^revert", group = "Revert" }, -] -# protect breaking changes from being skipped due to matching a skipping commit_parser -protect_breaking_commits = false -# filter out the commits that are not matched by commit parsers -filter_commits = true -# glob pattern for matching git tags -tag_pattern = "v[0-9]*" -# regex for skipping tags -skip_tags = "v0.1.0-beta.1" -# regex for ignoring tags -ignore_tags = "" -# sort the tags topologically -topo_order = false -# sort the commits inside sections by oldest/newest order -sort_commits = "oldest" -# limit the number of commits included in the changelog. -# limit_commits = 42