[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Plugins
. . -> [Subject]  ATCP plugin for Achaea
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

ATCP plugin for Achaea

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


Pages: 1 2  3  4  

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Tue 09 Mar 2010 01:45 AM (UTC)
Message
The plugin below uses the new telnet subnegotiation built into recent version of MUSHclient to intercept ATCP messages from IRE MUDs such as Achaea.

Simply install it, and it will do a BroadcastPlugin when various messages are detected. These can be picked up by other plugins (such as experience bars, health bars, mappers).

Template:saveplugin=ATCP_NJG To save and install the ATCP_NJG plugin do this:
  1. Copy between the lines below (to the Clipboard)
  2. Open a text editor (such as Notepad) and paste the plugin into it
  3. Save to disk on your PC, preferably in your plugins directory, as ATCP_NJG.xml
  4. Go to the MUSHclient File menu -> Plugins
  5. Click "Add"
  6. Choose the file ATCP_NJG.xml (which you just saved in step 3) as a plugin
  7. Click "Close"



<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>

<muclient>
<plugin
   name="ATCP_NJG"
   author="Nick Gammon"
   id="85f72d0e263d75df7bde6f00"
   language="Lua"
   purpose="Nick Gammon's ATCP plugin"
   date_written="2010-03-09 10:04:32"
   requires="4.50"
   version="1.0"
   >
<description trim="y">
<![CDATA[
Install into IRE games to catch ATCP messages.

Other plugins can detect ATCP messages like this:

function OnPluginBroadcast (msg, id, name, text)
  if id == "85f72d0e263d75df7bde6f00" then
  
    if msg == 1 then
      do_ATCP_vitals (text)      -- eg. "H:496/496 M:412/412 E:1380/1380 W:960/960 NL:89/100 "
                                 --      health    mana      endurance   willpower experience
    elseif msg == 2 then
      do_ATCP_room_brief (text)  -- eg. "Continuing on the Parade of Zarathustra"
    elseif msg == 3 then
      do_ATCP_room_exit (text)   -- eg. "n,s"
    elseif msg == 4 then
      do_ATCP_room_number (text) -- eg. "401"
    end -- if   
 
  end -- if ATCP message
end

]]>
</description>

</plugin>


<!--  Script  -->


<script>
<![CDATA[

local CLIENT_ID = "MUSHclient " .. Version ()
local IAC, SB, SE, DO = 0xFF, 0xFA, 0xF0, 0xFD
local ATCP = 200


-- agree to use ATCP
function OnPluginTelnetRequest (type, data)
  
  if type == ATCP and data == "WILL" then
    return true
  end -- if
  
  if type == ATCP and data == "SENT_DO" then
    Note ("Enabling ATCP.")
    SendPkt (string.char (IAC, SB, ATCP) .. 
           "hello " .. CLIENT_ID .. "\n" ..
           "auth 1\n" ..
           "char_name 1\n" ..
           "char_vitals 1\n" ..
           "room_brief 1\n" ..
           "room_exits 1" ..
           string.char (IAC, SE)) 
     return true
  end -- if ATCP login needed (just sent DO)
  
  return false
  
end -- function OnPluginTelnetRequest

-- we got authorization request, eg. 
-- Auth.Request CH\n<identstr>
-- Auth.Request ON

function got_auth_request (s)
   
  -- calculate challenge response
  local function atcp_auth (seed)
    local a = 17
    local i = 0
    local n
    
    for letter in string.gmatch (seed, ".") do
      n = string.byte (letter) - 96
      if bit.band (i, 1) == 0 then  -- even/odd?
        a = a + n * bit.bor (i, 13)
      else
        a = a - n * bit.bor (i, 11)
      end -- if
      i = i + 1
    end -- for
    return a
  end

  if s:upper () == "ON" then
    Note ("ATCP authorization accepted.")
    return
  end -- if
    
  local identstr = string.match (s, "^CH\n(.+)$")
  
  if identstr then
    SendPkt (string.char (IAC, SB, ATCP) .. 
             "auth " .. 
             tostring (atcp_auth (identstr)) .. 
             " " .. CLIENT_ID .. 
             string.char (IAC, SE)) 
    return
  end -- if
  
end -- got_auth_request


function got_vitals (s)      -- eg. "H:496/496 M:412/412 E:1380/1380 W:960/960 NL:89/100"
  BroadcastPlugin (1, s)
end -- got_vitals

function got_room_brief (s)  -- eg. "Continuing on the Parade of Zarathustra"
  BroadcastPlugin (2, s)
end -- got_room_brief

function got_room_exits (s)  -- eg. "n,s"
  BroadcastPlugin (3, s)
end -- got_room_exits

function got_room_number (s)  -- eg. "441"
  BroadcastPlugin (4, s)
end -- got_room_number

handlers = {
  ['Auth.Request']  = got_auth_request,  -- handled here

  ['Room.Num']      = got_room_number,
  ['Room.Brief']    = got_room_brief,
  ['Room.Exits']    = got_room_exits,
  ['Char.Vitals']   = got_vitals,
  
  } -- end handlers
  
function OnPluginTelnetSubnegotiation (type, option)

  if type ~= ATCP then
    return
  end -- not Achaea subnegotiation

  local command, args = string.match (option, "^([%a.]+)%s+(.*)$")
  
  if not command then
    return
  end -- don't seem to have a command
  
  local f = handlers [command]
  
  if f then
    f (args)  -- call handler
  else
    BroadcastPlugin (0, option) -- other, just send whole message
  end -- handler
          
end -- function OnPluginTelnetSubnegotiation

]]>
</script>


</muclient>


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #1 on Tue 09 Mar 2010 01:57 AM (UTC)

Amended on Tue 09 Mar 2010 02:01 AM (UTC) by Twisol

Message
Several perfectly functional ATCP plugins have already been written, one of which I currently maintain, an early version of which you even (kindly) host here. Was there a pressing need for you to reinvent the wheel? If you just wanted to showcase the telnet subnegotiation facilities in MUSHclient, fine, but I would have (and still will) updated mine.

I'll also point out that there are plenty of plugins already written that depend on my version. Two ATCP plugins can't coexist without starving one of them, and thus their dependents.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Tue 09 Mar 2010 02:42 AM (UTC)
Message
Twisol said:

Several perfectly functional ATCP plugins have already been written, one of which I currently maintain, an early version of which you even (kindly) host here. Was there a pressing need for you to reinvent the wheel? If you just wanted to showcase the telnet subnegotiation facilities in MUSHclient, fine, but I would have (and still will) updated mine.

I'll also point out that there are plenty of plugins already written that depend on my version. Two ATCP plugins can't coexist without starving one of them, and thus their dependents.



"Several perfectly functional ATCP plugins have already been written" ... so, re-writing an ATCP plugin isn't a new idea?

I was in fact trying to demonstrate how to use the telnet subnegotiation callbacks rather than mucking around at the packet level detecting things like IAC IAC which is really a low-level client job.

I took some care to examine the existing ATCP plugin and make identical BroadcastPlugin messages. I have modified slightly the other two plugins I just posted to work with your existing ATCP plugin, or the one I posted here (basically just checking for either plugin ID in the OnPluginBroadcast function).

Testing shows they work with either one, so I haven't really introduced a new, incompatible, system.

I have to say I couldn't work out by looking at the code what your plugin does with the Room.Num message, so I made up a new code for the (message number 4).

There is no particular reason for people to switch to my version here if they are happy with what is working for them, and in any case, as I said, I tried to make it compatible.



- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #3 on Tue 09 Mar 2010 03:02 AM (UTC)
Message
I was thinking more in chronological order. My version is the latest in a series of improvements on the same base. Then you also have people like - who was it, WillFa? - who wrote their own personally. But mine is, AFAIK, the most known and used revision.

As for how mine works, it doesn't care what messages are recieved or count on the existence of specific messages (except Auth.Request). It just packages up a message and sends it to all plugins that said they wanted it, through my PPI library. It's purely a protocol-level plugin, offloading all data to interested parties.

I wrote the internal telnet parser because, at the time, the subnet functionality wasn't entirely fleshed out, and I was waiting for 4.50 and OnPlugin_IAC_GA to rewrite it.

Also, my version (not the one you have hosted) doesn't even use BroadcastPlugin anymore. The current version is on a page on my blog, which I linked to you a while back.

Lastly, presenting multiple implementations of ATCP will only confuse users, and it puts the burden on the dependant-plugin author to support both versions. It's better for the community as a whole to have a clear concensus in situations like these.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #4 on Tue 09 Mar 2010 03:12 AM (UTC)
Message
Just to reiterate, because this is very important, the version you have of my plugin is vastly out of date, and is incredibly different compared to the one I have now. This is probably my fault for not letting you know about the changes, but I did link you to my most recent version a bit ago too. So please take another look! Thanks.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Tue 09 Mar 2010 03:47 AM (UTC)
Message
Where? I couldn't find it at:

http://github.com/Twisol

I'm getting lost now, you may have sent me links before but my old brain is having trouble keeping track of the distinction between the "Twisol" stuff hosted here (which you specifically mentioned above), your GitHub files, your forum postings here, and other things hosted in a different place again.

Short of going back and re-reading I-don't-know-how-many forum messages, I can't really work out where the latest stuff is.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #6 on Tue 09 Mar 2010 03:59 AM (UTC)
Message
I linked it to you at the beginning of our email correspondence. ;) I'd get you a direct link, but I'm on the iPhone and it's hard right now. You can go to Jonathan.com and click the plugins link at the top, though. I'll edit a link in here when I'm home. (10 minutes-ish)

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #7 on Tue 09 Mar 2010 04:15 AM (UTC)

