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

Gammon Software Solutions forum

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

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Filtering out / altering part of the received text

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Filtering out / altering part of the received text

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page


Posted by Parduz   Italy  (8 posts)  [Biography] bio
Date Mon 30 Jul 2012 02:08 PM (UTC)  quote  ]

Amended on Mon 30 Jul 2012 02:11 PM (UTC) by Parduz

Message
The MUD i play have a dedicated client, with some nice features (like visual map, clickable icons at the left of the description, etc).
To implement this, when it connect it sends a special string, and the server then "switches" from normal telnet to "dedicated client".
I'd like to keep this "dedicated" set using MUSH 'cause there's more infos sent from the server, but i need then to "convert" some of data received.
These is a list of the first thing i'd like to convert:

1) Line colors are no more ansi codes, but defined by "&#", where "#" is the initial of one of the standard color (so "&y" means a yellow font color. I learned how to "trap" that lines with a trigger, but how can i remove the "&#" part and replace it with the standard ANSI code?

2) The map is sent using non-ascii charachters. How can i "grab" them and send them to the (still to be made) mapping window?

3) How can i search for a string that begins with, say, - "AbCd - (the " char is part of the string) followed by 5 numbers, comma separated, and show only what follow the last comma in a new line?
(examples:
"AbCd-123,1,2,0,456345,This is the text i need to show
"AbCd-78,1,2,0,1234,This is another text i need to show
)

Thanks
[Go to top] top

Posted by Fiendish   USA  (848 posts)  [Biography] bio   Global Moderator
Date Reply #1 on Tue 31 Jul 2012 12:41 AM (UTC)  quote  ]

Amended on Tue 31 Jul 2012 12:43 AM (UTC) by Fiendish

Message
Quote:
how can i remove the "&#" part and replace it with the standard ANSI code?


The simplest way to do this is

color_ANSI = {
   k = ANSI(0,30),
   r = ANSI(0,31),
   g = ANSI(0,32),
   y = ANSI(0,33),
   b = ANSI(0,34),
   m = ANSI(0,35),
   c = ANSI(0,36),
   w = ANSI(0,37),
   K = ANSI(1,30),
   R = ANSI(1,31),
   G = ANSI(1,32),
   Y = ANSI(1,33),
   B = ANSI(1,34),
   M = ANSI(1,35),
   C = ANSI(1,36),
   W = ANSI(1,37)
}

ANSIstring = string.gsub(str,"&([^&])", color_ANSI)


Quote:
The map is sent using non-ascii charachters. How can i "grab" them and send them to the (still to be made) mapping window?
Plenty of other threads talk about how to make triggers.

Quote:
How can i search for a string that begins with, say, - "AbCd - (the " char is part of the string) followed by 5 numbers, comma separated, and show only what follow the last comma in a new line?
Plenty of other threads talk about how to make triggers.

http://aardwolfclientpackage.googlecode.com/
[Go to top] top

Posted by Parduz   Italy  (8 posts)  [Biography] bio
Date Reply #2 on Thu 30 Aug 2012 03:59 PM (UTC)  quote  ]

Amended on Thu 30 Aug 2012 04:02 PM (UTC) by Parduz

Message
Fiendish said:

Quote:
how can i remove the "&#" part and replace it with the standard ANSI code?


The simplest way to do this is

color_ANSI = {
   k = ANSI(0,30),
   r = ANSI(0,31),
   g = ANSI(0,32),
   y = ANSI(0,33),
   b = ANSI(0,34),
   m = ANSI(0,35),
   c = ANSI(0,36),
   w = ANSI(0,37),
   K = ANSI(1,30),
   R = ANSI(1,31),
   G = ANSI(1,32),
   Y = ANSI(1,33),
   B = ANSI(1,34),
   M = ANSI(1,35),
   C = ANSI(1,36),
   W = ANSI(1,37)
}

ANSIstring = string.gsub(str,"&([^&])", color_ANSI)

It works, but then i'd like to add some other values to this table.... how can i add a "-" to it (the client receive lines containing the string "&-")?


Fiendish said:
Quote:
The map is sent using non-ascii charachters. How can i "grab" them and send them to the (still to be made) mapping window?
Plenty of other threads talk about how to make triggers.
Quote:
How can i search for a string that begins with, say, - "AbCd - (the " char is part of the string) followed by 5 numbers, comma separated, and show only what follow the last comma in a new line?
Plenty of other threads talk about how to make triggers.

