View unanswered posts | View active topics It is currently Tue Apr 21, 2026 4:18 pm



Reply to topic  [ 11 posts ] 
 Server Monitor Script 
Author Message
Ambassador
User avatar

Joined: Mon Feb 09, 2004 3:00 am
Posts: 3141
Location: Kansas
Unread post Server Monitor Script
Due to the speed at which the screen scrolls sometimes, it is sometimes next to impossible to read the server shutdown messages. The script below will monitor for system shutdown notices:

# pop a window to warn if server going down
# minimal spoof checking, suggest you add additional
# do not close the popup window after it opens - turn
# off the script and restart to get rid of it.
# I don't know of a way to close windows - anyone?

systemscript
setVar $warn1 0

:begin
setVar $window ""
setTextTrigger min5 :shutDownTime "The server will shut down in 5 minutes."
setTextTrigger min3 :shutDownTime "The server will shut down in 3 minutes."
setTextTrigger min2 :shutDownTime "The server will shut down in 2 minutes."
setTextTrigger min1 :shutDownTime "The server will shut down in 1 minute."
setTextTrigger final :shutDownFinal "The server is shutting down"
setTextTrigger abort :shutDownAborted "Aborting shutdown."
pause

:shutDownTime
getword currentLine $test 1
if ($test <> "The")
killalltriggers
goto :begin
end
# yes the following is unnecessary, you could just store currentline to a var and use it
getText currentline $min "shut down in " "minute"
add $warn1 1
if ($warn1 = 1)
window shutdown 325 200 " SERVER SHUTTING DOWN!!" ONTOP
end
# and this is where you would use the var with currentline
setVar $window $window & "*Server shutting down in " & $min & " minute(s)*"
setWindowContents shutdown $window
pause


:shutDownFinal
getTime $time "hh:mm:ss"
setVar $window $window & "*Server shutdown @: " & $time & "*"
setWindowContents shutdown $window
waitfor "Command [TL="
getTime $time "hh:mm:ss"
setVar $window $window & "*Back online @: " & $time & "*"
setWindowContents shutdown $window
killalltriggers
goto :begin

:shutDownAborted
setVar $window $window & "*Shutdown aborted*"
setWindowContents shutdown $window
killalltriggers
goto :begin

_________________
               / Promethius / Enigma / Wolfen /

"A man who has no skills can be taught, a man who has no honor has nothing."


Sun Dec 21, 2008 6:23 pm
Profile ICQ
Commander
User avatar

Joined: Fri Aug 20, 2004 2:00 am
Posts: 1801
Location: Outer Rims
Unread post Re: Server Monitor Script
Good idea. Now I won't have to wonder if users saw the message. Thanks for that.

_________________
-Thrawn

But risk has always been an inescapable part of warfare.

--

Knight to Queen's Bishop 3


Sun Dec 21, 2008 10:55 pm
Profile
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post Re: Server Monitor Script
Have a solution to the window problem.. and i found a way to include the server msg in the popup window too. threw in spoof checking too 8)

Code:
# FileName: Mon_Main.ts
systemscript
setVar $Support_Script "C:\Mon_Support.ts"
gosub :Kill_Kill_Kill
Load $Support_Script

:begin
   setTextLineTrigger   Continuity   :Continuity   "The server will shut down"
   setTextLineTrigger   ShutDown      :ShutDown   "The server is shutting down"
   setTextLineTrigger   Abort       :Abort      "Aborting shutdown."
   pause

:ShutDown
   killalltriggers
   Echo "**" & ANSI_14 & "Shutdown"
   setVar $Temp CURRENTANSILINE
   getWordPos $Temp $pos1 "Shutdown"
   getWordPos $Temp $pos2 "The"
   if ($pos1 <> 0) OR ($pos2 <> 0)
      waiton "Command [TL="
      gosub :Kill_Kill_Kill
      Load $Support_Script
   end
   goto :begin

:Continuity
   killalltriggers
   setVar $Count 0
   setVar $Temp CURRENTANSILINE
   getWordPos $Temp $pos "The"
   if ($pos <> 0)
      ListActiveScripts $INDEX
      SetVar $IDX 1
      while ($IDX <= $INDEX)
         if ($INDEX[$IDX] = $Support_Script)
            add $Count 1
         end
         add $IDX 1
      end
      if ($Count > 1)
         gosub :Kill_Kill_Kill
         goto :Continuity
      end
   end
   goto :begin

:Abort
   killalltriggers
   setVar $Temp CURRENTANSILINE
   getWordPos $Temp $pos "Aborting"
   if ($pos <> 0)
      setDelayTrigger   Kill_Delay   :Kill_Delay   200
      pause
      :Kill_Delay
      killalltriggers
      gosub :Kill_Kill_Kill
      Load $Support_Script
   end
   goto :begin

