Try   HackMD

GSM Websocket API

Configuration

You need to have the following in your config:

{
    "api": {
        "enabled": true,
        "blacklist": [],
        "ip": "0.0.0.0",
        "port": 3680,
        "whitelist": []
    }
}

You can configure the users in the users.json.
Make sure that the passwords in the config are sha512 hashed.

General Architecture

There are currently three types of messages:

  • Events
  • Requests
  • Answer

Event Message Format

{
    "type": "event",
    "subtype": "<...>",
    "data": <json_object>
}

Request Message Format

{
    "type": "request",
    "subtype": "<...>",
    "id": <snowflake_number>,
    "data": <json_object>
}

You can send any id which you will get back in the corresponding answer

Answer Message Format

{
    "type": "answer",
    "subtype": "<...>",
    "id": <same_as_request_id>,
    "error": 0,
    "errormessage": "",
    "data": <json_object>
}

The "data" object depends on the "subtype" (See Message Catalogue).

General Protocol Overview

ServerClientServerClientloop[Requests]loop[Events]Open Websocket ConnectionRequest: apiloginAnswer: tokenAnswer: ErrorRequestsAnswersErrorEvent

Connection Loss

After a connection loss, the token is valid for another 15 minutes to relogin without using the users credentials.

You will get a new token after a successful relogin.

Error Codes

Error Message
1 request format error (id hardcoded to -1. Connection will get closed)
2 too much data for one frame
3 not logged in
4 unknown request subtype
5 wrong message data format
6 failed apilogin request
7 no permission to process request
8 (getconfig/getlanguage) error reading file
9 (writeconfig/writelanguage) error writing file
10 (deleteconfig/deletelanguage) error deleting file

Message Catalogue

Only the data object will be shown

apilogin

Request

Either token or username and password are null.

{
    "username": <string|null>,
    "password": <string|null>,
    "token": <string|null>
}

Answer

{
    "token": <string>
}

getplayers

Request

null

Answer

Array of all players (Player::getPlayerInfos())

[
    {"ip": "1.2.3.4", "pid": 8 },
    {"ip": "2.3.4.5", "pid": 9 }
]

getconfig

Request

{
    "file": "filename"
}

Answer

"content of file"

deleteconfig

Request

{
    "file": "filename"
}

Answer

null

writeconfig

Request

{
    "file": "filename",
    "content": "content of file"
}

Answer

null

getlanguage

Request

{
    "file": "filename"
}

Answer

"content of file"

deletelanguage

Request

{
    "file": "filename"
}

Answer

null

writelanguage

Request

{
    "file": "filename",
    "content": "content of file"
}

Answer

null

addtoken

Request

{
    "group": "name of group"
}

Answer

"token"

gettokens

Request

null

Answer

{
    "tokenstr": "groupname",
    "token2str": "groupname"
}

deletetoken

Request

{
    "token": "tokenstr"
}

Answer

true

executeingamecommand

Request

{
    "command": "readconfig"
}

Answer

The data string contains the output the user would normally get via a PM ingame.
So most of the time this will be an empty string.

"Command PM output"

getplugins

Request

null

Answer

{
    "plugin.name.space1": {
        "information": "<...>",
        "compatibility": [],
        "state": {}
    },
    "plugin.name.space2": {
        "information": "<...>",
        "compatibility": [],
        "state": {}
    }
}

quitgsmanager

Request

null

Answer

true

getbanlist

Request

null

Answer

Output of BanHelper::getAllBans()

["List of all bans"]

permissiontest

Request

["permission1", "permission2"]

Answer

{
    "permission1": true,
    "permission2": false
}

getcommandpermissions

Request

null

Answer

[
    "permission1",
    "permission2",
    "some.other.per.mission"
]

getplayerinfo

Request

{
    "databaseid": 5
}

Answer

{
    "user": "<database_row>",
    "stats": "<database_row>",
    "rest": "of player info from db"
}

subscribeevent

For List of events check https://www.gsmanager.de/lexicon/entry/34-list-of-events/
(07.03.2018: Status incomplete)

Request

{
    "name": "playerJoined"
}

Response

null

unsubscribeevent

Request

{
    "name": "playerJoined"
}

Response

null

listpresetfiles

Request

null

Response

["file1", "file2"]