Author Topic: Jay's Server Watcher  (Read 4039 times)

0 Members and 2 Guests are viewing this topic.

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Jay's Server Watcher
« on: September 03, 2007, 05:40:17 PM »
For all of you who are looking for a some what simple batch script to start and restart you server after a crash.

 Selectable game,map,players,rcon,password,vac, and server restart.

Code: [Select]
@ echo off
title Jays Server Watch
echo ================================================
echo =          Created By: Jay209015               =
echo =          Email: jay209015@suddenlink.net     =
echo ================================================
echo :Just follow directions, and enter your options:
echo ================================================

:game
cd c:\srcds\
attrib +h "hl2"
attrib +h "bin"
attrib +h "reslists"
attrib +h "platform"
dir /b/A-h *.
attrib -h "hl2"
attrib -h "bin"
attrib -h "reslists"
attrib -h "platform"
echo ________________________________________________
echo \ What game do you want to start a server for? /
echo /___________Options are listed above.__________\

set game=
set /p game=

if exist c:\srcds\%game%\ goto map
if not exist c:\srcds\%game%\ goto game_e

:game_e
echo,
echo :::::::::::::::::::_ERROR_::::::::::::::::::::::
echo :%game% Is not valid, Please re-enter selection:
echo ::::::::::::::::::::::::::::::::::::::::::::::::
goto game

:map
title Jays Server Watch (%game%)
echo ================================================
cd c:\srcds\%game%\maps\
dir /b/A *.bsp
echo ================================================
echo ________________________________________________
echo \    What map do you want to run on %game%? /
echo /___________Options are listed above.__________\

set map=
set /p map=

if exist "c:\srcds\%game%\maps\%map%.bsp" goto players
if not exist "c:\srcds\%game%\maps\%map%.bsp" goto map_e

:map_e
echo,
echo :::::::::::::::::::_ERROR_:::::::::::::::::::::
echo :%map% Is not valid, Please re-enter selection:
echo :::::::::::::::::::::::::::::::::::::::::::::::
goto map

:players
echo =================================================
echo ________________________________________________
echo \  How many players do you want to be allowed  /
echo /_____________ In your server?_________________\

set players=
set /p players=
goto rcon

:rcon
echo =================================================
echo _________________________________________________
echo \Pleaser enter your rcon password now. Note if  /
echo /_you don't enter a password you can't use rcon_\

set rcon=
set /p rcon=
goto password

:password
echo ==================================================
echo ________________________________________________
echo \  What would you like your server password    /
echo /________to be?(TO SKIP PRESS ENTER)___________\

set password=
set /p password=
goto vac

:vac
echo ==================================================
echo ________________________________________________
echo \  Do you want your server to be VAC secured?  /
echo /______________________________________________\

set vac=
set /p vac=yes/no:

if %vac%==yes set secured=
if %vac%==no set secured=-insecure
if %vac%==Yes set secured=
if %vac%==No set secured=-insecure
goto name

:name
echo ==================================================
echo ________________________________________________
echo \   Please enter a hostname, or default will   /
echo /________________be used_______________________\

set name=
set /p name=
goto start

:start
echo ==================================================
echo ________________________________________________
echo \    Do you want the server to restart after   /
echo /______________A server crash__________________\

set start=
set /p start=yes/no:

if %start%==yes goto srcds
if %start%==no goto srcds_no
if %start%==Yes goto srcds
if %start%==No goto srcds_no

:srcds
echo ===============================================
echo (%time%) %game% server started___________Auto Restart Enabled......Created by:jay209015.
start /wait c:\srcds\srcds.exe -console -game %game% +hostname %name% +rcon_password %rcon% +sv_password %password% %secure% +map %map% +maxplayers %players% > C:\test.txt
echo (%time%) WARNING: server closed or crashed, restarting.
goto srcds

:srcds_no
echo ================================================
echo (%time%) %game% server started___________Auto Restart disabled......Created by:jay209015.
start /wait c:\srcds\srcds.exe -console -game %game% +hostname %name% +rcon_password %rcon% +sv_password %password% %secure% +map %map% +maxplayers %players%
echo (%time%) WARNING: server closed or crashed.
echo ________________________________________________
echo \    Do you want the server to restart?        /
echo /______________server crashed__________________\

set restart=
set /p restart=yes/no:

if %restart%==yes goto srcds_no
if %restart%==Yes goto srcds_no
if %restart%==no goto end
if %restart%==No goto end

:end





Copy and paste into notepad and save as anything.bat

This only works for the c:\srcds directory.
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline Chironex

  • Full Member
  • ***
  • Posts: 197
  • Karma: 11
  • Formerly known as Kyzer
Re: Jay's Server Watcher
« Reply #1 on: September 03, 2007, 06:20:55 PM »
I see a problem, /wait command is not on Windows XP (iirc)
And..it should restart the server automatically when crashed, as an option maybe.

I remember my SA-MP server restarter :P

Well i've checked, /wait is here, hmm maybe i dreamed or something :o
« Last Edit: September 03, 2007, 06:22:36 PM by Kyzer »

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Jay's Server Watcher
« Reply #2 on: September 03, 2007, 06:34:43 PM »
I use to use this on my server, but I kinda posted here for advice as well as distribution. This was my first script in batch, so it's no the greatest but it functions. I was wondering if there was a way it could make a log of you previously used settings and give you the option to select one of your previous settings and skip entering all the information in. That would be especially useful with the server name. I'm new and I look at your script and I don't have any idea what going on there, so if anyone could help me improve I would be grateful.
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Jay's Server Watcher
« Reply #3 on: September 03, 2007, 07:08:01 PM »
I was wondering if there was a way it could make a log of you previously used settings and give you the option to select one of your previous settings and skip entering all the information in. That would be especially useful with the server name.

As with any (almost all) scripting language, be it command prompt or lua, you can use variables.

I have mine start dedicated server through Steam. There are a multitude of other ways, most efficient would be to just start srcds.exe.
In simplest terms;
Code: [Select]
rem --- Set STEAM location
set steamloc=C:\Progra~1\Steam\
rem --- Set Game runtime console parameters.
set parameters= -console -game "garrysmod" +map freespace03 +maxplayers 6 -nocrashdialog
rem --- Start steam from above variable location steamloc, run dedicated server. (app 205 = ded server), using above line %parameters%
start /D "%steamloc%" Steam.exe -applaunch 205 %parameters%

Setting a variable with options you chose already is just as easy
Pseudo code would look like following
Code: [Select]
choice option blah1
set parameters= blah1
choice option blah2
set parameters= %parameters% blah2
choice option blah3
set parameters= %parameters% blah3

The 'parameters' variable would now be equal to "blah1 blah2 blah3"

"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Jay's Server Watcher
« Reply #4 on: September 04, 2007, 03:43:23 AM »
Code: [Select]
rem --- Set STEAM location
set steamloc=C:\Progra~1\Steam\
rem --- Set Game runtime console parameters.
set parameters= -console -game "garrysmod" +map freespace03 +maxplayers 6 -nocrashdialog
rem --- Start steam from above variable location steamloc, run dedicated server. (app 205 = ded server), using above line %parameters%
start /D "%steamloc%" Steam.exe -applaunch 205 %parameters%

See, the only part of that I understand what is going on it 
Code: [Select]
set parameters= -console -game "garrysmod" +map freespace03 +maxplayers 6 -nocrashdialogI've never ran my server through steam but what's the
Code: [Select]
~ for?
Code: [Select]
set steamloc=C:\Progra~1\Steam\
Code: [Select]
start /D "%steamloc%" Steam.exe -applaunch 205 %parameters%
So if I understand it correctly, this a call to
start c:\programfiles\steam\Steam.exe -applaunch 205 -console -game garrysmod +map freespace03 +maxplayers 6 -nocrashdialog
Ok I get that, but what is
Code: [Select]
/D    -nocrashdialogIs the nocrash dialog to keep a window from comming letting you know it crashed and so you can continue on restarting automatically?
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Jay's Server Watcher
« Reply #5 on: September 04, 2007, 03:55:22 PM »
Is the nocrash dialog to keep a window from comming letting you know it crashed and so you can continue on restarting automatically?

Yes.

However, one thing batch files never do, and I've seen Gmod ded server do quite frequently, is detect a lockup. No crash. Just a lockup.
See http://developer.valvesoftware.com/wiki/Command_Line_Options for various Srcds and Steam command line options.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Jay's Server Watcher
« Reply #6 on: September 05, 2007, 02:40:56 PM »
Oh thank you very much, I hated this when the server freezes and it doesn't unstick or restart.
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly