Dedicated Multiplayer Server Guide

Find multiplayer games.
Tools/scripts to run a dedicated server.
icecube45
Burner Inserter
Burner Inserter
Posts: 18
Joined: Mon Nov 03, 2014 5:36 am
Contact:

Dedicated Multiplayer Server Guide

Post by icecube45 »

REVISED VERSION FOLLOWS:

This guide was written as if you were using ubuntu 14.04 server.

First off, we need to install some dependencies, do this with the following:

Code: Select all

apt-get install xorg xfce4-session x11vnc xdotool
x11vnc is not completely needed, but it's nice for debugging.

now, we're going to start a screen and xdummy interface

Code: Select all

screen -R x
sudo Xorg -noreset +extension GLX +extension RANDR +extension RENDER -logfile ./10.log -config ./xorg.conf :10
Press ctrl+a+d to quit the screen.

We now need to start xfce on xdummy, as xdotool (which I used for my pausing script) needs a window manager.

Code: Select all

screen -R xfce
export DISPLAY=:10
startxfce4
again, ctrl+a+d will quit this

Now, we need to turn off xfce's screensaver, this might cause some issues if you skip this step

Code: Select all

xset s off
Now, the following is lacking a guide, due to it involving acquiring factorio.
Download factorio, and upload it to your server

back at the server, we need to create a save directory, and make factorio executable

Code: Select all

cd factorio
chmod +x bin/x64/factorio
mkdir saves
We now need to create a save file, this must be done on a local copy of factorio
In your new savefile, type the following into the console:

Code: Select all

/c local char = game.players[1].character; game.players[1].character = nil; char.die()
Save your game, and then upload the savefile to the server's factorio/saves directory

Back to the server, we need to make a script for launching factorio

Code: Select all

cd
nano startfactorio
Inside of this, copy paste the following

Code: Select all

#!/bin/bash
name="mapname.zip"
~/factorio/bin/x64/factorio --mp-load-game $name #assumes 64 bit 
Change mapname.zip to the name of your map.

now, we need to change startfactorio's permissions

Code: Select all

chmod +x startfactorio
now we can actually start running factorio

Code: Select all

screen -R factorio
export DISPLAY=:10
./startfactorio
ctrl+a+d to quit this.

The last thing left is the autopauser script (prevents biters from destroying your base when you are offline).

Code: Select all

screen -R pauser
nano pauser
now paste into it the following

Code: Select all

	

    #!/bin/bash
    PATHTOLOG="/root/factorio/factorio-current.log"
     
    OLDPLAYERCOUNT=0
    PLAYERCOUNT=0
    NUMBEROFLINESOLD=0
     
    while :; do
      #get the current nuber of log entries
      NUMBEROFLINES=$(wc -l /root/factorio/factorio-current.log | grep -o "[0-9]\+")
      ABSOLUTELINES=$((NUMBEROFLINES-NUMBEROFLINESOLD))
      #only look at new lines
      TAILEDLOG=$(tail -$ABSOLUTELINES $PATHTOLOG)
      #grab Joins PlayerJoinGame
      JOINSGAME=$(echo $TAILEDLOG | grep "MultiplayerManager changing state from(InGameSendingMap) to(InGame)" | wc -l | grep -o "[0-9]\+")
      #grab peer leaving
      QUITS=$(echo $TAILEDLOG | grep "PlayerLeaveGame" | wc -l | grep -o "[0-9]\+")
      #grab peer timeout
      DROPOUTS=$(echo $TAILEDLOG | grep "is not responding, dropping" | wc -l | grep -o "[0-9]\+")
      BOOT=$(echo $TAILEDLOG | grep "MultiplayerManager changing state from(CreatingGame) to(InGame)" | wc -l | grep -o "[0-9]\+")
      QUITS=$((QUITS+DROPOUTS))
      echo "QUITS: "$QUITS
      JOINS=$((JOINSGAME))
      echo "JOINS: "$JOINS
      echo "JOINSGAME:"$JOINSGAME
      PLAYERCOUNT=$((PLAYERCOUNT+JOINS))
      PLAYERCOUNT=$((PLAYERCOUNT-QUITS))
      if [ $BOOT -eq 1 ]
      then
        WID=$(xdotool search Factorio 2>/dev/null)
        xdotool windowactivate --sync $WID
        xdotool key Escape
        xdotool key shift+space
      fi
     
      if [ $PLAYERCOUNT -eq 1 -a $OLDPLAYERCOUNT -eq 0 ]
      then
        echo "detected players, unpausing"
        WID=$(xdotool search Factorio 2>/dev/null)
        xdotool windowactivate --sync $WID
        xdotool key shift+space
      fi
      if [ $PLAYERCOUNT -eq 0 -a $OLDPLAYERCOUNT -eq 1 ]
      then
        echo "0 players, pausing"
        WID=$(xdotool search Factorio 2>/dev/null)
        xdotool windowactivate --sync $WID
        xdotool key shift+space
      fi
     
     
      #REMOVE the following line if you don't want to see current players.
      echo $PLAYERCOUNT
     
      OLDPLAYERCOUNT=$PLAYERCOUNT
      NUMBEROFLINESOLD=$NUMBEROFLINES
      #change to number of seconds between player count update [default: 1 sec]
      sleep 1
    done

