zopanix / docker_factorio_server

Factorio Server in Docker
MIT License
31 stars 275 forks source link

Added server-settings.json usage #21

Closed hub23 closed 8 years ago

hub23 commented 8 years ago

As stated in Including server-settings.json #19, I would like to use the settings defined in server-settings.json. The needed settings can not be called by a parameter passed to the server binary, the file server-settings.json must be used to set the values.

Including these changes, /opt/factorio/server-settings.json will be generated and populated by cat in new_smart_launch.sh. If one or more variables are set while starting the container, the server-settings.json config file will be used to define additional settings by adding --server-settings /opt/factorio/server-settings.json to $factorio_command.

The following parameters are passable at container start to define settings:

FACTORIO_SERVER_NAME
FACTORIO_SERVER_DESCRIPTION
FACTORIO_SERVER_MAX_PLAYERS
FACTORIO_SERVER_VISIBILITY
FACTORIO_USER_USERNAME (needed if visibility is set to public)
FACTORIO_USER_PASSWORD (neede if visibility is set to public)
FACTORIO_USER_TOKEN (can be used instead of password)
FACTORIO_SERVER_GAME_PASSWORD (define server password)
FACTORIO_SERVER_VERIFY_IDENTITY (requires factorio.com account for user at login)

Conditions for execution of: factorio_command="$factorio_command --server-settings /opt/factorio/server-settings.json"

Are the following:

if [ "$FACTORIO_SERVER_NAME" ] \
|| [ "$FACTORIO_SERVER_DESCRIPTION" ] \
|| [ "$FACTORIO_SERVER_MAX_PLAYERS" ] \
|| [ "$FACTORIO_SERVER_VISIBILITY" ] \
|| [ "$FACTORIO_USER_USERNAME" ] \
|| [ "$FACTORIO_USER_PASSWORD" ] \
|| [ "$FACTORIO_USER_TOKEN" ] \
|| [ "$FACTORIO_SERVER_GAME_PASSWORD" ] \
|| [ "$FACTORIO_SERVER_VERIFY_IDENTITY" ]

The defaults (/opt/factorio/data/server-settings.example.json in zopanix/factorio:0.13.8) for the server-settings.json to contain are:

  "name": "Name of the game as it will appear in the game listing",
  "description": "Description of the game that will appear in the listing",
  "tags": ["game", "tags"],
  "max_players": "0",
  "visibility": "public",
  "username": "",
  "password": "",
  "game_password": "",
  "verify_user_identity": true

Some lines are hidden in this comment because of comments and braces.

If default values are missing from server-settings.json, the server wont start (Although I did not test one by one, just tested by removing "name", I assume all defaults are needed.).

I changed the following values away from default because I think default factorio.com account verification for user login or public listing, which also requires factorio.com account, is not wanted by most users:

  "name": "Factorio Server $VERSION"
  "visibility": "hidden",
  "verify_user_identity": false

Required credentials for public listing can be supplied by setting FACTORIO_USER_USERNAME and FACTORIO_USER_PASSWORD or FACTORIO_USER_TOKEN variables. A check for public visibility without FACTORIO_USER_USERNAME and FACTORIO_USER_PASSWORD or FACTORIO_USER_TOKEN defaults back to "hidden" when parameters are missing.

psykzz commented 8 years ago

You should remove the lineending and filespace changes. No need to modify them just to suit style as it can disturbs git blame.

psykzz commented 8 years ago

Other then some small comments, 👍 Saves having to hack together a solution by polluting an environment variable.

hub23 commented 8 years ago

You should remove the lineending and filespace changes.

I'm pretty new to git, that makes sense :grin:. I reverted the changes in new_smart_launch.sh.

hub23 commented 8 years ago

I will update here if new changes are tested.

psykzz commented 8 years ago

LGTM :+1:

hub23 commented 8 years ago

Tested a few cases and almost everything is working :+1: except factorio.com login token.

zopanix commented 8 years ago

hey, I'm accepting this bud only had time to read it quickly