A Node.js Library for connecting to Openttd's admin interface.
This module can be seen as an update to yorickvP/node-ottdadmin, however its completely rewritten to be a bit more tidy and standard, as well as working on more recent versions of node. I have kept the interface reasonably similar, however, its not a drop-in replacement.
var libOpenttdAdmin = require("libOpenttdAdmin"),
ottdConnection = new libOpenttdAdmin.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();
});
Examples can be found in the examples/
folder
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 ) |
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 servermap - 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 |
console |
Fired on receiving output | origin - origin of the output output - body of the output |
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
Just a little todo for me :)
Write initial documentation- Look up unknowns in documentation
Break up long switch into functions in another file- work out some way of doing tests
- Proof read everything