Save the file, then we can continue

Code: Select all

chmod +x pauser
export DISPLAY=:10
./pauser
ctrl+a+d

hopefully, everything should be running at this point

the pauser script will require a restart after desyncs.
Last edited by icecube45 on Sun Nov 09, 2014 7:11 pm, edited 1 time in total.

x10sion
Inserter
Inserter
Posts: 24
Joined: Fri Oct 31, 2014 9:42 am
Contact:

Re: Dedicated Multiplayer Server Guide

Post by x10sion »

Hi,

Thank you for this, i can kind of understand this but maybe some others may have a big issue with this. Once you have had your sleep could you put a step by step guide on what needs to be done.

Another thing have you tried this on a hosted server or local only?

thank you again

Ekibit
Manual Inserter
Manual Inserter
Posts: 3
Joined: Sat Nov 08, 2014 4:44 pm
Contact:

Re: Dedicated Multiplayer Server Guide

Post by Ekibit »

What kind of devil's chanting is this??? :oops:

x10sion
Inserter
Inserter
Posts: 24
Joined: Fri Oct 31, 2014 9:42 am
Contact:

Re: Dedicated Multiplayer Server Guide

Post by x10sion »

FYI

This doesnt seem to work on Centos

icecube45
Burner Inserter
Burner Inserter
Posts: 18
Joined: Mon Nov 03, 2014 5:36 am
Contact:

Re: Dedicated Multiplayer Server Guide

Post by icecube45 »

x10sion wrote:Hi,

Thank you for this, i can kind of understand this but maybe some others may have a big issue with this. Once you have had your sleep could you put a step by step guide on what needs to be done.

Another thing have you tried this on a hosted server or local only?

thank you again
I have revised it, and have done this on both a local server, a vps, and a virtual machine.
Ekibit wrote:What kind of devil's chanting is this??? :oops:
Yea.. I was pretty tired.
Hopefully you can understand it now
x10sion wrote:FYI

This doesnt seem to work on Centos
Please let me know what fails, chances are I missed something in my guide

x10sion
Inserter
Inserter
Posts: 24
Joined: Fri Oct 31, 2014 9:42 am
Contact:

Re: Dedicated Multiplayer Server Guide

Post by x10sion »

Ok just rebuilt my server in ubuntu now and it seems to be working better. will let you know if this works fine on my hosted VPS

Thanks for this guide! if this works you will be labelled Factorio Server God :P

kagurazaki
Burner Inserter
Burner Inserter
Posts: 15
Joined: Thu May 29, 2014 6:11 pm
Contact:

Re: Dedicated Multiplayer Server Guide

Post by kagurazaki »

is there going to be a windows server guide?

x10sion
Inserter
Inserter
Posts: 24
Joined: Fri Oct 31, 2014 9:42 am
Contact:

Re: Dedicated Multiplayer Server Guide

Post by x10sion »

kagurazaki wrote:is there going to be a windows server guide?
dont think so just yet.... i think this guide is a "hack" as there is no official dedicated server so the chances that there is a windows version seems very unlikely

icecube45
Burner Inserter
Burner Inserter
Posts: 18
Joined: Mon Nov 03, 2014 5:36 am
Contact:

Re: Dedicated Multiplayer Server Guide

