Before, an options object containing properties and values to be used
was how decorated instances of the class would be created. This meant
the constructor could assign anything you feel like to `this`. Rather
than that, the constructor now assigns a strict set of values, and
methods are redefined in subclasses.
Basic unit tests were added to test if they could be written for after
the final refactor to fix the other memory leak here.
User#games no longer retains games; it instead gets them from
Rooms(roomid).game.
The Trivia tests needed to be fixed for fidelity to continue passing.
User#games, previously a null-prototype roomid:game Object,
is now User#games, a roomid:game Map.
It would have been refactored into a roomid Set, but I'm afraid of
inconsistent state, even more so than I am of the corresponding
problem in Connection#inRooms. TODO: that.
This also fixes the handling of the race condition where a ladder
battle starts after a user starts a name change but before the name
change finishes.
Now, the battle is force-forfeited. Perhaps the ladder battle
should be prevented if the user changes name...
`battle.tour` is now just a reference to the tour.
`battle.rated` is now just the minimum Elo rating of the two players
in the battle.
With the new RoomGame battles, neither of their old values are
necessary anymore.
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.
onUpdateConnection is called when a user in a room merges with
another user. There are various corner cases when one might want
to handle this situation differently from onConnect
Also document the events in room-game.js in more detail, and fix
up simulator.js's RoomGame implementation a bit.
This is a huge refactor that's a half-scratch rewrite of simulator.js.
Everything seems to be working so far, but with such a huge change,
I wouldn't be surprised if something went wrong.
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.
JSHint is now a fair bit stricter, and is now correctly checking
files in `mods/`.
The code has been fixed to match the new stricter standards.
JSHint has now caught its second actual bug: Gen 5 Pinap Berry
was Ice instead of Grass.
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.