<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://bf2tech.uturista.pt/index.php?action=history&amp;feed=atom&amp;title=Scripts%3AAutoShutdown</id>
	<title>Scripts:AutoShutdown - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://bf2tech.uturista.pt/index.php?action=history&amp;feed=atom&amp;title=Scripts%3AAutoShutdown"/>
	<link rel="alternate" type="text/html" href="https://bf2tech.uturista.pt/index.php?title=Scripts:AutoShutdown&amp;action=history"/>
	<updated>2026-08-06T01:11:00Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.40.1</generator>
	<entry>
		<id>https://bf2tech.uturista.pt/index.php?title=Scripts:AutoShutdown&amp;diff=106&amp;oldid=prev</id>
		<title>Pireax: Created page with &quot;== Introduction ==  I got tired of manually warning my users before shutdown, so I wrote this to automate the task for me. It warns players at intervals before shutting down....&quot;</title>
		<link rel="alternate" type="text/html" href="https://bf2tech.uturista.pt/index.php?title=Scripts:AutoShutdown&amp;diff=106&amp;oldid=prev"/>
		<updated>2018-06-22T15:26:22Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;== Introduction ==  I got tired of manually warning my users before shutdown, so I wrote this to automate the task for me. It warns players at intervals before shutting down....&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
I got tired of manually warning my users before shutdown, so I wrote this to automate the task for me. It warns players at intervals before shutting down. The warnings occur at 60, 30, 15, 10, 5, 4, 3, 2, 1 minutes before shutdown. This script needs serious work from someone who actually knows Python. I post it here in the hopes that people will improve on it (perhaps by moving the configuration variables into an easily-modified external file?)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
&lt;br /&gt;
Copy/Paste this script into a text file. Save it as &amp;lt;code&amp;gt;autoshutdown.py&amp;lt;/code&amp;gt; in your &amp;lt;code&amp;gt;standard_admin&amp;lt;/code&amp;gt; folder. Modify your &amp;lt;code&amp;gt;__init__.py&amp;lt;/code&amp;gt; file to import and execute it.&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import datetime&lt;br /&gt;
import time&lt;br /&gt;
import host&lt;br /&gt;
import bf2&lt;br /&gt;
from bf2 import g_debug&lt;br /&gt;
&lt;br /&gt;
shutdownTime = &amp;quot;01:00&amp;quot; #use 24-hour time. Format should be &amp;quot;hh:mm&amp;quot;&lt;br /&gt;
quitOrPause = &amp;quot;pause&amp;quot; #options are &amp;quot;pause&amp;quot; (pause game but leave server running) or &amp;quot;quit&amp;quot; (kill the server)&lt;br /&gt;
&lt;br /&gt;
shutdownTimer = None&lt;br /&gt;
def init():&lt;br /&gt;
    global shutdownTime, shutdownTimer&lt;br /&gt;
    shutdownHour = int(time.strftime(&amp;quot;%H&amp;quot;,time.strptime(shutdownTime,&amp;quot;%H:%M&amp;quot;)))&lt;br /&gt;
    shutdownMinute = int(time.strftime(&amp;quot;%M&amp;quot;,time.strptime(shutdownTime,&amp;quot;%H:%M&amp;quot;)))&lt;br /&gt;
    today = datetime.datetime.now()&lt;br /&gt;
    shutdownTime = datetime.datetime(today.year, today.month, today.day, shutdownHour, shutdownMinute)&lt;br /&gt;
    if shutdownHour &amp;lt; today.hour:&lt;br /&gt;
        shutdownTime = datetime.datetime(today.year, today.month, today.day + 1, shutdownHour, shutdownMinute)&lt;br /&gt;
    shutdownTimer = bf2.Timer(checktime, 1, 1)&lt;br /&gt;
    shutdownTimer.setRecurring(60)&lt;br /&gt;
    host.rcon_invoke(&amp;#039;echo &amp;quot;autoshutdown.py loaded&amp;quot;&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
def checktime(whatever):&lt;br /&gt;
    global shutdownTime&lt;br /&gt;
    global quitOrPause&lt;br /&gt;
   &lt;br /&gt;
    timeTilShutdown = shutdownTime - datetime.datetime.now()&lt;br /&gt;
    minsTilShutdown = int((timeTilShutdown.seconds / 60))&lt;br /&gt;
    host.rcon_invoke(&amp;#039;echo &amp;quot;Debug: &amp;#039; + str(minsTilShutdown) + &amp;#039; minutes to shutdown.&amp;quot;&amp;#039;)&lt;br /&gt;
    msg = None&lt;br /&gt;
    if minsTilShutdown == 60:&lt;br /&gt;
        msg = &amp;#039;ADMIN: SERVER SHUTDOWN IN 60 MINUTES&amp;#039;&lt;br /&gt;
    if minsTilShutdown == 30:&lt;br /&gt;
        msg = &amp;#039;ADMIN: SERVER SHUTDOWN IN 30 MINUTES&amp;#039;&lt;br /&gt;
    if minsTilShutdown == 15:&lt;br /&gt;
        msg = &amp;#039;ADMIN: SERVER SHUTDOWN IN 15 MINUTES&amp;#039;&lt;br /&gt;
    if minsTilShutdown == 10:&lt;br /&gt;
        msg = &amp;#039;ADMIN: SERVER SHUTDOWN IN 10 MINUTES&amp;#039;&lt;br /&gt;
    if minsTilShutdown == 5:&lt;br /&gt;
        msg = &amp;#039;ADMIN: SERVER SHUTDOWN IN 5 MINUTES&amp;#039;&lt;br /&gt;
    if 0 &amp;lt; minsTilShutdown &amp;lt; 5:&lt;br /&gt;
        msg = &amp;#039;ADMIN: SERVER SHUTDOWN IN &amp;#039; + str(minsTilShutdown) + &amp;#039; MINUTE(S)&amp;#039;&lt;br /&gt;
       &lt;br /&gt;
    if msg != None:&lt;br /&gt;
        adminMessage(msg)&lt;br /&gt;
       &lt;br /&gt;
    if minsTilShutdown &amp;lt;= 0:&lt;br /&gt;
        msg = &amp;#039;ADMIN: SERVER WILL SHUTDOWN *NOW*&amp;#039;&lt;br /&gt;
        adminMessage(msg)&lt;br /&gt;
        timestamp = time.strftime(&amp;quot;%Y-%m-%d, %I:%M:%S %p&amp;quot;,time.localtime())&lt;br /&gt;
        if quitOrPause == &amp;quot;quit&amp;quot;:&lt;br /&gt;
            if g_debug: print timestamp + &amp;#039; -- Server halted.&amp;#039;&lt;br /&gt;
            host.rcon_invoke(&amp;#039;quit&amp;#039;)&lt;br /&gt;
        if quitOrPause == &amp;quot;pause&amp;quot;:&lt;br /&gt;
            host.rcon_invoke(&amp;#039;echo &amp;quot;&amp;#039; + timestamp + &amp;#039; -- Game paused.&amp;quot;&amp;#039;)&lt;br /&gt;
            if g_debug: print timestamp + &amp;#039; -- Game paused.&amp;#039;&lt;br /&gt;
            host.rcon_invoke(&amp;#039;gamelogic.togglepause&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
def adminMessage(msg):&lt;br /&gt;
    for i in range(1,26):&lt;br /&gt;
        host.rcon_invoke(&amp;#039;game.sayAll &amp;quot;&amp;#039; + msg + &amp;#039;&amp;quot;&amp;#039;)&lt;br /&gt;
    host.rcon_invoke(&amp;#039;echo &amp;quot;&amp;#039; + msg + &amp;#039;&amp;quot;&amp;#039;)&lt;br /&gt;
    if g_debug: print msg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
: Greeze 07:50, 1 Jul 2005 (MDT)&lt;br /&gt;
: Greeze 04:13, 2 Jul 2005 (MDT) --&lt;br /&gt;
&lt;br /&gt;
::* Removed game status check (was creating multiple timer instances everytime the map changed); moved timer creation to init()&lt;br /&gt;
::* Slightly reordered message-sends in the checkTime function&lt;/div&gt;</summary>
		<author><name>Pireax</name></author>
	</entry>
</feed>