Commit Graph

126 Commits

Author SHA1 Message Date
Mia
44fc0123ad
Chat: Refactor CommandContext and PageContext to use ErrorMessage more (#7234) 2020-09-06 00:15:16 -07:00
Guangcong Luo
a315c93836 Switch to using import type
We were previously using `type Foo = import('bar').Foo` which works
actually equally well, because sucrase didn't support `import type`,
but now it does!
2020-08-09 08:07:00 -05:00
Annika
05a9f9a1e5
Minor code quality improvements based on LGTM (#7092) 2020-07-30 14:24:37 -07:00
Lusamine
3a2ca90040
Minor cleanup of global demotion messages (#7011) 2020-07-17 01:17:36 -07:00
Kirk Scheibelhut
2691b91062
Fix tour challenges (#6972) 2020-07-06 22:58:12 -07:00
Kirk Scheibelhut
eea2196280
Server side changes to support persistent user settings and privacy changes (#6947)
NOTE: This is changes the semantics of `hidenext`/`ionext` from
applying to the next created *battle* to applying to the next
created *search*/*challenge*.
2020-07-06 21:18:38 -07:00
Kris Johnson
4043f6e118
Fix bugs from recent restrictions update (#6967) 2020-07-06 15:54:14 -07:00
Mia
4997a47314
Commands: Allow the room parameter to be null (#6948)
Co-authored-by: Guangcong Luo <guangcongluo@gmail.com>
2020-07-05 14:25:09 -07:00
urkerab
ea30e9d48d
Don't sort player array in-place when scoring round robin tournaments (#6945) 2020-07-02 15:46:55 -07:00
Guangcong Luo
46c9afa2f3
"Remove" the global room (#6885)
I couldn't completely remove the global room in one commit, but this
solves basically every problem with it by making it no longer a `Room`.

In particular, this means:

- It's no longer of type `Room`
- It's no longer in the `Rooms.rooms` table
- Its class name is now `GlobalRoomState` rather than `GlobalRoom`
- It no longer tracks its own user list (online user count is now
  provided by `Users.onlineCount`)
- It's no longer a socket channel (there's new syntax for "send this
  message to every user")
2020-07-02 11:31:34 -07:00
Austin Couturier
25c185c010
Fix /tour forcepublic to prevent /hiddenroom (#6932) 2020-06-30 12:09:30 -07:00
Austin Couturier
f08bc21f26
Add an option to force public replays for room tournaments (#6927) 2020-06-29 19:21:21 -07:00
Mia
6839a1f4db
Add a library for utility functions (#6817) 2020-06-09 22:06:43 -07:00
Mia
15fed24b40
Refactor auth and room.settings (#6777)
This implements two big changes:

- All settings shared between `room.chatRoomData` and `room` have been
  merged into `room.settings` (so, for instance, `room.slowchat` is now
  only `room.settings.slowchat`).

  This makes it so we never have to worry about them getting "out of
  sync".

  - Checking to see if a room is persistent is now `if (room.persist)`
    instead of `if (room.chatRoomData)`

  - `Rooms.global.writeChatRoomData()` is now rarely called directly;
    there's a new `room.saveSettings()` which will handle it for you.

  - All properties of `room.settings` are now optional (except
    `title`).

- There's a new file `user-groups.ts` which handles authority.

  - `room.auth` and `Users.globalAuth` are now
    `Auth extends Map<ID, GroupSymbol>` objects.

  - `room.auth` is now always defined, removing the need for
    `room.auth?.[userid]` workarounds.

  - A lot of code relating to usergroups and permission checks have
    been refactored.

Co-authored-by: Guangcong Luo <guangcongluo@gmail.com>
2020-06-09 08:22:25 -07:00
Annika
1386a9c930
Tournaments: Escape usernames in /tour getusers (#6764) 2020-05-29 18:57:24 -07:00
Guangcong Luo
5cd743c88a Fix eslint no-unused-expressions issue 2020-03-25 20:34:03 -07:00
whales
003c696f2f Allow tour banning/unbanning without a running tour 2020-03-21 15:48:10 +10:30
Leonard Craft III
5a581a762d
Fix autostart timer bug with less than 2 players (#6451) 2020-03-12 21:46:47 -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
Kris Johnson
cc9b6f6c22
Tournaments: Remove space from DQ modlog (#6427) 2020-03-06 21:34:27 -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
242e9a3ac0 Implement /tour formats
This adds nicer output for the tour formats error message, and also
creates a broadcastable command for it.

Fixes #6419
2020-03-06 10:41:33 -08:00
Guangcong Luo
b21c9047e2
Migrate to typescript-eslint (#6342) 2020-03-05 08:33:06 -08:00
fart
5a6ea0edc5
Fix /tour autodq off (#6401)
The most recent change to this file prevents "/tour autodq off" from working and sends a "That isn't a valid timeout value." error to the client. This is because it checks for a condition where timeout is greater than 1 hour, but when turning autodq off, the timeout variable is set to Infinity. This proposed change adds a check in the condition for if the timeout value is Infinity and does not send the error if that is the case (but if timeout is a numeric value greater than 1 hour, it still will fail).
2020-02-28 05:38:30 -08:00
HoeenHero
704772794e Cap tournament disqualification timer at 1 hour 2020-02-16 17:44:16 -05:00
Kris Johnson
9aaab2c57b
Typescript Help Tickets and Modlog and fix warnings (#6352) 2020-02-12 21:48:03 -08:00
Kris Johnson
d1c0fb26a6
Tournaments: Send name and format to room separately (#6335) 2020-02-05 07:47:06 -08:00
Waleed Hassan
f7e024e009
Allow safer and exact type retrieval of Room#game (#6315)
By adding a `getGame` function of type:

```
// null is returned if the gameids don't match
// or the game doesn't exist
getGame<T extends RoomGame>(constructor: new (...args: any[]) => T) => T | null
```
(Credits @urkerab and @whalemer for the function signature.)

It allows refactoring previous code of:

```
if (room.game && room.game.gameid !== 'hangman') return;
const game = room.game as Hangman;
```

to:

```
const game = room.getGame(Hangman);
if (!game) return;
```

This has a couple of advantages:
- TypeScript will throw an error if the if condition is not present.

- In the new code, the template must extends `RoomGame` and be assignable to the same ID, so it's 100% typesafe
2020-02-03 05:09:37 -08:00
Waleed Hassan
df14f875ec Add a RoomBattle#challengeType property (#5940)
This commit adds a `challengeType` property to `RoomBattle` of
type `rated | unrated | challenge | tour`.

Previously, there was no way to programatically differ an unrated
battle from a challenge, which is useful in places like filters.
2019-12-12 19:09:43 +09:00
whales
0b9d8dd109 Support declarative roomsettings syntax (#6119) 2019-12-06 23:16:55 +09:00
whales
f7d5cefc7d Refactor tournament plugin loading (#6118) 2019-11-30 17:53:01 +13:00
urkerab
09b66da216 Use Chat.html`` a bit more 2019-11-27 15:14:46 +01:00
Waleed Hassan
a518cf102a Take steps to statically type Config (#5920)
This commit changes the TypeScript global variable of `Config` from
`AnyObject` to `Config & AnyObject`.

It still falls back to `AnyObject` (hence the 'Take steps') because of
the main-specific `Config` properties that are used without being in the
`Config` object itself.

These can be added by someone with access to the PS main server.

Regardlesss, this is an improvement as IntelliSense can display and
autocomplete the known properies.

In addition, the TypeScript compiler will now report bugs
concerning the types of the properties, which I have fixed in this
commit.
2019-10-30 18:45:20 +10:30
TheMezStrikes
9a4b23ca7e Don't escape HTML for tour names (#5911)
The client already does this, and doing it twice causes `[Gen 7 Let&apos;s Go] OU Single Elimination Tournament!` this, which doesn't seem necessary
2019-10-26 15:25:10 +10:30
Aurolux
4fcc8535c3 Modnote Tours Player Count Upon Start (#5863)
* Modnote Tours Format and Player Count Start

* Fix Trailing Whitespace on line 610

* String Interpolation Injects Integers Too

No need for a method to change the Integer's type to String

* Add a Private Modaction

* Simplify modnote to just player count

* Update server/tournaments/index.ts

Co-Authored-By: Guangcong Luo <guangcongluo@gmail.com>

* Change CommandContext Element to output

Co-Authored-By: Guangcong Luo <guangcongluo@gmail.com>

* Shorten Modlog Entry
2019-10-25 11:49:26 +02:00
Waleed Hassan
28e870c4fb Server: Use readonly where appropriate (#5902) 2019-10-21 16:12:32 +10:30
asgdf
b2d623de64 Fix typo in modlog entry of /tour forcetimer (#5884) 2019-10-15 08:44:12 +10:30
Waleed Hassan
5607c158e4 Use void in promises to appease TSLint (#5827) 2019-10-03 19:08:30 +10:00
Waleed Hassan
da4b887054 Rename Room#id -> Room#roomid, User#userid -> User#id (#5826)
These should make it clearer that userids are IDs but roomids aren't.
2019-10-03 18:57:38 +10:00
TheJetOU
f2783c642d Add a RoomID type (#5759) 2019-09-07 14:15:27 -05:00
whales
b15dd2a528 Typescript punishments (#5728) 2019-08-29 19:46:42 -05:00
whales
ba328099d2 Remove Tournaments.tournaments map (#5734) 2019-08-27 07:34:19 -07:00
HoeenHero
bb7dde3b93 Make tournaments not break when hotpatched
It might be wise to refactor this to not use a standalone
tournaments object later.
2019-08-26 15:12:30 -04:00
TheJetOU
2b28c9fd6b Refactor Rooms(), Users() to Rooms.get(), Users.get() (#5725) 2019-08-25 06:33:56 -07:00
whales
3e7b30dbda Fix lint errors in tournaments (#5730) 2019-08-25 04:17:47 -07:00
TheJetOU
7fe2e5338c TypeScript Tournaments (#5723) 2019-08-24 03:48:13 -07:00
TheJetOU
5597916644 TypeScript Rooms and Roomlogs (#5699) 2019-08-14 20:44:57 +02:00
Quinton Lee
24e01843d2 Tournaments: Always enforce scouting setting (#5671)
Previously players were able to join battles as soon as they ended
2019-08-08 21:05:39 -07:00
whales
45c0777ed6 Fix tour replacing for real (#5613) 2019-07-15 20:54:42 -05:00
whales
97cba5a732 Fix alt checking for tour subs (#5612) 2019-07-15 20:48:05 -05:00
Kirk Scheibelhut
8b82693168 Add /help documentation for /tour sub 2019-07-15 11:46:34 -07:00
whales
82a666cc0e Fix tour format reporting (#5609) 2019-07-15 11:22:13 -05:00
Guangcong Luo
22ca01123d Refactor tournaments for better prop names
- `tour.originalFormat` -> `tour.baseFormat`
- `tour.teambuilderFormat` -> `tour.fullFormat`

These should better reflect what they actually mean.
2019-07-15 00:35:31 -05:00
whales
9147863403 Tournaments: Support replacing players (#5600) 2019-07-15 00:07:37 -05:00
whales
e918287cd6 Allow starting tournaments with a custom name (#5604) 2019-07-15 00:04:49 -05:00
TheJetOU
3c8b4f6872 Tournaments: Fix crash in /tournament cap (#5605)
`note` in this.modlog expects a string.
2019-07-14 17:46:39 -04:00
Kirk Scheibelhut
e85ebf2bcc Include player count in |tournament|start and /tour getusers (#5581) 2019-07-03 15:56:07 -07:00
Guangcong Luo
c5eeea2818 Fully fix double-elimination tournaments
(Also improve documentation of ElimNode)

PR #5509 was the correct direction, but it missed a spot.
2019-07-01 15:10:59 -07:00
Kirk Scheibelhut
df083d7528 Remove Object.assign(function) pattern from TeamValidator{Async} 2019-07-01 08:20:51 -07:00
whales
a87143f613 Fix crash in multi elim tours (#5516)
With the old api, node.getChildAt would return null if the node had no children
2019-06-02 00:17:57 -05:00
whales
448a25212e Fix multi-elimination tours (#5509) 2019-05-22 00:53:57 +01:00
HoeenHero
5202d7cc5b Tournaments: Only increase player count by 1 2019-05-16 11:12:42 -04:00
Quinton Lee
33663ac040
Tournaments: Fix disqualifying and signups list sorting 2019-05-15 19:30:44 -05:00
HoeenHero
3c1294bcca Properly handle users leaving tournaments 2019-05-15 11:13:31 -04:00
Kirk Scheibelhut
3d24166cdf toId -> toID
Closes #5479
2019-05-12 17:53:01 -07:00
Guangcong Luo
2093539e06
Update RoomGame API (#5492)
- The big change here is that player.userid can now be empty. You can
  now fit state into RoomGamePlayer subclasses even when there are no
  users associated with them.

- `game.players` has been introduced as the new canonical list of
  players, including userless players. The old `game.players` has been
  renamed `game.playerTable`, for clarity.

- `game.addPlayer` now returns the added player

All existing RoomGames have been updated for the new API, and
RoomBattle is now officially a RoomGame subclass.

Tournaments was also massively refactored to be properly updated for
the old API, since that never happened, and should now be a lot more
readable.
2019-05-12 12:56:32 +09:30
Kirk Scheibelhut
10c744f733 Introduce an ID type to sim (#5468) 2019-05-04 13:13:12 +12:00
Guangcong Luo
17ebb805a4 Fix typechecking in punishments.js
It turns out the line `let Punishments = module.exports;` makes it into
`any`, and disables nearly all typechecking of anything to do with
`Punishments`. This refactor fixes that, and also fixes a bunch of flaws
newly caught by TypeScript.

I tried my best not to make any changes to actual functionality. These
changes should be effectively purely code cleanup.
2019-04-22 08:39:05 +09:30
whales
770d3e6b50 Typescript tours (#5323) 2019-04-06 15:51:32 +08:00
MacChaeger
28affbc0ce Prevent a tournament exploit (#5353) 2019-03-31 18:19:47 +08:00
JetOU
1d70080d02 Fix crash in server/tournaments/index.js 2019-03-11 01:29:45 -05:00
Ben Davies
d8006887e4 Fix typo in server/tournaments/index.js 2019-03-10 23:04:42 -03:00
JetOU
85533ee3a0 Change forEach to for...of (#5269) 2019-03-08 11:24:58 -06:00
Jacob McLemore
34f90a9b55 Tours: Fix a forfeit being reported as failed even though it succeeded (#5188) 2019-02-20 02:11:43 -06:00
Guangcong Luo
b498bb222c Require object literal method shorthand 2019-02-11 18:14:09 -06:00
Guangcong Luo
f3e45fbb72 Move server code to server/
Also move mods/ to data/mods/

This makes PS more monorepo-like. The intent is to further separate
the sim and the server code, but without fully committing to splitting
the repository itself.

We now support `./pokemon-showdown start` in addition to
`./pokemon-showdown`. I'm not clear which I want to be the default
yet.
2019-02-03 16:07:06 -06:00