Amended on Tue 09 Mar 2010 04:18 AM (UTC) by Twisol

Message
http://jonathan.com/?page_id=29

All of the ATCP-based plugins I've made are hosted there, barring my MapWindow plugin which I'm happy to deprecate in favor of your new mapper.

EDIT: By the way, I notice that on GitHub you made a commit for compatability with Trevize's version. Trevize has officially turned over his ATCP-based plugin development to me, his ATCP versions are no longer available, and mine are directly based off of his. In other words, it's not worth the trouble ;)

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #8 on Tue 09 Mar 2010 04:19 AM (UTC)
Message
Twisol said:

It’s pretty interesting to see how a program I’ve used for a long time actually functions (even though he uses the Whitesmiths indentation style, which I cannot abide.


I love that style.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #9 on Tue 09 Mar 2010 04:22 AM (UTC)
Message
Nick Gammon said:

Twisol said:

It’s pretty interesting to see how a program I’ve used for a long time actually functions (even though he uses the Whitesmiths indentation style, which I cannot abide.


I love that style.


Not only does it feel really weird to me, VS2005 defaults to Allman and I don't know how to change it (nor, honestly, do I want to). But that was really for comedic effect anyhow. :D

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #10 on Tue 09 Mar 2010 04:23 AM (UTC)

Amended on Tue 09 Mar 2010 04:25 AM (UTC) by Nick Gammon

Message
Twisol said:

By the way, I notice that on GitHub you made a commit for compatability with Trevize's version. ... In other words, it's not worth the trouble ;)


Where did I say that?

[EDIT] Oh sorry, I read "commit" as "commitment".

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #11 on Tue 09 Mar 2010 04:24 AM (UTC)
Message
Twisol said:

Not only does it feel really weird to me, VS2005 defaults to Allman and I don't know how to change it (nor, honestly, do I want to). But that was really for comedic effect anyhow. :D


Don't worry, probably more duels at dawn over indentation than anything else.

;)

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #12 on Tue 09 Mar 2010 05:30 AM (UTC)
Message
Twisol said:

