home · contact · privacy
Fix buggy healthy_addch().
[plomrogue] / start_server_client_union.sh
1 #!/bin/sh
2
3 # Abort the script on error.
4 set -e
5
6 # Run script in its own process group so SIGINT doesn't kill parent script.
7 set -m
8
9 # Don't let any log leftovers from before interfere.
10 if [ -e ./log ]
11 then
12     rm log
13 fi
14
15 # Abort if no proper Python version installed.
16 test=`command -v python3 | wc -l`
17 if [ 1 -gt $test ]
18 then
19     echo "FAILURE:"
20     echo "No python3 installed, but it's needed!"
21     exit 1
22 fi
23
24 # Give helpful message to players that want to start without compiling first.
25 if [ ! -e ./libplomrogue.so ]
26 then
27     echo 'No ./libplomrogue.so library found. Building …'
28     ./build.sh
29 fi
30
31 # Use shell script's arguments for server and pipe server output to log file.
32 # This script's wrapper script will read it out on exit.
33 python3 ./roguelike-server "$@" > log 2>&1 &
34
35 # Give server some time to start up and exit on error.
36 sleep 0.1
37
38 # The client should not start if the server is not running. (If the server was
39 # running in the foreground, any error exit of it so far would be caught by "set
40 # -e" above. But "set -e" is blind to error codes generated in the background.)
41 kill -0 $! 2> /dev/null
42
43 # Give server some time (max. 10 seconds) to generate its worldstate file.
44 i=0
45 echo -n "Waiting for server to set up world: "
46 while [ ! -e server_run/worldstate ] && [ $i -le 100 ]
47 do
48     echo -n '.'
49     sleep 0.1
50     i=`expr $i + 1`
51 done
52 echo
53 if [ ! -e server_run/worldstate ]
54 then
55     kill -9 $!
56     rm -rf server_run
57     echo "Server failed generating worldstate file within time limit."
58     false
59 fi
60
61 # Only start the interface when everything else went well.
62 kill -0 $! 2> /dev/null
63 python3 ./roguelike-client