home · contact · privacy
Server, plugin: Refactor ai (plugin hooks).
[plomrogue] / start_server_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 # Abort if no proper Python version installed.
13 test=`command -v python3 | wc -l`
14 if [ 1 -gt $test ]
15 then
16     echo "FAILURE:"
17     echo "No python3 installed, but it's needed!"
18     exit 1
19 fi
20
21 # Give helpful message to players that want to start without compiling first.
22 if [ ! -e ./libplomrogue.so ]
23 then
24     echo 'No ./libplomrogue.so library found. Building …'
25     ./build.sh
26 fi
27
28 # Use shell script's arguments for server and pipe server output to log file.
29 # This script's wrapper script will read it out on exit.
30 python3 ./roguelike-server "$@" > log 2>&1 &
31
32 # Give server some time to start up and exit on error.
33 sleep 0.01
34
35 # The client should not start if the server is not running. (If the server was
36 # running in the foreground, any error exit of it so far would be caught by "set
37 # -e" above. But "set -e" is blind to error codes generated in the background.)
38 kill -0 $! 2> /dev/null
39
40 # Give server some time (max. 10 seconds) to generate its worldstate file.
41 i=0
42 while [ ! -e server_run/worldstate ] && [ $i -le 1000 ]
43 do
44     sleep 0.01
45     i=`expr $i + 1`
46 done
47 if [ ! -e server_run/worldstate ]
48 then
49     echo "Server failed generating worldstate file within given time limit."
50     false
51 fi
52
53 # Only start the interface when everything else went well.
54 kill -0 $! 2> /dev/null
55 python3 ./roguelike-client