Two ATCP plugins can't coexist without starving one of them, and thus their dependents.


Why?

I notice once I installed your plugin mine was indeed starved of the telnet sequences but why did that have to be?

Plugins were intended to be independent of other plugins, so that installing one should not crimp the style of another. I see in the code for main.lua of your atcp.plugin download you have this:


OnPluginPacketReceived = function(packet)
  return parser.parse(packet)
end


This effectively seems to be stripping out the telnet sequences. But why do that? I changed it to:


OnPluginPacketReceived = function(packet)
  parser.parse(packet)
  return packet
end


... and my plugins then worked as they were intended to. And yours would too would they not? Why make a plugin that reduces the amount of data available to other plugins?


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #13 on Tue 09 Mar 2010 05:36 AM (UTC)

Amended on Tue 09 Mar 2010 05:38 AM (UTC) by Twisol

Message
Nick Gammon said:

... and my plugins then worked as they were intended to. And yours would too would they not? Why make a plugin that reduces the amount of data available to other plugins?



Because it reveals - or used to, I suppose, with the new subnegotiation support - some ATCP messages. Specifically Char.Vitals, which for some reason was actually displayed on-screen when the ATCP plugin was disabled or crashed (mostly during development and testing) after ATCP was requested from the server.

Also because, as I mentioned in another thread, ATCP requires a hello message listing the modules you want to activate. You can only send one 'hello' message, and this one 'hello' needs to know all of the modules that are to be used. There's just no good way around this in a distributed fashion. My current solution is to enable all modules and allow dependent plugins to simply ask for specific messages as they come in. This has the excellent bonus that dependent plugins that are added after you've already connected are highly likely to still work perfectly fine.

EDIT: I've updated my ATCP plugin now to replace my parser with the subnegotiation callbacks. I'm just checking that everything works properly and I'll upload the new version. But my point about 'hello' still stands firm.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #14 on Tue 09 Mar 2010 05:48 PM (UTC)
Message
The conversion was pretty quick and simple, I just replaced the parser callbacks I wrote with the associated OnPlugin callbacks. The new version is up at [1], but there's no major difference in how it actually operates.

[1] http://jonathan.com/?attachment_id=98

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] 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.


36,442 views.

This is page 1, subject is 4 pages long: 1 2  3  4  [Next page]

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]