Post by icecube45 »

x10sion wrote:
kagurazaki wrote:is there going to be a windows server guide?
dont think so just yet.... i think this guide is a "hack" as there is no official dedicated server so the chances that there is a windows version seems very unlikely
Unfortunatly I am lacking in experience for windows server, so I won't be able to write that guide.
However, the flag for loading a game and hosting it (--mp-load-game) should exsist withen any factorio binary

kagurazaki
Burner Inserter
Burner Inserter
Posts: 15
Joined: Thu May 29, 2014 6:11 pm
Contact:

Re: Dedicated Multiplayer Server Guide

Post by kagurazaki »

i did make a server on windows, and use the command for removing the server player, but i cant seem to get the game to pause when everyone leaves and also the server is not autosaving, So if/When it crashes you cant reload a save.
(i Used Teamviewer)

icecube45
Burner Inserter
Burner Inserter
Posts: 18
Joined: Mon Nov 03, 2014 5:36 am
Contact:

Re: Dedicated Multiplayer Server Guide

Post by icecube45 »

kagurazaki wrote:i did make a server on windows, and use the command for removing the server player, but i cant seem to get the game to pause when everyone leaves and also the server is not autosaving, So if/When it crashes you cant reload a save.
(i Used Teamviewer)

Well, the script is written in bash... I might rewrite it in python

Alkalyne
Inserter
Inserter
Posts: 25
Joined: Sun Jun 15, 2014 11:39 pm
Contact:

Re: Dedicated Multiplayer Server Guide

Post by Alkalyne »

Very nice :)

I got it working, thank you very much :)

Alkalyne
Inserter
Inserter
Posts: 25
Joined: Sun Jun 15, 2014 11:39 pm
Contact:

Re: Dedicated Multiplayer Server Guide

Post by Alkalyne »

I just made a change in the startfactorio script :

Code: Select all

name=$(find /path/to/factorio/saves -type f -printf '%T@ %f\n' | sort -n | tail -1 | cut -f2- -d" ")
That's allows to restart factorio easily using the last autosave.

NOTE : The pauser script don't work, since the key Shift+space does not pause the game in multiplayer since 11.2 ( :( )

But with the autosave I just need to stop the game to start it later

EDIT :
I have updated the pauser script, now it will pause the game :

Code: Select all

#!/bin/bash
PATHTOLOG="/var/www/factorio/factorio-current.log"

OLDPLAYERCOUNT=0
PLAYERCOUNT=0
NUMBEROFLINESOLD=0
 
