mpp-server-dev2/README.md

168 lines
6.4 KiB
Markdown
Raw Normal View History

2023-09-12 07:59:54 +02:00
![MPP](https://github.com/multiplayerpiano/mpp-frontend-v1/blob/master/static/128-piano.png?raw=true)
2023-09-08 03:19:13 +02:00
# mpp-server-dev2
2021-03-20 20:16:59 +01:00
2024-07-09 10:55:52 +02:00
This is an MPP server currently in development for [MPP.dev](https://www.multiplayerpiano.dev). The original server is old and the site desperately needs a new one.
2023-09-09 11:27:16 +02:00
2024-07-09 10:55:52 +02:00
This server uses Bun - not just the runtime, but the libraries as well. This is because Bun provides easy access to uWebSockets.js, a speedy implementation of WebSockets that heavily outperforms the old `ws` module that is used so frequently.
2023-09-09 11:27:16 +02:00
2024-07-09 10:55:52 +02:00
I have tried to comply well with Brandon Lockaby's original MPP server so that this server stays widely accessible for any frontend implementation, including the ones used by MultiplayerPiano.net, LapisHusky's frontend, and the frontends used by nagalun's server, as well as the smnmpp and mpp.hri7566.info frontends.
Of course, most of the ones I have listed probably won't work yet because I haven't implemented a way to switch between token authentication and legacy connections yet.
Regardless, this server is meant for speed, stability, and compatability.
This server uses Prisma as an ORM for saving user data, and is currently setup to interface with SQLite. I may be switching this to PostgreSQL in the very near future, so don't get too comfortable with SQLite.
Brandon's server originally used MongoDB for storing user data, but there are too many reasons to list why it isn't fit for this project here, so I will link [this video by Theo](https://www.youtube.com/watch?v=cC6HFd1zcbo) instead.
## List of features
- Chat
- Original chat filter by chacha and Brandon Lockaby
2024-08-03 07:00:20 +02:00
- Commands for debugging or administrative purposes
2024-07-09 10:55:52 +02:00
- Piano Notes
- Uses the same `NoteQuota` implementation from the client
- Usernames/colors
2024-08-03 07:00:20 +02:00
- Allowing color changing can be toggled in the config, similar to MPP.com
- Default user parameters can be set
- Configurable ID and color generation methods
2024-07-09 10:55:52 +02:00
- Channels
- Channel list
- Channel settings
- Rate limits
- Borrowed from Brandon's GitHub Gist account
- Brandon-style admin messages
- Remote name changing
- Color changing
- User flag settings
- Ability to change the volume of users' notes (affects note velocity)
- Chat muting
- Rate limit bypasses
2024-07-12 23:26:21 +02:00
- Channel/User-targeted notifications
2024-08-03 07:00:20 +02:00
- Server-wide/channel-specific/user-specific notifications
2024-07-12 23:26:21 +02:00
- New admin messages
- Restart message
- Triggers notification on every connected socket, then shuts down after 20 seconds
2024-08-03 07:00:20 +02:00
- Server must be setup as a pm2/docker/systemd process for automatic restarting
2024-07-12 23:26:21 +02:00
- Ability to change tags
2024-08-03 09:49:46 +02:00
- Similar to the MPP.net server, but uses a Brandon-style admin message
- Ability to rename channels
- Chat clearing similar to MPP.net
2024-07-09 10:55:52 +02:00
## TODO
2024-08-01 01:59:51 +02:00
- Fully implement and test tags
2024-08-03 07:00:20 +02:00
- Tags are sent to clients now
- Check if tags are sent to everyone
- Permission groups and permissions
- Probable permission groups: owner, admin, mod, trialmod, default
- Setup tags for each permission group
2024-08-03 09:49:46 +02:00
- Redo ratelimits
2024-08-03 07:00:20 +02:00
- Full server-wide event bus
- Channel events
- Socket events
- User data events
- Permission-related events
2024-07-23 20:02:12 +02:00
- Redo all of the validations with Zod
- This probably means making Zod schemas for every single message type
- Also user and channel data
2024-07-09 10:55:52 +02:00
- Test every frontend
2024-07-12 23:26:21 +02:00
- Test fishing bot
2024-08-03 07:00:20 +02:00
- Remote console
- Modify frontend to use templating
2024-07-12 23:26:21 +02:00
## Backlog/Notes
- Use template engine instead of raw HTML?
- Change frontend files at runtime?
- Split script.js into multiple files
- Implement tags as a server option, toggles code on frontend
- Same with color changing
- Reload config files on save
- Expose API?
2023-09-09 11:27:16 +02:00
## How to run
2024-07-09 10:55:52 +02:00
Don't expect these instructions to stay the same. They might not even be up to date already! This is due to frequent changes in this repository, as this project is still in active development.
2023-09-09 11:27:16 +02:00
0. Install bun
```
$ curl -fsSL https://bun.sh/install | bash
```
2024-07-13 20:10:45 +02:00
1. Clone the repo and setup Git submodules
2023-09-11 06:52:03 +02:00
2024-07-23 11:55:13 +02:00
This step is subject to change, due to the necessity of testing different frontends, where the frontend may or may not be a git submodule.
This will probably be updated in the near future. Expect a step asking to download the frontend manually.
If you are forking this repository, you can just setup a new submodule for the frontend.
The frontend files go in the `public` folder.
I am also considering using handlebars or something similar for templating, where the frontend will require completely different code.
The reason behind this decision is that I would like different things to change on the frontend based on the server's config files,
such as enabling the color changing option in the userset modal menu, or sending separate code to server admins/mods/webmasters.
2023-09-11 06:52:03 +02:00
```
2024-07-13 20:10:45 +02:00
$ git clone https://git.hri7566.info/Hri7566/mpp-server-dev2
$ cd mpp-server-dev2
2023-09-11 06:57:20 +02:00
$ git submodule update --init --recursive
2023-09-11 06:52:03 +02:00
```
2. Configure
2023-09-09 11:27:16 +02:00
- Copy environment variables
```
$ cp .env.template .env
```
Edit `.env` to your needs. Some variables are required for certain features to work.
2023-09-09 11:27:16 +02:00
- Edit the files in the `config` folder to match your needs
2024-08-01 01:56:58 +02:00
For token auth, there are a few options to consider. In `config/users.yml`, you can set `tokenAuth` to a few different values:
- `jwt`: Use JWT token authentication
- `uuid`: Use UUID token authentication
- `none`: Disable token authentication
If you are using UUID token authentication, the server will generate a UUID token for each user when they first connect.
If you are using JWT token authentication, you will need to generate a key for the server to use.
This can be done by running the following command:
```
$ openssl genrsa -out mppkey 2048
```
For antibot/browser detection there are also a few options to consider. In `config/users.yml`, you can set `browserChallenge` to a few different values:
- `none`: Disable browser challenge
- `basic`: Use a simple function to detect browsers
- `obf`: Use an obfuscated function to detect browsers - TODO: implement this
The `basic` option only sends a simple function to the client, and the `obf` option sends an obfuscated mess to the client.
This option requires the newer-style (MPP.net) frontend to be used.
2023-09-11 06:52:03 +02:00
3. Install packages
2023-09-09 11:27:16 +02:00
```
$ bun i
```
2023-09-11 06:52:03 +02:00
4. Setup database
2023-09-09 11:27:16 +02:00
```
$ bunx prisma generate
$ bunx prisma db push
```
5. Run
2023-09-09 11:27:16 +02:00
```
$ bun .
2023-09-09 11:27:16 +02:00
```