I know. I've read a lot of page. It may be that LUA is new for me, it may be that RegExp are barely understandable, for me; it may be that being English not my first language i'm missing something. It may be that i'm dumb, also.
Anyway, i've still to found a solution.
I tried with a regExp generator (http://osteele.com/tools/rework/#) but the result is not "valid" in the script.

I'll try to ask again, expanding my question.

This are a packet i receive, breaking it in multiple lines to show the various "fields" i need to work with:
1) &d001100
2) &!pi" [»²»2©]2»²])2»2)6»²]\» \;"
3) &!t"Le stalle"
4) &!d"Questa deve essere la stanza dove vengono custoditi i cavalli. Qui il tipico odore di cavalli e ronzini e' molto piu' forte. Non riesci a scorgere il pavimento, tanta e' la paglia che lo ricopre. Su un soppalco sono accumulati grossi fasci di fieno ed avena e alzando lo sguardo noti le grosse travi che sorreggono il soffitto."
5) &!ao"605,0,1,0,70312,Vedi una torcia accesa, posta su un sostegno di ferro infisso alla parete. "
5) &!am"157,0,1,0,632008,Un grasso nano si gratta nervosamente la barba."
6) &o6
7) &!st"22,22,0,0,115,131"

They are, in the order:
1) Unknown data
2) Map data (contains also non ascii chars)
3) Title
4) Description
5) Room contents
6) Weather graphics
7) Status data (health, stamina, mana)

What i'd need, after some thoughs, is to remove the "&!" special code, save the relative lines (and numeric fields) in some global variables, and put in the output everything is between the << " >> chars.
So i put your code in the plugin OnPluginPacketReceived function, and i tried to expand that function.

Trying to follow your example, and using that RegExp generator, i wrote a line to remove the numeric fields from 5)

ANSIstring,n = string.gsub (ANSIstring, '&!ao"([0-9]*,)([0-9]*,)([0-9]*,)([0-9]*,)([0-9]*,)', "\n&g")

Still, i have problems 'cause i'm not able to search for the ([0-9]*,) pattern 5 times, i don't know how to save what i've found in a variable, and how to keep only what's inside the quotes.

Thanks



[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Fri 31 Aug 2012 11:16 PM (UTC)  quote  ]
Message
Quote:

Still, i have problems 'cause i'm not able to search for the ([0-9]*,) pattern 5 times, i don't know how to save what i've found in a variable, and how to keep only what's inside the quotes.


Just to address that point:


(([0-9]+,){5})



Template:regexp Regular expressions
  • Regular expressions (as used in triggers and aliases) are documented on the Regular expression tips forum page.
  • Also see how Lua string matching patterns work, as documented on the Lua string.find page.

- Nick Gammon

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

Posted by Fiendish   USA  (848 posts)  [Biography] bio   Global Moderator
Date Reply #4 on Sat 01 Sep 2012 03:32 AM (UTC)  quote  ]

Amended on Sat 01 Sep 2012 03:33 AM (UTC) by Fiendish

Message
Parduz said:
It works, but then i'd like to add some other values to this table.... how can i add a "-" to it (the client receive lines containing the string "&-")?

I don't understand. What color is "&-" supposed to be?

Quote:
Trying to follow your example, and using that RegExp generator, i wrote a line to remove the numeric fields from 5)

ANSIstring,n = string.gsub (ANSIstring, '&!ao"([0-9]*,)([0-9]*,)([0-9]*,)([0-9]*,)([0-9]*,)', "\n&g")

Er, I think maybe you should read about string.gsub at http://lua-users.org/wiki/StringLibraryTutorial
And why are you doing things there instead of as simple triggers?

http://aardwolfclientpackage.googlecode.com/
[Go to top] top

Posted by Parduz   Italy  (8 posts)  [Biography] bio
Date Reply #5 on Sat 01 Sep 2012 11:33 AM (UTC)  quote  ]
Message
Fiendish said:

Parduz said:
It works, but then i'd like to add some other values to this table.... how can i add a "-" to it (the client receive lines containing the string "&-")?

I don't understand. What color is "&-" supposed to be?

It's the "command" to reset to default color (white) so that each line that have no "&" key is shown in that color.

Fiendish said:

Quote:
Trying to follow your example, and using that RegExp generator, i wrote a line to remove the numeric fields from 5)

ANSIstring,n = string.gsub (ANSIstring, '&!ao"([0-9]*,)([0-9]*,)([0-9]*,)([0-9]*,)([0-9]*,)', "\n&g")

Er, I think maybe you should read about string.gsub at http://lua-users.org/wiki/StringLibraryTutorial

I read a lot about it, and still feeling lost.

Fiendish said:

And why are you doing things there instead of as simple triggers?

'cause i see this all as the necessary "work" to make the server packet "compatible" with MUSHclient. At "packet level" i'd do all the jobs that are related to what the user "can't see" (so converting the strings in maps, weather and stats images, etc). Without user triggers, just loading the plugin will make MUSHclient similar to the original client behaviour as much as possible.
Then i plan to write triggers to add features that that client/server actually lacks.
Is this a bad/wrong/inefficent approach? If yes, why?
[Go to top] top

