Skip to content

Null-Pointer Private Server 4: Comprehensive SIF1 Private Server Implementation

License

Notifications You must be signed in to change notification settings

DarkEnergyProcessor/NPPS4

Repository files navigation

Null-Pointer Private Server: Revisited

Python: 3.12 Static Type Checker: PyRight Code Style: Black Syntax Check

WIP SIF 9.11 private server written in Python 3.12 using FastAPI.

Notes

  • This project is currently in need of funding.

  • Database schema changes constantly. Expect frequent database wipes.

Requirements

NPPS4 currently supports only Python 3.12 (and possibly later version). Python 3.11 and earlier is not supported.

Install

  1. Install Python 3.12 or later.
  2. Create virtual environment.
  3. Activate it.
  4. pip install -r requirements.txt

Starting Up

Before starting the server, you need 3 things:

  1. Create configuration file.
  2. Get private key.
  3. Get client game database.

Create configuration file.

Copy out config.sample.toml to config.toml and adjust as needed. The file has extensive comments on each configuration values.

Get private key.

Warning

A private key is required due to internal request-response verification done in the game.

Using provided private key

NPPS4 provides default private key which is used to develop other private servers by the community and compatible with community-patched APK.

There's nothing to do to use this private key. This private key is used by default as per the sample configuration key main.server_private_key.

The public key of the default server key is:

-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDE0RNd6047aeBirzVb61DolatY
YWpaEUIPugOIkobHDc9qVR5iliMLyC0ErXO1siLBwN+U3zaDVOa5uhXbiS7uYq5c
cpxComxTnZtcn/b+mKDpYWLaC0Gv7UoiT8rpNqN3Vko645usz9OFc4VciijsHGRP
XmmmoP6qykfI/vba8wIDAQAB
-----END PUBLIC KEY-----

Using your own private key

Important

The private key must be 1024-bit RSA stored in PEM format!

If you already have your existing private key, simply put them as server_key.pem.

To get the public key, run:

python make_server_key.py -p

Generating your own private key

To generate a new private key, run:

python make_server_key.py

The public key, for your game client will be printed to stdout in PEM format. Patch your game to use the newly-provided public key.

Get client game database.

There's 2 simple methods: Having local copy of SIF client files or loading it directly through internet.

Create local copy

First, follow the instruction at https://gist.github.com/MikuAuahDark/ece4eb73b3396403c6a2f11610a783b8.

Then set the download.backend to internal and configure the download.internal.archive_root directory in the configuration file to your local copy of SIF client files.

Loading directly from internet

Look at the URL in https://gist.github.com/MikuAuahDark/ece4eb73b3396403c6a2f11610a783b8.

Set the download.backend to n4dlapi and configure download.n4dlapi.server to the URL writen in above gist (not the gist itself).

Database

Please consult SQLAlchemy supported database backends for more information. If in doubt, SQLite3 is a safe choice if you don't need performance as it's already a part of NPPS4 required dependencies.

Otherwise, install the additional dependencies depending on which backend you want to use. Ensure to install the "async" version of the database packages!

  • SQLite3: aiosqlite (already installed)
  • PostgreSQL: asyncpg
  • MySQL/MariaDB: asyncmy

Running

After all is set, initialize the database:

alembic upgrade head

Then run the server

uvicorn npps4.run.app:main --port 51376 --host <your lan IP or 0.0.0.0>

Caveat: Currently, --workers option is not supported when using NPPS4-DLAPI download backend.

Updating

Before updating, please ensure if database breakage is not happening. See DBBREAKAGE.md for information.

If there's no database breakage or you already know a way to handle the breakage (either by doing stuff manually or destroying the database), run:

git pull --ff-only
alembic upgrade head

Most changes requires a server restart. However, changes that only touch server_data.json does not require server restart as that particular file is hot-reloaded by the server.

Client App

To get compatible client, please look at https://ethanaobrien.github.io/sif-patcher/. Both iOS and Android are supported.

Contribute

See CONTRIBUTE.md

License

zLib license, excluding any files in external/.

Public domain/unlicense, any files in external/.