[9] | 1 | #!/bin/bash
|
---|
[14] | 2 | # Version 3
|
---|
[10] | 3 |
|
---|
[9] | 4 | # Lists available 7dtd instances.
|
---|
| 5 | # Returns:
|
---|
| 6 | # 0
|
---|
[11] | 7 |
|
---|
[9] | 8 | . /usr/local/bin/7dtd-common.sh
|
---|
| 9 | checkRootLoadConf
|
---|
| 10 |
|
---|
[13] | 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// /-}
|
---|
[14] | 15 | for I in $(getInstanceList); do
|
---|
[16] | 16 | if [ $(isRunning $I) -eq 1 ]; then
|
---|
[13] | 17 | run="yes"
|
---|
[14] | 18 | tel=$(telnetCommand $I lp)
|
---|
[13] | 19 | cur=`echo $tel | sed "s/\r/\n/g" | sed "s/^ //g" | grep "Total of " | cut -d\ -f 3`
|
---|
| 20 | else
|
---|
| 21 | run="no"
|
---|
[14] | 22 | cur="-"
|
---|
[13] | 23 | fi
|
---|
| 24 |
|
---|
[14] | 25 | max=$(getConfigValue $I ServerMaxPlayerCount)
|
---|
| 26 | port=$(getConfigValue $I ServerPort)
|
---|
[13] | 27 |
|
---|
[14] | 28 | printf "%-*s | %*s | %2s/%2d | %5d\n" 20 "$I" 8 "$run" $cur $max $port
|
---|
[13] | 29 | done
|
---|
| 30 | exit 0
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | showInfo() {
|
---|
[14] | 34 | checkInstanceValid $1
|
---|
[13] | 35 |
|
---|
| 36 | line() {
|
---|
| 37 | printf " %-*s %s\n" 15 "$1" "$2"
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | echo
|
---|
| 41 |
|
---|
| 42 | echo "7dtd instance: $1"
|
---|
| 43 | echo
|
---|
| 44 |
|
---|
[16] | 45 | if [ $(isRunning $1) -eq 1 ]; then
|
---|
[13] | 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)
|
---|
[11] | 50 | cur=`echo $tel | sed "s/\r/\n/g" | sed "s/^ //g" | grep "Total of " | cut -d\ -f 3`
|
---|
[13] | 51 | echo "Players: $cur"
|
---|
[9] | 52 | else
|
---|
[13] | 53 | echo "Status: NOT running"
|
---|
[9] | 54 | fi
|
---|
| 55 |
|
---|
[13] | 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
|
---|