-
Notifications
You must be signed in to change notification settings - Fork 0
/
wserver.sh
executable file
·98 lines (70 loc) · 1.87 KB
/
wserver.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# /bin/bash
#/* Copyright (C) 2018-2019 Fully Toasted <[email protected]> - All Rights Reserved
# *
# * This file is part of Toasted Watchdog by Fully Toasted, Toasted Watchdog is Proprietary and Confidential.
# * Unauthorized copying of this file, project, and associated files via any medium is strictly prohibited.
# *
# * Written by Fully Toasted.
# */
# Server for the TTK
# WIP
# First, lock the environment so there is only ever 1 server.
set -a
refreshRate="0.03" #In seconds
args="$@"
function stopHandler(){
echo "[INFO] Stopping server..."; rm $slock 2>/dev/null
exit 0
}
trap stopHandler INT
slock="/home/minecraft/.sl"
function checkLock(){
if [ -f "$slock" ]; then
# Just start up the watchdog
echo "[INFO] Connecting to server..."
./wserver.sh -wc
else
if [ "$args" == "start" ]; then
echo "[INFO] Starting watchdog server..."
echo
touch $slock
./watchdog -d
else
./watchdog $args
serverLoopWrapper;
fi
fi
}
function serverLockToggle(){
if [ ! -f "$slock" ]; then
touch $slock
echo "[INFO] Lock state updated: locked"
else
rm $slock 2>/dev/null
echo "[INFO] Lock state updated: unlocked"
fi
exit 0
}
function serverLoopWrapper(){
tmux new-session -c $(pwd) -n ws -s ws "./wserver.sh -ws"
}
function doConnect(){
tmux -c $(pwd) attach -t ws || echo "[ERROR] Couldn't find watchdog server."
}
function doMainServerLoop(){
sleep 3
}
function doServerWatchLoop(){
serverLoopWrapper & echo "[INFO] Waiting for server..."; sleep 2
while true; do
sleep $refreshRate;
screenDraw; 2>/dev/null
done
}
case $1 in
-ls) serverLockToggle;;
-ws) doMainServerLoop;;
-wc) doConnect;;
start) checkLock; serverLoopWrapper;;
*) checkLock;;
esac