1 | #!/bin/bash
|
---|
2 | # Version 3
|
---|
3 |
|
---|
4 | # Lists available 7dtd instances.
|
---|
5 | # Returns:
|
---|
6 | # 0
|
---|
7 |
|
---|
8 | . /usr/local/bin/7dtd-common.sh
|
---|
9 | checkRootLoadConf
|
---|
10 |
|
---|
11 | listInstances() {
|
---|
12 | printf "%-*s | %-*s | %-*s | %-*s\n" 20 "Instance name" 8 "Running" 7 "Players" 5 "Port"
|
---|
13 | printf -v line "%*s-+-%*s-+-%*s-+-%*s\n" 20 " " 8 " " 7 " " 5 " "
|
---|
14 | echo ${line// /-}
|
---|
15 | for I in $(getInstanceList); do
|
---|
16 | if [ $(isRunning $I) -eq 1 ]; then
|
---|
17 | run="yes"
|
---|
18 | tel=$(telnetCommand $I lp)
|
---|
19 | cur=`echo $tel | sed "s/\r/\n/g" | sed "s/^ //g" | grep "Total of " | cut -d\ -f 3`
|
---|
20 | else
|
---|
21 | run="no"
|
---|
22 | cur="-"
|
---|
23 | fi
|
---|
24 |
|
---|
25 | max=$(getConfigValue $I ServerMaxPlayerCount)
|
---|
26 | port=$(getConfigValue $I ServerPort)
|
---|
27 |
|
---|
28 | printf "%-*s | %*s | %2s/%2d | %5d\n" 20 "$I" 8 "$run" $cur $max $port
|
---|
29 | done
|
---|
30 | exit 0
|
---|
31 | }
|
---|
32 |
|
---|
33 | showInfo() {
|
---|
34 | checkInstanceValid $1
|
---|
35 |
|
---|
36 | line() {
|
---|
37 | printf " %-*s %s\n" 15 "$1" "$2"
|
---|
38 | }
|
---|
39 |
|
---|
40 | echo
|
---|
41 |
|
---|
42 | echo "7dtd instance: $1"
|
---|
43 | echo
|
---|
44 |
|
---|
45 | if [ $(isRunning $1) -eq 1 ]; then
|
---|
46 | echo "Status: Running"
|
---|
47 | echo "Open ports:"
|
---|
48 | netstat -nlp | grep $(getInstancePID $1) | sed -r 's/^([^ ]*)\s+.*[^ :]*:([^ ]*).*[^ :]*:[^ ]*.*/ \2 (\1)/g' | sort
|
---|
49 | tel=$(telnetCommand $1 lp)
|
---|
50 | cur=`echo $tel | sed "s/\r/\n/g" | sed "s/^ //g" | grep "Total of " | cut -d\ -f 3`
|
---|
51 | echo "Players: $cur"
|
---|
52 | else
|
---|
53 | echo "Status: NOT running"
|
---|
54 | fi
|
---|
55 |
|
---|
56 | echo
|
---|
57 | echo "Game info:"
|
---|
58 | line "Server name:" $(getConfigValue $1 ServerName)
|
---|
59 | line "Password:" $(getConfigValue $1 ServerPassword)
|
---|
60 | line "Max players:" $(getConfigValue $1 ServerMaxPlayerCount)
|
---|
61 | line "World:" $(getConfigValue $1 GameWorld)
|
---|
62 |
|
---|
63 | echo
|
---|
64 | echo "Network info:"
|
---|
65 | line "Port:" $(getConfigValue $1 ServerPort)
|
---|
66 | line "Public:" $(getConfigValue $1 ServerIsPublic)
|
---|
67 | if [ "$(getConfigValue $1 ControlPanelEnabled)" = "false" ]; then
|
---|
68 | cp="off"
|
---|
69 | else
|
---|
70 | cp="Port $(getConfigValue $1 ControlPanelPort), Pass $(getConfigValue $1 ControlPanelPassword)"
|
---|
71 | fi
|
---|
72 | line "Control Panel:" "$cp"
|
---|
73 | if [ "$(getConfigValue $1 TelnetEnabled)" = "false" ]; then
|
---|
74 | tn="off"
|
---|
75 | else
|
---|
76 | tn="Port $(getConfigValue $1 TelnetPort), Pass $(getConfigValue $1 TelnetPassword)"
|
---|
77 | fi
|
---|
78 | line "Telnet:" "$tn"
|
---|
79 |
|
---|
80 | echo
|
---|
81 | exit 0
|
---|
82 | }
|
---|
83 |
|
---|
84 | showHelp() {
|
---|
85 | name=`basename $0`
|
---|
86 | echo "Unknown parameter: $1"
|
---|
87 | echo "Usage:"
|
---|
88 | echo " $name [list] - List all instances"
|
---|
89 | echo " $name show <instance> - Show detailed info on the given instance"
|
---|
90 | exit 0
|
---|
91 | }
|
---|
92 |
|
---|
93 | COMMAND=${1:-list}
|
---|
94 |
|
---|
95 | case "$COMMAND" in
|
---|
96 | list)
|
---|
97 | listInstances
|
---|
98 | ;;
|
---|
99 | show)
|
---|
100 | showInfo $2
|
---|
101 | ;;
|
---|
102 | *)
|
---|
103 | showHelp $COMMAND
|
---|
104 | esac
|
---|
105 | exit 1
|
---|