Skip to content

Commit

Permalink
Merge branch 'master' into chess
Browse files Browse the repository at this point in the history
  • Loading branch information
mia-pi-git authored Jan 17, 2025
2 parents 8c0b705 + d9ebe4a commit 8505f2f
Show file tree
Hide file tree
Showing 608 changed files with 362,157 additions and 82,227 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Publish to npm
on:
push:
branches:
- master
paths:
- 'package.json'
jobs:
test:
uses: ./.github/workflows/test.yml
get-version:
runs-on: ubuntu-latest
outputs:
current_version: ${{ steps.current_version.outputs.version }}
last_version: ${{ steps.last_version.outputs.version }}
token_exists: ${{ steps.check_token.outputs.token }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 50
# Check if the package.json version field has changed since the last push
- name: Get current version from package.json
id: current_version
run: |
echo "version=$(jq -r .version package.json)" >> $GITHUB_OUTPUT
- name: Get the version from the last push
id: last_version
run: |
git checkout ${{ github.event.before }}
echo "version=$(jq -r .version package.json)" >> $GITHUB_OUTPUT
- name: Check if NPM_TOKEN exists
id: check_token
run: |
echo "token=$(if [ -n "${{ secrets.NPM_TOKEN }}" ]; then echo true; else echo false; fi)" >> $GITHUB_OUTPUT
npm-publish:
needs:
- test
- get-version
runs-on: ubuntu-latest
# We only want to publish if the package.json version field has changed
if: needs.get-version.outputs.current_version != needs.get-version.outputs.last_version && needs.get-version.outputs.token_exists == 'true'
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
cache: 'npm'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npm run build
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
60 changes: 55 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_call:

jobs:
build:
Expand All @@ -16,15 +17,64 @@ jobs:

strategy:
matrix:
node-version: [14.x]
node-version: [16.x]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 100 # assumes PR/push to master is no larger than 100 commits. Other solutions are needlessly complex.

- name: Use Node.js ${{ matrix.node-version }}
uses: Zarel/setup-node@patch-1
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm run full-test
cache: 'npm'

- run: npm ci

- name: Determine which files to lint (if pull request)
if: ${{ github.event_name == 'pull_request' }}
id: changed-files
uses: tj-actions/changed-files@v35
with:
files: |
./config/*.ts
./data/**/*.ts
./lib/*.ts
./server/**/*.ts
./server/**/*.tsx
./sim/**/*.ts
./tools/set-import/*.ts
files_ignore: |
./logs/
./node_modules/
./dist/
./data/**/learnsets.ts
./tools/set-import/importer.js
./tools/set-import/sets
./tools/modlog/converter.js
./server/global-variables.d.ts
- name: Determine whether test/sim or test/random-battles need to run (if pull request)
if: ${{ github.event_name == 'pull_request' }}
id: changed-directories
uses: tj-actions/changed-files@v35
with:
files: |
config/formats.ts
data/**
sim/**
- name: Run selective lint & neccessary tests (if pull request)
if: ${{ github.event_name == 'pull_request' }}
run: npm run full-test-ci
env:
CI: true
FILES: ${{ steps.changed-files.outputs.all_changed_and_modified_files }}
SKIPSIMTESTS: ${{ steps.changed-directories.outputs.all_changed_and_modified_files == '' }}

- name: Run full lint & test (if push to master)
run: npm run full-test
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
env:
CI: true
42 changes: 42 additions & 0 deletions .github/workflows/update_version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Update the npm package version

on:
workflow_dispatch:
inputs:
version:
required: true
type: choice
description: Version type
default: patch
options:
- major
- minor
- patch
- premajor
- preminor
- prepatch
- prerelease
jobs:
update_version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
cache: 'npm'
- id: bump_version
run: |
echo "old_version=$(jq -r .version package.json)" >> $GITHUB_OUTPUT
npm version ${{ github.event.inputs.version }} --no-git-tag-version
echo "new_version=$(jq -r .version package.json)" >> $GITHUB_OUTPUT
- uses: peter-evans/create-pull-request@v4
with:
title: Bump package.json version to v${{ steps.bump_version.outputs.new_version }}}
body: |
Bump package.json version from `v${{ steps.bump_version.outputs.old_version }}` to `v${{ steps.bump_version.outputs.new_version }}`
commit-message: Bump package.json version to v${{ steps.bump_version.outputs.new_version }}
branch: npm-version-bump
base: master

3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/config/*
!/config/formats.ts
/logs/*
/logs/**/*
/test/modlogs
/test/replays/*.html
/node_modules
Expand All @@ -11,7 +11,6 @@
npm-debug.log
.eslintcache
.eslintcache-no-types
package-lock.json
/tools/set-import/sets
databases/*.db*
*.o
Expand Down
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

/config/*
!/config/formats.ts
!/config/config-example.js
/logs/*
/test/modlogs
/node_modules
Expand Down
1 change: 0 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
package-lock=false
NODE_OPTIONS=--max-old-space-size=3072
28 changes: 19 additions & 9 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@ Pokemon Showdown architecture

At the highest level, PS is split into three parts:

- Client
- Login server
- Game server
- Game server (**[smogon/pokemon-showdown](https://github.com/smogon/pokemon-showdown)**)
- Client (**[smogon/pokemon-showdown-client](https://github.com/smogon/pokemon-showdown-client)**)
- Login server (**[smogon/pokemon-showdown-loginserver](https://github.com/smogon/pokemon-showdown-loginserver)**)

The game server is in this repository, **[smogon/pokemon-showdown](https://github.com/smogon/pokemon-showdown)**, while the client and login server are in **[smogon/pokemon-showdown-client](https://github.com/smogon/pokemon-showdown-client)**. All three communicate directly with each other.
All three communicate directly with each other.

A user starts by visiting `https://play.pokemonshowdown.com/`. This is handled by an Apache server (in the Client), which serves mostly static files but uses some PHP (legacy, intended to be migrated to Loginserver).

The user's web browser (running Client code) will then communicate with the Login server (mounted at `https://play.pokemonshowdown.com/api/` to handle logins mostly, or otherwise interface with the Client databases one way or another).

The user's web browser will also connect to the Game server, through SockJS. The Game server handles the chat rooms, matchmaking, and actual battle simulation.

The Game server also communicates with the Login server, to handle replay uploads (and, for the main server, ladder updates).


Game server
Expand All @@ -25,22 +33,24 @@ Its entry point is [server/index.ts](./server/index.ts), which launches several

- [server/chat.ts](./server/chat.ts) sets up `Chat`, which handles chat commands and messages coming in from users (all client-to-server commands are routed through there)

`Rooms` also includes support for battle rooms, which is where the game simulation itself is done. Game simulation code is in [sim/](./sim/).
`Rooms` also includes support for battle rooms, which is where the server connects to the game simulator itself. Game simulation code is in [sim/](./sim/).


Client
------

The client is built in a mix of TypeScript and JavaScript, with a mostly hand-rolled framework built on Backbone. There’s a rewrite to migrate it to Preact but it’s very stalled.

Its entry point is [index.template.html](https://github.com/smogon/pokemon-showdown-client/blob/master/index.template.html).
Its entry point is [index.template.html](https://github.com/smogon/pokemon-showdown-client/blob/master/play.pokemonshowdown.com/index.template.html)

It was written long ago, so instead of a single JS entry point, it includes a lot of JS files. Everything important is launched from [js/client.js](https://github.com/smogon/pokemon-showdown-client/blob/master/js/client.js).
It was written long ago, so instead of a single JS entry point, it includes a lot of JS files. Everything important is launched from [js/client.js](https://github.com/smogon/pokemon-showdown-client/blob/master/play.pokemonshowdown.com/js/client.js)


Login server
------------

The client’s login server, which handles logins and most database interaction, is written in PHP, with a rewrite to TypeScript in progress. The backend is split between a MySQL InnoDB database and a Percona database, with a migration to Postgres planned.
The client’s login server, which handles logins and most database interaction, is written in TypeScript. The backend is currently split between a MySQL InnoDB database (for users, ladder, and most other things) and a Postgres (technically Cockroach) database (for Replays).

Its entry point is [server.ts](https://github.com/smogon/pokemon-showdown-loginserver/blob/master/src/server.ts).

Its entry point is [action.php](https://github.com/smogon/pokemon-showdown-client/blob/master/action.php).
It's intended to replace all of the old PHP code in the Client, but that migration is only halfway done at the moment.
12 changes: 8 additions & 4 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
config/formats.ts @KrisXV @Marty-D
data/mods/*/random-teams.ts @AnnikaCodes
data/mods/ssb/ @HoeenCoder @KrisXV
data/mods/gen9ssb/ @HoeenCoder @HisuianZoroark @KrisXV
data/random-sets.json @MathyFurret @ACakeWearingAHat @livid-washed @adrivrie
data/random-teams.ts @AnnikaCodes @KrisXV @MathyFurret @ACakeWearingAHat @livid-washed @adrivrie
data/text/ @Marty-D
databases/ @monsanto
lib/sql.ts @mia-pi-git
server/artemis/* @mia-pi-git
server/chat-plugins/chess.ts @mia-pi-git
server/chat-plugins/abuse-monitor.ts @mia-pi-git
server/chat-plugins/friends.ts @mia-pi-git
server/chat-plugins/github.ts @mia-pi-git
server/chat-plugins/hosts.ts @AnnikaCodes
server/chat-plugins/helptickets*.ts @mia-pi-git
server/chat-plugins/mafia.ts @HoeenCoder
server/chat-plugins/othermetas.ts @KrisXV
server/chat-plugins/permalocks.ts @mia-pi-git
server/chat-plugins/quotes.ts @mia-pi-git @KrisXV
server/chat-plugins/random-battles.ts @KrisXV @AnnikaCodes
server/chat-plugins/repeats.ts @AnnikaCodes
server/chat-plugins/responder.ts @mia-pi-git
server/chat-plugins/rock-paper-scissors.ts @mia-pi-git
server/chat-plugins/sample-teams.ts @KrisXV
server/chat-plugins/scavenger*.ts @xfix @sparkychildcharlie
server/chat-plugins/scavenger*.ts @xfix @sparkychildcharlie @PartMan7
sever/chat-plugins/teams.ts @mia-pi-git
server/chat-plugins/the-studio.ts @KrisXV
server/chat-plugins/abuse-monitor.ts @mia-pi-git
server/chat-plugins/trivia/ @AnnikaCodes
server/friends.ts @mia-pi-git
server/private-messages/* @mia-pi-git
server/chat-plugins/username-prefixes.ts @AnnikaCodes
server/chat-plugins/wifi.ts @KrisXV
server/friends.ts @mia-pi-git
Expand Down
2 changes: 1 addition & 1 deletion COMMANDLINE.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Note: Commands that ask for a team want the team in [packed team format](./sim/T
- Simulates a battle, taking input to stdin and writing output to stdout

Using Pokémon Showdown as a command-line simulator is documented at:
[sim/README.md](./README.md)
[sim/README.md](./sim/README.md)

`./pokemon-showdown json-team`

Expand Down
24 changes: 6 additions & 18 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ BAD:

```ts
// if ten seconds have passed and the user is staff
if (now > then + 10_000 && '&@%'.includes(user.tempGroup)) {
if (now > then + 10_000 && '~@%'.includes(user.tempGroup)) {
```
GOOD:
```ts
const tenSecondsPassed = now > then + 10_000;
const userIsStaff = '&@%'.includes(user.tempGroup);
const userIsStaff = '~@%'.includes(user.tempGroup);
if (tenSecondsPassed && userIsStaff) {
```
Expand Down Expand Up @@ -317,26 +317,14 @@ We oppose the usual JavaScript culture of casually adding dependencies from NPM.
There are, of course, a lot of libraries like SockJS doing valuable things that we shouldn't reimplement ourselves. However, most libraries on NPM have very different priorities than we do (not caring about performance or bugs in subdependencies).
But in practice, for any dependency we could reimplement in around 30 lines of code, we'll write it ourselves and maintain it in `lib/`. Such maintenance is usually worth avoiding a `left-pad` situation, and also is generally better for performance, and also helps us easily craft the API to be most convenient for our own use-case.
A common reason given for preferring dependencies is because someone else is more likely to have encountered and fixed bugs. But in practice many dependencies are worse-maintained than Showdown. And many bugs come from misusing a dependency.
In practice, for any dependency we could reimplement in around 30 lines of code, we'll write it ourselves and maintain it in `lib/`. Such maintenance is usually worth avoiding a `left-pad` situation, and also is generally better for performance, and also helps us easily craft the API to be most convenient for our own use-case.
To be clear, we're not _opposed_ to new dependencies and will accept them where they make sense. But we try to avoid them more most than other Node projects do.
`package-lock.json`
------------------------------------------------------------------------
We don't use `package-lock`. This is against NPM's (and most others') official advice that we should.
: First, what's `package-lock` and why is it recommended? `package-lock.json` is basically a snapshot of the `node_modules/` directory. You can think of it like `node_modules.zip`, except more human-readable, and requires an internet connection to unzip.
: The main advantage of adding it to Git is that it lets you know exactly the state of `node_modules/` at the time the programmer commits it. So if a dependency breaks, it's easier to trace exactly when it broke.
: It also makes sure `node_modules/` is exactly the same between different development environments, so differences don't cause bugs to appear for some developers but not others.
This comes with a number of disadvantages. The biggest one is that it causes package-lock changes to appear in random commits, which can outright lead to merge conflicts. It also makes diffs in general significantly less readable. It also [introduces security vulnerabilities](https://snyk.io/blog/why-npm-lockfiles-can-be-a-security-blindspot-for-injecting-malicious-modules/).
The biggest supposed advantage (ensure everyone's on the same version) isn't even an advantage! We'd specify the versions as `4.15.4` instead of `^4.15.4` if we wanted everyone on the same version, rather than the latest version. Writing `^4.15.4` is an explicit choice to opt into automatic updating.
We can still have everyone on the same version if we all re-run `npm install`, which we would STILL have to do if we were using a package-lock file. The package-lock file does not improve this situation.
(The last time we polled our developers, most supported not having a `package-lock` file.)
In the past, we didn't use `package-lock`. The reasons are historical. We do now. If you see a project without package-lock, feel free to add it.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2011-2022 Guangcong Luo and other contributors http://pokemonshowdown.com/
Copyright (c) 2011-2024 Guangcong Luo and other contributors http://pokemonshowdown.com/

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
8 changes: 4 additions & 4 deletions PROTOCOL.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Messages from the user to the server are in the form:

`ROOMID` can optionally be left blank if unneeded (commands like `/join lobby`
can be sent anywhere). Responses will be sent to a PM box with no username
(so `|/command` is equivalent to `|/pm &, /command`).
(so `|/command` is equivalent to `|/pm ~, /command`).

`TEXT` can contain newlines, in which case it'll be treated the same
way as if each line were sent to the room separately.
Expand Down Expand Up @@ -237,10 +237,10 @@ represented by a space), and the rest of the string being their username.
> You just connected to the server, and we're giving you some information you'll need to log in.
>
> If you're already logged in and have session cookies, you can make an HTTP GET request to
> `https://play.pokemonshowdown.com/action.php?act=upkeep&challstr=CHALLSTR`
> `https://play.pokemonshowdown.com/api/upkeep?challstr=CHALLSTR`
>
> Otherwise, you'll need to make an HTTP POST request to `https://play.pokemonshowdown.com/action.php`
> with the data `act=login&name=USERNAME&pass=PASSWORD&challstr=CHALLSTR`
> Otherwise, you'll need to make an HTTP POST request to `https://play.pokemonshowdown.com/api/login`
> with the data `name=USERNAME&pass=PASSWORD&challstr=CHALLSTR`
>
> `USERNAME` is your username and `PASSWORD` is your password, and `CHALLSTR`
> is the value you got from `|challstr|`. Note that `CHALLSTR` contains `|`
Expand Down
Loading

0 comments on commit 8505f2f

Please sign in to comment.