while :; do
  #get the current nuber of log entries
  NUMBEROFLINES=$(wc -l /var/www/factorio/factorio-current.log | grep -o "[0-9]\+")
  ABSOLUTELINES=$((NUMBEROFLINES-NUMBEROFLINESOLD))
  #only look at new lines
  TAILEDLOG=$(tail -$ABSOLUTELINES $PATHTOLOG)
  #grab Joins PlayerJoinGame
  JOINSGAME=$(echo $TAILEDLOG | grep "MultiplayerManager changing state from(InGameSendingMap) to(InGame)" | wc -l | grep -o "[0-9]\+")
  #grab peer leaving
  QUITS=$(echo $TAILEDLOG | grep "PlayerLeaveGame" | wc -l | grep -o "[0-9]\+")
  #grab peer timeout
  DROPOUTS=$(echo $TAILEDLOG | grep "is not responding, dropping" | wc -l | grep -o "[0-9]\+")
  BOOT=$(echo $TAILEDLOG | grep "MultiplayerManager changing state from(CreatingGame) to(InGame)" | wc -l | grep -o "[0-9]\+")
  QUITS=$((QUITS+DROPOUTS))
  echo "QUITS: "$QUITS
  JOINS=$((JOINSGAME))
  echo "JOINS: "$JOINS
  echo "JOINSGAME:"$JOINSGAME
  PLAYERCOUNT=$((PLAYERCOUNT+JOINS))
  PLAYERCOUNT=$((PLAYERCOUNT-QUITS))
  if [ $BOOT -eq 1 ]
  then
	echo "BOOT : Pause on Boot"
	WID=$(xdotool search Factorio 2>/dev/null)
	xdotool windowactivate --sync $WID
	unset x y w h
        #need to press Escape once because of the Audio popup
        xdotool key Escape
	sleep 1
        xdotool key Escape
	sleep 1
        eval $(xwininfo -id $(xdotool getactivewindow) |
        sed -n -e "s/^ \+Absolute upper-left X: \+\([0-9]\+\).*/x=\1/p" \
           -e "s/^ \+Absolute upper-left Y: \+\([0-9]\+\).*/y=\1/p" \
           -e "s/^ \+Width: \+\([0-9]\+\).*/w=\1/p" \
           -e "s/^ \+Height: \+\([0-9]\+\).*/h=\1/p" )
        width=`echo "0.5 * $w" | bc`
        height=`echo "0.45 * $h" | bc`
        xdotool mousemove --window $WID $width $height
        xdotool click 1
	sleep 1
	xdotool key Escape
	echo "Paused"
  fi
 
  if [ $PLAYERCOUNT -eq 1 -a $OLDPLAYERCOUNT -eq 0 ]
  then
	echo "detected players, unpausing"
	WID=$(xdotool search Factorio 2>/dev/null)
	xdotool windowactivate --sync $WID
	unset x y w h
	xdotool key Escape
	sleep 1
	eval $(xwininfo -id $(xdotool getactivewindow) |
	sed -n -e "s/^ \+Absolute upper-left X: \+\([0-9]\+\).*/x=\1/p" \
           -e "s/^ \+Absolute upper-left Y: \+\([0-9]\+\).*/y=\1/p" \
           -e "s/^ \+Width: \+\([0-9]\+\).*/w=\1/p" \
           -e "s/^ \+Height: \+\([0-9]\+\).*/h=\1/p" )
	width=`echo "0.5 * $w" | bc`
	height=`echo "0.45 * $h" | bc`
	xdotool mousemove --window $WID $width $height
	xdotool click 1
	sleep 1
	xdotool key Escape
  fi
  if [ $PLAYERCOUNT -eq 0 -a $OLDPLAYERCOUNT -eq 1 ]
  then
	echo "0 players, pausing"
	WID=$(xdotool search Factorio 2>/dev/null)
	xdotool windowactivate --sync $WID
	        unset x y w h
        xdotool key Escape
	sleep 1
        eval $(xwininfo -id $(xdotool getactivewindow) |
        sed -n -e "s/^ \+Absolute upper-left X: \+\([0-9]\+\).*/x=\1/p" \
           -e "s/^ \+Absolute upper-left Y: \+\([0-9]\+\).*/y=\1/p" \
           -e "s/^ \+Width: \+\([0-9]\+\).*/w=\1/p" \
           -e "s/^ \+Height: \+\([0-9]\+\).*/h=\1/p" )
        width=`echo "0.5 * $w" | bc`
        height=`echo "0.45 * $h" | bc`
        xdotool mousemove --window $WID $width $height
        xdotool click 1
	sleep 1
	xdotool key Escape
  fi
 
 
  #REMOVE the following line if you don't want to see current players.
  echo $PLAYERCOUNT
 
  OLDPLAYERCOUNT=$PLAYERCOUNT
  NUMBEROFLINESOLD=$NUMBEROFLINES
  #change to number of seconds between player count update [default: 1 sec]
  sleep 1
done

Spike121
Manual Inserter
Manual Inserter
Posts: 3
Joined: Sat Nov 29, 2014 1:58 pm
Contact:

Re: Dedicated Multiplayer Server Guide

Post by Spike121 »

I followed this pretty well, however when I ./startfactorio, I get an error. I'm not sure if this is a bug in the code or something I've done, but...

Code: Select all

./startfactorio: line 3: 9211 Segmentation fault            (core dumped) 
I did try this twice... another time it was

Code: Select all

2659 Segmentation fault
- any ideas? Thanks in advance!

Alkalyne
Inserter
Inserter
Posts: 25
Joined: Sun Jun 15, 2014 11:39 pm
Contact:

Re: Dedicated Multiplayer Server Guide

Post by Alkalyne »

When did you have this error ? (Did you have some logs before this error ?)

What is your game version ? Savegame version ?

EDIT : I found the problem
Before running startfactorio type this :

Code: Select all

export DISPLAY=:10
If you already did that, maybe you have an error with Xorg

