source: scripts/usr/local/lib/7dtd/commands/status.sh@ 302

Last change on this file since 302 was 258, checked in by alloc, 9 years ago

Scripts: License

File size: 2.2 KB
Line 
1#!/bin/bash
2
3# Copyright 2016 Christian 'Alloc' Illy
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17
18
19# Print status of given instance.
20
21sdtdCommandStatus() {
22 if [ $(isValidInstance $1) -eq 0 ]; then
23 echo "No instance given or not a valid instance!"
24 return
25 fi
26
27 line() {
28 printf " %-*s %s\n" 15 "$1" "$2"
29 }
30
31 echo "Instance: $1"
32 echo
33
34 if [ $(isRunning $1) -eq 1 ]; then
35 echo "Status: Running"
36 echo "Open ports:"
37 netstat -nlp | grep $(getInstancePID $1) | sed -r 's/^([^ ]*)\s+.*[^ :]*:([^ ]*).*[^ :]*:[^ ]*.*/ \2 (\1)/g' | sort
38 cur=$(telnetCommand $1 lp | grep -aE "^\s?Total of " | cut -d\ -f 3)
39 echo "Players: $cur"
40 else
41 echo "Status: NOT running"
42 fi
43
44 echo
45 echo "Game info:"
46 line "Server name:" "$(getConfigValue $1 ServerName)"
47 line "Password:" "$(getConfigValue $1 ServerPassword)"
48 line "Max players:" "$(getConfigValue $1 ServerMaxPlayerCount)"
49 line "World:" "$(getConfigValue $1 GameWorld)"
50
51 echo
52 echo "Network info:"
53 line "Port:" "$(getConfigValue $1 ServerPort)"
54 line "Public:" "$(getConfigValue $1 ServerIsPublic)"
55 if [ "$(getConfigValue $1 ControlPanelEnabled)" = "false" ]; then
56 cp="off"
57 else
58 cp="Port $(getConfigValue $1 ControlPanelPort), Pass $(getConfigValue $1 ControlPanelPassword)"
59 fi
60 line "Control Panel:" "$cp"
61 if [ "$(getConfigValue $1 TelnetEnabled)" = "false" ]; then
62 tn="off"
63 else
64 tn="Port $(getConfigValue $1 TelnetPort), Pass $(getConfigValue $1 TelnetPassword)"
65 fi
66 line "Telnet:" "$tn"
67
68 echo
69}
70
71sdtdCommandStatusHelp() {
72 echo "Usage: $(basename $0) status <instance>"
73 echo
74 echo "Print status information for the given instance."
75}
76
77sdtdCommandStatusDescription() {
78 echo "Print status for the given instance"
79}
80
81sdtdCommandStatusExpects() {
82 case $1 in
83 2)
84 getInstanceList
85 ;;
86 esac
87}
88
Note: See TracBrowser for help on using the repository browser.