Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Jscript ➜ Auto-log off thing?

Auto-log off thing?

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Bobo_the_bee   USA  (6 posts)  Bio
Date Fri 17 Nov 2006 03:44 AM (UTC)
Message
I was wondering if there was a way to cause a world to automatically disconnect after a certain time frame (say 10 minutes) of you not entering anything into the command line. Kind of an "anti-botting trigger" that won't look at, say, commands issued by other triggers or timers, but only the commands that you have typed in.

The lions sing and the hills take flight.
The moon by day, and sun by night.
Blind woman, deaf man, jackdaw fool.
Let the Lord of Chaos rule.
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #1 on Fri 17 Nov 2006 04:35 AM (UTC)
Message
This is similar to the question in this thread:

http://www.gammon.com.au/forum/?id=7470&page=999


In his case he wanted to send something to keep the connection alive, until a certain time expired. In your case you want to send something to drop the connection after a certain time. It is very similar in concept.

Read that post and ask if you have any more questions.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Bobo_the_bee   USA  (6 posts)  Bio
Date Reply #2 on Sat 18 Nov 2006 12:23 PM (UTC)
Message
Oh ... well ... I will be the first to say that I have no idea how to do Plugins :o .

The lions sing and the hills take flight.
The moon by day, and sun by night.
Blind woman, deaf man, jackdaw fool.
Let the Lord of Chaos rule.
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #3 on Sun 19 Nov 2006 07:05 PM (UTC)

Amended on Sun 19 Nov 2006 09:21 PM (UTC) by Nick Gammon

Message
If it is going to be a plugin, may as well do it in Lua, which I prefer to use these days. This plugin will do what you want:


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Monday, November 20, 2006, 6:52 AM -->
<!-- MuClient version 3.82 -->

<!-- Plugin "Inactivity_Disconnect" generated by Plugin Wizard -->

<muclient>
<plugin
   name="Inactivity_Disconnect"
   author="Nick Gammon"
   id="f1490db9fc25805a46b407e9"
   language="Lua"
   purpose="Disconnects from MUD after being AFK for a while"
   date_written="2006-11-20 06:51:44"
   requires="3.76"
   version="1.0"
   >

</plugin>

<!-- change these 3 lines to customize the plugin -->

<script>

time_until_disconnect = 10   -- time in minutes until we disconnect
warning_seconds = 60         -- how many seconds of warning we get
disconnect_command = "quit"  -- how we disconnect

</script>


<!--  Timers  -->

<timers>
  <timer name="disconnect_timer" script="timer_fired" second="15.00" >

  </timer>
</timers>

<!--  Script  -->


<script>
<![CDATA[

last_command = os.time ()  -- time now

-- check os.time available
function OnPluginInstall ()
  if type (os) ~= "table" or 
     type (os.time) ~= "function" or
     type (os.difftime) ~= "function" then
    ColourNote ("white", "red", "Function os.time or os.difftime not available")
    ColourNote ("white", "red", "See Lua sandbox in Global Preferences")
    EnablePlugin (GetPluginID (), false) -- disable this plugin
  end -- if
end -- OnPluginInstall

-- reset timer when connecting to world
function OnPluginConnect ()
  ColourNote ("white", "green", "Connected to " .. GetInfo (2))
  last_command = os.time ()
  EnableTimer ("disconnect_timer", true)
end -- OnPluginConnect 

-- reset timer when a command is typed
function OnPluginCommand (sText)
  last_command = os.time ()
  return true
end -- OnPluginCommand 

-- check elapsed time every 15 seconds
function timer_fired (sName)
  local time_since_command = os.difftime (os.time (), last_command)
  local seconds_to_disconnect = time_until_disconnect * 60

  -- disconnect, if time (plus grace period) is up
  if time_since_command > (seconds_to_disconnect + warning_seconds) then
    ColourNote ("white", "tomato", "AFK - disconnecting")
    Send (disconnect_command)
    EnableTimer ("disconnect_timer", false)   -- just do it once
    return
  end -- if time plus warning_seconds is up

  -- give warning if time is up, for a few seconds
  if time_since_command > seconds_to_disconnect then
    ColourNote ("black", "yellow", "AFK - disconnecting in " .. 
                (seconds_to_disconnect + warning_seconds) - time_since_command  ..
                " seconds")
  end -- if time is up

end -- end timer_fired
]]>
</script>


</muclient>



Copy from between the lines and save as Inactivity_Disconnect.xml. Then install that file as a plugin in the MUSHclient file menu.

You can customize the lines in bold to alter:


  • Number of minutes before you are logged out
  • Number of seconds of warning messages you get
  • How to log out (eg. send "quit")


What the plugin does is find the current time when you connect, and whenever you type something it resets its "time till disconnect".

The time is checked by a timer every 15 seconds, and when your specified time is up you get a warning every few seconds, like this:


AFK - disconnecting in 51 seconds
AFK - disconnecting in 36 seconds
AFK - disconnecting in 21 seconds


During that time you can type something, which will therefore reset the AFK timer. If not, it disconnects you when the "grace period" is up.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #4 on Mon 20 Nov 2006 12:46 AM (UTC)
Message
There is a small subtlety to this plugin. It counts as activity things that are "send to execute". This includes typing commands, using macros, and using the numeric keypad.

It also includes a trigger, which sends to "execute". Thus, such a trigger would confuse the plugin into thinking you had actually typed something. So far there is no easy way of telling the difference, but normal triggers that just send text straight to the world should be OK.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #5 on Wed 29 Nov 2006 12:56 AM (UTC)
Message
I have added an amendment to version 3.83 to handle this situation. You can now call GetInfo (239) which will return a number indicating whether a script is running because of genuine user input, or something which has been called from a trigger or timer.

If GetInfo (239) returns a number in the range 1 to 5 (see the release notes for more details) then the script is running in response to actual user interaction.

Thus the plugin could be amended to change the function OnPluginCommand as follows:


-- reset timer when a command is typed
function OnPluginCommand (sText)
  if GetInfo (239) >= 1 and GetInfo (239) <= 5 then
    last_command = os.time ()
  end -- actual player input
  return true
end -- OnPluginCommand 

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


20,206 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.