The new FS module is an abstraction layer over the built-in fs module.
The main reason it exists is because I need an abstraction layer I can
disable writing from. But that'll be in another commit.
Currently, mine is better because:
- paths are always relative to PS's base directory
- Promises (seriously wtf Node Core what are you thinking)
- PS-style API: FS("foo.txt").write("bar") for easier argument order
- mkdirp
This also increases the minimum supported Node version from v6.0 to
v7.7, because we now use async/await. Sorry for the inconvenience!
This is a surprisingly minor refactor considering how many files it
touches, but most of this is only renames.
In terms of file renames:
- `tools.js` is now `sim/dex.js`
- `battle-engine.js` is now `sim/index.js` and its three classes are
in `sim/battle.js`, `sim/side.js`, and `sim/pokemon.js`
- `prng.js` is now `sim/prng.js`
In terms of variable renames:
- `Tools` is now `Dex`
- `BattleEngine` is now `Sim`
- `BattleEngine.Battle` is now `Sim.Battle`
- `BattleEngine.BattleSide` is now `Sim.Side`
- `BattleEngine.BattlePokemon` is now `Sim.Pokemon`
Missing dependencies are still installed by ./pokemon-showdown, which
is the officially documented way to launch PS. The app now assumes that
if you're launching app.js directly, you know what you're doing.
We still give an error message that explains what's going on, but it's
no longer an auto-install the way it is if you use the launch script.
simulator.js doesn't actually contain the simulator, but is really just
an implementation of battles in the RoomGame interface.
Renames:
`Simulator.Battle` -> `Rooms.RoomBattle`
`Simulator.BattlePlayer` -> `Rooms.RoomBattlePlayer`
`Simulator.SimulatorManager` -> `Rooms.SimulatorManager`
`Simulator.SimulatorProcess` -> `Rooms.SimulatorProcess`
`Simulator.create` -> no longer exists, use `new Rooms.RoomBattle(...)`
We had a lot of discussion in Dev and a somewhat-close poll, but in
the end "Chat" was a better name than "Messages", and also has the
advantage of being shorter (which is nice for Chat.html and
Chat.plural which should be short).
The following functions have been renamed:
- Tools.html to CommandParser.html
- Tools.plural to CommandParser.plural
- Tools.escapeHTML to CommandParser.escapeHTML
- Tools.toDurationString to CommandParser.toDurationString
- Tools.toTimeStamp to CommandParser.toTimestamp
(notice the lowercase 's')
This is in preparation for a rename of Tools to Dex (by removing the
non-dex-related functions) and a rename of CommandParser to either
Messages or Chat.
These changes were supposed to be in de524c1a26 but got lost in my
Git stash...
Once again, this is very experimental code; please don't base any
serious changes on it.
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.
Apparently sockets-nocluster.js doesn't support specifying port
on the command line like
./pokemon-showdown [port]
Now that workarounds exist for the cluster crashes, there's no
longer a need for sockets-nocluster, and it's too buggy to keep
"just in case".
Locks, bans, and namelocks are now stored in `config/punishments.tsv`
and last through restarts. They expire after a set amount of time.
By default, locks and namelocks last 37 hours, and bans last 7 days.
Namelocks now imply regular locks, so namelocked users can't talk.
Locks, bans, and namelocks can no longer be stacked. Now only one
can be active at a time. Since locks < namelocks < bans, this
shouldn't be a big deal in practice.
This all involves a huge refactor. Basically every function in
punishments.js has been changed, and most of them have been renamed,
too. In terms of public API, `lockName` has been renamed `namelock`.
Lock/namelock/ban reasons tracking is supported but currently
unused. It'll probably be fully supported in a later commit.
More punishment-related functionality has been moved from users.js
to punishments.js as well.
Closes#1471
An external dependency is kind of overkill when the only
implementation we need is three lines.
This also lets us write a more performant implementation that
omits the parts irrelevant to us.
The callback code in TeamValidator and the functions that use it have
been refactored to use Promises.
Pretty much all signatures have been changed, for instance:
TeamValidator.validateTeamSync(format, team)
-> TeamValidator(format).validateTeam(team)
TeamValidator.validateTeam(format, team, callback)
-> TeamValidator(format).prepTeam(team) // returns a Promise
Validators are no longer cached since they're really lightweight. They
contain a format and a Tools instance, and Tools instances are already
cached in Tools anyway. This saves a tiny bit of RAM in exchange for a
tiny bit of CPU time, but more importantly makes the code more
readable.
I'm introducing a new pattern/API for managing the parts of code with
child processes - their process managers are now at .PM and are now
opt-in, so you can use them synchronously without needing to spawn
any processes.
Fixes#2448
So far, we've had to deal with tons of issues with cluster in Node 4
and later. A subtle crash, a memory leak, and plenty of other
problems...
child_process has nearly the same API as cluster, so as long as you
only need one child process for your WebSocket server, it's pretty
much a drop-in replacement. That's what sockets-nocluster.js is.
The real question is, how many of these problems will this actually
avoid?
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.
Crashlogger now supports passing in a dictionary of additional
information to report, so we no longer need to resort to making fake
errors.
The hadException parameter has now been removed entirely. I don't know
of a use case for it to be false.
`Tools.includeMods()` is unfortunately still massively broken and
unable to be loaded on-demand. This commit restores the old Tools
behavior of loading it at the beginning, which is horrible for
startup time but is the only way of fixing incorrect /learn
results in past gens.
The previous displayed message for 'sourcesBefore' in gen 1-2 was
also wrong.
This was, as far as I can tell, a mistaken interpretation of what
'sourcesBefore' means; possibly due to a past bug in its
implementation.
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.
tools.js no longer needs sugar and a toId definition included externally,
which should make using it in scripts a lot easier, as well as cut
down the repeated toId definitions in every PS process.
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.
ResourceMonitor has been moved from app.js into monitor.js and
renamed to simply Monitor. It also gains the ability to fine-
grained control the log level, although in a pretty crude way.
Monitor.debug - bugs in PS's engine that we need to fix
someday - by default, these aren't reported
Monitor.warn - issues that suggest an attacker or poorly
coded custom client - these should probably be looked at
Monitor.notice - issues that staff probably want to know.
These are usually also written to the Staff room.
Personal rooms are temporary rooms that are neither stored nor logged.
The purpose of this kind of room is twofold:
First, it serves as a multiple user Private Message conversation.
Second, it serves as a private friend chat.
This eliminates the need to register private rooms for groups of friends.
Personal rooms are destroyed when no one is on them.
They are to be used with /invite only.
They can be created by anyone.
They require a name, but the creator name will be present on title.
Users can't be redirected to a personal room.
This initial local ladder support is really basic. Just Elo/W/L/T in
.tsv files. No support for /rank yet.
Servers are encouraged to write and share their own ladder
implementations. The protocol is designed to allow basically any kind
of ladder you want.