Skip to content

Development environment

Jay Malhotra edited this page Dec 29, 2022 · 19 revisions

Here is a quick guide for getting started with a development environment to contribute to the project.

Cloning and running the repository

Start by cloning the repository into a directory of your choosing. Docker Compose is used to run the repository locally. On Windows, the recommended setup is Visual Studio as an IDE and Docker Desktop which enables debugging in containers.

Once you have cloned the repository, copy .env.default to .env and choose a database username and password, and a developer token. The developer token is expected in the Authorization header of any requests that want to import or delete a savefile.

You should then be able to run the server by running 'Docker Compose' in the top toolbar in Visual Studio (or docker compose up if using the CLI/an IDE which doesn't support container tools). Verify that all 3 containers start up properly and that they appear healthy. The server should now be live on localhost:5000 -- try navigating to localhost:5000/health in your browser. If it says 'Healthy' this means that the app has successfully started and can connect to the database and Redis.

Setting up a client

It is a good idea to set up a real Dragalia client to enable end-to-end testing. While it is possible to verify that your code works automated testing, the fact that we are working with a proprietary client means that seemingly valid response data can sometimes cause unforeseen issues when received by the client.

Currently the development set-up for clients uses a patch that disables encryption and emulator/root checks, and then uses mitmproxy to route traffic away

Patched apk files

The first step is to patch an APK of the game to remove transport encryption as well as the emulator and root checks. Xdelta patches for this can be found here. While there exists an excellent tool by LukeFZ to patch Dragalia Lost to connect to server emulators, it appears that the game doesn't accept URLs with ports (e.g. localhost:5000) as valid URLs.

Emulator

Once you have the patched APK files, you will need to set up an emulator. The recommended choices are WSA or the Android Studio emulator. If using WSA, using the rooted version is preferred so that you can access the game's internal data directory. Also note that it is possible to run WSA on Windows 10

mitmproxy

Because the above patches don't change the url as Dragalipatch does, the connection to the server is achieved by routing traffic away from the official servers via mitmproxy using a Python script extension. **It is highly recommended to install mitmproxy via pip to ensure compatibility with Python. The script simply redirects all urls matching Dragalia traffic to localhost:5000`.

You will need to run mitmproxy on your local machine and then set up your emulator to proxy via <local IP address of mitmproxy runner>:8080. This can be done via adb shell settings put global http_proxy xxx.xxx.x.xxx:8080. You will also need to install the mitmproxy certificates by navigating to mitm.it in a browser on the proxied device and following the instructions. This may be tricky on WSA as it doesn't expose an easy way of accessing Android settings to install certificates; it may be necessary to do it via ADB. Here are some commands that should work (courtesy of Ceris):

adb push <cert> <path on device>
adb shell am start -n com.android.certinstaller/.CertInstallerMain -a android.intent.action.VIEW -t application/x-x509-ca-cert -d file://path/on/device.cer
<install userland / set up MITMProxy>
adb shell settings put global http_proxy <proxy address>:<proxy port>

Troubleshooting

ASP.NET container crashes on startup with certificate error

Sometimes the container crashes on startup due to issues with the development certificates. In that event, it's possible to troubleshoot this but since this is a local development setup it is probably easier to disable HTTPS (the mitmproxy addon routes via HTTP anyway). To do this, change docker-compose.yml to have - ASPNETCORE_URLS=http://+:80 instead of - ASPNETCORE_URLS=https://+:443;http://+:80 in services.dragaliaapi.environment[0].

Postgres container crashes on startup

This is possibly due to database credential issues -- did you set up .env as described at the start of this guide? Alternatively the database is persisted with docker-compose and if the credentials are changed after it has been created then these will now be invalid. To address this, delete the dragaliaapi-pgdata volume in Docker and the database will be recreated on next startup.

Clone this wiki locally