Skip to content

Backend Games API

Puscasu Felix edited this page Jun 11, 2021 · 26 revisions

This page presents the API presented by the backend for the Games.

Retrieve a List of Games

Games can be ordered in multiple ways:

  • By the date the game was added.

  • By the number of submissions made to the game.

  • By the number of people who solved the game.

  • Increasing / decreasing.

  • Permissions required: None

  • Address: /api/Games/GetAll

  • Request JSON:

    {
        "requested_games": "Number of requested games",
        "requested_games": 10,
        "requested_offset": "Number of games to skip (for pagination)",
        "requested_offset": 0,

        "order_by": "By default is 'solved'. Option: 'date' / 'solved' / 'submissions'",
        "result_order": "'increasing' or 'decreasing'. By default 'decreasing'",
    }
  • Response JSON:
    {
        "games_found": "total number of games found",
        "games_found": 314,
        "games_returned": "Number of returned games",
        "games_returned": 10,

        "games": "List of the games, in order",
        "games": [{
            "Name": "Game title",
            "Description": "Game statement",
            "GameID": "id of the game",
            "AuthorID": "id of creator of the game",
            "AuthorUsername": "username of the author (not yet implemented)",
            "Date": "date the game was added",
        }],
    }

Retrieve a Game

  • Permissions required: None
  • Address: /api/Games/GetGame
  • Request JSON:
    {
        "GameID": "id of the game",
    }
  • Response JSON:
    {
        "error_message": "Reason why the action failed. Doesn't exist if successful",
        "status": "'ok' if successful, 'fail' if not",
        "game": {
            "Name": "Game title",
            "Description": "Game statement",
            "GameID": "id of the game",
            "AuthorID": "id of creator of the game",
            "AuthorUsername": "username of the author (not yet implemented)",
            "Date": "date the game was added",
            "OfficialBots": "number of bots this Game has",
        }
    }

Create or Update a Game

The syntax used for creating and updating games is similar, and the API is the same. The only difference is that the game_id field doesn't exist if the game is a new one.

  • Permissions required: Creator of the game or administrator for Update, signed-in for Create
  • Address: /api/Games/Alter
  • Request JSON:
    {
        "Name": "Game title",
        "Description": "Game statement",
        "GameID": "Id of the game. Doesn't exist if the game is a new one",
        "AuthorID": "Id of the author (User Id)",
        "GameEngine": "Engine of the game. Optional if the game is an update",
        "OfficialGameBots": "Optional if the game is an update",
        "OfficialGameBots": [{
            "BotName": "Name of the bot (e.g. 'Naive Greedy'). Optional",
            "BotCode": "Code of the bot in C++",
        }]
    }
  • Response JSON:
    {
        "error_message": "Reason why the action failed. Doesn't exist if successful",
        "status": "'ok' if successful, 'fail' if not",
        "GameID": "game id of the created / updated game. Exists if the action is successful",
    }

Additional Game Details

If the user is an administrator or is the creator of the game, then he can additionally download the game engine and bots.

  • Permissions required: Creator of the game or administrator
  • Address: /api/Games/Sources
  • Request JSON:
    {
        "GameID": "Id of the game",
    }
  • Response JSON:
    {
        "error_message": "Reason why the action failed. Doesn't exist if successful",
        "status": "'ok' if successful, 'fail' if not",
        "GameEngine": "Engine of the game",
        "OfficialGameBots": [{
            "BotID": "id of the bot",
            "BotName": "Name of the bot (e.g. 'Naive Greedy').",
            "BotRank": "Rank of the bot",
            "BotCode": "Code of the bot in C++",
            "DateSubmitted": "When the bot was submitted",
            "AuthorID": "ID of the author",
            "CompilationMessage": "Compilation message",
        }]
    }

Delete a game

If the user is an administrator or is the creator of the game, then he can delete the game.

  • Permissions required: Creator of the game or administrator
  • Address: /api/Games/Delete
  • Request JSON:
    {
        "GameID": "Id of the game",
    }
  • Response JSON:
    {
        "error_message": "Reason why the action failed. Doesn't exist if successful",
        "status": "'ok' if successful, 'fail' if not",
    }

Clone this wiki locally