Config.ofe toggles whether or not to write heapdumps if sockets workers
run out of memory, since ofe is an optional dependency but is not
installed by default. nodemailer is now a nonDefaultDependency, and
will complain if it's not installed when Config.crashguardemail is
enabled.
If the connections aren't destroyed when the worker is disconnected,
its process will not exit until the remaining connections have closed.
This cleans them up manually so using Sockets.killWorker or
Sockets.killPid does not force any users connected over that worker to
refresh twice in order to reconnect to the server.
This also makes workers respawn automatically after being killed, which
they weren't doing before.
- `Config.repl` enables/disables using REPL sockets since it doesn't
make as much sense to configure whether or not it's enabled with the
REPL_ENABLED const
- exports.start takes a filename parametre rather than a prefix and a
suffix one to avoid having to mutate parametres
- dead REPL sockets are removed from the sockets list when the server
emits an error, and the server closes on error now before respawning
the server
- made the file ready for Typescript
* Sockets: fix Sockets.killWorker not disconnecting connections
* Sockets: fix unit tests
- Fix crash when constructing mock sockets in certain cases
- Properly prevent workers from writing to stdout
- Fix race conditions in workers-related tests that were causing false
positives
* Tests: mock workers now more closely imitate sockets' workers
This helps catch cases where messages are being sent in the wrong order
to the workers, e.g. messages sent to sockets that no longer exist.
It was previously entirely wrong! We haven't supported iframes as a
transport for a long time! Unsurprisingly, no one complained since
we don't support particularly old browsers and even old browsers
support JSONP polling...
This should make it easier to hunt down that bug that's causing SockJS
not to disconnect.
(I have suspicions that it's related to websocket-raw but it's always
nice to get more data...)
dnsbl.js is kind of a misnomer, but it has been for a long time. It's
currently a collection of various tools useful for IP-based blocking.
Maybe iptools.js?
Anyway, the two files are now one file, and have been refactored a
bit for performance. Dnsbl.query is also a Promise API now.
These messages are most likely some sort of DDoS; PS doesn't natively
use any messages larger than I think 3KB (is that what teams are?)
server->client messages, on the other hand, can be much longer because
if you join an in-progress battle, PS will send you the entire battle
log up to that point, which can be pretty huge.
sockjs can't actually disable websockets.
The option actually only disabled the /showdown/websocket address,
which spoke the raw protocol, where the "normal"
/showdown/x/y/websocket address that speaks the sockjs protocol
still worked.
Now that nodejs/node#3072 is mostly fixed, we can finally start using
Node 4+ features.
This refactor:
- uses arrow functions where appropriate
Note that arrow functions still aren't used in Mocha, where `this`
is sometimes meaningful.
This also removes the need for .bind() nearly everywhere, as well
as the `self = this` trick.
- refactors Validator and Connection into ES6 classes
- no longer uses Array#forEach for iterating arrays
We strongly prefer for (let i = 0; i < arr.length; i++) because of
performance reasons. Most forEaches have been replaced with for..of,
though, which is 5x slower than the long-form loop but 2x faster
than forEach, which is good enough outside of most inner loops.
The only exception is tournaments, which is due for a more invasive
refactor soon anyway.
If a child process dies in a way that it can't recover from, the main
process now exits, to prevent loops of 'Error: channel closed'
thousands of times a second, filling up the error log and making it
hard to track down the real error.
Previously, include('./sockets.js') and include('./app.js') would
automatically spawn listener processes.
Now, you have to actually use .listen() to spawn listener processes.
This makes the testing framework simpler, since it no longer needs an
ugly hack to suppress spawning socket processes, and also makes it
easier for the ./pokemon-showdown "binary" to pass a port to app.js.
./pokemon-showdown will now also install dependencies if necessary.
Specifically, Users.users, Users.connections, and Users.pastUsers
are now ES6 Maps. In theory, this should be a minor performance
upgrade, but we still need to profile to make sure.
JSHint's ES6 support is shaky, and its development has stalled as of late.
Since ESLint can do by itself both JSHint and JSCS' jobs, this commit replaces them.
Gulp and its related dependencies are also hereby removed.
This is relevant information as some crashes may only happen after some other crash
has created inconsistent state either in PS itself or in Node.js internals.
This is intended to be used as a last resort for if a socket process
needs to be hotpatched, and kota's REPL code is too unstable to be
used.
Usage: manually `socket.send('$code')`
If the port is overridden (either through commandline, test framework,
or environment variable), we probably don't want to listen on any
other port, like the SSL port.
Setting Config.bindaddress = '0.0.0.0' (meaning "listen on all IP
addresses") would result in the message "Go to 0.0.0.0:8000 to
test your server" on startup, but 0.0.0.0 is not a valid IP address.
This now says "Go to localhost:8000".
It wasn't getting propagated to socket processes correctly. Also change
the default bind address from 'localhost' to undefined (accept all
connections).
I used a hack to make the multiple declaration errors go away,
so all that remained in jsHint were actual errors, which I've
now mostly fixed.
All this linting ended up uncovering one actual bug: Uproar's
message not showing. It's a very minor bug in a move no one uses,
so I'm going to fold it into this commit.