Code Monkey home page Code Monkey logo

battlegame_server's Introduction

Battlegame

Aliases

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'

Setup

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.txt

Make 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

  1. Create user u_battlegame with same password as in .env
  2. 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-ttl

Load staging data (recommended):

Staging 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.

  1. ssh into server: ssh <USER>@salutationstudio.com
  2. activate virtual environment: cd /home/battlegame && source venv/bin/activate
  3. enter the Django shell: cd /home/battlegame/battlegame && ./manage.py shell
  4. export the staging database: from battlegame.dumpstaging import dump; dump()
  5. copy the database over locally: scp <USER>@salutationstudio.com:/home/battlegame/battlegame/dump.json dump.json
  6. re-create the database: dropdb battlegame && createdb battlegame && ./manage.py migrate
  7. load the staging database: ./manage.py loaddata dump.json

Load existing data:

  1. ssh into server
  2. Make sure to activate venv (source venv/bin/activate)
  3. ./manage.py dumpdata --exclude auth.permission --exclude contenttypes > ~/db.json
    • Ignore error Cannot export Prometheus /metrics/ - no available ports in supplied range
  4. Run scp {INSERT_USERNAME}@salutationstudio.com:/home/{INSERT_USERNAME}/db.json {INSERT_LOCAL_DIRECTORY} locally to copy db.json to your local workstation.
  5. Run ./manage.py loaddata db.json locally 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):

  1. Install ufw, and open up port 8000
  2. In battlegame/settings.py, add the server machine's ip (check with ifconfig) to ALLOWED_HOSTS. Don't commit this!
  3. run with python manage.py runserver 0.0.0.0:8000

Chat

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 channels package
  • Python channels_redis package
  • docker is 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.

Deployment

Currently we have auto deployment setup, which installs new dependencies, runs migrations, and restarts supervisor.

Quests

Creating new Cumulative Quest

  1. Create a BaseQuest with one of the types in playerdata/constants.py or create a new one
  2. Select the quest on the BaseQuest Admin Panel, and perform the "Propagate cumulative BaseQuest to all Users" action

Queueing Daily/Weekly Quests

Cron jobs update and remove the first n quests from each table at expiration time

  1. Add BaseQuests to ActiveDailyQuest or ActiveWeeklyQuest

For more info on cron jobs: battlegame/cron.py

Tracking new Quests

Quest tracking is managed by QuestUpdater

Regular Daily/Weekly Quests:

  1. add_progress_to_quest_list: increments progress
  2. set_progress_to_quest_list: sets progress

Cumulative Quests:

  1. update_cumulative_progress: Manages updating of the CumulativeTracker as well

Dungeon

Creating Worlds

  1. World names and actual distinctions come from client-side hardcoding of which stages belong to which levels, so look there to add changes
  2. Dungeon mob teams are just Placements, so create a Placement first, then create a DungeonStage

Tournament

Testing

Actions in Admin Panel

  1. setup_tourney in TournamentRegistrations: Running this will create the tourney groups and set up the first round.
  2. next_round in Tournament: Run the next round.
  3. end_tourney in Tournament: Ends tourney and cleans up.

battlegame_server's People

Contributors

daniel-wang avatar yanske avatar wilsoncwu avatar shaunlazaro avatar advait-m avatar

Watchers

 avatar  avatar

battlegame_server's Issues

Better elimination tie breaking in tournament

  • current we sort for most losses, and eliminate the first two in the list

Ideas:

  • add more tie breaking stuff (damage dealt?)
  • randomly pick if you have more than 2 of the same worst losses records

Api status

In the majority of the code,we’re not using return statuses properly, and instead manually setting and checking a return field in unity. This has the side effect that if an api breaks consistently from wrong status, our logging won’t detect that

server warning

Im getting a warning for the use of 'is' https://github.com/WilsonCWu/battlegame_server/blob/master/playerdata/models.py#L563, seems like the warning is introduced in python 3.8.

does this have to be is, or can we change to ==?

/Users/wilson/Desktop/github/battlegame_server/playerdata/models.py:563: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if interval is 1:
/Users/wilson/Desktop/github/battlegame_server/playerdata/models.py:567: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if delta is 0:
No changes detected

Build failing, but CircleCI still approves

Seems like we have a key violation that causes the circleCI build/test process to fail, but isn't caught. We should probably fix the error, and maybe catch it in the future?

image

generic event

Similar to the launch event, lets repurpose it to be a generic thing with a scroller. We want to be able to have a list of upcoming events, and a countdown for when it'll start. This is similar to the events tab in AFK arena.

This is so we can hype up events, before the event is actually ready

(doesnt need to be like this, just pasting here for reference)

Refactor placement characters / positions into array

snippets like this happen when we modify or get Placement
Refactor this into arrays of pos and char instead

pos_1 = serializer.validated_data['pos_1']
char_1 = serializer.validated_data['char_1']
pos_2 = serializer.validated_data['pos_2']
char_2 = serializer.validated_data['char_2']
pos_3 = serializer.validated_data['pos_3']
char_3 = serializer.validated_data['char_3']
pos_4 = serializer.validated_data['pos_4']
char_4 = serializer.validated_data['char_4']
pos_5 = serializer.validated_data['pos_5']
char_5 = serializer.validated_data['char_5']

Will need to change:

  • data being sent
  • team loaders for dungeon and quickplay to check for end of char list by size rather than seeing -1 index

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.