Commit Graph

231 Commits

Author SHA1 Message Date
Guangcong Luo
574bb28bbe
Implement Utils.Multiset (#8260)
If you grep the codebase for `|| 0) + 1` you get a lot of results,
all of which would be better implemented with a multiset.
2021-05-04 21:53:23 -07:00
Guangcong Luo
04243bc731 Fix crash in Utils.sortBy 2021-04-26 14:57:35 -04:00
Guangcong Luo
486f292904
Refactor everything to use Utils.sortBy (#8220)
A few uses of `array.sort()` have been left alone:

- sorting in `data/` because they aren't supposed to import anything

- `set-importer` because I still have no clue what that's for and what
  dependencies it is/isn't allowed to have

- `sort()` with no arguments used as a lexical sort (at which point
  `sortBy` offers no benefits)

All other cases have been replaced with `Utils.sortBy`, which should
be a massive increase in readability.

Sort orders should be much more readable now, without needing to puzzle
through sign issues. The order is always low-to-high, A-to-Z,
true-to-false.
2021-04-23 22:41:00 -07:00
Guangcong Luo
13189fdb02
Update Dex API (#8181)
This is the change that renames:

- `Dex.getMove` -> `Dex.moves.get`
- `Dex.getAbility` -> `Dex.abilities.get`
- `Dex.getItem` -> `Dex.items.get`
- `Dex.getSpecies` -> `Dex.species.get`
- `Dex.getEffect` -> `Dex.conditions.get`
- `Dex.getNature` -> `Dex.natures.get`
- `Dex.getType` -> `Dex.types.get`
- `Dex.getFormat` -> `Dex.formats.get`

In addition, some other APIs have been updated:

- `getByID` methods have also been added to every other table.
- `Dex.moves.all()` now gets an array of all moves
  - Plus equivalent methods for `abilities`, `items`, `species`, `formats`, `natures`, `types`
  - Note: there's no `Dex.conditions.all()`
- new API: `Dex.stats` for naming/iterating stats
- `Dex.getEffectByID` -> `Dex.conditions.getByID`
- `Dex.getType` -> `Dex.types.get`
- `Dex.data.Formats` -> `Dex.data.Rulesets`
- `Dex.formats` -> now an array `Dex.formats.all()`
- `Dex.getRuleTable` -> `Dex.formats.getRuleTable`
- `Dex.validateFormat` -> `Dex.formats.validate`

Team functions have been split off into a new `sim/teams` package:

- `Dex.packTeam` -> `Teams.pack`
- `Dex.fastUnpackTeam` -> `Teams.unpack`
- `Dex.generateTeam` -> `Teams.generate`
- `Dex.stringifyTeam` -> `Teams.export`

`Teams.export` has also been rewritten to better match how it works in client.

This implements #8178
2021-04-08 03:00:37 -07:00
Mia
07b1c01f75
Support hotpatching User/Room/ProcessManager protos (#8095) 2021-03-08 05:23:17 -08:00
Mia
736e38e4af
ProcessManager: Handle Monitor#slow in subprocesses (#7990) 2021-03-03 12:39:53 -08:00
Guangcong Luo
61ea2dd916 Implement Utils.escapeHTMLForceWrap
Combining escapeHTML and forceWrap allows us to use <wbr /> instead
of U+200B, fixing a copy/paste bug.
2021-02-15 06:09:58 -05:00
Guangcong Luo
d2ba0c7a9f Fix hotpatching 2021-02-02 13:15:09 -08:00
Mia
76c10841ea
Lib: Add an index file for all exports (#7972) 2021-01-31 18:00:19 -08:00
Guangcong Luo
a4d722ed65
PM: Support querying in a new process (#7968)
Better subprocess query system for #7937.

I mentioned in #7937 that it should be a regular `child_process`, but
Mia's not _wrong_ that PM has some useful features that make it more
convenient than `child_process`. This change allows a
`QueryProcessManager` to easily run a query in a new child process.
2021-01-30 12:11:48 -08:00
Guangcong Luo
67f6d3908e Improve ProcessManager typing
This removes the need for some more casting... although I'm starting
to worry if generics are too unreadable. I suppose anyone working on
library code is likely to prefer generics to casting, and it's safer,
anyway.
2021-01-30 11:53:34 -08:00
Guangcong Luo
f4abf52f61 Fix QueryProcessManager type signatures 2021-01-30 11:35:35 -08:00
Mia
184e867761
Hangman: Support saving hangman entries (#7630) 2021-01-28 11:24:46 -08:00
Mia
ca94dea20f
FS: Fix hotpatching and add more throttling (#7878)
- `writeUpdate` state is now stored in a global variable, so hotpatching doesn't crash it
- throttling now writes on the tail (so two throttled `writeUpdate` calls will write one update, not two)
- room settings, punishments, and helptickets are now throttled
2021-01-09 15:49:30 -08:00
Guangcong Luo
b5c25a84e2 Fix typo 2021-01-06 11:18:56 -08:00
Guangcong Luo
c44af3286d Implement Utils.forceWrap
I wrote a `forceWrap` method to support break-word wrapping in table
cells for scavengers, but apparently code blocks need it too, so I'm
moving it to Utils.

Fixes #7854
2020-12-30 17:41:41 -08:00
Mia
1b1d91df02
Utils: Visualize Maps/Sets in a cleaner fashion (#7830)
* Utils: Visualize Maps/Sets in a cleaner fashion

* OK

* Update lib/utils.ts

Co-authored-by: Guangcong Luo <guangcongluo@gmail.com>

* Update lib/utils.ts

Co-authored-by: Guangcong Luo <guangcongluo@gmail.com>

* Update lib/utils.ts

Co-authored-by: Guangcong Luo <guangcongluo@gmail.com>

Co-authored-by: Guangcong Luo <guangcongluo@gmail.com>
2020-12-27 12:51:11 -08:00
Guangcong Luo
6e281dbe31 Move build-utils from lib to tools
The current idea is for `lib` to contain shared libraries useful to
many projects. `build-utils` is specific to this repo and so doesn't go
there.
2020-12-26 10:08:30 -08:00
Guangcong Luo
3cbf3f8a30 Fix build
Building from a fresh install currently fails since #7797

The problem is that `require('sucrase')` needs to be done _after_
sucrase is installed, which is a lot harder than it sounds.
2020-12-26 10:04:41 -08:00
Mia
f792cfe28e
Move FSPath#waitUntil to Utils (#7805) 2020-12-14 14:15:52 -08:00
Adam Tran
c7c5f4253b
Support generating sourceMaps for source debugging (#7797) 2020-12-13 19:42:19 -08:00
Mia
fca97b418c Fix build errors 2020-11-30 13:17:52 -06:00
Annika
34cab27a74
Properly type Promises (#7712) 2020-11-19 23:19:42 -08:00
Mia
89d127eafd
ProcessManager: Add a static execFile (#7566) 2020-11-02 11:35:07 -08:00
Guangcong Luo
c8dfed19db Better handle races when reading Streams 2020-11-01 22:08:59 +00:00
Guangcong Luo
8b68cdd736 Fix Streams bug
It turns out 001f98b4f2 was wrong.

When urkerab asked why it `peek` wasn't awaited:

e91c4c5260 (commitcomment-41364837)

The answer was because clearing the buffer after peeking needed to
happen synchronous: if the buffer is written to after peeking but
before the buffer is cleared, that write is lost forever.

This just goes to show, if you do something subtle enough to require
type assertions, you should probably add a comment about what's going
on.

Fixes #7605

This also removes `BattleStream#start()` which is completely useless
API complication. A better implementation would properly forward
crashes between streams (maybe `pipeTo` should do this) but as it
stands, it's not doing anything.
2020-11-01 02:06:24 +00:00
Guangcong Luo
a38f0597f8 Remove last vestiges of tslint 2020-10-27 22:49:00 +00:00
Guangcong Luo
9d87616176
Add more style linting rules (#7537)
* Lint arrow-body-style

* Lint prefer-object-spread

Object spread is faster _and_ more readable.

This also fixes a few unnecessary object clones.

* Enable no-parameter-properties

This isn't currently used, but this makes clear that it shouldn't be.

* Refactor more Promises to async/await

* Remove unnecessary code from getDataMoveHTML etc

* Lint prefer-string-starts-ends-with

* Stop using no-undef

According to the typescript-eslint FAQ, this is redundant with
TypeScript, and they're not wrong. This will save us from needing to
specify globals in two different places which will be nice.
2020-10-19 02:42:28 -07:00
Annika
9aa837b9df
ProcessManager: Support timing out queries (#7502) 2020-10-16 02:56:02 -07:00
Guangcong Luo
1c0c77ff6b
Update to TypeScript 4.0 (#7504) 2020-10-10 14:43:32 -07:00
Guangcong Luo
3d68248efa Update to latest eslint
We're skipping two major typescript-eslint versions, so there are a
bunch of changes here, including:

- it's catching a lot of things it didn't catch in the past, for
  reasons unclear to me

- no-unused-vars has to be explicitly disabled in global-types now

- a lot of `ts-ignore`s were never necessary and have been fixed

- Crashlogger can now handle being thrown things that aren't errors.
  This has never been a problem in the past, but to satisfy TypeScript
	we might as well not die in a fire on the off chance someone tries to
	`throw null` or something.
2020-09-29 15:28:08 -07:00
Guangcong Luo
d3ecb74121 Fix bug in ReadStream buffer expansion
This prevented the buffer from properly expanding as needed for long
reads.

This also fixes a bug when the buffer wasn't being used optimally.
2020-09-27 16:44:40 -07:00
Guangcong Luo
9fe45238f5
Introduce chunk readers for ReadStream (#7215)
This adds new functions `stream.byChunk(bytes)`, `stream.byLine()` etc
which parse a `ReadStream` into an `ObjectReadStream<string>` which
can then be consumed with for-await.

Fixes #7195
2020-09-27 08:55:59 -07:00
Guangcong Luo
8d79bf9725 Rename Dex.deepClone to Utils.deepClone
`this.dex.deepClone` still exists as an alias to `Utils.deepClone` for
use in `data/`. I'll need to spend more time figuring out the correct
solution there.
2020-08-21 04:24:34 -07:00
Guangcong Luo
18948c8c2c Refactor ObjectReadStreams to use for-await
Regular ReadStreams still can't; I now believe they shouldn't have a
"default" read method, and you should explicitly choose whether you
want to read "by chunks as they become available", "by chunks of a
specific line" or "by a delimiter".

So you would specifically use `stream.byLine()` or
`stream.byChunk([size])`, which would return an
`ObjectReadStream<string>`.

Inspired by #7195
2020-08-15 15:11:53 -07:00
Guangcong Luo
001f98b4f2 Fix some Streams weirdness
Pointed out by @urkerab in e91c4c5260

I'm confused it ever worked in the past.

I also added `Symbol.asyncIterator` to make `for await` work correctly.
I'm still very annoyed by `Symbol`. Especially since the spec saw no
reason not to name the other function `next`, but calling it
`asyncIterator` instead of `[Symbol.asyncIterator] was too much of a
risk??? Complete bullshit that does nothing but break backwards
compatibility.
2020-08-15 14:32:21 -07:00
Ben Davies
86c1aca097 Streams: fix ObjectReadStream _destroy method setting 2020-08-11 00:08:27 -03:00
Ben Davies
e91c4c5260 Streams: return buffers from ReadStream#readBuffer, not strings 2020-08-11 00:04:51 -03:00
Ben Davies
5cee3b401f Streams: fix _destroy method setting in ReadStream 2020-08-10 23:06:58 -03:00
Annika
b3771214d5
Fix modlog tests on Windows (#7187) 2020-08-10 09:37:08 -07:00
Mia
deeed6c789
Remove sim/ and data/'s globals (#7091) 2020-08-07 06:44:15 -07:00
Annika
f34ffa9e74
Refactor Modlog into one file (#7127) 2020-08-06 00:39:37 -07:00
Guangcong Luo
8eeec74ce0 Use TypeScript tuples for low splitFirst limits 2020-07-02 15:06:53 -04:00
Guangcong Luo
160efc9898 Fix crash after failed Net request 2020-07-02 11:25:34 -07:00
Guangcong Luo
f6d5e7f5c2 Stop showing REPL error in Windows 2020-07-01 16:37:36 -07:00
Guangcong Luo
db975b2b39
Don't automatically restart REPL server on crash
This leads to a spinlock that causes #6873
2020-06-25 02:28:23 -07:00
Guangcong Luo
9f0d6d03d3 Attempt to fix REPL crash in WSL2
For some reason, my last try failed. The error just wasn't getting
caught. This is an attempt to make it not listen to the `'close'` event
if the `listen` function throws, which might work? I'll reboot to test
in Windows when I have time.

Refs #6873
2020-06-19 22:53:31 -07:00
Guangcong Luo
dffd9dbff8 Fix stream destroying
`SubprocessStream` wasn't getting properly destroyed.
2020-06-18 21:47:03 -07:00
Guangcong Luo
39206a6959 Don't crash if FS doesn't support Unix sockets
Fixes #6873
2020-06-18 18:30:43 -07:00
Guangcong Luo
e0f97dcf6b Replace Chat.uncache* with Utils.clearRequireCache
This replaces the old approach with a new "clear everything except a
whitelist" approach, which should overall involve much less code and
lead to fewer bugs of the "the path changed for a module and I forgot
to update the uncache paths" variety.

I considered a lot of other approaches, but they seem to have more
flaws without any advantages in exchange for them. (We moved away
from `uncacheTree` because it only tracks the first require: there's
no way to get a full list of dependents for a module, only its first
dependent.)
2020-06-12 22:02:32 -07:00
Guangcong Luo
6b0b7c3228 Fix "push after end" crash 2020-06-11 17:07:36 -07:00
Guangcong Luo
713f914d75 Fix Net error behavior
A lot of Net functions returned Promises that would not reliably
resolve/reject if a Net request failed. This fixes it so they should
now all reliably reject on request failure.

(Yes, this fixes the ladder issues and memory leak in Main.)
2020-06-10 16:08:48 -07:00
Guangcong Luo
1e5b5ab465 Update Streams API with pushEnd/writeEnd
Previously, ending a read stream was `stream.push(null)`, and ending a
write stream was `stream.end()`. This was often confusing, and so now,
these are consistently `stream.pushEnd()` and `stream.writeEnd()`.

This refactor already found a bug in which `stream.end()` was used
where `stream.push(null)` should have been.

Also in this refactor: By default, `pushError` ends the stream. You can
pass `true` as the second parameter if the error is recoverable (the
stream shouldn't end).
2020-06-10 16:07:24 -07:00
Mia
6839a1f4db
Add a library for utility functions (#6817) 2020-06-09 22:06:43 -07:00
Guangcong Luo
b53480b364 Fix memory leak in ladders-remote 2020-06-09 18:31:29 -07:00
Guangcong Luo
b99c8db5d2 Fix Net library 2020-06-05 10:38:27 -07:00
Mia
cf42c6269a
Add a library for making HTTP/S requests (#6744) 2020-06-04 11:53:58 -07:00
Guangcong Luo
58b958c6fe Improve TS 3.9 property checks
These were previously fixed in 6e2b475dac, but I prefer an approach
that makes sure e.g. `pipeTo = undefined` doesn't break this check.
2020-06-04 10:23:04 -07:00
Kirk Scheibelhut
6e2b475dac Change property checks to TypeScript 3.9 2020-05-12 20:11:56 -07:00
Guangcong Luo
1dada44a2a Support server/chat-plugins/private as symlink 2020-04-25 15:51:11 -04:00
Mia
1a62036aaf
Typescript Thing of the Day (#6603) 2020-04-23 10:12:56 -07:00
Guangcong Luo
611b186265 Fix port config not being passed to child process
Fixes #6597
2020-04-21 07:26:29 -07:00
Guangcong Luo
776ccf9796
Refactor Sockets to ProcessManager+TypeScript (#6584) 2020-04-17 04:05:45 -07:00
Guangcong Luo
a74fe6e0cc Improve debugging support 2020-03-13 23:57:41 -04:00
Guangcong Luo
125fe31d06 Improve eslintrc
Fixed some more code style, allowing these rules to be enabled:

- `comma-dangle`
- `function-paren-newline`
- `member-delimiter-style`
- `no-eval`
- `no-fallthrough`
- `no-misused-promises`
- `no-unused-vars`
- `operator-linebreak`
2020-03-06 22:35:55 -08:00
Guangcong Luo
2f0e83c14b Categorize eslintrc rules
eslintrc rules are now sorted into categories, in theory making them
easier to maintain.
2020-03-06 22:35:45 -08:00
Waleed Hassan
8aa4f053bb
Use optional chaining and linter improvements (#6422)
This is mostly just a follow up to #6342.

`prefer-optional-chaining` was turned on and fixed in every location it
complained in. The transformed function [0] looks expensive from a
glance but from skimming through the replaced sites it doesn't appear
to be ran in any important place, so it should be OK.

The linter improvements are:
- Increase linter performance
	- Make `full-lint` and `lint` write to different caches so we
	  avoid overwriting their caches since they're different configs
	- Change husky's hook to `npm run lint` so as to write to the
	  same cache
	- Remove `@typescript-eslint/eslint-plugin-tslint` which is
	  essentially a wrapper to TSLint because the rules aren't worth
	  running another linter
- Convert `.eslintrc.json` and `.eslintrc-syntax.json` to two spaces
  rather than four tabs to respect PS' `.editorconfig`
- Rename `fulllint` to `full-lint` to ease spelling it

[0] - https://pastie.io/mmtxpf.js (prettified)
2020-03-06 11:44:32 -08:00
Guangcong Luo
b21c9047e2
Migrate to typescript-eslint (#6342) 2020-03-05 08:33:06 -08:00
Guangcong Luo
b1ea19d5b5 Further improve handling of crashed subprocesses 2020-02-23 01:33:35 -08:00
Guangcong Luo
e36aa987e4 Make ProcessManager more crash-resistant
ProcessManager is now able to automatically respawn subprocesses that
have crashed.
2020-02-21 22:31:16 -08:00
Waleed Hassan
34e215c7a6
Support renaming rooms (#6295) 2020-02-21 00:47:07 -08:00
Spandan Punwatkar
b6b66de896 Update Repo Links (#6102) 2019-11-28 12:47:38 +04:00
Guangcong Luo
10062ece4f Fix Koffing/Weezing Gen 7 Abilities
PS apparently doesn't have gen-accurate Ability data for Pokémon in
Gen 3 that gained Abilities between Gen 3 and Gen 4 (like Pidgeot
still has Tangled Feet in Gen 3), but that will have to be left for
a future commit.
2019-11-16 14:39:14 +13:00
Guangcong Luo
23f9bfa1b7
Split up server/chat-commands/ (#5943)
`server/chat-commands.js` is now a directory. It's been split into
`core`, `moderation`, and `admin`. `info` and `roomsettings` from
`chat-plugins` have also moved to `chat-commands`.

Some cleanup:

- Bot commands for inserting HTML into rooms like `/adduhtml` have been
  moved from `info` into `admin`.

- `/a` has been renamed `/addline`, for clarity (and also moved from
  `info` into `admin`).

- Room management commands like `/createroom` and `/roomintro` were
  moved to `room-settings`

- `chat-commands/admin` has been TypeScripted
2019-11-15 11:12:54 +13:00
asgdf
edebcbc4a9 Support loading plugins from chat-plugins/private/ (#5867) 2019-10-14 11:11:37 +11:00
Waleed Hassan
5607c158e4 Use void in promises to appease TSLint (#5827) 2019-10-03 19:08:30 +10:00
Kirk Scheibelhut
9ab3f5a668
Make /hotpatch fail if git history hasn't changed (#5688)
/forcehotpatch can be used to perform the hotpatch regardless.
2019-08-12 10:23:24 +02:00
Guangcong Luo
af8ed06abf
Fix bug in ProcessManager#destroy
Fixes #5654
2019-07-24 17:41:08 -05:00
Guangcong Luo
f374a13370 Support \u0000 in Dashycode 2019-07-12 23:38:31 -05:00
Guangcong Luo
5f6af9049f
Clarify Dashycode documentation 2019-07-12 02:04:07 -05:00
Guangcong Luo
4653cd6b15 Add documentation for Dashycode 2019-07-11 06:17:14 -05:00
Guangcong Luo
257cb76a90 Fix Dashycode non-ASCII encoding
Dashycode had a bug that made it incorrectly encode non-ASCII
characters. I think this was fixed at some point but never made it
to PS's copy of Dashycode? Anyway, fixed now.
2019-07-11 05:13:25 -05:00
Guangcong Luo
7436c1f0f2 Remove import = and export =
`import =` and `export =` are really only intended for backwards
compatibility with CommonJS. While I really don't like the new module
system TC39 has designed for us, it's what we should be using, and
consistency is important.
2019-05-16 01:27:07 +04:00
Guangcong Luo
e1c364fb79 Refactor DNSBL -> IPTools
This is mostly a TypeScript refactor, but it does come with several
renames:

Dnsbl -> IPTools
Dnsbl.query -> IPTools.queryDnsbl
Dnsbl.reverse -> IPTools.getHost
2019-05-14 10:57:08 +10:00
Kirk Scheibelhut
dfd8fc504a Wrap long line in lib/streams.ts 2019-04-10 14:19:12 -07:00
Kirk Scheibelhut
334ca88b50 Update dependencies (#5430) 2019-04-10 18:46:37 +08:00
Kirk Scheibelhut
15fe4d2ff1 Stop closing STDOUT/STDERR in lib/streams.ts (#5419)
Fixes #5403 for Node versions prior to v10.12.0.
2019-04-07 15:34:06 +08:00
Guangcong Luo
6d563f555a Fix stream ending 2019-03-24 02:31:39 +09:00
Guangcong Luo
78c0433436 Fix ./pokemon-showdown simulate-battle
Fixes #5338
2019-03-23 17:39:11 +09:00
Kirk Scheibelhut
2b1c278c42 Fix 'floating' promises and enable lint errors going forward (#5297) 2019-03-22 02:21:17 +09:00
Guangcong Luo
efa0af0ef1 Propagate errors through streams 2019-03-17 07:48:02 +09:00
Guangcong Luo
9073a5a8bf Improve Streams typing
When I originally wrote the Streams library, TypeScript-in-JS didn't
support generics. But now the library can have significantly nicer
typing, and so it now does.
2019-03-16 17:12:21 +09:00
Kirk Scheibelhut
0e1708bf9f Enable prefer-const and max 120 character lines for .ts files (#5292) 2019-03-16 07:14:04 +09:00
JetOU
85533ee3a0 Change forEach to for...of (#5269) 2019-03-08 11:24:58 -06:00
Kirk Scheibelhut
6e122d5d74 Refactor lib/ to be native Typescript (#5217) 2019-03-02 11:12:24 -06:00
Guangcong Luo
b7c252fbd6 Automatically end BattleStreams at end of battle
PS prefers to keep battle streams open (for `/evalbattle`) until
manually ended, but this is confusing some other users. We now
automatically end streams unless the `keepAlive` option is set.

Fixes #5157
2019-02-09 21:16:45 -06:00
Guangcong Luo
75dd2f408e Fix minor typos 2019-02-09 00:03:51 -06:00
Guangcong Luo
6f185f0b2e Fix listener overflow in FS write streams
This happens if you write to an FS write stream more than like 15
times at once.
2019-01-26 00:33:32 -06:00
Guangcong Luo
6a32e53890 Forward team validator crashes to main process 2019-01-11 00:41:49 -06:00
Guangcong Luo
6424bd5e72 Forward battle process crashes to main process
This makes it so battle process crashes now appear in the Dev room,
instead of failing more silently.

This should also help them be easier to debug.
2019-01-07 20:15:17 -06:00
Guangcong Luo
6245b2f8fe Fix FS.writeUpdate
The old FS.writeUpdate throttle code was broken and unnecessarily
complicated. Since cancelable Promises don't exist and I was thinking
in Promises, I forgot about the existence of `clearTimeout`.

Rewriting with `clearTimeout` produces significantly more readable
code, which should no longer be bugged, and should in fact handle
complicated mixes of throttle times exactly the way I want them to
be handled.

(I rewrote this so many times in unpushed code, and each time turned
out unnecessarily complicated because I didn't remember `clearTimeout`
until now.)
2018-12-31 02:41:14 -06:00
Guangcong Luo
43dc92f652 Make ProcessManager slightly safer 2018-10-22 15:45:23 -05:00
Guangcong Luo
c934c04bbc Fix bug in previous commit 2018-10-20 17:55:54 -05:00
Guangcong Luo
4e9ad4e373 Handle process crashes slightly more gracefully 2018-10-20 17:45:17 -05:00
Guangcong Luo
c872a8f766
Improve FS throttle (#4867)
PS's FS(...).writeUpdate(...) has a `throttle` option.

This changes it so it's possible to call it with the throttle on
sometimes and off sometimes, and "throttle off" will pre-empt "throttle
on" calls.
2018-10-08 01:49:11 -05:00
Quinton Lee
94016f6218 Update Typescript to 3.1 (#4879) 2018-10-05 04:02:54 -05:00
MacChaeger
82c792f82c Update to TypeScript 3.0.1 (#4710) 2018-08-07 03:27:28 +09:00
Guangcong Luo
467b545496 Add example code for using the Sim API 2018-04-15 06:10:08 -05:00
Guangcong Luo
724c5ce7bc Fix more bugs in FileReadStream 2018-02-13 12:49:56 -05:00
Guangcong Luo
879d0a0e12 Fix FileReadStream
It hasn't been kept up to date for various stream API changes. This fix
makes it work properly again.
2018-02-14 02:29:20 +09:00
Guangcong Luo
da55a7b443 Fix crash on large modlogs 2018-02-13 23:02:18 +09:00
Guangcong Luo
1531b662c6 Refactor battle stream system
This contains a lot of minor refactors, but the main thing that's going
on here is that battle stream writes have been streamlined to be a lot
easier for others to use.

We even support:

    ./pokemon-showdown simulate-battle

which provides a stdio interface for anyone using any programming
language to simulate a battle.
2018-01-28 21:06:49 -06:00
Guangcong Luo
e6cc393109 Fix unused variable in ProcessManager 2018-01-23 07:45:03 -06:00
Guangcong Luo
0c2d712540 Fix Process Manager releasing
This now makes processWrapper.release() a lot more consistent about
actually releasing a process.
2018-01-21 11:37:30 -06:00
Guangcong Luo
2ea6f39876 Fix Process Manager default respawn
Now calling respawn() without any arguments will respawn the same
number of processes currently running.
2018-01-21 11:37:30 -06:00
Guangcong Luo
1c119bf3fa Fix streams.js doc comment
(Also improve STREAMS documentation a bit)
2018-01-20 12:16:47 -06:00
Guangcong Luo
6c10e3ade4 Fix stream destroying
This should correctly fix the memory leak in subprocess streams.
2018-01-18 20:25:28 -06:00
Guangcong Luo
327b004b74 Better support for destroying streams 2018-01-18 04:14:58 -06:00
Guangcong Luo
43103f98ae Disable ProcessManager in tests 2018-01-18 04:10:19 -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
8f3bed7e59 Make fsPath.read() return a string by default
This is an update to match how Streams work: .read() returns a string,
and .readBuffer() returns a Buffer.

Being able to statically predict what type .read() will return is
really useful to TypeScript, in addition to being generally useful for
readability.

As a side benefit, readTextIfExists() is renamed readIfExists().
2018-01-18 03:31:13 -06:00
Guangcong Luo
df4aeebcd5 Use new Streams for FS streams 2018-01-13 03:59:09 -06:00
Guangcong Luo
4969fb0790 Add Streams library
I've finally been sufficiently frustrated by Node's Streams API to
straight-up write my own.

This is what a Streams API looks like when you don't try to pretend
Promises don't exist. So much easier to use.
2018-01-12 22:19:05 -06:00
Guangcong Luo
91d112dd98 Fix misc TypeScript bugs
The dev version of TypeScript found a variety of bugs not previously
caught for some reason; these are fixed now.
2017-12-26 14:36:13 -06:00
Guangcong Luo
0310f99f02 Refactor repl.js 2017-12-23 23:04:03 -06:00
Guangcong Luo
193e948592 Move crashlogger.js -> lib/crashlogger.js 2017-12-16 15:40:45 -06:00
Guangcong Luo
738c60ed8b Move repl.js -> lib/repl.js 2017-12-16 15:40:45 -06:00
Guangcong Luo
a9540917f5 Move fs.js -> lib/fs.js 2017-12-16 15:40:45 -06:00
Guangcong Luo
d07113dd35 New library: Dashycode
Dashycode is a library for encoding string data in restricted strings
in the [a-z0-9-] character set (namely, roomids).

...its main use is passing arbitrary string data in roomids, for HTML
rooms.
2017-12-12 03:22:09 -06:00
asgdf
c25d23a7f0 Refactor modlog (#3569) 2017-06-10 12:32:55 -05:00
Freigeist
48bfa02eb0 Some cleanup in /modlog 2014-12-09 00:32:11 +01:00