Aliases used for convenience
alias vact='source /home/battlegame/venv/bin/activate'
alias dmm='python /home/battlegame/battlegame/manage.py makemigrations'
alias dm='python /home/battlegame/battlegame/manage.py migrate'
alias sr='sudo supervisorctl restart all'
alias ss='sudo supervisorctl status'
alias shell='python /home/battlegame/battlegame/manage.py shell'
install postgres, virtualenv
sudo apt-get -y install postgresql postgresql-contrib
sudo pip3 install virtualenv
Python installation
virtualenv venv -p python3
source venv/bin/activate
pip install -r requirements.txtMake an .env in the root git folder with the following:
SECRET_KEY=<type something here>
POSTGRES_PASSWORD=postgres
CREATEUSER_TOKEN=<ask someone for this>
REDIS_PVP_PASSWORD=REDISPASSWORD
Set up Postgres
- Create user
u_battlegamewith same password as in.env - Create db
battlgame
sudo su - postgres
createuser u_battlegame
createdb battlegame --owner u_battlegame
psql -c "ALTER USER u_battlegame WITH PASSWORD 'postgres'"
Check which port Postgres is running on with:
cat /etc/postgresql/10/main/postgresql.conf
Look for port = XXXX. In most cases, this should be 5432. If it is not 5432, you will need to change battlegame/settings.py to match your port.
Migrate:
python manage.py migrate
Set up Redis Cache
We run two instances of Redis for Chat and Cache (pvp queueing). Chat is port 6379, Cache is 6380.
docker run --name redis-6380 -d -p 127.0.0.1:6380:6379 --restart always redis redis-server --requirepass REDISPASSWORD --maxmemory 3gb --maxmemory-policy volatile-ttlStaging data (see battlegame/dumpstaging.py) can be loaded, which is a
fragment of the existing database with only selected users in the universe.
The current size of staging data at this commit is ~2MB, versus the ~148MB actual DB, which is only expected to grow.
- ssh into server:
ssh <USER>@salutationstudio.com - activate virtual environment:
cd /home/battlegame && source venv/bin/activate - enter the Django shell:
cd /home/battlegame/battlegame && ./manage.py shell - export the staging database:
from battlegame.dumpstaging import dump; dump() - copy the database over locally:
scp <USER>@salutationstudio.com:/home/battlegame/battlegame/dump.json dump.json - re-create the database:
dropdb battlegame && createdb battlegame && ./manage.py migrate - load the staging database:
./manage.py loaddata dump.json
- ssh into server
- Make sure to activate venv (
source venv/bin/activate) ./manage.py dumpdata --exclude auth.permission --exclude contenttypes > ~/db.json- Ignore error
Cannot export Prometheus /metrics/ - no available ports in supplied range
- Ignore error
- Run
scp {INSERT_USERNAME}@salutationstudio.com:/home/{INSERT_USERNAME}/db.json {INSERT_LOCAL_DIRECTORY}locally to copydb.jsonto your local workstation. - Run
./manage.py loaddata db.jsonlocally to load the data.
To export data:
./manage.py dumpdata --exclude auth.permission > db.json to export data for future iterations (untested)
To run on same computer as Unity instance:
python manage.py runserver
To run on local server (eg: separate computer, same internet):
- Install ufw, and open up port 8000
- In battlegame/settings.py, add the server machine's ip (check with
ifconfig) to ALLOWED_HOSTS. Don't commit this! - run with
python manage.py runserver 0.0.0.0:8000
Tutorial reference: https://channels.readthedocs.io/en/latest/tutorial/
For chat, you will need to start redis using Docker. Make sure you have the following dependencies:
- Python
channelspackage - Python
channels_redispackage dockeris installed
Then run the following command to start redis, with a pre-built Docker image:
docker run -p 6379:6379 -d redis:5
Finally, restart the Django server.
See https://channels.readthedocs.io/en/latest/tutorial/part_2.html#enable-a-channel-layer for more details.
Currently we have auto deployment setup, which installs new dependencies, runs migrations, and restarts supervisor.
- Create a
BaseQuestwith one of the types inplayerdata/constants.pyor create a new one - Select the quest on the BaseQuest Admin Panel, and perform the "Propagate cumulative BaseQuest to all Users" action
Cron jobs update and remove the first n quests from each table at expiration time
- Add BaseQuests to
ActiveDailyQuestorActiveWeeklyQuest
For more info on cron jobs:
battlegame/cron.py
Quest tracking is managed by QuestUpdater
Regular Daily/Weekly Quests:
add_progress_to_quest_list: increments progressset_progress_to_quest_list: sets progress
Cumulative Quests:
update_cumulative_progress: Manages updating of theCumulativeTrackeras well
- World names and actual distinctions come from client-side hardcoding of which stages belong to which levels, so look there to add changes
- Dungeon mob teams are just
Placements, so create aPlacementfirst, then create aDungeonStage
Actions in Admin Panel
setup_tourneyinTournamentRegistrations: Running this will create the tourney groups and set up the first round.next_roundinTournament: Run the next round.end_tourneyinTournament: Ends tourney and cleans up.