:Kill_Kill_Kill
   stop $Support_Script
   stop $Support_Script
   stop $Support_Script
   stop $Support_Script
   return

And the secret to my solution
Code:
#FileName: Mon_Support.ts
setVar $ArraySizeOf 50
setArray $LINES $ArraySizeOf
setVar $MSGD FALSE
setVar $MSG ""
setVar $PTR 1
:begin
setTextLineTrigger min5 :shutDownTime "The server will shut down in 5 minutes."
setTextLineTrigger min3 :shutDownTime "The server will shut down in 3 minutes."
setTextLineTrigger min2 :shutDownTime "The server will shut down in 2 minutes."
setTextLineTrigger min1 :shutDownTime "The server will shut down in 1 minute."
setTextLineTrigger final :shutDownFinal "The server is shutting down"
setTextLineTrigger abort :shutDownAborted "Aborting shutdown."
setTextLineTrigger LINE :LINE
pause
:LINE
   if ($PTR >= $ArraySizeOf)
      setVar $CR 2
      while ($CR <= $ArraySizeOf)
         setVar $LINES[($CR - 1)] $LINES[$CR]
         add $CR 1
      end
      setVar $PTR $ArraySizeOf
   end
   setVar $Tmp CURRENTANSILINE
   replaceText $Tmp #9 "   "
   stripText $Tmp #10
   stripText $Tmp #13
   setVar $LINES[$PTR] $Tmp
   add $PTR 1
   setTextLineTrigger   LINE         :LINE
   pause

:shutDownTime
setVar $window ""
setVar $Temp CURRENTANSILINE
getWordPos $Temp $Pos "The"
setVar $Temp CURRENTLINE
getword $Temp $test 1
if ($test <> "The") OR ($Pos = 0)
   killalltriggers
   goto :begin
end
getText $Temp $min "shut down in " " min"
add $warn1 1
if ($warn1 = 1)
   window shutdown 600 400 " SERVER SHUTTING DOWN!!" ONTOP
end

setVar $window $window & "*Game      : " & GAMENAME & " (" & GAME & ")"
if ($min = 1)
   setVar $window $window & "*Shut Down : " & $min & " minute*"
else
   setVar $window $window & "*Shut Down : " & $min & " minutes*"
end
if ($MSG <> "")
   setVar $window $window & $msg
end

if ($MSGD = FALSE)
   setVar $MSG ""
   if ($ptr > $ArraySizeOf)
      setVar $ptr $ArraySizeOf
   end
   setVar $CR $PTR
   while ($CR > 0)
      setVar $Tmp $LINES[$CR]

      if ($Tmp = "")
         subtract $CR 1
      else
         while ($CR > 0)
            setVar $Tmp $LINES[$CR]
            getWordPos $Tmp $pos "["
            if ($pos = 0)
               if ($Tmp <> "0")
                  if ($Tmp = "")
                     setVar $MSG ("*  "&$MSG)
                  else
                     setVar $MSG ("*"&$Tmp&$MSG)
                  end
               end
            else
               setVar $CR 0
            end
            subtract $CR 1
         end
         if ($MSG <> "")
            setVar $MSGD TRUE
            setVar $msg ("*   [SERVER MSG]==========================================[SERVER MSG]" & $msg)
            setVar $window $window & $msg
         end
      end
   end
end
setWindowContents shutdown $window
pause
:shutDownFinal
killalltriggers
setVar $Temp CURRENTANSILINE
getWordPos $Temp $pos1 "Shutdown"
getWordPos $Temp $pos2 "The"
if ($pos1 <> 0) OR ($pos2 <> 0)
   getTime $time "hh:mm:ss"
   setVar $window $window & "*Server shutdown @: " & $time & "*"
   setWindowContents shutdown $window
   waitfor "Command [TL="
   getTime $time "hh:mm:ss"
   setVar $window $window & "*Back online @:     " & $time & "*"
   setWindowContents shutdown $window
end
goto :begin

:shutDownAborted
killalltriggers
setVar $Temp CURRENTANSILINE
getWordPos $Temp $pos "Aborting"
if ($pos <> 0)
   setVar $window $window & "*Shutdown aborted*"
##   setWindowContents shutdown $window
end
goto :begin


Attachments:
Monitor.zip [1.61 KiB]
Downloaded 418 times

_________________
----------------------------
-= QUANTUM Computing 101: 15 = 3 x 5 ... 48% of the time.
Mon Dec 22, 2008 11:46 am
Profile ICQ YIM
Ambassador
User avatar

