0.2.4 • Published 5 years ago

node-openttd-admin v0.2.4

Weekly downloads
13
License
MIT
Repository
github
Last release
5 years ago

node-openttd-admin

A Node.js Library for connecting to Openttd's admin interface.

Preface

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.

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 NameDescriptionparameters
authenticateSend and authentication request - this must be performed within 10 seconds of the server connectingusername - name of the client (can be null for a default) password - server admin password
send_rconSend an rcon commandcommand - command to execute on the server
send_chatSend a chat messageaction - an action from enums.Actions desttype - a destination from enums.DestTypes id - TODO: Lookup msg - message body
send_update_frequencySet a new update frequencytype - type of update (enums.UpdateTypes) frequency - frequency of update (enums.UpdateFrequencies)
send_pingSend a ping requestint32 - 32bit integer that will be returned with pong

Events

Event NameDescriptionOptions
connectCalled when the tcp connection to the server is connectednone
authenticateCalled when successfully authenticated. welcome is more useful for connection howeverversion- I have no idea TODO: Lookup
welcomeCalled when the server sends its "welcome packet", which contains info about the servername - 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)
newgamefired when a new game startsnone
shutdownfired when a new game endsnone
datefired when information about the date is receiveddate - the current date
clientjoinfired when a client joinsid - id of joining client
clientinfoFired when information about the client is receivedid - 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
clientupdateFired when an update from a client is receivedid - 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
clientquitfired when a client quitsid - id of the client
clienterrorFired when a client has an errorid - id of the clienterr - error
companyinfoFired when info about a company is receivedid - 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
companyupdateFired when an update happens to a companyid - 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.
companyremoveFired when a company is deletedid - company idreason - reason for deletion (enums.CompanyRemoveReasons)
companyeconomyfired on receiving information about the company's performanceid - 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.
companystatsFired on receiving information about the assets of a companyvehicles - number of trains, lorries, busses, planes and ships that the company owns stations - number of stations of each type that the company owns
chatFired on receiving a chat messageaction - 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
rconFired on receiving the output of an rcon commandcolour - what colour the message is displayed in output - output of the rcon
rconendFired on receiving the end of an rcon commandcommand - the command that was sent to rcon
consoleFired on receiving outputorigin - origin of the output output - body of the output
pongFired on receiving ping replyint - 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

Todo

  • 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

Thanks To

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago