[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]  Lua
. . -> [Subject]  Output/Parse garbled mix of raw ANSI and MXP?
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Output/Parse garbled mix of raw ANSI and MXP?

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


Posted by Gsmith   (14 posts)  [Biography] bio
Date Fri 28 Oct 2016 10:28 PM (UTC)

Amended on Fri 28 Oct 2016 10:57 PM (UTC) by Gsmith

Message
The mud I play has the ability to send out it's ASCII maps via GMCP, though no public plugins utilise this feature at all yet. The ASCII maps for each room come in different formats - the player can select raw "plaintext" (no colour codes, no mxp)... they can select colours and inverse colours... and they can have MXP enabled to make some of the rooms clickable. So maps may be plain... coloured by just ANSI... or a mix of ANSI and MXP colour and link codes. Mushclient handles them just fine, of course... but I have no idea how to handle it myself in LUA. (the end goal is to have it output to a floating window with windowtexts).

Here's one, single example room as it is received over GMCP, if you have colours + mxp enabled for your map option:


-- This is actually all received as a SINGLE line
-- I have inserted line-breaks so this forum post doesn't stretch out - the \n literal strings are received as text over GMCP, I have hit return after each!
sLastFullAscii = [[--
      \u001b[3z\u001b[4zMXP<RedMXP>+\u001b[3z   \n
    \u001b[3z\u001b[4zMXP<YellowMXP>\u001b[4zMXP<send href=\"goto 3c\"MXP>@\u001b[4zMXP<\/sendMXP>\u001b[3z-\u001b[3z\u001b[4zMXP<CyanMXP>\u001b[4zMXP<send href=\"goto 4c\"MXP>*\u001b[4zMXP<\/sendMXP>\u001b[3z-\u001b[3z\u001b[4zMXP<CyanMXP>\u001b[4zMXP<send href=\"goto 5c\"MXP>*\u001b[4zMXP<\/sendMXP>\u001b[3z \n
    \u001b[3z|\u001b[3z   \u001b[3z|\u001b[3z \n
    \u001b[3z\u001b[4zMXP<CyanMXP>\u001b[4zMXP<send href=\"goto 3d\"MXP>*\u001b[4zMXP<\/sendMXP>\u001b[3z     \n
    \u001b[3z|\u001b[3z     \n
    \u001b[3z\u001b[4zMXP<CyanMXP>\u001b[4zMXP<send href=\"goto 3e\"MXP>*\u001b[4zMXP<\/sendMXP>\u001b[3z-\u001b[3z    \n]]


(NOTE: this is all *ONE* single line received, one single GMCP text packet, with the literal strings of "\n", and the intentional space padding at the start of each "line" etc.)

The map when NOT sent over GMCP, and instead handled and output by Mushclient, actually looks like this:

http://i.imgur.com/RRGyxcB.png

I've tried playing with "ANSINote", "StripANSI" and such but it seems these ANSI codes aren't normal, or the mix of MXP and newlines just makes it impossible. And I couldn't spot anything for handling MXP codes when receives in this raw format.

I've had a good go at making something primitive to strip down those codes (keep in mind I have never encountered ANSI codes before so I really have no idea what they are doing, what they mean etc., I've just taken wild stabs in the dark). Here's the code I came up with just to ATTEMPT to attack that garble of GMCP received text;

  -- Delete this part of the ANSI codes, not needed?
  sLastFullAscii = string.gsub(sLastFullAscii, "\u001b", "")
  -- This code seems to mean "white", or "silver"?
  sLastFullAscii = string.gsub(sLastFullAscii, "%[3z", "<silver>")
  -- This code seems to mean "reset", which means let Mushclient use the default Note colour - turn it into a blank tag for now
  sLastFullAscii = string.gsub(sLastFullAscii, "%[4z", "<>")
  -- Delete the clickable links, not wanted
  sLastFullAscii = string.gsub(sLastFullAscii, 'MXP<send href=\"goto %d%l\"MXP>', "")
  -- And delete the closing tag for the links
  sLastFullAscii = string.gsub(sLastFullAscii, 'MXP<\/sendMXP>', "")
  -- Convert all the MXP-based colour tags to a simpler tag system just for ease of understanding
  sLastFullAscii = string.gsub(sLastFullAscii, 'MXP<RedMXP>', "<red>")
  sLastFullAscii = string.gsub(sLastFullAscii, 'MXP<GreenMXP>', "<green>")
  sLastFullAscii = string.gsub(sLastFullAscii, 'MXP<CyanMXP>', "<cyan>")
  sLastFullAscii = string.gsub(sLastFullAscii, 'MXP<YellowMXP>', "<yellow>")
-- Convert backslash-n to a pound symbol for now...
  sLastFullAscii = string.gsub(sLastFullAscii, '\n', "£")
  -- Split by the pound symbol and loop through each line
  for sNewLine in sLastFullAscii:gmatch("([^£]+)") do
    -- CREATE a new tag at the very beginning to make the gmatch work and handle the whitespace padding at the beginning of lines
    sNewLine = "<white>" .. sNewLine
    -- Gmatch through all my manually inserted colour codes and output the text associated with them
    for sColourCode, sNewString in sNewLine:gmatch("<([^>]*)>([^<]+)") do
      ColourTell(sColourCode, "", tostring(sNewString))
    end
    -- Blank note for a newline
    Note("")
  end


(I've done weird things I know, I was playing around).

Now, while that code DOES manage to strip out the MXP (I don't want/need them), and does actually output an identical looking map, with matching colours, into the Mushclient window... it's horribly clunky, and doesn't cover other possible unexpected colours, and doesn't handle if a user might have MXP disable so it's only ANSI codes (in which case I'll need to work out all the ANSI colours instead of using the MXP colours as I am above).... etc. etc.

I just wanted to show that I *HAD* made an attempt at breaking these codes down and turning it into something it's meant to look like (and this doesn't even dive into the fact I'm going to need to turn this into "WindowText" commands to put this into a miniwindow, rather than have nice easy to use ColourTell commands!)

What I'd love is a way to convert that huge mess received by GMCP, which may or may not contain just text... just ANSI... or ANSI and MXP... into a "Styles" table. A way to quickly strip all of those codes out, or to give the received GMCP data back to Mushclient and say "Please convert all these codes for me" as if it was being sent by the MUD itself. Or just some help!
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sat 29 Oct 2016 02:48 AM (UTC)
Message
What's your overall objective? To capture the incoming map and show in a miniwindow, keeping the colours, is that it?

- Nick Gammon

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

Posted by Gsmith   (14 posts)  [Biography] bio
Date Reply #2 on Sat 29 Oct 2016 10:01 AM (UTC)
Message
Yes, exactly that Nick! I thought I'd abandon the miniwindow part just for now, for simplicity sake (perhaps wrongly) just to try and get something that can translate that mix of ANSI/MXP (which depending on user settings could also be pure ANSI colour codes with no MXP) and output something identical looking with ColourTells/Notes, and then if I could get a parser that worked regardless of MXP/ANSI codes, then I'd work on turning that into WindowTexts instead (not overly difficult!).

I *CAN* do the whole thing another way - I can scrap any idea of handling that GMCP data, and instead I can harvest the non-GMCP ASCII map the MUD sends to the user's screen (as in the one in the screenshot), that Mushclient has already parsed and coloured appropriately etc., loop through the styles on that and put THAT in a Miniwindow instead - but the GMCP way feels like the more "proper" way, and would in theory be more reliable - if it wasn't for the parsing problems!
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Sat 29 Oct 2016 09:51 PM (UTC)
Message
I'm still trying to come to grips with what the real problem is. There is a GMCP plugin that does all the GMCP stuff, you should get nicely-parsed data that could be easiy used to draw a map.

And then your original post mentions MXP, which is confusing. Is that MXP inside GMCP? I don't think I have seen that before.

- Nick Gammon

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

Posted by Gsmith   (14 posts)  [Biography] bio
Date Reply #4 on Sun 30 Oct 2016 12:47 AM (UTC)
Message
Nick Gammon said:

And then your original post mentions MXP, which is confusing. Is that MXP inside GMCP? I don't think I have seen that before.


Yes, it's an odd one. You can request the "ASCII Map" be sent over GMCP. But it seems all this does is get the mud to spit out the exact data it spits out to the user to draw the non-GMCP map.

So the GMCP data receives exactly the same data as the MUD sends to the client to draw the regular ascii map to the output.

Which means the GMCP text, instead of being say, a nice string of an array I can JSON.decode... is just that huge long string I pasted in my original post. A big mess of raw ANSI codes, MXP codes (if the player has MXP enabled on the MUD, if not it's all pure ANSI codes for all the colouring)... and the little ASCII icons, plus the whitespace and literal "\n" strings to represent new lines.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Sun 30 Oct 2016 06:37 AM (UTC)
Message
Can you please turn on "debug packets" (Edit menu) and capture one of those map entries? I want to be confident I have the exact data you have.

- Nick Gammon

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

Posted by Gsmith   (14 posts)  [Biography] bio
Date Reply #6 on Sun 30 Oct 2016 09:46 AM (UTC)
Message
Nick Gammon said:

Can you please turn on "debug packets" (Edit menu) and capture one of those map entries? I want to be confident I have the exact data you have.


Sure, here's one in full in a single packet, for a much smaller ascii map indoors. It's the "room.map" GMCP entity. If it's going to be too much effort to manually try and filter out and handle/convert all the mix of MXP + ANSI (or just ANSI if user has MXP disabled), then I shall abandon using this part of the GMCP and go the capture-route of capturing the "real MUD-outputting" ASCII map pre-parsed and formatted by Mushclient instead (and omit it + stick it in a miniwindow). Please don't try and spend a long time on this if it's a tricky one, since I do have alternatives!

Incoming packet: 16 (1024 bytes) at Sunday, October 30, 2016, 9:42:50 AM

room.info {"iden   72 6f 6f 6d 2e 69 6e 66 6f 20 7b 22 69 64 65 6e
tifier":"2b0640d   74 69 66 69 65 72 22 3a 22 32 62 30 36 34 30 64
90cce7f39de263b0   39 30 63 63 65 37 66 33 39 64 65 32 36 33 62 30
2701633423efbd9d   32 37 30 31 36 33 33 34 32 33 65 66 62 64 39 64
9","name":"atriu   39 22 2c 22 6e 61 6d 65 22 3a 22 61 74 72 69 75
m","kind":"insid   6d 22 2c 22 6b 69 6e 64 22 3a 22 69 6e 73 69 64
e"}ÿðÿúÉroom.map   65 22 7d ff f0 ff fa c9 72 6f 6f 6d 2e 6d 61 70
 "    \u001b[3z\   20 22 20 20 20 20 5c 75 30 30 31 62 5b 33 7a 5c
u001b[4zMXP<Cyan   75 30 30 31 62 5b 34 7a 4d 58 50 3c 43 79 61 6e
MXP>\u001b[4zMXP   4d 58 50 3e 5c 75 30 30 31 62 5b 34 7a 4d 58 50
<send href=\"got   3c 73 65 6e 64 20 68 72 65 66 3d 5c 22 67 6f 74
o 3b\"MXP>*\u001   6f 20 33 62 5c 22 4d 58 50 3e 2a 5c 75 30 30 31
b[4zMXP<\/sendMX   62 5b 34 7a 4d 58 50 3c 5c 2f 73 65 6e 64 4d 58
P>\u001b[3z        50 3e 5c 75 30 30 31 62 5b 33 7a 20 20 20 20 20
\n    \u001b[3z|   5c 6e 20 20 20 20 5c 75 30 30 31 62 5b 33 7a 7c
\u001b[3z \u001b   5c 75 30 30 31 62 5b 33 7a 20 5c 75 30 30 31 62
[3z|\u001b[3z      5b 33 7a 7c 5c 75 30 30 31 62 5b 33 7a 20 20 20
\n    \u001b[3z\   5c 6e 20 20 20 20 5c 75 30 30 31 62 5b 33 7a 5c
u001b[4zMXP<Yell   75 30 30 31 62 5b 34 7a 4d 58 50 3c 59 65 6c 6c
owMXP>\u001b[4zM   6f 77 4d 58 50 3e 5c 75 30 30 31 62 5b 34 7a 4d
XP<send href=\"g   58 50 3c 73 65 6e 64 20 68 72 65 66 3d 5c 22 67
oto 3c\"MXP>@\u0   6f 74 6f 20 33 63 5c 22 4d 58 50 3e 40 5c 75 30
01b[4zMXP<\/send   30 31 62 5b 34 7a 4d 58 50 3c 5c 2f 73 65 6e 64
MXP>\u001b[3z-\u   4d 58 50 3e 5c 75 30 30 31 62 5b 33 7a 2d 5c 75
001b[3z\u001b[4z   30 30 31 62 5b 33 7a 5c 75 30 30 31 62 5b 34 7a
MXP<CyanMXP>\u00   4d 58 50 3c 43 79 61 6e 4d 58 50 3e 5c 75 30 30
1b[4zMXP<send hr   31 62 5b 34 7a 4d 58 50 3c 73 65 6e 64 20 68 72
ef=\"goto 4c\"MX   65 66 3d 5c 22 67 6f 74 6f 20 34 63 5c 22 4d 58
P>*\u001b[4zMXP<   50 3e 2a 5c 75 30 30 31 62 5b 34 7a 4d 58 50 3c
\/sendMXP>\u001b   5c 2f 73 65 6e 64 4d 58 50 3e 5c 75 30 30 31 62
[3z   \n"ÿðÿúÉro   5b 33 7a 20 20 20 5c 6e 22 ff f0 ff fa c9 72 6f
om.writtenmap "A   6f 6d 2e 77 72 69 74 74 65 6e 6d 61 70 20 22 41
n exit north of    6e 20 65 78 69 74 20 6e 6f 72 74 68 20 6f 66 20
one east, the li   6f 6e 65 20 65 61 73 74 2c 20 74 68 65 20 6c 69
mit of your visi   6d 69 74 20 6f 66 20 79 6f 75 72 20 76 69 73 69
on is one east f   6f 6e 20 69 73 20 6f 6e 65 20 65 61 73 74 20 66
rom here and the   72 6f 6d 20 68 65 72 65 20 61 6e 64 20 74 68 65
 limit of your v   20 6c 69 6d 69 74 20 6f 66 20 79 6f 75 72 20 76
ision is one nor   69 73 69 6f 6e 20 69 73 20 6f 6e 65 20 6e 6f 72
th from here.\n"   74 68 20 66 72 6f 6d 20 68 65 72 65 2e 5c 6e 22
ÿð[atrium].[4z<B   ff f0 5b 61 74 72 69 75 6d 5d 1b 5b 34 7a 3c 42
R>    .[3z.[4z<C   52 3e 20 20 20 20 1b 5b 33 7a 1b 5b 34 7a 3c 43
yan>.[4z<send hr   79 61 6e 3e 1b 5b 34 7a 3c 73 65 6e 64 20 68 72
ef="goto 3b">*.[   65 66 3d 22 67 6f 74 6f 20 33 62 22 3e 2a 1b 5b
4z</send>.[3z      34 7a 3c 2f 73 65 6e 64 3e 1b 5b 33 7a 20 20 20
  .[4z<BR>    .[   20 20 1b 5b 34 7a 3c 42 52 3e 20 20 20 20 1b 5b
3z|.[3z .[3z|.[3   33 7a 7c 1b 5b 33 7a 20 1b 5b 33 7a 7c 1b 5b 33
z   .[4z<BR>       7a 20 20 20 1b 5b 34 7a 3c 42 52 3e 20 20 20 20
.[3z.[4z<Yellow>   1b 5b 33 7a 1b 5b 34 7a 3c 59 65 6c 6c 6f 77 3e
.[4z<send href="   1b 5b 34 7a 3c 73 65 6e 64 20 68 72 65 66 3d 22
goto 3c">@.[4z</   67 6f 74 6f 20 33 63 22 3e 40 1b 5b 34 7a 3c 2f
send>.[3z-.[3z.[   73 65 6e 64 3e 1b 5b 33 7a 2d 1b 5b 33 7a 1b 5b
4z<Cyan>.[4z<sen   34 7a 3c 43 79 61 6e 3e 1b 5b 34 7a 3c 73 65 6e
d href="goto 4c"   64 20 68 72 65 66 3d 22 67 6f 74 6f 20 34 63 22
>*.[4z</send>.[3   3e 2a 1b 5b 34 7a 3c 2f 73 65 6e 64 3e 1b 5b 33
z   .[4z<BR>This   7a 20 20 20 1b 5b 34 7a 3c 42 52 3e 54 68 69 73
 is a small atri   20 69 73 20 61 20 73 6d 61 6c 6c 20 61 74 72 69
um.  The floor a   75 6d 2e 20 20 54 68 65 20 66 6c 6f 6f 72 20 61
nd ceiling are f   6e 64 20 63 65 69 6c 69 6e 67 20 61 72 65 20 66
itted with white   69 74 74 65 64 20 77 69 74 68 20 77 68 69 74 65
 oak boards and    20 6f 61 6b 20 62 6f 61 72 64 73 20 61 6e 64 20
the other surfac   74 68 65 20 6f 74 68 65 72 20 73 75 72 66 61 63
es are covered w   65 73 20 61 72 65 20 63 6f 76 65 72 65 64 20 77
ith apple white    69 74 68 20 61 70 70 6c 65 20 77 68 69 74 65 20
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Sun 30 Oct 2016 10:16 PM (UTC)
Message
Hmm, it's very weird. I don't think I have seen anything like it. I can explain a bit of it.


\u001b[3z


The sequence \u001b is simply the "escape" character (0x1B) so that is just ESC [ 3z which is an undocumented MXP sequence.

I think these guys have just made stuff up.

Quote:

... and go the capture-route of capturing the "real MUD-outputting" ASCII map pre-parsed and formatted by Mushclient instead (and omit it + stick it in a miniwindow)


I think that would be way simpler.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[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.


2,539 views.

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]