Posted by Fiendish   USA  (848 posts)  [Biography] bio   Global Moderator
Date Reply #6 on Sat 01 Sep 2012 07:01 PM (UTC)  quote  ]
Message
Parduz said:

Fiendish said:

Parduz said:
It works, but then i'd like to add some other values to this table.... how can i add a "-" to it (the client receive lines containing the string "&-")?

I don't understand. What color is "&-" supposed to be?

It's the "command" to reset to default color (white) so that each line that have no "&" key is shown in that color.

Ah, interesting. In order to have special characters like - as a table key, you need to do use ["-"] instead of just -.
So change the color_ANSI table to be this:

color_ANSI = {
   k = ANSI(0,30),
   r = ANSI(0,31),
   g = ANSI(0,32),
   y = ANSI(0,33),
   b = ANSI(0,34),
   m = ANSI(0,35),
   c = ANSI(0,36),
   w = ANSI(0,37),
   K = ANSI(1,30),
   R = ANSI(1,31),
   G = ANSI(1,32),
   Y = ANSI(1,33),
   B = ANSI(1,34),
   M = ANSI(1,35),
   C = ANSI(1,36),
   W = ANSI(1,37),
   ["-"] = ANSI(0)
}


Parduz said:

Fiendish said:

And why are you doing things there instead of as simple triggers?

'cause i see this all as the necessary "work" to make the server packet "compatible" with MUSHclient. At "packet level" i'd do all the jobs that are related to what the user "can't see" (so converting the strings in maps, weather and stats images, etc). Without user triggers, just loading the plugin will make MUSHclient similar to the original client behaviour as much as possible.
Then i plan to write triggers to add features that that client/server actually lacks.
Is this a bad/wrong/inefficent approach? If yes, why?
I think it is a bad/inefficient approach. You are doing twice the work in two different places to convert the lines to a different format and then convert them again to another different format. You could just trigger on the original lines and do one conversion in one place to the final output.

http://aardwolfclientpackage.googlecode.com/
[Go to top] top

Posted by Parduz   Italy  (8 posts)  [Biography] bio
Date Reply #7 on Sat 01 Sep 2012 08:39 PM (UTC)  quote  ]
Message
Fiendish said:

Ah, interesting. In order to have special characters like - as a table key, you need to do use ["-"] instead of just -.

Thanks!
Fiendish said:

I think it is a bad/inefficient approach. You are doing twice the work in two different places to convert the lines to a different format and then convert them again to another different format. You could just trigger on the original lines and do one conversion in one place to the final output.

Perhaps i've not been clear, sorry for that.
The conversion we're talking on the first lines (the function that use the table) is the last "step" in the received packet event. Before of it i do the other jobs (removing the "&!" lines). So everything happens in the same "event" (the packet received) before making it "available" on the output window.
If this is still inefficient, then pls teach me where should i do it all. Pls note that i need to "grab" that "&!" lines as they contains needed data....

.... and while we're talking about them, how could i store that data while i remove them from the output?
I'm reading LUA tables, and seems to me that i could use them both as "structures" and as arrays.... my C++ heritage makes understanding LUA a bit hard :)
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Reply #8 on Sat 01 Sep 2012 11:37 PM (UTC)  quote  ]
Message
Just to keep the steam from emerging from my ears, please refer to it as Lua, not LUA. It isn't an acronym.

Yes, tables can be used, in effect, as structures. Since a table can contain other data types, including tables, you can effectively make the top-level table be an "array" so to speak, and then each array item is another table, this being the structure.

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

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

- Nick Gammon

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

Posted by Fiendish   USA  (848 posts)  [Biography] bio   Global Moderator
Date Reply #9 on Sun 02 Sep 2012 08:52 PM (UTC)  quote  ]

Amended on Sun 02 Sep 2012 09:02 PM (UTC) by Fiendish

Message
Parduz said:

I'm reading Lua tables, and seems to me that i could use them both as "structures" and as arrays.... my C++ heritage makes understanding Lua a bit hard :)


In C++ terms, Lua's table is a class that inherits from std::map. It does two things differently than std::map.
1) It overloads insert with a function that automatically assigns a sequential numeric key if no key is provided
2) It allows for other arbitrary dynamic method and operator overrides (via the Lua metatable) as if each C++ member method were actually entries in a map of <method name, function pointer> pairs that happen to point to the default set of functions but can be reassigned or removed or created at any time.

http://aardwolfclientpackage.googlecode.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.


1,151 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

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

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]