Skip to content

brenodanyel/mtasa-api

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
March 1, 2023 09:29
May 22, 2022 15:43
August 5, 2022 04:36
June 9, 2022 16:00
August 6, 2022 13:52
March 1, 2023 09:31
August 5, 2022 16:35
May 22, 2022 15:43

MTA:SA API

Read the Swagger Docs

Why I created this API?

As MTA doesn't have a proper API to fetch server information, I decided to create it by myself, because its being requested by the community for a long time.

How does it work?

  • GET https://mtasa-api.com/servers
    • How it works behind the scenes?

    • Note: On our side the result is only updated every 5 minutes, but I have no idea how long it takes to update on MTA side.

    • Expected result:

      [
          {
              "ip": string,
              "port": number,
              "playerCount": number,
              "playerSlots": number,
              "name": string,
              "version": string,
              "passworded": boolean,
              "httpPort": number
          },
          ...
      ]
  • GET https://mtasa-api.com/server/?ip=SERVER_IP&asePort=SERVER_ASE_PORT
    • How it works behind the scenes?

      • We send a packet to the server using dgram.
      • We parse the response.
      • We return the parsed data.
    • Note: the result is only updated once every minute.

    • Note: the asePort value is equal the connection port (default 22003) + 123 (default 22126)

    • Expected result:

      {
          "game": string,
          "port": number,
          "name": string,
          "gameType" string,
          "mapName": string,
          "version": string,
          "passworded": boolean,
          "playerCount": number,
          "playerSlots": number,
          "players": [
              {
                  "name": string,
                  "ping": number
              },
              ...
          ]
      }

How to run this code on your side?

  • Step-by-step to run on your machine:
    • Clone the project
    • Rename .env.example -> .env
    • Open the terminal in root folder
    • Run the following commands:
      1. npm install
      2. npm run dev
    • Navigate to http://localhost:3000/stats

Note:

This is a unofficial API, which means it's not maintained by the MTA Team.

Special Thanks:

  • The MTA Team for maintaining this great game.
  • Tederis for the ase2json repository.