avdg / openttd-js-api

Lightweight openttd admin api in js - Check out for instructions in the wiki - Not actively maintained but open for pr
MIT License
4 stars 0 forks source link

OpenTTD 1.5 Issue #3

Open aidanmorgan opened 9 years ago

aidanmorgan commented 9 years ago

Hi,

I am really interested in using this project for something I am working on, however I have tried the latest version of OpenTTD and I can't get this to work with the latest version of OpenTTD (1.5.0).

I start a new multiplayer game, hosting the server and with a password set. When attempting to get node to connect I get the folllowing error:

Client connected <- 3 ADMIN_PACKET_ADMIN_POLL

buffer.js:582 throw new RangeError('Trying to access beyond buffer length'); ^ RangeError: Trying to access beyond buffer length at checkOffset (buffer.js:582:11) at Buffer.readUInt32LE (buffer.js:609:5) at Object.generics.typeTableReceive.uint32le (C:\programming\projects\OpenTT D\Game\nodejs\lib\generics.js:117:55) at Object.generics.extractContent (C:\programming\projects\OpenTTD\Game\node js\lib\generics.js:188:43) at Socket.module.exports.tcpPacketListener.defaultOnData (C:\programming\pro jects\OpenTTD\Game\nodejs\lib\openttd-adminport.js:71:15) at Socket.emit (events.js:95:17) at Socket. (_streamreadable.js:764:14) at Socket.emit (events.js:92:17) at emitReadable (_stream_readable.js:426:10) at emitReadable (_stream_readable.js:422:5)

The code I am executing is:

var openttd = require('./openttd-js-api.js'); var client = new openttd.adminport({ 'host': 'localhost', 'port': '3979', 'botname': 'PollerBot', 'password': 'password', 'version': '0.0.1' });

client.poll('cmd names');

avdg commented 9 years ago

I will take a look at it

avdg commented 9 years ago

A possible The cause seems to be that client.poll is called before a connection is opened.

avdg commented 9 years ago

Current workaround: replace client.poll('cmd names') with

client.on('welcome', function() {
    client.poll('cmd names');
});

Does that workaround the issue? I would still call this a bug as there are errors that shouldn't be happening though.

aidanmorgan commented 9 years ago

The welcome function never seems to trigger which is why I moved my code into the authorize handler instead.

avdg commented 9 years ago

Yeah, I had that problem too and I have to figure out that (the code base is still pretty new and lots of bugs still have to be found). Though the code in the documentation folder works just fine...

Anyway, if you get the code working I'm happy for you :-)

avdg commented 9 years ago

(hmm now I don't know how to reproduce the welcome event bug...)