home · contact · privacy
Server/py: Use -O3 for libplomrogue.
[plomrogue] / start_server_python_client_union.sh
1 #!/bin/sh
2
3 # Abort the script on error.
4 set -e
5
6 # Don't let any log leftovers from before interfere.
7 if [ -e ./log ]
8 then
9     rm log
10 fi
11
12 # Give helpful message to players that want to start without compiling first.
13 if [ ! -e ./roguelike-client ]
14 then
15     echo 'No ./roguelike-client file found to execute. Try "./redo" first?'
16     false
17 fi
18
19 # Use shell script's arguments for server and pipe server output to log file.
20 # This script's wrapper script will read it out on exit.
21 python3 ./plomrogue-server.py "$@" > log 2>&1 &
22
23 # Give server some time to start up and exit on error.
24 sleep 0.01
25
26 # The client should not start if the server is not running. (If the server was
27 # running in the foreground, any error exit of it so far would be caught by "set
28 # -e" above. But "set -e" is blind to error codes generated in the background.)
29 kill -0 $! 2> /dev/null
30
31 # Give server some time (max. 10 seconds) to generate its worldstate file.
32 i=0
33 while [ ! -e server/worldstate ] && [ $i -le 1000 ]
34 do
35     sleep 0.01
36     i=`expr $i + 1`
37 done
38 if [ ! -e server/worldstate ]
39 then
40     echo "Server failed generating worldstate file within given time limit."
41     false
42 fi
43
44 # Only start the interface when everything else went well.
45 kill -0 $! 2> /dev/null
46 ./roguelike-client