Joined: Mon Feb 09, 2004 3:00 am
Posts: 3141
Location: Kansas
Unread post Re: Server Monitor Script
Very nice on having the second script handle that part. The use of byte code (think that is the correct term) along with currentansiline was the only real way of spoof checking. I wish we had a clean way of closing TWX windows.

_________________
               / Promethius / Enigma / Wolfen /

"A man who has no skills can be taught, a man who has no honor has nothing."


Mon Dec 22, 2008 12:54 pm
Profile ICQ
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1134
Location: Augusta, GA
Unread post Re: Server Monitor Script
Forgive me, I've never tried to write a shutdown monitor script, but these approaches seem overly complex. Shouldn't it be much simpler?

_________________
Claim to Fame: only guy to ever crack the TW haggle algorithm, and fig/shield/hold price formula, twice.


Mon Dec 22, 2008 11:14 pm
Profile WWW
Ambassador
User avatar

Joined: Mon Feb 09, 2004 3:00 am
Posts: 3141
Location: Kansas
Unread post Re: Server Monitor Script
ElderProphet wrote:
Forgive me, I've never tried to write a shutdown monitor script, but these approaches seem overly complex. Shouldn't it be much simpler?


They are somewhat, but written on the fly. Now if we just had a closeWin command.....

A more concise version that I have NOT tested:

Code:
# pop a window to warn if server going down
# minimal spoof checking, suggest you add additional



:begin
  killalltriggers
  setVar $window ""
  setVar $warn1 0
  setTextTrigger min5 :shutDownTime "The server will shut down in"
  setTextTrigger final :shutDownFinal "The server is shutting down"
  setTextTrigger abort :shutDownAborted "Aborting shutdown."
  pause

  :shutDownTime
    setVar $lineIn currentline
    getword $lineIn $test 1
    if ($test <> "The")
       setTextTrigger min5 :shutDownTime "The server will shut down in"
       pause
    end

    if ($warn1 = 0)
       window shutdown 325 200 " SERVER SHUTTING DOWN!!" ONTOP
       add $warn1 1
    end
    setVar $window $window & "*" & $lineIn & "*"
    setWindowContents shutdown $window
    setTextTrigger min5 :shutDownTime "The server will shut down in"
    pause

  :shutDownFinal
   getTime $time "hh:mm:ss"
   setVar $window $window & "*Server shutdown @: " & $time & "*"
   setWindowContents shutdown $window
   waitfor "Command [TL="
   getTime $time "hh:mm:ss"
   setVar $window $window & "*Back online @:     " & $time & "*"
   setVar $window $window & "*Please close the warning window*"
   setWindowContents shutdown $window
   goto :begin

  :shutDownAborted
    setVar $window $window & "*Shutdown aborted*"
    setVar $window $window & "*Please close the warning window*"
    setWindowContents shutdown $window
    goto :begin


_________________
               / Promethius / Enigma / Wolfen /

"A man who has no skills can be taught, a man who has no honor has nothing."


Tue Dec 23, 2008 12:31 am
Profile ICQ
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post Re: Server Monitor Script
Promethius wrote:
They are somewhat, but written on the fly. Now if we just had a closeWin command.....



There is a KillWindow command listed in the Twx-script-reference help file. but i've never been able to get it to work properly. Perhaps someone could look at the source and see if the Syntax in th eHelp file is correct.
killWindow


Purpose: Unloads a script window.

Syntax: killWindow {windowName}

{windowName}: The name of the window to remove.


Notes: This command is provided for backwards compatibility. There is currently no support for script windows in v2.00.

_________________
----------------------------
-= QUANTUM Computing 101: 15 = 3 x 5 ... 48% of the time.


Tue Dec 23, 2008 6:07 am
Profile ICQ YIM
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post Re: Server Monitor Script
ElderProphet wrote:
Forgive me, I've never tried to write a shutdown monitor script, but these approaches seem overly complex. Shouldn't it be much simpler?


PHead has one in his bot. if he ever reads this would be interssting to read his thoughts on his approach.

The most complicated part of my suggestion is the obtaining the actual Shutdown Msg for display in the Popup Window. Personally I'd never use a script like this; since Prom asked the question re a workaround/solution I thought I'd get my scripting-fix.

_________________
----------------------------
-= QUANTUM Computing 101: 15 = 3 x 5 ... 48% of the time.


Tue Dec 23, 2008 6:58 am
Profile ICQ YIM
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1134
Location: Augusta, GA
Unread post Re: Server Monitor Script
Here is a short example that does spoof checking. LS, take a look how I'm keeping the display to 10 lines. Your example is similar to my original ANSI parsing script, which gets slower as the Lines array increases in size. This particular script should not reach a size where it slows down, but I think you'll see the benefit to this approach, which doesn't use an array at all.

