Commit Graph

80 Commits

Author SHA1 Message Date
Quinton Lee
58b20d99eb Dex: Support custom rules altering complex bans (#4738)
Also adds some tests for custom rules
2018-07-03 17:22:28 -07:00
whales
eb61aac282 Tests#Ban: Ignore shared IPs (#4565) 2018-04-09 01:58:31 -05:00
asgdf
324e853f4a Enable explicit allowing/disallowing of renames in battles (#4510) 2018-03-22 10:07:47 -05:00
Guangcong Luo
8b19a546b8 Fix chainbreeding validator 2018-02-01 21:06:37 -06:00
Guangcong Luo
245af440d4 Fix style error 2018-01-31 22:26:24 -06:00
Guangcong Luo
78c327028e Fix Blissey Present + Heal Bell egg move bug
I originally thought this would have to be hardcoded, but actually this
can be coded slightly less hardly than expected!

Getting a Blissey with Present + Heal Bell in Gen 2 works like this:

- Teach Smeargle Present + Heal Bell
- Breed Present + Heal Bell into Snubbull
- Chainbreed Present + Heal Bell into Blissey

The main issue is that checking chainbreeding is very hard, so PS
mostly just takes the stance of "chainbreeding multiple moves is
probably impossible; hardcode exceptions".

BUT! BUT!!!!

Instead of hardcoding this exact move combination, we can actually
just hardcode the fact "the first step of chainbreeding is always legal
if the first father is Smeargle". Which I did and it works!
2018-01-31 21:53:11 -06:00
Guangcong Luo
ab1f995daa Rewrite Process Manager
Process Manager is now lib/process-manager.js

It's been entirely rewritten to reflect what I think a process manager
API should look like.

In particular, there are now two Process Managers, QueryProcessManager
and StreamProcessManager.

Pass QueryProcessManager a pure-ish query function (sync or async) that
takes a JSON value and returns a JSON value, and PM.query() will
execute that function in a subprocess, and return a Promise for its
return value.

StreamProcessManager is the same idea: Pass it a function to create an
ObjectReadWriteStream, and PM.createStream() will create a stream in a
subprocess and return a stream connected to it.
2018-01-18 03:34:16 -06:00
Guangcong Luo
d395424fd3 TeamValidator: Return null, not false, for valid team
As usual, having `T | false` be our optional is a really old PHP
convention; we should be using `T | null` basically everywhere.
2018-01-18 03:32:32 -06:00
Guangcong Luo
5094631fcf Implement Roomlog library
Rooms now have their logging abstracted into their own file, which also
allows the rest of rooms.js to be simplified by a decent margin.

This is in preparation for using Redis as a backing for scrollback log
storage, which will give us a lot more RAM to work with.

My newest newest plan is actually to locally cache room scrollback, and
only read battle logs from Redis. This will make chatroom-joining
faster.
2017-12-16 15:40:45 -06:00
Bär Halberkamp
65a82f28f0 Add a system for subrooms (#4014) 2017-12-13 23:33:25 -06:00
Guangcong Luo
7e02b57016 Refactor Matchmaker to subclass Ladder
As expected, this resulted in zero API changes. (Aside from a minor
test change.)
2017-12-09 15:45:10 -06:00
Guangcong Luo
799a6a1e44 Improve Matchmaker API
Ladder is now a subclass of Matchmaker, and all the APIs previously
attached to Matchmaker are now directly available in Ladder.

In addition, all functions that take a formatid are now of the form
`Ladders(formatid).function(other arguments)`

TODO: Reverse polarity; it makes more sense for Matchmaker to be
a subclass of Ladder. Fortunately, this wouldn't involve API changes.
2017-12-09 15:04:29 -06:00
Guangcong Luo
5d11ec89f1 Fix base-pokemon banning 2017-12-08 22:27:30 -06:00
Guangcong Luo
0613939874 Refactor tournament rule validation
It was happening in two different places. It's been consolidated now.
2017-12-08 21:04:05 -06:00
Guangcong Luo
bb598ed6c2 Add rule validator for format rules 2017-12-07 22:07:12 -06:00
Quinton Lee
b13098a684 Formatter: fix linking text followed by > (#4222) 2017-12-07 16:13:35 -06:00
Guangcong Luo
f4e535bbd6 Enforce consistent key spacing
This was previously not enforced because we used `:1` in too many
places, but those places seem to all be refactored out at this point.
2017-12-01 08:16:23 -06:00
Guangcong Luo
1d41e73199 Formatter: Change rel="noopener" output
The client now interprets `rel="noopener"` to mean "check links for
interstice whitelist", and bypasses the interstice if it's not there.

This is is the best approach for [[google links]] to bypass the
interstice, while not whitelisting all of Google because Google
redirects are not generally trustworthy.
2017-11-28 09:53:21 -06:00
Bär Halberkamp
5b542c5f4c Formatter: re-implement [[pokemon: name]] and [[item: name]] 2017-11-28 16:34:48 +01:00
Guangcong Luo
fda5ab4fcc Support paren spans in chat formatter
This mainly adds support for parenthetical spoilers:

(parenthetical spoiler: these)

They'll be useful for closing any other autoclosing spans in the
future, but currently spoiler is the only one.
2017-11-28 08:34:21 -06:00
Guangcong Luo
3c5b4ca0fb Formatter: Fix parsing for [[wiki: links]] 2017-11-28 08:34:21 -06:00
Guangcong Luo
d0f66895c3 Update text formatter link syntax
Now matches old link syntax [[Text <uri>]]

Also now supports alternate search engines [[wiki: Text]]
2017-11-28 07:59:51 -06:00
Guangcong Luo
45dd012840 Refactor chat-formatter main loop
The new loop makes the loop invariant a lot easier to enforce, although
it makes certain parts less readable.
2017-11-28 07:17:36 -06:00
Guangcong Luo
65517f279c Rewrite chat formatter
This new version supports significantly more client chat formatting
than before, and is more readable.

Also new: the `code` formatting now uses basically the same system as
Markdown, where you can use as many `` ` `` in a row as you want as
your delimiter.
2017-11-27 12:16:15 -06:00
Guangcong Luo
e25eeb9eb0 Correctly validate Rockruff-Dusk 2017-11-16 21:45:24 -06:00
Guangcong Luo
e377d69395 Fix core team-validation intersection check 2017-11-05 00:11:51 -07:00
Guangcong Luo
7904e7791b Fix Gen 2 Hidden Power IV validation 2017-11-05 00:11:51 -07:00
Guangcong Luo
b01e4794a0 Rephrase team validator test 2017-11-04 12:14:21 -07:00
Guangcong Luo
011528bd5a Fix Hidden Ability validation
Previously, a mix of past-gen and modern event sources for a move would
confuse the validator. This case is now properly handled.
2017-11-02 13:36:05 -05:00
Guangcong Luo
0039db7a84 Add more tests for team validator 2017-11-02 00:15:04 -05:00
Guangcong Luo
0e728281e6 Move team-validator to sim/team-validator 2017-11-01 05:22:37 -05:00
Guangcong Luo
a47077bbe9 Split TeamValidator and TeamValidatorAsync
I'm not really sold on "TeamValidatorAsync" as a class name or file
name, so I'm open to suggestions.

The long-term plan is to put TeamValidator in sim/ but this is in three
commits because I really want the right file to retain blame history.
2017-10-31 15:49:09 -05:00
Guangcong Luo
d1bf3737a8 Improve chat formatter tests 2017-10-30 21:51:37 -05:00
Guangcong Luo
3f3eaa1ac0 Formatter: Fix subscript parsing 2017-10-30 21:48:14 -05:00
Guangcong Luo
39b52e7dda Rename Chat.parseText -> Chat.formatText
(And move it to its own file, chat-formatter.js)
2017-10-30 21:41:59 -05:00
Guangcong Luo
0ccf846eab Add tests for Chat.parseText 2017-10-30 21:31:03 -05:00
Guangcong Luo
88159c41bc Refactor BattleRoom -> GameRoom
BattleRoom is now GameRoom, a slightly more abstract room type capable
of holding any of a number of possible roomgames. Currently, battles
are the only such roomgame, but any future roomgame could possibly use
it.

Differences between ChatRoom and GameRoom:

- GameRooms start at the left, ChatRooms start at the right
- GameRooms have chat on the right, and a game area on the left, with a
  view area at the top left and a controls area at the bottom left
- GameRooms retain all their logs, ChatRooms only retain the latest 100
  lines
- GameRooms expire after 40 minutes of inactivity or 10 minutes of zero
  online users (configurable in the future)
- GameRooms are guaranteed to have an associated game, while ChatRooms
  may or may not
2017-10-18 05:41:03 -05:00
Guangcong Luo
8d12d1e0d2 Refactor matchmaker
This removes the outdated user.searching object, instead tracking all
searching state from inside the matchmaker.
2017-09-05 05:34:27 -04:00
Guangcong Luo
7a9310ac66 Fix Matchmaker hotpatching
Matchmaker is now globally accessible under Ladders, rather than
needing to be manually required.

This fixes a crash when hotpatching certain things.
2017-09-01 06:29:21 -04:00
Guangcong Luo
cb459a37bc Rename matchmaker.startBattle -> Rooms.createBattle 2017-09-01 04:46:37 -04:00
Guangcong Luo
95e8bebeaf Revert "ProcessManager: refactor, fix memory leak, use Typescript (#3706)"
This reverts commit c9b93d3529.
2017-07-02 08:11:18 -04:00
Ben Davies
c9b93d3529 ProcessManager: refactor, fix memory leak, use Typescript (#3706)
- spawning and setting up child processes is now handled by
ProcessManager#constructor rather than needing to be done manually for
each module that uses ProcessManager
- direct references to ProcessManager in ProcessWrapper were removed to
prevent dead ProcessWrapper instances from being leaked when hotpatching
- process-manager.js and verifier.js now use Typescript
2017-06-30 09:09:13 +09:00
Konrad Borowski
56a05a82b6 Rename Gen6 formats to have [Gen 6] in name (#3683)
* Rename Gen6 formats to have [Gen 6] in name

* Add Gen 6 format aliases for bots

Those will be removed later when bots will be updated to know
about new format names.
2017-06-24 01:51:06 -07:00
Ben Davies
8de4bdfecb Sockets: refactor to use maps (#3474) 2017-04-23 16:39:38 -07:00
Ben Davies
7d27efb817 Matchmaking: move battle logging back to Rooms.global (#3454)
* Matchmaking: move battle logging back to Rooms.global

For now, logging should be dealt by the global room until logging can be
abstracted away from it. This makes it simpler to refactor the logic in
Matchmaker#startBattle to be handled by Rooms.createBattle where it belongs.

* Matchmaking: use Matchmaker#cancelSearch format parametre

Optimizes cancelling searches if the format is known
2017-04-15 17:51:34 -04:00
Ben Davies
5adac2bc56 Matchmaking: fix crash on user disconnect/merge
Challenges and searches weren't being cleared properly after moving
them out of GlobalRoom#onLeave.
2017-03-20 17:01:42 -05:00
Ben Davies
fa3136f6f4 Prevent JSON writers from being able to block I/O (#3368)
These are the last place process.nextTick should be used. Also fixes
BattleRoom's unit tests.
2017-03-17 17:42:10 -05:00
Ben Davies
213b697d7c Rooms: move matchmaking logic to ladders-matchmaker.js (#3364)
This abstracts matchmaking logic from the global room away to its own
module, allowing the two to be decoupled from each other entirely with
some refactoring.

Related to #3361
2017-03-17 02:42:30 -05:00
Ben Davies
5031794f97 Sockets: fix unit tests (#3281)
* 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.
2017-02-24 05:38:37 -06:00
Ben Davies
8a9ce4a12a Sockets: temporarily skip unit tests (#3235)
Until the crashes and workers' flooding of stdout are resolved.
2017-02-14 22:00:06 -06:00