get unique room id from mccp

Posted by Shwick on Tue 25 May 2010 02:31 PM — 8 posts, 30,449 views.

#0
In aardwolf, I know the underlying mccp protocol contains a unique room id for each room you visit. For example,

RoomEnvironment: aylorcity
RoomNum: 32418
RoomFullExits: n(32539), e(32698), s(32419), w(30518), u(35200), d(32615)

Is there a function that can access the RoomNum and RoomFullExits, or how would I go about doing that.
Amended on Tue 25 May 2010 07:52 PM by Shwick
Australia Forum Administrator #1
It is the ATCP protocol (using telnet subnegotiation), not MCCP which is data compression.

First, grab the ATCP_NJG plugin from here

http://github.com/nickgammon/plugins/blob/master/ATCP_NJG.xml

My mapper module can be downloaded from here:

http://github.com/nickgammon/mushclient/blob/master/lua/mapper.lua

My mapper plugin (which works with Aardwolf) can be downloaded from here:

http://github.com/nickgammon/plugins/blob/master/ATCP_Mapper.xml

You don't need the mapper module or mapper plugin, however they show how you can interact with the ATCP stuff to grab the room numbers.

Basically the important stuff is here, if you want do write your own:


handlers = {
  [1] = got_vitals,             -- eg. "H:496/496 M:412/412 E:1380/1380 W:960/960 NL:89/100"
                                --      health    mana      endurance   willpower experience
  [2] = got_room_name,          -- eg. "Continuing on the Parade of Zarathustra"
  [3] = got_room_exit,          -- eg. "n,s"
  [4] = got_room_number,        -- eg. "401"
  [5] = got_room_full_exits,    -- eg. "ne(8564),w(8428)"
  [6] = got_environment,        -- eg. "Urban"
  [7] = got_coordinates,        -- eg. "38,3,1,0"
  [8] = got_info,               -- eg. "shops,postoffice"
  }
  
function OnPluginBroadcast (msg, id, name, text)
  if id == "85f72d0e263d75df7bde6f00" then
  
    local f = handlers [msg]
    
    if f then
      f (text)
    end -- have handler
 
  end -- if ATCP message
end


The Atcp_NJG module basically detects the various types of messages in the telnet subnegotiation stream, and does a BroadcastPlugin of a different "id" number for each one. The code above simply detects that, and calls a handler (from the table above) to handle each different case. You would need to write your own handlers, the plugin I linked to shows the sort of thing you could do.
Amended on Tue 25 May 2010 08:34 PM by Nick Gammon
#2
I can't get my test function to work.

I upgraded from mushclient 4.33 to 4.51, added the Atcp_NJG plugin and made sure it was enabled.

In my python scripts file I added a function,


def OnPluginBroadcast (msg, id, name, text):
    global test
    test = "IT WORKS"
    world.Note ("msg: " + msg)
    if id == "85f72d0e263d75df7bde6f00":
        if msg == 4:
            world.Note("4")
        elif msg == 5:
            world.Note("5")
        world.Note("text: " + text)


I never saw "msg: " printed, and the function that printed the test var never printed "IT WORKS". It seems like OnPluginBroadcast isn't being called.

I also tried a quick lua script, same thing no result


function OnPluginBroadcast (msg, id, name, text)
  world.Note("works")


I try to trigger OnPluginBroadcast by just moving to different rooms.

Also, OnPluginBroadcast doesn't depend on triggers at all, it's just called by the Atcp_NJG plugin? I tried it with triggers enabled/disabled.


I also noticed something with 4.51; I have one trigger ".*" that catches everything, and I do regex work in the scripts file.

The map tags seem to now be a hidden output in the main window, even though they are displayed in the Map window. My ".*" trigger, triggers much more often.

Also I keep getting a {stats} line too.

It could be my settings cause I upgraded mushclient.
Amended on Wed 26 May 2010 12:09 AM by Shwick
Australia Forum Administrator #3
Using version 4.51, I installed just two plugins. The ATCP_NJG plugin I mentioned and this test one:


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Wednesday, May 26, 2010, 9:58 AM -->
<!-- MuClient version 4.51 -->

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

<muclient>
<plugin
   name="ATCP_Test"
   author="Nick Gammon"
   id="cee16d1d4f3c5f6681438fc2"
   language="Lua"
   purpose="Catches OnPluginBroadcast messages"
   date_written="2010-05-26 09:57:47"
   requires="4.51"
   version="1.0"
   >

</plugin>


<!--  Script  -->


<script>
<![CDATA[
function OnPluginBroadcast (msg, id, name, text)
  print ("OnPluginBroadcast called, got", msg, id, name, text)
end -- function
]]>
</script>


</muclient>


I logged into Aardwolf and moved around and saw this:


OnPluginBroadcast called, got 4 85f72d0e263d75df7bde6f00 ATCP_NJG 30608
OnPluginBroadcast called, got 2 85f72d0e263d75df7bde6f00 ATCP_NJG The Shores of Verume
OnPluginBroadcast called, got 7 85f72d0e263d75df7bde6f00 ATCP_NJG verume,0,0,0
OnPluginBroadcast called, got 6 85f72d0e263d75df7bde6f00 ATCP_NJG ocean
OnPluginBroadcast called, got 5 85f72d0e263d75df7bde6f00 ATCP_NJG n(30607),e(30612),s(30609),w(30601)


So it seems to work. You may need to log out and log back in to trigger the telnet negotiation. It may not detect it if you don't have the ATCP_NJG plugin installed at login time.
#4
Ok that works for me now.

Problem was I wasn't exporting as a plugin.

Thanks this looks like it will help me a lot.
#5
I keep getting a "type mismatch" error when I replicate that function in python.

Before I just copied your plugin and it worked, but that plugin is using lua.

Now that I'm using python,


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Thursday, May 27, 2010, 3:33 PM -->
<!-- MuClient version 4.51 -->

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

<muclient>
<plugin
   name="pluginBroadcast"
   id="fc96c4b049a3ad06f5f232d5"
   language="Python"
   date_written="2010-05-27 15:33:14"
   requires="4.51"
   version="1.0"
   >

</plugin>


<!--  Script  -->


<script>
<![CDATA[
def OnPluginBroadcast (msg, id, name, text):
    print ("OnPluginBroadcast called, got", msg, id, name, text)
    
]]>
</script>


</muclient>


I get the type mismatch whenever OnPluginBroadcast is triggered.

Also tried changing the print statement to pass, no luck.

Is it possible to do this in python?

Amended on Thu 27 May 2010 07:42 PM by Shwick
USA #6
You need an explicit "return 0" in Python for the plugin callbacks.
#7
omg twisol ty

thought i was gonna have to switch to lua again

damn you're only 17? you sound like some old professional on your webpage