Also note the self-sustaining trigger routines. Don't hesitate to ask for clarification, as I want all of you guys to use similar methods when possible. I've been preaching this method for a while.

Let me know if you guys see something I've missed, but I *think* it has the same functionality as earlier examples.

+EP+

Code:
setVar $windowText ""
setTextLineTrigger shutdown :shutdownOrAbort "The server will shut down in "
setTextTrigger aborting :shutdownOrAbort "Aborting shutdown."
setTextTrigger final :shuttingDown "The server is shutting down"
pause

:shutdownOrAbort
killTrigger shutdown
killTrigger aborting
setVar $line CURRENTLINE & "*"
gosub :update
setTextLineTrigger shutdown :shutdownOrAbort "The server will shut down in "
setTextTrigger aborting :shutdownOrAbort "Aborting shutdown."
pause

:shuttingDown
setVar $line CURRENTLINE & " @ " & TIME & "*"
gosub :update
if ($legit)
   # Pause here until we are reconnected
   waitOn "Command [TL="
   setVar $windowText $windowText & "Back online @: " & TIME & "*"
   add $lines 1
   gosub :trim10
   setWindowContents shutdown $windowText
end
setTextTrigger final :shuttingDown "The server is shutting down"
pause

:update
setVar $legit FALSE
cutText CURRENTANSILINE $char 1 1
#7 is the Bell character, and is sent by the TW server as an alert.  It is not a spoof if it is present.
if ($char = #7)
   setVar $legit   TRUE
   # See if we have any window text.  If not, create a window.
   if ($windowText = "")
      window shutdown 375 200 "SHUT DOWN MONITOR" ONTOP
   end
   setVar $windowText $windowText & $line
   add $lines 1
   gosub :trim10
   setWindowContents shutdown $windowText
end
return

:trim10
# Trim to 10 lines
while ($lines > 10)
   getWordPos $windowText $pos "*"
   cutText $windowText $windowText ($pos + 1) 9999
   subtract $lines 1
end
return

_________________
Claim to Fame: only guy to ever crack the TW haggle algorithm, and fig/shield/hold price formula, twice.


Tue Dec 23, 2008 1:27 pm
Profile WWW
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post Re: Server Monitor Script
ElderProphet wrote:
Let me know if you guys see something I've missed, but I *think* it has the same functionality as earlier examples.


Splitting hairs a bit here. But the Sysop usually sends a msg regarding the details of the shutdown which people can see. In doing this the actual Shutdown string that everyone is Triggering off of, is sent by the Server *after* the sysop's Text Msg.

In my example i used a 50 element array (only really needs to be about 20 elements), to maintain a log of every line sent by the server (See Image below this post), when the scripts detects the 5,3,2,1-Minute Warning the script reads through the Log parses out the Sysops Text Msg and puts it into the TWX-Window.

If any one has a question please feel free to hit me up.

Thanks

[EDIT] I have fixed up my original script example. See Attached


Attachments:
Monitor.zip [2.5 KiB]
Downloaded 457 times
shutdown.jpg
shutdown.jpg [ 61.08 KiB | Viewed 5509 times ]

_________________
----------------------------
-= QUANTUM Computing 101: 15 = 3 x 5 ... 48% of the time.


Last edited by LoneStar on Tue Dec 23, 2008 3:11 pm, edited 1 time in total.

Tue Dec 23, 2008 2:00 pm
Profile ICQ YIM
Ambassador
User avatar

Joined: Mon Feb 09, 2004 3:00 am
Posts: 3141
Location: Kansas
Unread post Re: Server Monitor Script
EP: One of the problems will be the window for the server shutdown will remain open from what I can tell, and the user may just "x" it out. If the Op does a second shutdown (which I have seen several times) within a few minutes, the script "should" crash writing to a closed window. I saw where LoneStar talked about a killwindow command - I have never used it, and really hadn't ever noticed it before, but will have to give it a shot. If it will work that would take care of the issue.

I had thought the sound (which I usually keep turned off - wSST with sound will drive you crazy, not to mention what the wife says about the constant sounds) came from SWATH as an information warning and not from TWGS. I saw the square box in front of the messages when I used currentansiline, but wasn't sure the code. Using the "bell" makes spoof checking very simple.

I think LS has a good idea on the server messages - gives an idea of how long a server might be down in addition to giving me time to get the heck away from a hostile area and scrubbed (would really hate to not connect quickly and find a limp hunter powering up).

_________________
               / Promethius / Enigma / Wolfen /

"A man who has no skills can be taught, a man who has no honor has nothing."


Tue Dec 23, 2008 2:24 pm
Profile ICQ
Display posts from previous:  Sort by  
Reply to topic   [ 11 posts ] 

Who is online

Users browsing this forum: No registered users and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by wSTSoftware.