Skip to content

Commit

Permalink
Misc cleanup (#484)
Browse files Browse the repository at this point in the history
* Refactor server.py

* Remove unraised error

* Add pipenv script for running the server in development mode

* Remove the last remaining references to UPLOAD_MOD and UPLOAD_MAP

While these were being parsed by QDataStreamProtocol, they were not 
being handled by LobbyConnection meaning that sending one of these 
commands would abort your connection anyways. Better to remove them 
entirely, now that this is handled by the API

* Remove references to non existent commands from readme

* Clean up formatting

* Add setup.cfg for autoformatter config

* Rename server command to devserver and add vulture for finding dead code

* Remove unused variables from Player

* Remove some unused GPGNetServerProtocol commands

* Remove unused variables from servercontext

* Clean up readme. Add section about vulture

* Run auto formatter

* Add a constant for FFA team to increase readability

* Use tuples instead of lists for module exports

* Bump travis to latest faf-stack release

* Clean up some dictionaries and replace sendJSON with send everywhere

* Clean up more dict's

* Clean up some formatting in ladder_service
  • Loading branch information
Askaholic committed Aug 30, 2019
1 parent d98ee06 commit c337089
Show file tree
Hide file tree
Showing 32 changed files with 432 additions and 342 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ before_install:
- sudo /etc/init.d/mysql stop
- git clone https://github.com/FAForever/faf-stack.git faf-stack
&& pushd faf-stack
&& git checkout 8e9e3bd
&& git checkout v19.8.12
&& cp -r config.template config
&& ./scripts/init-db.sh
&& wget https://raw.githubusercontent.com/FAForever/db/$(grep -oP 'faforever/faf-db-migrations:\K(.*)$' ./docker-compose.yml)/test-data.sql
Expand Down
3 changes: 3 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[scripts]
devserver = "env LOG_LEVEL=TRACE python server.py"
tests = "scripts/pipenv_run_tests.sh"
vulture = "vulture server.py server/ --sort-by-size"

[[source]]
url = "https://pypi.org/simple"
Expand Down Expand Up @@ -27,6 +29,7 @@ pytest-mock = "*"
pytest-cov = "*"
coveralls = "*"
mock = "*"
vulture = "*"

[requires]
python_version = "3.6"
128 changes: 69 additions & 59 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 32 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ master|develop
------------ | -------------
[![Build Status](https://travis-ci.org/FAForever/server.svg?branch=master)](https://travis-ci.org/FAForever/server) | [![Build Status](https://travis-ci.org/FAForever/server.svg?branch=develop)](https://travis-ci.org/FAForever/server)
[![Coveralls Status](https://img.shields.io/coveralls/FAForever/server/master.svg)](https://coveralls.io/github/FAForever/server) | [![Coveralls Status](https://img.shields.io/coveralls/FAForever/server/develop.svg)](https://coveralls.io/github/FAForever/server)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/FAForever/server/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/FAForever/server/?branch=master) | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/FAForever/server/badges/quality-score.png?b=develop)](https://scrutinizer-ci.com/g/FAForever/server/?branch=develop)

## Installation

Expand Down Expand Up @@ -34,14 +33,6 @@ If you have a different root password, database name then the default (see [conf

docker run --link faf-db:db -p 8001:8001 -p 30351:30351 -e FAF_DB_PASSWORD=<wanted_password> -e FAF_DB_NAME=<db_name> faf-server

## Running the tests

Some of the tests require the database to be pre-populated with test data. Download
the latest `test-data.sql` from [FAForever/db](https://github.com/FAForever/db
into the root of this project, then run:

$ pipenv run tests

# Contributing

To contribute, please fork this repository and make pull requests to the develop branch.
Expand All @@ -52,6 +43,34 @@ Use the normal git conventions for commit messages, with the following rules:
- For non-trivial commits, always include a commit message body, describing the change in detail
- If there are related issues, reference them in the commit message footer

## Setting up for development

First make sure you have an instance of `faf-db` running as described in the
installation section. Then install the dependencies to a virtual environment
using pipenv:

$ pipenv install --dev

You can start the server in development mode with:

$ pipenv run devserver

**Note** *The pipenv scripts are not meant for production deployment. For
deployment use `faf-stack`*

## Running the tests

Some of the tests require the database to be pre-populated with test data. Download
the latest `test-data.sql` from [FAForever/db](https://github.com/FAForever/db
into the root of this project, then run:

$ pipenv run tests

## Other tools

You can check for possible unused code with `vulture` by running:

$ pipenv run vulture

# License

Expand All @@ -72,25 +91,19 @@ With most carrying a footer containing:
LOGIN: QString
SESSION: QString

With a few message-types (`UPLOAD_MOD`, `UPLOAD_MAP`), there are more fields.

## Incoming Packages

##### Mod Vault

* `{command: modvault, type: start}`: show the last 100 mods
* `{command: modvault, type: like, uid: <uid>}`: check if user liked the mod, otherwise increase the like counter
* `{command: modvault, type: download, uid: <uid>}`: notify server about a download (for download counter), does not start the download
* `{command: modvault, type: addcomment}`: not implemented

##### Social
Can be combined !, e.g. `{command: social, teaminvite: <...>, friends: <..>}`
* `{command: social, teaminvite: <player_name>}`: Invite a Player to a Team
* `{command: social, friends: <list of ALL friends>}`: Update the friends on the db
* `{command: social, foes: <list of ALL foes>}`: Update the foe (muted players) on the db
* `{command: social_add, friend|foe: <player_id>}`: Add a friend or foe
* `{command: social_remove, friend|foe: <player_id>}`: Remove a friend or foe

##### Avatar
* `{command: avatar, action: upload_avatar, name: <avatar_name>, file: <file_content>, description: <desc>}`: Admin Command to upload an avatar
* `{command: avatar, action: list_avatar}`: Send a list of available avatars
* `{command: avatar, action: select, avatar: <avatar_url>}`: Select a valid avatar for the player

Expand All @@ -101,16 +114,11 @@ Can be combined !, e.g. `{command: social, teaminvite: <...>, friends: <..>}`
##### Misc

* [deprecated] `{command: ask_session}`: response with a welcome command and a valid session (can be delayed)
* `{command: fa_state, state: <on|...>}`: notify the server if the game has launched or closed
* `{command: quit_team}`: Leave a team
* `{command: accept_team_proposal, leader: <leader_name>}`: Accept Team Invitation
* `{command: hello, version: <...>, login: <...>, password: <...>, unique_id: <...>, (session: <...>)}`: Accept Team Invitation
* `{command: hello, version: <...>, login: <...>, password: <...>, unique_id: <...>, (session: <...>)}`: Log in to the server

## Stream
## Stream (Deprecated)

The stream API is deprecated, but currently the following message types are supported:

* `PING`: response with a `PONG`
* `PONG`: internal state changed to ponged
* `UPLOAD_MOD, login, session, zipmap, infos, size, fileDaatas`: Upload a mod
* `UPLOAD_MAP, login, session, zipmap, infos, size, fileDatas`: Upload a map

0 comments on commit c337089

Please sign in to comment.