Advertisement
Guest User

Untitled

a guest
Oct 18th, 2014
937
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.70 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ############################################################################
  4. # #
  5. # Counter-Strike Source/GO and TF 2 (HL2) Server Script #
  6. # #
  7. # This program is free software: you can redistribute it and/or modify #
  8. # it under the terms of the GNU General Public License as published by #
  9. # the Free Software Foundation, either version 3 of the License, or #
  10. # (at your option) any later version. #
  11. # #
  12. # This program is distributed in the hope that it will be useful, #
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of #
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  15. # GNU General Public License for more details. #
  16. # #
  17. # You should have received a copy of the GNU General Public License #
  18. # along with this program. If not, see http://www.gnu.org/licenses/ #
  19. # #
  20. # Gebrauch: ./css.sh {start|stop|restart|update|console|check} #
  21. # #
  22. # start/restart/stop: Server An und aus schalten #
  23. # #
  24. # update: Mit dem Steam Updatetool den Server aktualisieren #
  25. # #
  26. # console: Wechselt auf die Counter-Strike Serverkonsole #
  27. # Mit strg+a + d die Konsole wieder in den Hintergrund schicken #
  28. # #
  29. ############################################################################
  30.  
  31. function init {
  32. # Absoluter Pfad zum Server
  33. DIR="/home/csgo/server1"
  34.  
  35. # Startscript des Servers
  36. DEAMON="srcds_run"
  37.  
  38. # Externe IP unter der der Server erreichbar sein soll
  39. IP="92.222.252.194"
  40.  
  41. # Port auf den der Server lauschen soll
  42. PORT="27015"
  43.  
  44. # Client Port des Servers
  45. CLIENTPORT="28000"
  46.  
  47. # Source TV aktivieren
  48. SOURCETV=0
  49.  
  50. # Falls SourceTV genutzt wird, wird der SourceTV Server auf diesem Port gestartet
  51. SOURCETVPORT="29000"
  52.  
  53. # Slot Anzahl
  54. MPLAYERS="30"
  55.  
  56. # Startmap
  57. MAP="surf_greatriver_xdre4m_d"
  58.  
  59. # Team Fortress 2 - tf, Counter-Strike: Source - cstrike, Counter-Strike: Global Offensive - csgo
  60. GAME="csgo"
  61. if [ "$GAME" == "csgo" ]; then
  62. # Dieser Teil ist nur fuer CS:GO
  63. GAMETYPE=0
  64. GAMEMODE=1
  65. MAPGROUP="mg_bomb"
  66. TICK=66
  67. CSGO="-tickrate $TICK +game_type $GAMETYPE +game_mode $GAMEMODE +mapgroup $MAPGROUP -usercon"
  68. else
  69. CSGO=""
  70. fi
  71.  
  72. PARAMS="-game $GAME -ip $IP -port $PORT +tv_port $SOURCETVPORT +clientport $CLIENTPORT +maxplayers $MPLAYERS +map $MAP +tv_enable $SOURCETV $CSGO"
  73.  
  74. SCREENNAME="css"
  75.  
  76. if [ "`whoami`" = "root" ]; then
  77. echo "Verantwortungsvolle Admins starten Gameserver nicht mit root! Allen anderen ist es untersagt!"
  78. exit 0
  79. fi
  80. if [ -z "$DIR" ]; then
  81. echo "Es wurde nichts bei der Variable DIR angegeben."
  82. exit 0
  83. fi
  84. if [ -z "$DEAMON" ]; then
  85. echo "Es wurde nichts bei der Variable DEAMON angegeben."
  86. exit 0
  87. fi
  88. if [ -z "$PARAMS" ]; then
  89. echo "Es wurde nichts bei der Variable PARAMS angegeben."
  90. exit 0
  91. fi
  92. if [ -z "$SCREENNAME" ]; then
  93. echo "Es wurde nichts bei der Variable SCREENNAME angegeben."
  94. exit 0
  95. fi
  96. if [ -z "$IP" ]; then
  97. echo "Es wurde nichts bei der Variable IP angegeben."
  98. exit 0
  99. fi
  100. if [ -z "$PORT" ]; then
  101. echo "Es wurde nichts bei der Variable PORT angegeben."
  102. exit 0
  103. fi
  104. }
  105.  
  106. function start_server {
  107. if [[ `screen -ls | grep $SCREENNAME` ]]; then
  108. echo "Der Server laeuft bereits unter dem Screentab $SCREENNAME"
  109. else
  110. echo "Starte $SCREENNAME"
  111. if [ -d $DIR ]; then
  112. cd $DIR
  113. screen -d -m -S $SCREENNAME ./$DEAMON $PARAMS
  114. else
  115. echo "Das Serververzeichnis wurde nicht angegeben"
  116. fi
  117. fi
  118. }
  119.  
  120. function stop_server {
  121. if [[ `screen -ls | grep $SCREENNAME` ]]; then
  122. echo -n "Stoppe $SCREENNAME"
  123. kill `screen -ls | grep $SCREENNAME | awk -F . '{print $1}'| awk '{print $1}'`
  124. echo " ... done."
  125. else
  126. echo "Konnte den Screentab $SCREENNAME nicht finden"
  127. fi
  128. }
  129.  
  130. function update_server {
  131. if [ -f ~/steamcmd.sh ]; then
  132. stop_server
  133. echo "Update"
  134. cd
  135. if [ "$GAME" == "csgo" ]; then
  136. ./steamcmd.sh +login anonymous +app_update 740 +force_install_dir $DIR validate +quit
  137. elif [ "$GAME" == "cstrike" ]; then
  138. ./steamcmd.sh +login anonymous +app_update 232330 +force_install_dir $DIR validate +quit
  139. elif [ "$GAME" == "tf" ]; then
  140. ./steamcmd.sh +login anonymous +app_update 232250 +force_install_dir $DIR validate +quit
  141. else
  142. echo "Falscher Wert fuer die Variable GAME!"
  143. fi
  144. start_server
  145. else
  146. echo "Konnte die Datei steamcmd.sh nicht im Homeverzeichnis finden!"
  147. fi
  148. }
  149.  
  150. function wrong_input {
  151. echo "Usage: $0 {start|stop|restart|update|console|check}"
  152. exit 1
  153. }
  154.  
  155. function get_screen {
  156. screen -r $SCREENNAME
  157. }
  158.  
  159. # Veraltet:
  160. #function check_ping {
  161. # if [ "`/usr/bin/quakestat -a2s $IP:$PORT | grep -v ADDRESS | awk '{ print $2 }' | awk -F/ ' { print $1}'`" = "DOWN" ]; then
  162. # sleep 10
  163. # if [ "`/usr/bin/quakestat -a2s $IP:$PORT | grep -v ADDRESS | awk '{ print $2 }' | awk -F/ ' { print $1}'`" = "DOWN" ]; then
  164. # stop_server
  165. # start_server
  166. # fi
  167. # fi
  168. #}
  169.  
  170. function check_ping {
  171. if [[ "`printf '\xFF\xFF\xFF\xFF\x54\x53\x6F\x75\x72\x63\x65\x20\x45\x6E\x67\x69\x6E\x65\x20\x51\x75\x65\x72\x79\x00' | netcat -u -w 1 $IP $PORT`" == "" ]]; then
  172. sleep 10
  173. if [[ "`printf '\xFF\xFF\xFF\xFF\x54\x53\x6F\x75\x72\x63\x65\x20\x45\x6E\x67\x69\x6E\x65\x20\x51\x75\x65\x72\x79\x00' | netcat -u -w 1 $IP $PORT`" == "" ]]; then
  174. stop_server
  175. start_server
  176. fi
  177. fi
  178. }
  179.  
  180. init
  181.  
  182. case "$1" in
  183. start)
  184. start_server
  185. ;;
  186.  
  187. stop)
  188. stop_server
  189. ;;
  190.  
  191. restart)
  192. stop_server
  193. start_server
  194. ;;
  195.  
  196. update)
  197. update_server
  198. ;;
  199.  
  200. console)
  201. get_screen
  202. ;;
  203.  
  204. check)
  205. check_ping
  206. ;;
  207.  
  208. *)
  209. wrong_input
  210. ;;
  211. esac
  212. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement