Jump to content

Steam SRCDS Server Restarter


Coolw
 Share

Recommended Posts

If you run a server, I run a Garry's Mod server, you will love this.

SRCDS is known to crash, as if you use it, I am sure you know.

So, I decided to do something to keep it up more often, and have a very cool functionality.

What it does:

-Monitor your server every 30 seconds

-Check for 2 windows, both known for crashes

-CAN SEND TEXT MESSAGES TO AT&T/CINGULAR PHONES

-Process only takes up about 5KB of space. (Up to 14,000kb after checking send sms, and starting) IDK WHY

-Nice GUI, but it could be prettyer (I KNOW I SPELLED IT WRONG)

-Keeps a log file (server log.txt)

Update #2.0

-Grr dumb me, I set it so it only worked for my server location, added a fileselectlocation() for you guys

-Fixed server not restarting due to run error

-Customizeable checking time

-Broke the X button, trying to find the fix

-Fixed up the code a little bit

Working on:

-Using less memory

-More kinds of crashes

-Program not closing when you hit X all the time

-Testing connection to server, to find out if it freezes

Suggestions/Ideas/Comments are welcome!

CODE
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****

#AutoIt3Wrapper_Outfile=Server Monitor.exe

#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include<sms.au3>

Global Const $GUI_ENABLE = 64

Global Const $GUI_DISABLE = 128

Global Const $GUI_EVENT_CLOSE = -3

Global Const $GUI_CHECKED = 1

Global Const $ES_PASSWORD = 32

Global Const $ES_NUMBER = 8192

;--------------------------------------------------------------------------------

HotKeySet("{ESC}", "_Exit")

Opt("TrayIconHide", 1)

;--------------------------------------------------------------------------------

$msg = ""

$next = 0

$State = "Stopped"

;--------------------------------------------------------------------------------

GUICreate("Server Watcher - By David L.", 205, 215)

$label1 = GUICtrlCreateLabel("Your 10 digit phone number: ", 10, 10)

$phone = GUICtrlCreateInput("1234567890", 10, 25, 70, 20, $ES_NUMBER)

$label2 = GUICtrlCreateLabel("Your GMAIL Email address", 10, 50)

$Username = GUICtrlCreateInput("Your_email@gmail.com", 10, 65)

$label3 = GUICtrlCreateLabel("Your GMAIL password", 10, 90)

$Password = GUICtrlCreateInput("12", 10, 105, -1, 20, $ES_PASSWORD)

$warning = GUICtrlCreateLabel("WARNING: If any of this is wrong,", 10, 130)

$warning2 = GUICtrlCreateLabel("SMS messaging will not work.", 10, 145)

$warning3 = GUICtrlCreateLabel("Click on the skip button to skip this", 10, 160)

$submit = GUICtrlCreateButton("Submit Information", 10, 180)

$skip = GUICtrlCreateButton("Skip this Step", 120, 180)

GUISetState()

;--------------------------------------------------------------------------------

$phonelen = StringLen(GUICtrlRead($phone))

While $next <> 1

$msg = GUIGetMsg()

Select

Case $msg = $submit

If $phonelen = 10 Then

$s_ToAddress = GUICtrlRead($phone) & "@cingularme.com"

$s_Username = GUICtrlRead($Username)

$s_Password = GUICtrlRead($Password)

$smsenable = 1

$next = 1

ElseIf $phonelen <> 10 Then

MsgBox(0, "Error", "Your phone number has more or less than 10 digits.")

EndIf

Case $msg = $skip

$smsenable = 0

$next = 1

Case $msg = $GUI_EVENT_CLOSE

Exit

EndSelect

WEnd

GUICtrlDelete($label1)

GUICtrlDelete($phone)

GUICtrlDelete($label2)

GUICtrlDelete($label3)

GUICtrlDelete($warning)

GUICtrlDelete($warning2)

GUICtrlDelete($warning3)

GUICtrlDelete($submit)

GUICtrlDelete($skip)

GUICtrlDelete($s_Password)

GUICtrlDelete($s_Username)

GUIDelete()

$srcdslocation = FileSelectFolder("Please select the folder that your srcds.exe is in", "")

If $srcdslocation = "" Then

MsgBox(0, "Error", "You closed the box with out selecting the srcds.exe location")

Exit

EndIf

;--------------------------------------------------------------------------------

GUICreate("Server Watcher - By David L.", 205, 130)

$Monitor = GUICtrlCreateButton("Start Monitoring", 10, 10)

$Stop = GUICtrlCreateButton("Stop Monitoring", 110, 10)

$Label = GUICtrlCreateLabel($State, 10, 50)

$checkerror = GUICtrlCreateInput("5", 10, 70, 25, 20, $ES_NUMBER)

GUICtrlCreateLabel("Time between checks for errors", 40, 70)

$SMS = GUICtrlCreateCheckbox("Send Text Message with", 10, 90)

$SMS2 = GUICtrlCreateLabel("server change in status?", 27, 110)

GUISetState()

;--------------------------------------------------------------------------------

Opt("WinTitleMatchMode", 2)

If $smsenable = 0 Then

GUICtrlSetState($SMS, $GUI_DISABLE)

GUICtrlSetState($SMS2, $GUI_DISABLE)

EndIf

;--------------------------------------------------------------------------------

While $msg <> $GUI_EVENT_CLOSE

$msg = GUIGetMsg()

Select

Case $msg = $Monitor

$State = "Monitoring"

GUICtrlSetData($Label, $State)

Case $msg = $Stop

GUICtrlSetData($Label, $State)

$State = "Stopped"

Case $msg = $GUI_EVENT_CLOSE

$as_Body = " Server:Exited Program"

_logfile()

_smscheck()

Exit

EndSelect

If $State = "Monitoring" Then

$as_Body = " Server:Started Monitoring"

_logfile()

_smscheck()

$starttime = TimerInit()

$checkerror1 = (GUICtrlRead($checkerror) * 1000)

While $State = "Monitoring"

If TimerDiff($starttime) >= $checkerror1 Then

If WinExists("srcds.exe - Application Error") Or WinExists("Engine Error") Then

$as_Body = " Server:Server Crashed, Attempting Restart"

_logfile()

_smscheck()

Sleep(5000)

_RestartServer()

EndIf

$starttime = TimerInit()

$checkerror1 = GUICtrlRead($checkerror) * 1000

EndIf

$msg = GUIGetMsg()

Select

Case $msg = $Stop

$State = "Stopped"

GUICtrlSetData($Label, $State)

$as_Body = " Server:Stopped Monitoring"

_logfile()

_smscheck()

Case $msg = $GUI_EVENT_CLOSE

$as_Body = " Server:Exited Program"

_logfile()

_smscheck()

Exit

EndSelect

WEnd

EndIf

WEnd

;--------------------------------------------------------------------------------

Func _RestartServer()

If WinExists("srcds.exe - Application Error") Then

WinActivate("srcds.exe - Application Error")

ElseIf WinExists("Engine Error") Then

WinActivate("Engine Error")

EndIf

Send("{ENTER}")

Sleep(1500)

$run = Run($srcdslocation & "\srcds.exe", $srcdslocation)

If $run = 0 Then

$as_Body = " Server:Error Restarting Server"

_logfile()

_smscheck()

Exit

EndIf

Sleep(5000)

Send("{ENTER}")

Sleep(20000)

ProcessSetPriority("srcds.exe", 5)

If @error = 1 Then

$as_Body = " Server:Error Setting Priority"

_logfile()

_smscheck()

Exit

EndIf

$as_Body = " Server:Server Successfully Restarted"

_logfile()

_smscheck()

EndFunc

;--------------------------------------------------------------------------------

Func _smscheck()

$inputsms = GUICtrlRead($SMS)

If $inputsms = $GUI_CHECKED Then

_INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, $s_Username, $s_Password, $IPPort, $ssl)

EndIf

EndFunc

;--------------------------------------------------------------------------------

Func _logfile()

;_FileWriteLog("log.txt", $as_Body)

$date = @MON & "/" & @MDAY & "/" & @YEAR

$time = @HOUR & ":" & @MIN & ":" & @SEC

$log = "At " & $date & " at " & $time & $as_Body

FileWrite("server log.txt", $log & @CRLF)

EndFunc

;--------------------------------------------------------------------------------

Func _Exit()

Exit

EndFunc

test.au3:

CODE
#include-once

Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

$s_SmtpServer = "smtp.gmail.com" ; address for the smtp-server to use - REQUIRED

$s_FromName = "Server" ; name from who the email was sent

$s_FromAddress = "" ; address from where the mail should come

$s_ToAddress = "" ; destination address of the email - REQUIRED

$s_Subject = "" ; subject from the email - can be anything you want it to be

$as_Body = "" ; the messagebody from the mail - can be left blank but then you get a blank mail

$s_Username = "" ; username for the account used from where the mail gets sent - Optional (Needed for eg GMail)

$s_Password = "" ; password for the account used from where the mail gets sent - Optional (Needed for eg GMail)

;$IPPort = 25 ; port used for sending the mail

;$ssl = 0 ; enables/disables secure socket layer sending - put to 1 if using httpS

$IPPort=465 ; GMAIL port used for sending the mail

$ssl=1 ; GMAILenables/disables secure socket layer sending - put to 1 if using httpS

;##################################

; Script

;##################################

Global $oMyRet[2]

Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

;$rc = _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, $s_Username, $s_Password, $IPPort, $ssl)

;If @error Then

; MsgBox(0, "Error sending message", "Error code:" & @error & " Rc:" & $rc)

;EndIf

Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_Username = "", $s_Password = "",$IPPort=25, $ssl=0)

$objEmail = ObjCreate("CDO.Message")

$objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'

$objEmail.To = $s_ToAddress

Local $i_Error = 0

Local $i_Error_desciption = ""

$objEmail.Subject = $s_Subject

If StringInStr($as_Body,"<") and StringInStr($as_Body,">") Then

$objEmail.HTMLBody = $as_Body

Else

$objEmail.Textbody = $as_Body & @CRLF

EndIf

$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer

$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort

;Authenticated SMTP

If $s_Username <> "" Then

$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1

$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username

$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password

EndIf

If $Ssl Then

$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True

EndIf

;Update settings

$objEmail.Configuration.Fields.Update

; Sent the Message

$objEmail.Send

if @error then

SetError(2)

return $oMyRet[1]

EndIf

EndFunc;==>_INetSmtpMailCom

;

;

; Com Error Handler

Func MyErrFunc()

$HexNumber = Hex($oMyError.number, 8)

$oMyRet[0] = $HexNumber

$oMyRet[1] = StringStripWS($oMyError.description,3)

ConsoleWrite("### COM Error ! Number: " & $HexNumber & " ScriptLine: " & $oMyError.scriptline & " Description:" & $oMyRet[1] & @LF)

SetError(1); something to check for when this function returns

Return

EndFunc;==>MyErrFunc

Edited by Coolw
My ProgramsMy WIP'sSteam Server Restarter
Link to comment
Share on other sites

This works nicely. I would look up ServerDoc. It is a very good server restarter. I would look at it for ideas.

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Link to comment
Share on other sites

HUGE Update #2.0

-Grr dumb me, I set it so it only worked for my server location, added a fileselectlocation() for you guys

-Fixed server not restarting due to run error

-Customizeable checking time

-Broke the X button, trying to find the fix

-Fixed up the code a little bit

Working on:

-Using less memory

-More kinds of crashes

-Program not closing when you hit X all the time

-Testing connection to server, to find out if it freezes'

Taken straight off the main post

If you want to help, just let me know :P

My ProgramsMy WIP'sSteam Server Restarter
Link to comment
Share on other sites

  • 2 weeks later...

Love your CSS restarter, thanx! I modified the code however, so it doesn't need no input anymore and i made the monitoring autostarting. This way i can let it run from the startup-folder, so it will start monitoring automatically when the server boots up. The only drawback of this method is that you have to enter all configs in the code itself, but who cares.. :P

What i'm still curious about is, how the restarter will act when the desktop is locked, but time will tell... :P

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...