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:

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 ?

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

Re: Dedicated Multiplayer Server Guide

Post by bkg »

On, i have now a char but get Stuck in the other one !

I try now to delete him again

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

Re: Dedicated Multiplayer Server Guide

Post by bkg »

Code: Select all

eysho@dev:~/private/factorio_alpha_x64_0.11.5$ wc -l /var/www/vhosts/factorio/private/factorio_alpha_x64_0.11.5/factorio-current.log | grep -o "[0-9]\+"
7
64
0
11
5
eysho@dev:~/private/factorio_alpha_x64_0.11.5$ ./pauser
./pauser: line 11: 7
64
0
11
5: syntax error in expression (error token is "64
0
11
5")
eysho@dev:~/private/factorio_alpha_x64_0.11.5$
Thats the error and you see teh grep work over shell

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

Re: Dedicated Multiplayer Server Guide

Post by bkg »

Ok now i have the problem that not 2 players can connect simul. anny idea why?

The peer broke, and he show the ip from the guy thats allready in, for no peer to ip. XX User 1 . But why peer to user. and not to server?

The user connect and then the console reload he show User () and user x and y , and reload.

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

Re: Dedicated Multiplayer Server Guide

Post by Alkalyne »

Hello, for your pauser script, what is your Operating System ?
can you add :
wc -l /var/www/vhosts/factorio/private/factorio_alpha_x64_0.11.5/factorio-current.log | grep -o "[0-9]\+" | head -1
in the script ?

And for your last problem I don't know maybe a 0.11.5 bug (I know there is some problems with 0.11.4 and 0.11.5)
The user connect and then the console reload he show User () and user x and y , and reload.
I don't know what do you mean.

I don't know how the multiplayer works, but maybe there is a problem between user 1 and user 2 ? Are you on the same network ? maybe a firewall problem ?

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

Re: Dedicated Multiplayer Server Guide

Post by bkg »

Ok after i edit the pasuer looks so :

bkg@dev:~/private/server/factorio.bkg.me/v0.11.3$ ./pauser_v0.11.3
QUITS: 1
JOINS: 1
JOINSGAME:1
BOOT : Pause on Boot
./pauser_v0.11.3: line 44: bc: command not found
./pauser_v0.11.3: line 45: bc: command not found
Usage: mousemove [options] <x> <y>
-c, --clearmodifiers - reset active modifiers (alt, etc) while typing
--screen SCREEN - which screen to move on, default is current screen
--sync - only exit once the mouse has moved
-w, --window <windowid> - specify a window to move relative to.
You specified the wrong number of args (expected 2 coordinates or 'restore').
Paused
0
QUITS: 0
JOINS: 0
JOINSGAME:0
0

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

Re: Dedicated Multiplayer Server Guide

Post by Alkalyne »

you need to install bc

Code: Select all

apt-get install bc
:

przerwap
Manual Inserter
Manual Inserter
Posts: 3
Joined: Fri Aug 29, 2014 9:01 pm
Contact:

Re: Dedicated Multiplayer Server Guide

Post by przerwap »

Parsing the log seems like such a ghetto hack.. Why not just have the client do the pausing/unpausing directly from the game?

EDIT: And by 'client' I mean the 'dedicated server'

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

Re: Dedicated Multiplayer Server Guide

Post by Alkalyne »

All this guide is a hack waiting for an official release.

Dedicaced server mode is not supported by the game, and the multiplayer is really buggy.

We parse the log to see when a player connect and we pause/unpause the game. It works, so why do you want to do it in another way ?

Code: Select all

 directly from the game?
How ?

If you know how to do it in another way you can share the information

przerwap
Manual Inserter
Manual Inserter
Posts: 3
Joined: Fri Aug 29, 2014 9:01 pm
Contact:

Re: Dedicated Multiplayer Server Guide

Post by przerwap »

All you're doing is counting the number of players by parsing the log, no? Why not just use the built-in LUA scripting to simply check if(games.players.length == 1) { game.pause(); } else { game.unpause() }

harch
Burner Inserter
Burner Inserter
Posts: 7
Joined: Tue Jan 20, 2015 7:37 am
Contact:

Re: Dedicated Multiplayer Server Guide

Post by harch »

if(games.players.length == 1) { game.pause(); } else { game.unpause() }
unfortunately there is no such function
i tried to reduce game speed to 0.1(it's minimum)
but i'm not too good in lua to do it, so just nothing happens

is there someone who got working solution for 0.11.13 without using xdotool?

Post Reply

Return to “Multiplayer / Dedicated Server”