node-openttd-admin-class
v0.2.5
Published
A nodejs library for connecting to OpenTTD's admin interface with allowing multiple connections.
Downloads
3
Readme
node-openttd-admin
A Node.js library for connecting to OpenTTD's admin interface.
Preface
This module is a slight modification of thbaumbach/node-openttd-admin, which is rewritten as a Class to allow multiple connections to OpenTTD servers. Please refer original README.md for further informations.
Basic Usage
var ottd = require("node-openttd-admin"),
ottdConnection = new ottd.connection();
ottdConnection.connect("myserver.com", 3977);
ottdConnection.on('connect', function(){
ottdConnection.authenticate("MyBot", "MyPass");
});
ottdConnection.on('welcome', function(data){
ottdConnection.send_rcon("say \"hello world\"");
ottdConnection.close();
});
Advanced Usage
Examples can be found in the examples/
folder
Functions
| Function Name | Description | parameters |
| :------------------ | :--------------------------------------------------------------------------------------- | :----------------------------------- |
|authenticate
| Send and authentication request - this must be performed within 10 seconds of the server connecting |username
- name of the client (can be null for a default) password
- server admin password|
|send_rcon
| Send an rcon command |command
- command to execute on the server |
|send_chat
| Send a chat message |action
- an action from enums.Actions
desttype
- a destination from enums.DestTypes
id
- TODO: Lookup msg
- message body|
|send_update_frequency
| Set a new update frequency |type
- type of update (enums.UpdateTypes
) frequency
- frequency of update (enums.UpdateFrequencies
) |
|send_ping
| Send a ping request |int32
- 32bit integer that will be returned with pong
|
Events
| Event Name | Description | Options |
| :------------------- | :--------------------------------------------------------------------------------------- | :----------------------------------- |
|connect
| Called when the tcp connection to the server is connected | none |
|authenticate
|Called when successfully authenticated. welcome
is more useful for connection however |version
- I have no idea TODO: Lookup|
|welcome
|Called when the server sends its "welcome packet", which contains info about the server |name
- name of the server version
- sematic version of the server. ie- 1.4.0-beta2 dedicated
- 0 or 1 depending on whether the server is running as a dedicated server map
- data about the map (seed
, landscape
, startdate
, mapheight
, mapwidth
)|
|newgame
|fired when a new game starts |none|
|shutdown
|fired when a new game ends |none|
|date
|fired when information about the date is received |date
- the current date|
|clientjoin
|fired when a client joins |id
- id of joining client|
|clientinfo
|Fired when information about the client is received |id
- id of the clientip
- ip address of the clientname
- username of the clientlang
- language idjoindate
- date the player joined the gamecompany
- id of the company that the player is in|
|clientupdate
|Fired when an update from a client is received |id
- id of the clientip
- ip address of the clientname
- username of the clientlang
- language idjoindate
- date the player joined the gamecompany
- id of the company that the player is in|
|clientquit
|fired when a client quits |id
- id of the client|
|clienterror
|Fired when a client has an error |id
- id of the clienterr
- error |
|companyinfo
|Fired when info about a company is received |id
- company id name
- company name manager
- company manager colour
- company primary colour protected
- whether the company is password protected startyear
- year of inaugaration isai
- whether the company is ai or a human player|
|companyupdate
|Fired when an update happens to a company |id
- company id name
- company name manager
- company manager colour
- company primary colour protected
- whether the company is password protected shares
- who owns the 4 shares, this is an object with elements 1, 2, 3 and 4.|
|companyremove
|Fired when a company is deleted |id
- company idreason
- reason for deletion (enums.CompanyRemoveReasons
)|
|companyeconomy
|fired on receiving information about the company's performance |id
- company id money
- money of the company loan
- amount the company has borrowed income
- income lastquarter
- value, performance and cargo delivered (cargo) of the last quarter prevquarter
- the same, but for the quarter before.|
|companystats
|Fired on receiving information about the assets of a company | vehicles
- number of trains, lorries, busses, planes and ships that the company owns stations
- number of stations of each type that the company owns|
|chat
|Fired on receiving a chat message |action
- what action is included in the message (enums.Actions
)desttype
- where the message is aimed at (enums.DestTypes
) id
- message id message
- message bodymoney
- amount of money sent if action is GIVE_MONEY|
|rcon
|Fired on receiving the output of an rcon command |colour
- what colour the message is displayed in output
- output of the rcon |
|rconend
|Fired on receiving the end of an rcon command |command
- the command that was sent to rcon
|console
|Fired on receiving output |origin
- origin of the output output
- body of the output|
|pong
|Fired on receiving ping reply |int
- integer passed to send_pong
|
Enums
There are several enums provided,these are taken almost directly from yorickvP/node-ottdadmin.
This is just a list of them. Rather than listing all the entries here, please see enums.js
- UpdateTypes
- UpdateFrequencies
- CompanyRemoveReasons
- Actions
- DestTypes
- NetworkErrorCodes