Dedicaded server guide [windows, portable]

Find multiplayer games.
Tools/scripts to run a dedicated server.
Post Reply
Tuetenk0pp
Burner Inserter
Burner Inserter
Posts: 7
Joined: Wed Nov 27, 2019 7:14 am
Contact:

Dedicaded server guide [windows, portable]

Post by Tuetenk0pp »

Dedicaded server guide [windows, portable]
I ran across this very special use-case for a factorio server and it became quite a challenge for me, but I managed to set up a portable factorio server on windows, which loads mod and game updates automatically. In case you don't need your server to be portable, you can always pick the .exe installer for factorio and python (and you won't need to deal with the hassle to get pip installed), but there should still be some information of interest :D
Please leave comments and questions! I will try to have the post up to date
  1. Go to https://factorio.com/, login with your factorio-account and download the latest ‘MS Windows (64 bit zip package)’.
  2. Create a folder named ‘server’ somewhere e.g. on your desktop, where we will set up the factorio server. You will be able to move the folder anywhere you want and run the server even from an USB-Stick (that’s the whole point of this guide). Now create two subfolders named ‘lib’ (for any programs and scripts we use) and ‘settings’ (for your server-settings ect.).
  3. Unzip the downloaded factorio game to your server folder and rename the game folder to ‘factorio’.
  4. Now we want to install the tools that let us update both mods and server:
    1. Go to https://www.python.org/downloads/windows/ and download the latest ‘python embedded zip’ file. Now unzip the python folder to ‘lib’ and rename it to ‘py’.
      • In ‘py’ open a file ending on ‘._pth’ (there is only one) and remove the ‘#’ in the last line.
      • Go to https://pip.pypa.io/en/stable/installing/ and download ‘get-pip.py’ to ‘py’
      • Now open cmd and run the following code:

        Code: Select all

        YOUR_FOLDER_PATH\server\lib\py\python.exe YOUR_FOLDER_PATH\server\lib\py\get-pip.py
      • In the same cmd, run:

        Code: Select all

        YOUR_FOLDER_PATH\server\lib\py\python.exe -m pip install requests
        to install the ‘requests’ library for python, which we need for update automation.
    2. Get the amazing factorio-updater by narc0tiq (https://github.com/narc0tiq/factorio-updater) and unzip it to ‘lib’. Now we need to write a batch file to run the updater: To create a batch file you simply create a .txt file and change it to end on .bat. Name it ‘server-update.bat’ and paste the following:

      Code: Select all

      mkdir %~dp0tmp-update-packages
      %~dp0lib\py\python.exe %~dp0lib\factorio-updater-master\update_factorio.py -u service-username -t service-token -O %~dp0tmp-update-packages -p core-win64 -a %~dp0factorio\bin\x64\factorio.exe -x
      rmdir %~dp0tmp-update-packages
      Please note that you have to save the file directly in your server folder. We use the variable ‘%~dp0’ to mark the working folder. This is what allows the server package to be portable. Replace service-username and service-token with the ones you find in player-data.json of your current factorio installation (usually under %APPDATA% > roaming > factorio).
    3. Get the amazing factorio-mod-updater by pdemonaco (https://github.com/pdemonaco/factorio-mod-updater) and unzip it to ‘lib’. Now create a second batch file in the server folder and name it ‘mod-update.bat’ and paste the following code:

      Code: Select all

      %~dp0lib\py\python.exe %~dp0lib\factorio-mod-updater-master\mod_updater.py -s %~dp0settings\server-settings.json -m %~dp0factorio\mods --fact-path %~dp0factorio\bin\x64\factorio.exe --update
      Go back to the github for both the factorio-updater and the mod-updater to find out more about the used command lines.
  5. As you can see, the mod-updater uses a file called ‘server-settings.json’. I suggest you take the ‘server-settings.example.json’ from the game folder and copy paste it to the ‘settings’ folder. Don’t forget to rename the file and adjust the server settings. Also don’t forget to put your service-username and service-token so that the mod-updater can work.
  6. Now create ‘server-quick-start.bat’ and paste the following:

    Code: Select all

    %~dp0factorio\bin\x64\factorio.exe --start-server-load-latest --server-settings %~dp0settings\server-settings.json --use-server-whitelist --server-whitelist %~dp0settings\server-whitelist.json --server-adminlist %~dp0settings\server-adminlist.json --mod-directory %~dp0factorio\mods --console-log %~dp0server-console-log.txt
    pause
    I like to use a whitelist for my server so that’s why it says the whitelist stuff. If that’s not your use-case just remove the corresponding commands, but I strongly recommend you to use a ‘server-adminlist.json’, which should contain your service-username. Just like the server settings, you can find an example file (server-whitelist.example.json) in the game folder.
  7. Now if you want to go really fancy and would like to click just one batch file to start the whole updating process and the server afterwards, then create ‘server-start.bat’ and paste the following:

    Code: Select all

    call %~dp0server-update.bat
    call %~dp0mod-update.bat
    call %~dp0server-quick-start.bat
    Now we're ready!
  8. To host a brand new game I recommend to start the game just like you would in your regular factorio session, download all the mods you desire, do the mod-settings and create a nice savegame. Then close factorio and hit the ‘server-quick-start.bat’ (or ‘server-start.bat’). Windows might prompt you with a network settings window. Just hit ‘ok’ and watch your server go online :o
  9. In case you ever finish playing and want to shut your server down, run

    Code: Select all

    /quit
    in the open console and it should save and shut down properly.
Thanks for reading!

Post Reply

Return to “Multiplayer / Dedicated Server”