[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 | run=$(isRunning $I)
|
---|
[13] | 17 | if [ $run -eq 1 ]; then
|
---|
| 18 | run="yes"
|
---|
[14] | 19 | tel=$(telnetCommand $I lp)
|
---|
[13] | 20 | cur=`echo $tel | sed "s/\r/\n/g" | sed "s/^ //g" | grep "Total of " | cut -d\ -f 3`
|
---|
| 21 | else
|
---|
| 22 | run="no"
|
---|
[14] | 23 | cur="-"
|
---|
[13] | 24 | fi
|
---|
| 25 |
|
---|
[14] | 26 | max=$(getConfigValue $I ServerMaxPlayerCount)
|
---|
| 27 | port=$(getConfigValue $I ServerPort)
|
---|
[13] | 28 |
|
---|
[14] | 29 | printf "%-*s | %*s | %2s/%2d | %5d\n" 20 "$I" 8 "$run" $cur $max $port
|
---|
[13] | 30 | done
|
---|
| 31 | exit 0
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | showInfo() {
|
---|
[14] | 35 | checkInstanceValid $1
|
---|
[13] | 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)
|
---|
[11] | 52 | cur=`echo $tel | sed "s/\r/\n/g" | sed "s/^ //g" | grep "Total of " | cut -d\ -f 3`
|
---|
[13] | 53 | echo "Players: $cur"
|
---|
[9] | 54 | else
|
---|
[13] | 55 | echo "Status: NOT running"
|
---|
[9] | 56 | fi
|
---|
| 57 |
|
---|
[13] | 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
|
---|