• Print

Author Topic: Maintenance script  (Read 20 times)

0 Members and 1 Guest are viewing this topic.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Maintenance script
« on: October 29, 2006, 08:46:52 pm »
I wrote a little script to warn players before taking a server offline for use on our server:

Code: Lua
  1. assert( _file.Exists( "lua/ULib/init.lua" ), "This script needs ULib to run!" )
  2. _OpenScript( "ULib/init.lua" )
  3. assert( ULib.ULIB_VERSION >= 1.2, "This script requires ULib version 1.2 or higher to run!" )
  4.  
  5. local textKey = 452
  6. local rectKey = 451
  7.  
  8. local timer
  9. local finish
  10.  
  11. local function update()
  12.         if _CurTime() > finish then
  13.                 _ServerCommand( "quit\n" )
  14.                 return
  15.         end
  16.  
  17.         local s = math.floor( finish - _CurTime() )
  18.         local m = math.floor( s / 60 )
  19.         s = math.mod( s, 60 )
  20.         m = math.mod( m, 60 )
  21.         s = string.format( "%02i", s )
  22.         m = string.format( "%02i", m )
  23.  
  24.         local str = "Time until server shutdown:\n                " .. m .. ":" .. s
  25.  
  26.         ULib.sendRect( userid, rectKey, 0.4, 0.2, 0.2, 0.07, 2, 255, 80, 80, 220, "ULib/menu", 0, 0, 0 )
  27.         ULib.sendText( userid, textKey, 0.41, 0.215, str, 2, 255, 255, 255, 255, "Default", 0, 0, 0 )
  28. end
  29.  
  30. local function cc_shutdown( userid, args, argv, argc )
  31.         if string.lower( argv[ 1 ] ) == "cancel" then
  32.                 if timer then
  33.                         HaltTimer( timer )
  34.                         timer = nil
  35.                        
  36.                         ULib.tsay( 0, "Timed shutdown has been halted!" )
  37.                 end
  38.                 return
  39.         end
  40.  
  41.         if not argv[ 1 ] or not tonumber( argv[ 1 ] ) then
  42.                 ULib.tsay( userid, "Please specify number of seconds until shutdown." )
  43.         end
  44.  
  45.         finish = _CurTime() + tonumber( argv[ 1 ] )
  46.         timer = AddTimer( 1, 0, update )
  47.  
  48.         ULib.tsay( userid, "Shutdown has been started. Use \"shutdown cancel\" to stop it." )
  49.         ULib.tsay( 0, "ATTENTION: A TIMED SERVER SHUTDOWN HAS BEEN ACTIVATED! Please take screenshots or save your work while you have time." )
  50. end
  51. ULib.CONCOMMAND( "shutdown", cc_shutdown, _, ACCESS_RCON )

Picture of it in action:
Experiencing God's grace one day at a time.

Offline spbogie

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 456
  • Karma: 41
Re: Maintenance script
« Reply #1 on: October 30, 2006, 04:35:46 pm »
Very nice. Looking at this got me thinking though that maybe we should add a mainLog the same way there is a mainUcl so that small things like this could be logged without having to create a new log that would only be written to once.
I have not failed. I've just found 10,000 ways that won't work. - Thomas A. Edison
I reject your reality and substitute my own. - Adam Savage

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Maintenance script
« Reply #2 on: October 30, 2006, 05:53:47 pm »
Yah, probably.

Also, I've thought this should be made into a more general timer script... IE, timer to change level so people can save work, timer to clean server, etc.
Experiencing God's grace one day at a time.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Maintenance script
« Reply #3 on: October 30, 2006, 07:15:39 pm »
Also, though the warning 'box' in the middle is nice... I'd be frustrated if I had to include that in the center of my screenshots.
Does it dissappear if I'm using a camera?
If not, perhaps we should move it to a corner, or center top/bottom.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Maintenance script
« Reply #4 on: October 30, 2006, 09:02:31 pm »
Good point! Maybe we should make a command that would disable it?
Experiencing God's grace one day at a time.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Maintenance script
« Reply #5 on: October 30, 2006, 09:06:16 pm »
To remove warning box for screenshots for 30 seconds, say "shutdown saycheese"
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline spbogie

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 456
  • Karma: 41
Re: Maintenance script
« Reply #6 on: October 31, 2006, 01:27:47 pm »
Have It appear in the middle of the screen then shrink off into the corner. That way people would be sure to see it, and it would be out of the way for screenshots and such.
I have not failed. I've just found 10,000 ways that won't work. - Thomas A. Edison
I reject your reality and substitute my own. - Adam Savage

  • Print