Commit Graph

372 Commits

Author SHA1 Message Date
Guangcong Luo
ba3016340a Update check for Node version 2017-06-23 14:29:13 -07:00
Guangcong Luo
86707e6ef5 Add new FS module
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!
2017-06-23 14:29:13 -07:00
Ben Davies
c61b2701dc App: create default config file in launch script (#3630) 2017-06-16 12:10:11 -05:00
Ben Davies
609bbcdb16 App: do not spawn double the workers when using the launch script (#3534)
app.js already is the main module when using the launch script due to
the way the module's required.
2017-05-18 05:07:13 -05:00
Guangcong Luo
6dd58b40d3 Refactor simulator into new sim/ directory
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`
2017-05-05 16:48:38 -05:00
Guangcong Luo
ed5e7392bc Don't install missing dependencies in app.js
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.
2017-02-15 00:23:16 -06:00
Ben Davies
474ffd5c53 Make the launch script compatible with Windows (#2889) 2017-02-14 15:44:29 -06:00
Guangcong Luo
87c41eb67c Rename simulator.js to room-battle.js
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(...)`
2016-10-21 13:21:12 -05:00
Guangcong Luo
4db67f3cca Report crashes in Dev
Currently, only crashes that require a server restart are reported
outside of the crash emailer and stdout. This makes it so all crashes
are reported.
2016-10-03 03:18:22 -07:00
Bär Halberkamp
a1b69a7b89 Refactor lockdowns (#2808) 2016-10-02 18:52:00 -07:00
The Immortal
44061fb75e Include Chat global earlier 2016-10-02 16:51:49 -04:00
Guangcong Luo
d6f5404e7e Rename CommandParser to Chat
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).
2016-09-30 18:31:15 -07:00
Guangcong Luo
da1b318707 Move text processing from Tools to CommandParser
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.
2016-09-30 18:04:13 -07:00
Guangcong Luo
ac388b3a59 Improve crashlogger
Only report the first crash to Lobby, instead of every crash. The
crash is now also reported to Staff.
2016-09-30 15:56:50 -04:00
Bär Halberkamp
dcfc521b59 Refactor rooms.js to use ES6 classes (#2787) 2016-09-26 15:06:47 -07:00
panpawn
56da7a8d6d Make Messages submodule of CommandParser (#2754)
I don't think this should have it's own global... Besides, this makes it hotpatchable with /hotpatch chat
2016-09-20 09:42:02 -07:00
Guangcong Luo
6b4eaf9422 REALLY support commands in PMs
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.
2016-09-17 01:16:56 -07:00
Guangcong Luo
ff229a16b9 Fix watchconfig
Broken in 1a1f64fe95
2016-09-10 03:47:23 -05:00
Taylor Everding
1a1f64fe95 Remove .js extension from requires (#2725) 2016-08-30 00:04:40 -05:00
Guangcong Luo
e82917fc95 Refactor/merge dnsbl.js and cidr.js
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.
2016-08-10 15:00:46 -05:00
Ivo Julca
62a5397083 Lint: Use latest version and features of ESLint 2016-08-03 01:24:36 -05:00
Ivo Julca
d5a4557246 Register unhandled rejections in crashlogger 2016-05-13 22:46:33 -05:00
Guangcong Luo
94f41e9e92 Remove sockets-nocluster.js
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".
2016-05-11 05:07:02 -04:00
Guangcong Luo
bb5d5066be Timed persistent locks/bans
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
2016-05-11 01:54:54 -07:00
Bär Halberkamp
815b6d1c82 Punishments (#2544)
* Update and improve punishments.js

* Move /loadbanlist to punishments.js
2016-05-03 14:29:17 -07:00
Bär Halberkamp
b450b0617f Move things relating to punishments to punishments.js (#2540) 2016-05-02 12:16:25 -07:00
Guangcong Luo
1c619ff7c0 Show message for config reload crash
This shows an error message on the console when config reloads crash,
to make it easier to debug problems with config updates.
2016-03-31 18:54:15 -04:00
Ivo Julca
7ac62d3cdb Refactor Verifier to use the PM API 2016-03-23 02:44:29 -05:00
Guangcong Luo
52cc7f2e37 Remove Object.values external dependency
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.
2016-03-21 10:15:55 -05:00
Guangcong Luo
a125a3ed7b Remove sugar-deprecated 2016-03-16 09:51:23 -05:00
Guangcong Luo
e87fd32550 Refactor TeamValidator
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
2016-03-16 09:43:59 -05:00
Ivo Julca
66c00d29af Remove usage of String|Number methods implemented by Sugar.js
Implements Tools#toDurationString to replace Number#duration.
2016-03-09 16:55:40 -05:00
Ivo Julca
bc1a46eee1 Deps: Deprecate sugar extensions 2016-03-09 16:31:44 -05:00
Guangcong Luo
1850c643a1 Introduce sockets-nocluster.js
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?
2016-02-17 01:30:13 -06:00
Guangcong Luo
b665660608 Refactor for more ES6 features
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.
2016-02-10 17:40:21 -06:00
Guangcong Luo
8a8838552d Improve crashlogger
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.
2016-02-04 03:04:05 -06:00
Guangcong Luo
77c667f617 Fix /learn in past gens
`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.
2016-01-31 16:52:23 -06:00
Guangcong Luo
573922f145 Give more control over when servers are spawned
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.
2016-01-07 00:20:49 -06:00
Guangcong Luo
8495dafe69 Make tools.js stand alone
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.
2015-12-24 02:55:52 -06:00
Ivo Julca
9116fea506 Fix config crashes possibly resulting in config reset 2015-12-04 01:01:50 -05:00
Guangcong Luo
66381f1317 Improve commenting 2015-12-02 22:14:23 -06:00
Guangcong Luo
1fc85dce48 Remove es6-shim dependency
We no longer support versions of Node so old they don't have the
level of ES6 support we used es6-shim for.
2015-11-07 22:51:44 -06:00
Ivo Julca
7dddb66253 Migrate build system to ESLint
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.
2015-11-07 21:36:49 -05:00
Ivo Julca
90973d5c0c Style fixes
- Cut down excessive spacing
- Add braces to missing conditionals
2015-11-07 17:08:09 -05:00
Juanma Serrano
c4ac8d6e2f Use strict mode and let and const instead of var
This commit also fixes some duplicated variable declarations.
2015-11-06 21:56:52 -05:00
Ivo Julca
68cf70c41b Restore dnsbl.js optionality 2015-10-21 02:04:56 -05:00
Guangcong Luo
ab71ae20fe Refactor ResourceMonitor into monitor.js
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.
2015-10-04 17:02:17 -04:00
Guangcong Luo
dd3134eb53 Merge pull request #2173 from Joimer/personal-rooms
Implement personal rooms
2015-09-23 03:55:25 -05:00
Juanma Serrano
817408c0ec Implement personal rooms
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.
2015-09-23 10:49:42 +02:00
Guangcong Luo
b7797ea725 Add basic local ladder support
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.
2015-09-22 04:52:43 -05:00