2019-10-19 10:27:04 +00:00
|
|
|
# OpenTTD's admin network
|
|
|
|
|
2011-01-20 21:28:38 +00:00
|
|
|
Last updated: 2011-01-20
|
2010-10-21 20:23:32 +00:00
|
|
|
|
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
## Table of contents
|
|
|
|
|
|
|
|
- 1.0) [Preface](#10-preface)
|
|
|
|
- 2.0) [Joining the network](#20-joining-the-network)
|
|
|
|
- 3.0) [Asking for updates](#30-asking-for-updates)
|
|
|
|
- 3.1) [Polling manually](#31-polling-manually)
|
|
|
|
- 4.0) [Sending rcon commands](#40-sending-rcon-commands)
|
|
|
|
- 5.0) [Sending chat](#50-sending-chat)
|
|
|
|
- 5.1) [Receiving chat](#51-receiving-chat)
|
|
|
|
- 6.0) [Disconnecting](#60-disconnecting)
|
|
|
|
- 7.0) [Certain packet information](#70-certain-packet-information)
|
2011-01-16 13:36:47 +00:00
|
|
|
|
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
## 1.0) Preface
|
|
|
|
|
2010-10-21 20:23:32 +00:00
|
|
|
The admin network provides a dedicated network protocol designed for other
|
|
|
|
applications to communicate with OpenTTD. Connected applications can execute
|
|
|
|
console commands remotely (rcon commands) with no further authentication.
|
|
|
|
Furthermore information about clients and companies can be provided.
|
|
|
|
|
|
|
|
Admin applications remain connected when starting a new game or loading a saved
|
|
|
|
game in contrast to normal OpenTTD clients that get disconnected.
|
|
|
|
|
|
|
|
This document describes the admin network and its protocol.
|
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
Please refer to the mentioned enums in `src/network/core/tcp_admin.h`
|
2010-10-21 20:23:32 +00:00
|
|
|
|
|
|
|
Please also note that further improvements to the admin protocol can mean that
|
|
|
|
more packet types will be sent by the server. For forward compatibility it is
|
|
|
|
therefore wise to ignore unknown packets. Future improvements might also add
|
|
|
|
additional data to packets. This data should be ignored. Data will never be
|
|
|
|
removed from packets in later versions, except the possibility that complete
|
|
|
|
packets are dropped in favour of a new packet.
|
2019-10-19 10:27:04 +00:00
|
|
|
|
2010-10-21 20:23:32 +00:00
|
|
|
This though will be reflected in the protocol version as announced in the
|
2019-10-19 10:27:04 +00:00
|
|
|
`ADMIN_PACKET_SERVER_PROTOCOL` in section 2.0).
|
2010-10-21 20:23:32 +00:00
|
|
|
|
2011-01-20 21:28:38 +00:00
|
|
|
A reference implementation in Java for a client connecting to the admin interface
|
2019-10-19 10:27:04 +00:00
|
|
|
can be found at: [http://dev.openttdcoop.org/projects/joan](http://dev.openttdcoop.org/projects/joan)
|
2011-01-20 21:28:38 +00:00
|
|
|
|
2010-10-21 20:23:32 +00:00
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
## 2.0) Joining the network
|
|
|
|
|
2010-10-21 20:23:32 +00:00
|
|
|
Create a TCP connection to the server on port 3977. The application is
|
|
|
|
expected to authenticate within 10 seconds.
|
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
To authenticate send a `ADMIN_PACKET_ADMIN_JOIN` packet.
|
2010-10-21 20:23:32 +00:00
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
The server will reply with `ADMIN_PACKET_SERVER_PROTOCOL` followed directly by
|
|
|
|
`ADMIN_PACKET_SERVER_WELCOME`.
|
2010-10-21 20:23:32 +00:00
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
`ADMIN_PACKET_SERVER_PROTOCOL` contains details about the protocol version.
|
2010-10-21 20:23:32 +00:00
|
|
|
It is the job of your application to check this number and decide whether
|
|
|
|
it will remain connected or not.
|
2019-10-19 10:27:04 +00:00
|
|
|
Furthermore, this packet holds details on every `AdminUpdateType` and the
|
|
|
|
supported `AdminFrequencyTypes` (bitwise representation).
|
2010-10-21 20:23:32 +00:00
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
`ADMIN_PACKET_SERVER_WELCOME` contains details on the server and the map,
|
2010-10-21 20:23:32 +00:00
|
|
|
e.g. if the server is dedicated, its NetworkLanguage, size of the Map, etc.
|
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
Once you have received `ADMIN_PACKET_SERVER_WELCOME` you are connected and
|
2010-10-21 20:23:32 +00:00
|
|
|
authorized to do your thing.
|
2019-10-19 10:27:04 +00:00
|
|
|
|
2010-10-21 20:23:32 +00:00
|
|
|
The server will not provide any game related updates unless you ask for them.
|
2010-11-23 23:06:30 +00:00
|
|
|
There are four packets the server will none the less send, if applicable:
|
2019-10-19 10:27:04 +00:00
|
|
|
|
2010-10-21 20:23:32 +00:00
|
|
|
- ADMIN_PACKET_SERVER_ERROR
|
|
|
|
- ADMIN_PACKET_SERVER_WELCOME
|
|
|
|
- ADMIN_PACKET_SERVER_NEWGAME
|
|
|
|
- ADMIN_PACKET_SERVER_SHUTDOWN
|
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
However, `ADMIN_PACKET_SERVER_WELCOME` only after a `ADMIN_PACKET_SERVER_NEWGAME`
|
2010-10-21 20:23:32 +00:00
|
|
|
|
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
## 3.0) Asking for updates
|
|
|
|
|
|
|
|
Asking for updates is done with `ADMIN_PACKET_ADMIN_UPDATE_FREQUENCY`.
|
2010-10-21 20:23:32 +00:00
|
|
|
With this packet you define which update you wish to receive at which
|
|
|
|
frequency.
|
|
|
|
|
|
|
|
Note: not every update type supports every frequency. If in doubt, you can
|
2019-10-19 10:27:04 +00:00
|
|
|
verify against the data received in `ADMIN_PACKET_SERVER_PROTOCOL`.
|
2010-10-21 20:23:32 +00:00
|
|
|
|
2020-06-27 16:21:17 +00:00
|
|
|
Please note the potential gotcha in the "Certain packet information" section below
|
|
|
|
when using the `ADMIN_UPDATE_FREQUENCY` packet.
|
|
|
|
|
2010-10-21 20:23:32 +00:00
|
|
|
The server will not confirm your registered update. However, asking for an
|
2019-10-19 10:27:04 +00:00
|
|
|
invalid `AdminUpdateType` or a not supported `AdminUpdateFrequency` you will be
|
|
|
|
disconnected from the server with `NETWORK_ERROR_ILLEGAL_PACKET`.
|
|
|
|
|
|
|
|
Additional debug information can be found with a debug level of `net=3`.
|
2010-10-21 20:23:32 +00:00
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
`ADMIN_UPDATE_DATE` results in the server sending:
|
2010-10-21 20:23:32 +00:00
|
|
|
|
|
|
|
- ADMIN_PACKET_SERVER_DATE
|
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
`ADMIN_UPDATE_CLIENT_INFO` results in the server sending:
|
|
|
|
|
2010-10-21 20:23:32 +00:00
|
|
|
- ADMIN_PACKET_SERVER_CLIENT_JOIN
|
|
|
|
- ADMIN_PACKET_SERVER_CLIENT_INFO
|
|
|
|
- ADMIN_PACKET_SERVER_CLIENT_UPDATE
|
|
|
|
- ADMIN_PACKET_SERVER_CLIENT_QUIT
|
|
|
|
- ADMIN_PACKET_SERVER_CLIENT_ERROR
|
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
`ADMIN_UPDATE_COMPANY_INFO` results in the server sending:
|
|
|
|
|
2010-10-21 20:23:32 +00:00
|
|
|
- ADMIN_PACKET_SERVER_COMPANY_NEW
|
|
|
|
- ADMIN_PACKET_SERVER_COMPANY_INFO
|
|
|
|
- ADMIN_PACKET_SERVER_COMPANY_UPDATE
|
|
|
|
- ADMIN_PACKET_SERVER_COMPANY_REMOVE
|
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
`ADMIN_UPDATE_COMPANY_ECONOMY` results in the server sending:
|
|
|
|
|
2010-10-21 20:23:32 +00:00
|
|
|
- ADMIN_PACKET_SERVER_COMPANY_ECONOMY
|
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
`ADMIN_UPDATE_COMPANY_STATS` results in the server sending:
|
|
|
|
|
2010-10-21 20:23:32 +00:00
|
|
|
- ADMIN_PACKET_SERVER_COMPANY_STATS
|
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
`ADMIN_UPDATE_CHAT` results in the server sending:
|
|
|
|
|
2010-10-21 20:23:32 +00:00
|
|
|
- ADMIN_PACKET_SERVER_CHAT
|
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
`ADMIN_UPDATE_CONSOLE` results in the server sending:
|
|
|
|
|
2010-10-21 20:23:32 +00:00
|
|
|
- ADMIN_PACKET_SERVER_CONSOLE
|
|
|
|
|
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
`ADMIN_UPDATE_CMD_LOGGING` results in the server sending:
|
|
|
|
|
2010-12-30 18:14:37 +00:00
|
|
|
- ADMIN_PACKET_SERVER_CMD_LOGGING
|
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
## 3.1) Polling manually
|
|
|
|
|
|
|
|
Certain `AdminUpdateTypes` can also be polled:
|
|
|
|
|
2010-10-21 20:23:32 +00:00
|
|
|
- ADMIN_UPDATE_DATE
|
|
|
|
- ADMIN_UPDATE_CLIENT_INFO
|
|
|
|
- ADMIN_UPDATE_COMPANY_INFO
|
|
|
|
- ADMIN_UPDATE_COMPANY_ECONOMY
|
|
|
|
- ADMIN_UPDATE_COMPANY_STATS
|
2010-12-30 18:14:37 +00:00
|
|
|
- ADMIN_UPDATE_CMD_NAMES
|
2010-10-21 20:23:32 +00:00
|
|
|
|
2020-06-27 16:21:17 +00:00
|
|
|
Please note the potential gotcha in the "Certain packet information" section below
|
|
|
|
when using the `ADMIN_POLL` packet.
|
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
`ADMIN_UPDATE_CLIENT_INFO` and `ADMIN_UPDATE_COMPANY_INFO` accept an additional
|
2010-10-21 20:23:32 +00:00
|
|
|
parameter. This parameter is used to specify a certain client or company.
|
2019-10-19 10:27:04 +00:00
|
|
|
Setting this parameter to `UINT32_MAX (0xFFFFFFFF)` will tell the server you
|
2010-10-21 20:23:32 +00:00
|
|
|
want to receive updates for all clients or companies.
|
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
Not supported `AdminUpdateType` in the poll will result in the server
|
|
|
|
disconnecting the application with `NETWORK_ERROR_ILLEGAL_PACKET`.
|
2010-10-21 20:23:32 +00:00
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
Additional debug information can be found with a debug level of `net=3`.
|
2010-10-21 20:23:32 +00:00
|
|
|
|
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
## 4.0) Sending rcon commands
|
|
|
|
|
|
|
|
Rcon runs separate from the `ADMIN_UPDATE_CONSOLE` `AdminUpdateType`. Requesting
|
2010-10-21 20:23:32 +00:00
|
|
|
the execution of a remote console command is done with the packet
|
2019-10-19 10:27:04 +00:00
|
|
|
`ADMIN_PACKET_ADMIN_RCON`.
|
2010-10-21 20:23:32 +00:00
|
|
|
|
|
|
|
Note: No additional authentication is required for rcon commands.
|
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
The server will reply with one or more `ADMIN_PACKET_SERVER_RCON` packets.
|
|
|
|
Finally an `ADMIN_PACKET_ADMIN_RCON_END` packet will be sent. Applications
|
|
|
|
will not receive the answer twice if they have asked for the `AdminUpdateType`
|
|
|
|
`ADMIN_UPDATE_CONSOLE`, as the result is not printed on the servers console
|
2010-10-21 20:23:32 +00:00
|
|
|
(just like clients rcon commands).
|
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
Furthermore, sending a `say` command (or any similar command) will not
|
2010-10-21 20:23:32 +00:00
|
|
|
be sent back into the admin network.
|
|
|
|
Chat from the server itself will only be sent to the admin network when it
|
|
|
|
was not sent from the admin network.
|
|
|
|
|
2013-07-13 09:59:09 +00:00
|
|
|
Note that when content is queried or updated via rcon, the processing
|
2019-10-19 10:27:04 +00:00
|
|
|
happens asynchronously. But the `ADMIN_PACKET_ADMIN_RCON_END` packet is sent
|
2013-07-13 09:59:09 +00:00
|
|
|
already right after the content is requested as there's no immediate output.
|
|
|
|
Thus other packages and the output of content rcon command may be sent at
|
|
|
|
an arbitrary later time, mixing into the output of other console activity,
|
|
|
|
e.g. also of possible subsequent other rcon commands sent.
|
|
|
|
|
2010-10-21 20:23:32 +00:00
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
## 5.0) Sending chat
|
|
|
|
|
|
|
|
Sending a `ADMIN_PACKET_ADMIN_CHAT` results in chat originating from the server.
|
2010-10-21 20:23:32 +00:00
|
|
|
|
|
|
|
Currently four types of chat are supported:
|
2019-10-19 10:27:04 +00:00
|
|
|
|
2010-10-21 20:23:32 +00:00
|
|
|
- NETWORK_ACTION_CHAT
|
|
|
|
- NETWORK_ACTION_CHAT_CLIENT
|
|
|
|
- NETWORK_ACTION_CHAT_COMPANY
|
|
|
|
- NETWORK_ACTION_SERVER_MESSAGE
|
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
`NETWORK_ACTION_SERVER_MESSAGE` can be sent to a single client or company
|
|
|
|
using the respective `DestType` and ID.
|
|
|
|
This is a message prefixed with the 3 stars, e.g. `*** foo has joined the game`
|
2010-10-21 20:23:32 +00:00
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
## 5.1) Receiving chat
|
|
|
|
|
|
|
|
Register `ADMIN_UPDATE_CHAT` at `ADMIN_FREQUENCY_AUTOMATIC` to receive chat.
|
2010-10-21 20:23:32 +00:00
|
|
|
The application will be able to receive all chat the server can see.
|
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
The configuration option `network.server_admin_chat` specifies whether
|
2010-10-21 20:23:32 +00:00
|
|
|
private chat for to the server is distributed into the admin network.
|
|
|
|
|
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
## 6.0) Disconnecting
|
|
|
|
|
2010-11-23 23:06:30 +00:00
|
|
|
It is a kind thing to say good bye before leaving. Do this by sending the
|
2019-10-19 10:27:04 +00:00
|
|
|
`ADMIN_PACKET_ADMIN_QUIT` packet.
|
|
|
|
|
2010-10-21 20:23:32 +00:00
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
## 7.0) Certain packet information
|
2010-10-21 20:23:32 +00:00
|
|
|
|
2020-06-27 16:21:17 +00:00
|
|
|
`ADMIN_PACKET_ADMIN_UPDATE_FREQUENCY` and `ADMIN_PACKET_ADMIN_POLL`
|
|
|
|
|
|
|
|
Potential gotcha: the AdminUpdateType integer type used is a
|
|
|
|
uint16 for `UPDATE_FREQUENCY`, and a uint8 for `POLL`.
|
|
|
|
This is due to boring legacy reasons.
|
|
|
|
It is safe to cast between the two when sending
|
|
|
|
(i.e cast from a uint8 to a uint16).
|
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
All `ADMIN_PACKET_SERVER_*` packets have an enum value greater 100.
|
2010-10-21 20:23:32 +00:00
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
`ADMIN_PACKET_SERVER_WELCOME`
|
|
|
|
|
|
|
|
Either directly follows `ADMIN_PACKET_SERVER_PROTOCOL` or is sent
|
2010-10-21 20:23:32 +00:00
|
|
|
after a new game has been started or a map loaded, i.e. also
|
|
|
|
after ADMIN_PACKET_SERVER_NEWGAME.
|
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
`ADMIN_PACKET_SERVER_CLIENT_JOIN` and `ADMIN_PACKET_SERVER_COMPANY_NEW`
|
|
|
|
|
2010-10-21 20:23:32 +00:00
|
|
|
These packets directly follow their respective INFO packets. If you receive
|
|
|
|
a CLIENT_JOIN / COMPANY_NEW packet without having received the INFO packet
|
|
|
|
it may be a good idea to POLL for the specific ID.
|
|
|
|
|
2019-10-19 10:27:04 +00:00
|
|
|
`ADMIN_PACKET_SERVER_CMD_NAMES` and `ADMIN_PACKET_SERVER_CMD_LOGGING`
|
|
|
|
|
2010-12-30 18:14:37 +00:00
|
|
|
Data provided with these packets is not stable and will not be
|
|
|
|
treated as such. Do not rely on IDs or names to be constant
|
|
|
|
across different versions / revisions of OpenTTD.
|
|
|
|
Data provided in this packet is for logging purposes only.
|