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