If you don't know where is the error you can give us Xorg logs here

1n5aN1aC
Burner Inserter
Burner Inserter
Posts: 7
Joined: Mon Feb 24, 2014 8:04 pm
Contact:

Re: Dedicated Multiplayer Server Guide

Post by 1n5aN1aC »

So I was incredibly exceited someone had made a guide for this, and I tried setting it up on my linux VM I had pretty much idle, the problem is I spent several hours banging my head against the wall, accomplishing nothing.

The problem originates fromt he fact that this seems like it shoudl work wonderfully on a dedicated server, or a fulll virtualization platform. (Such as KVM) BUT.... Won't work on a container-based virtualization platform. (such as OpenVZ)

On your second step, it can't start up X, throwing an error that:

Code: Select all

"xf86OpenConsole: Cannot find a free VT"
It seems to be that startx, and similar commands, (Xorg....) can't start an x instance in a truely virtualized way, but only work if you have virtual terminals, from an actual physical (even if the physical is emulated) terminal. (Ctl-Alt-F1, Ctrl-Alt-F2, etc)

What confuses me though, is that I was able to start a virtual X interface using:

Code: Select all

vnc4server :1
And then VNC'ing in to the server, on port 5901.

Do you know if there is a way to further emulate this? because all your commands assume that the server thinks it has a physical Virtual Terminal, and that tty0 actually exists. (I beleive that tty0 is essentually just a link to the currently active tty, which.... in many virtualized environments, doesn't exist.)

Alkalyne
Inserter
Inserter
Posts: 25
Joined: Sun Jun 15, 2014 11:39 pm
Contact:

Re: Dedicated Multiplayer Server Guide

Post by Alkalyne »

Before trying to resolve this problem, are you sure that your virtual machine is powerfull enough to run factorio ?

I was running factorio on a Intel E2180 2 GHz and this was not enough so you need to be sure that you can run it on your Virtual machine (Specs ?)

bkg
Burner Inserter
Burner Inserter
Posts: 8
Joined: Tue Dec 09, 2014 5:28 pm
Contact:

Re: Dedicated Multiplayer Server Guide

Post by bkg »

Hello i have a little probs so 2x first one is

Code: Select all

94548.962737  Info Scenario.cpp:157: Map version 0.11.5-0
94549.207123  Info PosixUDPSocket.cpp:33: Opening socket at port 34197
94549.207543  Info Router.cpp:365: Router state -> Connected
94549.207712  Info Synchronizer.cpp:61: NetworkTick(0) initialized Synchronizer local peer(0).
94549.207792  Notice Router.cpp:74: Hosting game at port 34197, peerID 0, session magic 44024
94549.207819  Info MultiplayerManager.cpp:388: MultiplayerManager changing state from(CreatingGame) to(InGame)
94549.207849  Info NetworkInputHandler.cpp:29: mapTick(79204) networkTick(0) initialized NetworkInputHandler local peer(0).
94549.279580  Info MultiplayerManager.cpp:727: Received peer info for peer(0) username().
94549.330149  Info GameActionHandler.cpp:1516: MapTick(79212) processed PlayerJoinGame peerID(0) playerIndex(1) mode(connect)
95915.361884  Info Router.cpp:522: networkTick(127009) adding peer(1) address(x.x.x.x:34197)
95915.561926  Info MultiplayerManager.cpp:727: Received peer info for peer(0) username().
95915.562017  Info MultiplayerManager.cpp:727: Received peer info for peer(1) username(bKg).
95915.562049  Info MultiplayerManager.cpp:727: Received peer info for peer(1) username(bKg).
95915.713049  Info MultiplayerManager.cpp:919: networkTick(127028) mapTick(161195) starting mapAlign
95915.713177  Info MultiplayerManager.cpp:398: changing mapAlign state from(NotAligned) to(Aligning)
95915.713279  Info NetworkInputHandler.cpp:311: expectedMapTick(161195) adding peer(1) success(true).
95915.713336  Info MultiplayerManager.cpp:876: networkTick(127028) mapTick(161195) adding mapAlignTask(MapUploadAlignTask peer(1))
95915.778709  Info MultiplayerManager.cpp:581: networkTick(127034) mapTick(161195) received MapAlignAction from peer(0), mapTickForAligning(161195) appliedTickClosuresCount(0)
95915.778829  Info MultiplayerManager.cpp:530: networkTick(127034) mapTick(161195) received mapAlignStateChanged peerID(1) mapAlignState(NotAligning)
95915.778883  Info MultiplayerManager.cpp:1019: networkTick(127034) mapTick(161195) mapAlign finished targetTick(161195) updating map and running the tasks ...
95915.778938  Info MultiplayerManager.cpp:398: changing mapAlign state from(Aligning) to(AlignedRunningTasks)
95916.162475  Info MultiplayerManager.cpp:388: MultiplayerManager changing state from(InGame) to(InGameSendingMap)
95916.162523  Info TransferSource.cpp:29: Serving file /var/*/private/factorio_alpha_x64_0.11.5/temp/mp-download.zip for peer 1
95922.314348  Notice TransferSource.cpp:64: Canceling serving for peer 1
95922.314644  Info MultiplayerManager.cpp:388: MultiplayerManager changing state from(InGameSendingMap) to(InGame)
95922.314711  Info MultiplayerManager.cpp:700: Received MapDownloadFinished from peer(1) stopping transfer.
95922.314738  Info MultiplayerManager.cpp:398: changing mapAlign state from(AlignedRunningTasks) to(AlignedTasksCompleted)
95922.314777  Info MultiplayerManager.cpp:398: changing mapAlign state from(AlignedTasksCompleted) to(AlignedFinished)
95922.314813  Info MultiplayerManager.cpp:999: networkTick(127610) mapTick(161195) stopping mapAlign
95922.314870  Info MultiplayerManager.cpp:398: changing mapAlign state from(AlignedFinished) to(NotAligned)
95922.430826  Info MultiplayerManager.cpp:530: networkTick(127622) mapTick(161202) received mapAlignStateChanged peerID(1) mapAlignState(NotAligned)
95922.431776  Info NetworkInputHandler.cpp:206: no crc for mapTick(161195) by peer(1)
95922.431889  Info GameActionHandler.cpp:1516: MapTick(161203) processed PlayerJoinGame peerID(1) playerIndex(0) mode(connect)
95922.449447  Info NetworkInputHandler.cpp:206: no crc for mapTick(161196) by peer(1)
95922.464090  Info NetworkInputHandler.cpp:206: no crc for mapTick(161197) by peer(1)
95922.484439  Info NetworkInputHandler.cpp:206: no crc for mapTick(161198) by peer(1)
95922.497411  Info NetworkInputHandler.cpp:206: no crc for mapTick(161199) by peer(1)
95922.514998  Info NetworkInputHandler.cpp:206: no crc for mapTick(161200) by peer(1)
95922.531496  Info NetworkInputHandler.cpp:206: no crc for mapTick(161201) by peer(1)
95922.548403  Info NetworkInputHandler.cpp:206: no crc for mapTick(161202) by peer(1)
I can join the server but can not move my Char etc.

The secend ist the pause script it make me a eroor like this :

Code: Select all

./pauser: line 11: 51
64
0
11
5: syntax error in expression (error token is "64
0
11
5")
YOu have mybe some idea?

Alkalyne
Inserter
Inserter
Posts: 25
Joined: Sun Jun 15, 2014 11:39 pm
Contact:

Re: Dedicated Multiplayer Server Guide

Post by Alkalyne »

The secend ist the pause script it make me a eroor like this :
It's seem to be a wrong path configured in pauser script :

What do you have here :
PATHTOLOG="/root/factorio/factorio-current.log"
And here
NUMBEROFLINES=$(wc -l /root/factorio/factorio-current.log | grep -o "[0-9]\+")
I can join the server but can not move my Char etc.
Do you see your Char ?

Can you try with a normal savegame (without /c local char = game.players[1].character; game.players[1].character = nil; char.die() ) ?

bkg
Burner Inserter
Burner Inserter
Posts: 8
Joined: Tue Dec 09, 2014 5:28 pm
Contact:

Re: Dedicated Multiplayer Server Guide

Post by bkg »

It´s have the right path setet, and yes let me short try it with the other save game

And thx for quik replay like to play online ^^

Ok look this errors :

http://pastebin.com/bL5R62aC

Thats normal ?

Post Reply

Return to “Multiplayer / Dedicated Server”