|
Nibbles Beginner
Joined: 01 Aug 2004 Posts: 15
|
Posted: Fri Aug 20, 2004 11:49 pm
Capturing Multiple Lines to a Variable |
I have a dilemma that I've been working all day to figure out. I'm trying to create an environment in ZMud for a MUD that uses a custom client. The MUD itself sends everything in command packets, which are in the format of
ðCMD Infoð
Where ð is a special escape character(Decimal #240) and CMD is a 3-character string. The problem I'm having, is that Info can be multiple lines, and the number of lines is not pre-determined. How can I capture all of Info to a variable to be passed to the command handler? There are no escape characters in the Info, so I know that it ends when one is encountered. There's no newline after the ending escape character.
The trigger I was using was a perl regular expression, ð(@std__commandhandlers)([^ð]*)ð
I thought that [^ð] would capture newlines, but it doesn't :-/
Is this even possible or am I pushing ZMud too much? |
|
|
|
Seb Wizard
Joined: 14 Aug 2004 Posts: 1269
|
Posted: Sat Aug 21, 2004 2:40 am |
It might help if you have some sample output from the mud?
|
|
|
|
Nibbles Beginner
Joined: 01 Aug 2004 Posts: 15
|
Posted: Sat Aug 21, 2004 3:15 am |
ðMSG\b\cf3 HolyGixm \cf3 has left the world. \b0\cf2 ððMSG\b\cf3 Talrun \cf3 has left the world. \b0\cf2 ððLNOSocket disconnected: Client did not send valid login packet within 4 seconds.ð
|
|
|
|
geniusclown Magician
Joined: 23 Apr 2003 Posts: 358 Location: USA
|
Posted: Sat Aug 21, 2004 2:23 pm |
Did you try...?:
Quote: |
#REGEX {ð(@std__commandhandlers)([.\r\n]*)ð |
This should allow any character, including carriage return or line feed, to match between the ð characters. |
|
_________________ .geniusclown |
|
|
|
Nibbles Beginner
Joined: 01 Aug 2004 Posts: 15
|
Posted: Sun Aug 22, 2004 10:36 pm |
That didn't seem to work. In ZMud's #REGEX help file, \r isn't listed as a valid character, however it still didn't seem to work even after I removed \r and left \n :-(.
|
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Mon Aug 23, 2004 12:24 am |
The #REGEX help file is by no means a complete reference to the capabilities of regular expressions.
It is very likely in any case that you will have to create your own parser for this anyway. zMud triggers fire once per line and your example shows multiple 'command packets' per line. This will require that the data be parsed out. By the look of the data you presented everything is delimeted with the 'ð' character. So a simple open end trigger will suffice for capture and then parsing can be preformed with the use of %word.
#VAR CommandStore {} {}
#TR {*} {CommandStore=%concat(@CommandStore,%line);#GAG 0;#WHILE (%pos("ð",@CommandStore)) {#WHILE (%begins(@CommandStore,"ð")) {CommandStore=%remove("ð",@CommandStore)};#IF (%pos("ð",@CommandStore)) {#ECHO Current command is %word(@CommandStore,1,"ð");CommandStore=%remove(%word(@CommandStore,1,"ð"),@CommandStore)}}}
The #ECHO in there is where you actually act on commands, overall it should be right but I occasionally forget the order of arguements in some functions so start by looking up the functions used in the help and try to understand it before you look to use it. There are other shortcuts that could be used, but they lose the integrity provided by a beginning and ending character on each command. |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
Nibbles Beginner
Joined: 01 Aug 2004 Posts: 15
|
Posted: Tue Aug 24, 2004 2:03 am |
I wasn't aware that ZMud implemented full regular expressions, I thought only the options mentioned in the help file were available.
Anyways, using a (*) trigger and a modified version of your code I was able to come up with something that works almost all of the time. However, for some reason, there's something that still doesn't get interpreted everytime I log on:
Male Warrior\b0
Exp: 30 (30.00%)
For Level: 100
\bStatistics:\b0
Strength: \cf0 15 \cf0 (15)
Toughness: \cf0 12 \cf0 (12)
Agility: \cf0 10 \cf0 (10)
Focus: \cf0 6 \cf0 (6)
Intelligence: \cf0 6 \cf0 (6)
Charisma: \cf0 6 \cf0 (6)
Damage: 6 - 13
Atk Spd: 3.0 (0%)
Kick: 5 - 11
Armor: 0
Absorb: 0%
Burden: 12 / 90
Gold: 0
\bMagic Resistance:\b0
NoneððCDG--- Faction Status ---
ððCDE ððUKL[Ready] Kick I,Swords I,|ððUSL|ððUPLyes Eldan_Avenue The_avenue_turns_to_the_north_here,_towards_Main_Street._To_the_west_is_the_large_manor_of_Harn
_Sedgeway_himself._With_all_his_wealth,_you_wonder_why_his_manor_is_simply_constructed_out_of_wood. ynyyn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_-1_0_14_,1_-2_0_14_,2_-2_0_14_,3_-1_0_14_,-4_-2_0_14_,5_-1_0_14_,5_1_0_14_,4_2_0_16_,
5_2_0_15_,-4_-1_0_7_,-4_1_0_7_,1_1_-1_14_,|ððMSG\b[Mail] You have no new mail. You have 0 total messages. Newest message received at .\b0ð
Added some linebreaks to the above sequence of numbers so they didn't run off the screen, but you get the idea.
Here's my trigger, notice that the first command is #GAG. I don't see how it's possible that this information comes through when I've got a (*) trigger that gags everything!
#GAG 0
#VAR std__recvbuf {%concat( @std__recvbuf, %1)}
#VAR __temp1 {1}
#WHILE (%begins( @std__recvbuf, ð) & (@__temp1 != 0)) {
#VAR __temp1 {%pos( ð, %remove( ð, @std__recvbuf))}
#IF (@__temp1 != 0) {
#VAR std__recvbuf {%remove( ð, @std__recvbuf)}
#VAR std__curcommand {%word( @std__recvbuf, 1, ð)}
#VAR std__recvbuf {%remove( @std__curcommand, @std__recvbuf)}
#VAR std__recvbuf {%remove( ð, @std__recvbuf)}
#VAR std__curinfo {%right( @std__curcommand, 3)}
#VAR std__curcommand {%left( @std__curcommand, 3)}
#IF (%ismember( @std__curcommand, @std__commandhandlers)) {std_comm@{std__curcommand}} {#WINDOW Errors {Invalid command @std__curcommand - @std__curinfo}}
} {#VAR std__recvbuf {%concat( @std__recvbuf, %char( 10))}}
}
#IF ((%len( @std__recvbuf) > 0) & (%begins( @std__recvbuf, ð) == 0)) {
#WINDOW Errors {Beginning of buffer is not escaped!}
#VAR std__recvbuf {}
}
#UNVAR __temp1
This basically puts the 3-letter command in std__curcommand and the rest of the information into std__curinfo. If there's only 1 escape character in the buffer, it assumes that it just received a newline that is part of a command and appends a newline to the buffer.
I get several "Beginning of buffer is not escaped!" errors everytime I logon, and whenever that same info is displayed(IE, whenever my character stats change). I have the trigger set to activate on either Prompt or Newline so... I'm all out of ideas. This is liveable, as the majority of things work now, but I'd like to get that ugly information off the screen and into a variable somewhere. |
|
|
|
Nibbles Beginner
Joined: 01 Aug 2004 Posts: 15
|
Posted: Tue Aug 24, 2004 5:37 am |
I figured it out! I had to separate it into two triggers, one as above that triggered on prompt, and one that triggered on newline which simply appends to the buffer and adds a newline. Thanks for help to everyone, it works perfectly now :-).
|
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|