Aardwolf telnet negotiation plugin helper

Posted by Nick Gammon on Sat 12 Jul 2008 10:01 PM — 3 posts, 18,742 views.

Australia Forum Administrator #0
The Lua file below is used by various Aardwolf plugins I will be describing.

It provides an interface with the Aardwolf server, as described in this post:

http://www.gammon.com.au/forum/?id=8771

More information is at:

http://www.aardwolf.com/blog/2008/07/10/telnet-negotiation-control-mud-client-interaction


To use it, download the code below and save as telnet_options.lua in the Aardwolf subdirectory below your Plugins directory. If you haven't used any Aardwolf plugins before you may need to make the Aardwolf directory.

Alternatively, RH click the link below and choose "Save Link As" (or "Save Linked File As") to save the linked file.

http://www.gammon.com.au/mushclient/plugins/Aardwolf/telnet_options.lua

Once installed, a plugin can turn an option on or off like this:


-- pull in telnet option handling
dofile (GetPluginInfo (GetPluginID (), 20) .. "telnet_options.lua")  --> get this file
  
function OnPluginConnect ()
  TelnetOptionOn (TELOPT_STATMON)   --> tell server to send stats
end -- function OnPluginConnect

function OnPluginClose ()
  TelnetOptionOff (TELOPT_STATMON)   --> tell server to stop sending stats
end -- OnPluginClose



The call to GetPluginInfo (GetPluginID (), 20) returns the directory in which the current plugin resides, so the file telnet_options.lua should be in the same directory as your plugins.


Module code follows:



-- well-known options


TELOPT_STATMON = 1
TELOPT_BIGMAP = 2
TELOPT_HELPS = 3
TELOPT_MAP = 4
TELOPT_CHANNELS = 5
TELOPT_TELLS = 6
TELOPT_SPELLUP = 7
TELOPT_SKILLGAINS = 8
TELOPT_SAYS = 9
TELOPT_SCORE = 11
TELOPT_ROOM_NAMES = 12
TELOPT_EXIT_NAMES = 14
TELOPT_EDITOR_TAGS = 15
TELOPT_EQUIPMENT = 16
TELOPT_INVENTORY = 17
            
TELOPT_QUIET = 50
TELOPT_AUTOTICK = 51
TELOPT_PROMPT = 52
TELOPT_PAGING = 53
TELOPT_AUTOMAP = 54
TELOPT_SHORTMAP = 55


TELOPT_REQUEST_STATUS = 100



local function TelnetOption (which, on)
  -- Telnet Negotiation Options
  local IAC, SB, SE = 0xFF, 0xFA, 0xF0
  local TELOPT_WILL, TELOPT_WONT, TELOPT_DO, TELOPT_DONT = 0xFB,0xFC, 0xFD, 0xFE       
  
  -- Telnet subnegotiation for Aardwolf
  local AARDWOLF_TELOPT = 102
  
  local TELOPT_ON, TELOPT_OFF = 1, 2  -- turn on or off
  


  if on then
    SendPkt (string.char (IAC, SB, AARDWOLF_TELOPT, which, TELOPT_ON, IAC, SE)) 
  else
    SendPkt (string.char (IAC, SB, AARDWOLF_TELOPT, which, TELOPT_OFF, IAC, SE)) 
  end -- if
  
end -- TelnetOption


function TelnetOptionOn (which)
  TelnetOption (which, true)
end -- TelnetOptionOn


function TelnetOptionOff (which)
  TelnetOption (which, false)
end -- TelnetOptionOff


if GetOption ("enable_triggers") ~= 1 then
  ColourNote ("white", "red", "Warning: Triggers not enabled")
end -- if no triggers


if GetOption ("enable_aliases") ~= 1 then
  ColourNote ("white", "red", "Warning: Aliases not enabled")
end -- if no triggers


if GetOption ("enable_timers") ~= 1 then
  ColourNote ("white", "red", "Warning: Timers not enabled")
end -- if no triggers


Amended on Sat 12 Jul 2008 10:04 PM by Nick Gammon
#1
At the risk of sounding stupid (a risk I often take), how do you install the lua file? Does it automatically take effect if it is downloaded to the correct folder, or is it necessary to somehow get Mushclient to access it?

Thanks for all the time and effort.
Australia Forum Administrator #2
The first line in my example does that:


dofile (GetPluginInfo (GetPluginID (), 20) .. "telnet_options.lua")  --> get this file


The function "dofile" in Lua reads Lua code into memory and executes it. The call to GetPluginInfo (GetPluginID (), 20) returns the directory in which the plugin that you are currently executing, resides in, so that is why you put the file into that directory.


http://www.gammon.com.au/scripts/doc.php?lua=dofile