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