Forcing newlines on prompt lines

Posted by Nick Gammon on Mon 13 Dec 2004 12:37 AM — 49 posts, 187,071 views.

Australia Forum Administrator #0
With the new functionality of OnPluginPacketReceived it is now possible to "fool" MUSHclient into thinking prompt lines have a newline after them, even if they don't.

This can be useful for situations where you want a trigger to match a prompt line the moment it arrives, which it won't normally because trigger matching happens when a newline is received.

The way it is done is this:

  • The plugin below receives all incoming text from the MUD.
  • It batches the packets into lines, as sometimes lines are split over packets
  • All of the lines, except the last one, are just reassembled into normal lines with a newline between them.
  • The final line (one with no newline after it), is tested against a regular expression which should be set up to match your prompt.

    In my test case the prompt was:


    (ESC)[0m<1000/1000hp 100/100m 110/110mv 2000/315816750xp>


    The very first character is the "Escape" character (hex 1B) which is used in this case to reset colours to the default. (ESC[0m). Since we are expecting that we build it into the regular expression.

    Note that in the regular expression we have to use two backslashes, as the first is used by Lua to indicate that the second is a "literal" backslash. This gets passed to the regular expression engine as \x1B to indicate the "escape" character.

    If the regular expression matches, then the final (partial) line is also returned to MUSHclient (with a newline after it) thus effectively adding the newline to the prompt line.
  • The lines (saved into table t) are concatenated back into a single string with a newline between each table entry, and returned as the function result.


To use this, just copy below the line, and paste into a text window (notepad window). Change the regular expression (line 3) to match your prompt line, save as Add_Newline_To_Prompt.xml and then install it as a plugin.

All being well, your prompt lines should now automatically end with a newline, and thus match triggers immediately.


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient[
  <!ENTITY prompt_regexp "^\\x1B\\[0m&lt;.+hp .+m .+mv .+xp&gt; $" > 
]>
<!-- MuClient version 3.59 -->

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

<muclient>
<plugin
   name="Add_Newline_To_Prompt"
   author="Nick Gammon"
   id="8316c19c35a9ebdb46055874"
   language="Lua"
   purpose="Adds a newline to prompt lines"
   date_written="2004-12-13 12:08:00"
   requires="3.59"
   version="1.0"
   >
<description trim="y">
Detects prompt lines without a newline, and if found, adds one.

Change ENTITY line on 3rd line of plugin to be a regular expression 
that matches your prompt.

</description>

</plugin>

<!--  Script  -->

<script>

  re = rex.new ("&prompt_regexp;")

<![CDATA[

partial = ""  -- partial line from last time through

function OnPluginPacketReceived (s)

  -- add packet to what we already have (excluding carriage-returns)
  
  partial = partial .. string.gsub (s, "\r", "")
  
  t = {}  -- table of lines to be returned
  
  -- iterate over each line
  
  partial = string.gsub (partial, "(.-)\n", 
    function (line) 
     table.insert (t, line) 
     return "" -- added for MUSHclient 3.80+
    end)
  
  -- look for prompt

  if (re:match (partial)) then
    table.insert (t, partial)
    partial = ""
  end -- if found prompt

  if table.getn (t) > 0 then
    table.insert (t, "")  -- to get final linefeed
  end -- if
    
  -- return table of lines, concatenated with newlines between each one
  return table.concat (t, "\n")
  
end -- function OnPluginPacketReceived
]]>
</script>

</muclient>



[EDIT] Amended on 22 October 2006 to make a change so that this plugins works with MUSHclient 3.80 onwards. The amended line is in bold (return "") and the surrounding lines have been reformatted a bit. See this forum post for a discussion:

http://www.gammon.com.au/forum/?id=7430&page=999
Amended on Sat 21 Oct 2006 10:30 PM by Nick Gammon
Australia Forum Administrator #1
Below is a simpler approach. The first one presented above, which breaks the packet into lines, is probably overkill for this application, although it is useful to illustrate how you would do that.

That version could be extended to omit certain lines, since it already processes each line individually.

The one below simply tests each packet against a regular expression, like:

(blah blah)<prompt line>

This uses a multi-line regular expression (hence the (?m) at the start) and if it find a prompt at the very end, adds a newline to it.


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient[
  <!ENTITY prompt_regexp "(?m)^.*&lt;.+hp .+m .+mv .+xp&gt; \\z" > 
]>
<!-- MuClient version 3.59 -->

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

<muclient>
<plugin
   name="Add_Newline_To_Prompt_2"
   author="Nick Gammon"
   id="a14e9768c3ad5ce50d202ee0"
   language="Lua"
   purpose="Adds a newline to prompt lines"
   date_written="2004-12-13 14:27"
   requires="3.59"
   version="1.0"
   >
<description trim="y">
Detects prompt lines without a newline, and if found, adds one.

Change ENTITY line on 3rd line of plugin to be a regular expression 
that matches your prompt.

</description>

</plugin>

<!--  Script  -->

<script>

re = rex.new ("&prompt_regexp;")

<![CDATA[

function OnPluginPacketReceived (s)

  if (re:match (s)) then
    return s .. "\n"	
  else
    return s
  end -- if 
  
end -- function OnPluginPacketReceived
]]>
</script>

</muclient>
Amended on Mon 13 Dec 2004 02:41 AM by Nick Gammon
#2
Hmmm, how can I use that in Achaea? I have a trigger firing great and the regexp looks like
^(\d+)h, (\d+)m (?:\d+[we] |)(?:\d+[we] |)(\D{0,7})\-

If I try to use that in the plugin nothing happens. Mush keeps waiting for an Enter/newLine before he continues. I have no idea what I am doing wrong. Can i use the regular trigger in the GUI and use the Plugin too, or do they interfere in a way?

Oh, and it works great on a USB-stick, including scite-editor...so the same thing at work and on the linux-box at home.

Flyto

USA #3
You need to escape your backslashes (\\) in the entity.

And yes, you do use normal triggers.
The trigger in the plugin only tells MC what to add a newline after. So make sure it is your full prompt.
You then use your normal triggers to actually do stuff with that prompt.
Amended on Sun 02 Jan 2005 08:24 PM by Flannel
Australia Forum Administrator #4
Flannel is right. The backslashes in the regular expression are swallowed up by the Lua interpreter, so you need to double them when putting them into the plugin.

eg. In Lua (and Jscript) if you write this:

a = "\n"

It puts a newline into a. If you want to put in the backslash literally (which you do for a regular expression) you need to put another backslash, eg.

a = "\\n"
#5
*scratch*, really trying hard, but it simply doesnt sip the vials when nothing else happens. I made the regexp more simple....from perl...
qr/(\d+)h,.+m\s(\d+)m(.+)-/o
I made in simple LUA-plugin (because I dont need the values):
<!ENTITY prompt_regexp ".+h, .+m(.+)-" >
or did I forget something. BTW the original Prompt looks like
3340h, 3796m ex-
Do I have to strip all Ansi-Codes too? And...*shrug*. Any Ideas? Thank you for the help.

Flyto
#6
Finally I found a Regexp firing..the entity is

<!ENTITY prompt_regexp "(\\d+)h,.+m\\s(\\d+)m(.+)-" >

This is about the only thing that matches the prompt. But the problem I have now that there is on effect by adding a "\n", still needing a manual Enter. The rest of the Plugin is exactly the same as in the forum.

This is my function

function OnPluginPacketReceived (s)
if (re:match(s)) then
return s .. "\n"
else
return s .. "not matched"
end -- if
end -- function OnPluginPacketReceived

I have no idea how OnPluginPacketReceived works so i lay my fate in your hands *chuckle*

...Flyto...
Australia Forum Administrator #7
Quote:

This is about the only thing that matches the prompt. But the problem I have now that there is on effect by adding a "\n", still needing a manual Enter.


What do you mean? It works, but it doesn't work?

Are you seeing "not matched" popping up all the time in your output window?

What the plugin is supposed to do is modify the incoming packet, so MUSHclient thinks the <enter> is there all along.

If the prompt has ANSI codes you will need to detect those, after all the trigger is matching literally. Try using Edit -> Debug Packets to see exactly what is arriving.
#8
The prompt is detected but I dont see any difference in behavior of my script.

I dont see any "not matched" in my window. But I have another script catching the health and mana-values and if it falls below x, I should sip some elixirs.

The bad thing is that I only drink if something else happens in the mud or ... if I press Enter manually, so the plugin doesnt affect that. The Autosipper is NO plugin or should it be one?

...Flyto...
Australia Forum Administrator #9
If the plugin is installed you should see the newline added to it, or "not matched" appearing for every packet.

What version of MUSHclient do you have? It was only recently changed to allow packet changing.
#10
I use 3.65, and the regexp matches the prompt.....if I do

function OnPluginPacketReceived (s)
if (re:match(s)) then
return s .. "Eureka!!\n"
else
return s .. "not matched"
end -- if
end -- function OnPluginPacketReceived

I see lots of Eurekas after every prompt, but no autosip until i hit Enter. Maybe I should check the Autosipper, I am very new to Mush and never heard of Lua before.


Australia Forum Administrator #11
If you are seeking Eurekas then clearly the plugin is working. Now you need to see what the autosipper is doing. Are there some tests in it that stop it working immediately?

Also, some of those were written before the days when you could force newlines on prompts, and detected a line *without* a newline.

Now, you just need a simple trigger to detect the incoming prompt.
#12
It took long, but after lots of debugging (thanks to Notes) I found the error. It wasnt the plugin, it was indeed the Sipper. This is what the problem caused...

DoAfterSpecial (5, 'SetVariable ("elBalance", 1)', 12)

elBalance is a variable checking if I can drink another sip - time-based - got a trigger-based balanced as backoff.

the Timer-part is being processed after an Enter (manually or by an input from the mud)
#13
Is there a possibility to solve the Timer/SetVariable-problem?
Australia Forum Administrator #14
What problem is that exactly?
#15
ok, here is the evil chunk of script causing the problem


function PromptCheck (name, output, wildcs)
   health = tonumber(wildcs[1])
   mana = tonumber(wildcs[2])
   if autoHeal == 1 and var.elixBalance == "1" then
     if health < 2500 then  
	Send ("drink health")
	SetVariable("elixBalance", "0")
	var.elixBalance = "0"
	DoAfterSpecial (5, "SetVariable('elixBalance', '1')", 12)
     end --if health
     if mana < 3500 then 
	Send ("drink mana")
	var.elixBalance = "0"
	SetVariable("healthBalance", "0")
	DoAfterSpecial (5, "SetVariable('elixBalance', '1')", 12)
    end --if mana
  end -- if autoheal
end --function


The problem is that the Variable healthBalance gets the new Value, and though the new sip-command is being triggered after another Enter/Mudoutput.

Amended on Fri 07 Jan 2005 07:50 PM by Nick Gammon
Australia Forum Administrator #16
This is in Lua, right? And you are using my "var" table from the example script file or this forum?

Then, these two lines are doing the same thing:


SetVariable("elixBalance", "0")
var.elixBalance = "0"


I presume you are doing this to re-enable drinking elixer after 5 seconds ...


DoAfterSpecial (5, "SetVariable('elixBalance', '1')", 12)


However with "send to script" you may as well be consistent and do it the same way:


DoAfterSpecial (5, "var.elixBalance = 1", 12)


You don't really need to quote the '1' because MUSHclient variables are always stored as strings, they will be converted for you.

I'm not sure what the variable healthBalance is being used for. You set it to zero at one point but never to any other value.

Perhaps it would work better like this:



function PromptCheck (name, output, wildcs)
  local health = tonumber (wildcs [1])
  local mana = tonumber (wildcs [2])

  if autoHeal == 1 then

    if health < 2500 and var.elixBalance == "1" then  
      Send ("drink health")
      var.elixBalance = 0
      DoAfterSpecial (5, "var.elixBalance = 1", 12)
    end --if health

    if mana < 3500 and var.healthBalance == "1" then 
      Send ("drink mana")
      var.healthBalance = 0
      DoAfterSpecial (5, "var.healthBalance = 1", 12)
    end --if mana

  end -- if autoheal
end --function

Amended on Fri 07 Jan 2005 08:07 PM by Nick Gammon
#17
oops, I was playing around with the two sets of varibles, this is why I had a double varible assignment. After trying various combinations of varibles (Mush/Scipt) I came to the conclusion that its much easier jsut using scrip-internal ones, and even the annoying "wait-for-enter" problem is solved. The sipper works great now.

Thank you for the help.
#18
IRE muds definitely send GA/EOR after each prompt. Nick, would it be so hard to add a checkbox so this newline is being added automatically?
USA #19
You could do it easily with packets in a plugin.
#20
I do understand that...But it's faster if a client does it itself, not some workaround plugin (GA/EOR gets sent, why just ignore it?) . To me, it is just a convenience question.
Australia Forum Administrator #21
Can you get an example packet for me? What is the GA/EOR in hex? Go to Edit -> Debug Packets, and get a prompt line (and then turn it off).

Find the edit window it appeared in (underneath or nearby) and copy and paste it here. Thanks.
#22
It is pretty straighforward for GA/EOR...

It is either IAC GA, or IAC EOR. In imperian, for example, it is IAC GA.

The packet is the following:

          H:.[32   68 65 20 6c 61 6e 64 2e 0d 0a 48 3a 1b 5b 33 32
m86.[37m M:.[32m   6d 38 36 1b 5b 33 37 6d 20 4d 3a 1b 5b 33 32 6d
117.[37m <.[32me   31 31 37 1b 5b 33 37 6d 20 3c 1b 5b 33 32 6d 65
.[37m.[32mb.[37m   1b 5b 33 37 6d 1b 5b 33 32 6d 62 1b 5b 33 37 6d
> ..               3e 20 ff f9


Notice FF F9 bytes in the end - it is IAC(FF) GA(F9). The prompt ends with > and space.
Amended on Sun 09 Jan 2005 06:50 AM by Nick Gammon
Australia Forum Administrator #23
OK, I have added this to version 3.66 along with telnet negotiation for it (IAC WILL GA -> IAC DO GA, IAC WILL EOR -> IAC DO EOR).

I hope EOR is 0xEF, the documentation is a bit obscure on that point. Or is EOR 0x19 without the IAC?

At present I am recognising 0xFF 0xEF as EOR, but not 0x19 on its own.
#24
EAR itself is IAC EOR (255, 239).

For negotiations, a command code for EOR is 25(hex 19) - is is used for IAC WILL, IAC DO and such.
#25
As for GA negotiations, there is no IAC WILL GA options, if i got it correctly from RFC.

The only option for GA is SUPRESS-GO-AHEAD(3), it is used for well, supressing GA-s. The RFC for it is: ftp://ftp.isi.edu/in-notes/rfc858.txt
Australia Forum Administrator #26
How confusing is that? Alright, I have changed the WILL/WONT to use 0x19 but the actual sequence to be acted on is still 0xFF 0xEF.
Canada #27
I have a question about this plugin.

It works great and achieves what I needed. However, when the trigger matches and the newline is put in, is there any way to get the next packet to start on that newline? I'm now getting an extra blank line after every prompt which is incredibly spammy when you're in combat on the MUD I play (Aetolia).

Here's an example of what my output looks like without the plugin:

H:2886 M:2952 E:14090 W:17420 B:100% [db eb]
(Novices): Bob says, "No? It is a friendly little competition that will 
earn you gold and perhaps a prize."
H:2886 M:2952 E:14090 W:17420 B:100% [db eb]
(Novices): Jim says, "Hmm, well i never did it before."
H:2886 M:2952 E:14090 W:17420 B:100% [db eb]
(Novices): Wendy says, "Ooh.. it can be fun."
H:2886 M:2952 E:14090 W:17420 B:100% [db eb]


With the plugin, the same output looks like this:


H:2886 M:2952 E:14090 W:17420 B:100% [db eb]

(Novices): Bob says, "No? It is a friendly little competition that will 
earn you gold and perhaps a prize."
H:2886 M:2952 E:14090 W:17420 B:100% [db eb]

(Novices): Jim says, "Hmm, well i never did it before."
H:2886 M:2952 E:14090 W:17420 B:100% [db eb]

(Novices): Wendy says, "Ooh.. it can be fun."
H:2886 M:2952 E:14090 W:17420 B:100% [db eb]



After each prompt, the newline is blank and the next bit of output starts on the line after that. Is there any way to gag that blank line?

I know this doesn't seem too major, but when you get into player vs. player fights on this MUD, the text starts scrolling off the screen at an incredible rate and a blank line after each prompt makes it fly off even faster.
Russia #28
Here's what I use to solve that problem:


<triggers>
  <trigger
   enabled="y"
   match="^([0-9]+)h, ([0-9]+)m, ([0-9]+)e, ([0-9]+)p ((?:e|)(?:l|)(?:r|)(?:x|)(?:k|)(?:d|)(?:b|)(?:|p))-$"
   regexp="y"
   script="SetPromptStats"
   sequence="0"
  >
  </trigger>
</triggers>
<triggers>
  <trigger
   keep_evaluating="y"
   match=".*"
   name="got_other_line"
   regexp="y"
   script="GotOtherLine"
   group="prompt_cleanup"
   sequence="2"
  >
  </trigger>
  <trigger
   match="^$"
   name="empty_line"
   omit_from_output="y"
   regexp="y"
   script="GotEmptyLine"
   group="prompt_cleanup"
   sequence="1"
  >
  </trigger>
</triggers>

def SetPromptStats(name, output, wildcs):
	world.EnableTriggerGroup("prompt_cleanup", 1)

def GotEmptyLine(name, output, wildcs):
	world.EnableTriggerGroup("prompt_cleanup", 0)

def GotOtherLine(name, output, wildcs):
	world.EnableTriggerGroup("prompt_cleanup", 0)


You'll need to translate that to your language of choice which shouldn't be a problem, and enable the "Triggers can match on empty line" option. This is probably most fitting inside a plugin.
Canada #29
Thanks Ked!

I had thought of something like this, but the ^$ trigger never fired, I imagine it's because I was unaware of the "match triggers on empty line" option.

My problem now is . . . .where is that option?!? I can't find it! :)
USA #30
Global Preferences > General Tab > Regular Expressions can Match on an Empty String

Russia #31
It's under File->Global Preferences, the General tab. And the actual name of that option is "Regular expressions can match on an empty string".
Russia #32
pwned, heh
Canada #33
I've come across another issue with the plugin.

It seems to be adding a line break at the end of every packet, regardless if it's a prompt or not. Now, this isn't usually a problem because, in most cases, the last line of a packet is the prompt, but when you stack a lot of commands and send them, the response from the server puts several prompts in a packet, and them sometimes ends the packet in the middle of a line, like this example:
You remove 1 gol   59 6f 75 20 72 65 6d 6f 76 65 20 31 20 67 6f 6c
denseal root, br   64 65 6e 73 65 61 6c 20 72 6f 6f 74 2c 20 62 72
inging the total   69 6e 67 69 6e 67 20 74 68 65 20 74 6f 74 61 6c
 in the cache to   20 69 6e 20 74 68 65 20 63 61 63 68 65 20 74 6f
 110....[32mH:28   20 31 31 30 2e 0d 0a 1b 5b 33 32 6d 48 3a 32 38
86.[37m.[32m M:4   38 36 1b 5b 33 37 6d 1b 5b 33 32 6d 20 4d 3a 34
814.[37m.[32m E:   38 31 34 1b 5b 33 37 6d 1b 5b 33 32 6d 20 45 3a
14090.[37m.[32m    31 34 30 39 30 1b 5b 33 37 6d 1b 5b 33 32 6d 20
W:18530.[37m.[1;   57 3a 31 38 35 33 30 1b 5b 33 37 6d 1b 5b 31 3b
31m B:100%.[0;37   33 31 6d 20 42 3a 31 30 30 25 1b 5b 30 3b 33 37
m [db eb]....You   6d 20 5b 64 62 20 65 62 5d ff f9 0d 0a 59 6f 75
 remove 1 kelp,    20 72 65 6d 6f 76 65 20 31 20 6b 65 6c 70 2c 20
bringing the tot   62 72 69 6e 67 69 6e 67 20 74 68 65 20 74 6f 74
al in the cache    61 6c 20 69 6e 20 74 68 65 20 63 61 63 68 65 20
to 104....[32mH:   74 6f 20 31 30 34 2e 0d 0a 1b 5b 33 32 6d 48 3a
2886.[37m.[32m M   32 38 38 36 1b 5b 33 37 6d 1b 5b 33 32 6d 20 4d
:4814.[37m.[32m    3a 34 38 31 34 1b 5b 33 37 6d 1b 5b 33 32 6d 20
E:14090.[37m.[32   45 3a 31 34 30 39 30 1b 5b 33 37 6d 1b 5b 33 32
m W:18530.[37m.[   6d 20 57 3a 31 38 35 33 30 1b 5b 33 37 6d 1b 5b
1;31m B:100%.[0;   31 3b 33 31 6d 20 42 3a 31 30 30 25 1b 5b 30 3b
37m [db eb]....Y   33 37 6d 20 5b 64 62 20 65 62 5d ff f9 0d 0a 59
ou remove 1 echi   6f 75 20 72 65 6d 6f 76 65 20 31 20 65 63 68 69
nacea, bringing    6e 61 63 65 61 2c 20 62 72 69 6e 67 69 6e 67 20
the total in the   74 68 65 20 74 6f 74 61 6c 20 69 6e 20 74 68 65
 cache to 29....   20 63 61 63 68 65 20 74 6f 20 32 39 2e 0d 0a 1b
[32mH:2886.[37m.   5b 33 32 6d 48 3a 32 38 38 36 1b 5b 33 37 6d 1b
[32m M:4814.[37m   5b 33 32 6d 20 4d 3a 34 38 31 34 1b 5b 33 37 6d
.[32m E:14090.[3   1b 5b 33 32 6d 20 45 3a 31 34 30 39 30 1b 5b 33
7m.[32m W:18530.   37 6d 1b 5b 33 32 6d 20 57 3a 31 38 35 33 30 1b
[37m.[1;31m B:10   5b 33 37 6d 1b 5b 31 3b 33 31 6d 20 42 3a 31 30
0%.[0;37m [db eb   30 25 1b 5b 30 3b 33 37 6d 20 5b 64 62 20 65 62
]....You remove    5d ff f9 0d 0a 59 6f 75 20 72 65 6d 6f 76 65 20
1 lobelia seed,    31 20 6c 6f 62 65 6c 69 61 20 73 65 65 64 2c 20
bringing the tot   62 72 69 6e 67 69 6e 67 20 74 68 65 20 74 6f 74
al in the cache    61 6c 20 69 6e 20 74 68 65 20 63 61 63 68 65 20
to 96....[32mH:2   74 6f 20 39 36 2e 0d 0a 1b 5b 33 32 6d 48 3a 32
886.[37m.[32m M:   38 38 36 1b 5b 33 37 6d 1b 5b 33 32 6d 20 4d 3a
4814.[37m.[32m E   34 38 31 34 1b 5b 33 37 6d 1b 5b 33 32 6d 20 45
:14090.[37m.[32m   3a 31 34 30 39 30 1b 5b 33 37 6d 1b 5b 33 32 6d
 W:18530.[37m.[1   20 57 3a 31 38 35 33 30 1b 5b 33 37 6d 1b 5b 31
;31m B:100%.[0;3   3b 33 31 6d 20 42 3a 31 30 30 25 1b 5b 30 3b 33
7m [db eb]....Yo   37 6d 20 5b 64 62 20 65 62 5d ff f9 0d 0a 59 6f
u remove 1 ginse   75 20 72 65 6d 6f 76 65 20 31 20 67 69 6e 73 65
ng root, bringin   6e 67 20 72 6f 6f 74 2c 20 62 72 69 6e 67 69 6e
g the total in t   67 20 74 68 65 20 74 6f 74 61 6c 20 69 6e 20 74
he cache to 132.   68 65 20 63 61 63 68 65 20 74 6f 20 31 33 32 2e
...[32mH:2886.[3   0d 0a 1b 5b 33 32 6d 48 3a 32 38 38 36 1b 5b 33
7m.[32m M:4814.[   37 6d 1b 5b 33 32 6d 20 4d 3a 34 38 31 34 1b 5b
37m.[32m E:14090   33 37 6d 1b 5b 33 32 6d 20 45 3a 31 34 30 39 30
.[37m.[32m W:185   1b 5b 33 37 6d 1b 5b 33 32 6d 20 57 3a 31 38 35
30.[37m.[1;31m B   33 30 1b 5b 33 37 6d 1b 5b 31 3b 33 31 6d 20 42
:100%.[0;37m [db   3a 31 30 30 25 1b 5b 30 3b 33 37 6d 20 5b 64 62
 eb]....You remo   20 65 62 5d ff f9 0d 0a 59 6f 75 20 72 65 6d 6f
ve 1 bellwort fl   76 65 20 31 20 62 65 6c 6c 77 6f 72 74 20 66 6c
ower, bringing t   6f 77 65 72 2c 20 62 72 69 6e 67 69 6e 67 20 74
he total in the    68 65 20 74 6f 74 61 6c 20 69 6e 20 74 68 65 20
cache to 133....   63 61 63 68 65 20 74 6f 20 31 33 33 2e 0d 0a 1b
[32mH:2886.[37m.   5b 33 32 6d 48 3a 32 38 38 36 1b 5b 33 37 6d 1b
[32m M:4814.[37m   5b 33 32 6d 20 4d 3a 34 38 31 34 1b 5b 33 37 6d
.[32m E:14090.[3   1b 5b 33 32 6d 20 45 3a 31 34 30 39 30 1b 5b 33
7m.[32m W:18530.   37 6d 1b 5b 33 32 6d 20 57 3a 31 38 35 33 30 1b
[37m.[1;31m B:10   5b 33 37 6d 1b 5b 31 3b 33 31 6d 20 42 3a 31 30
0%.[0;37m [db eb   30 25 1b 5b 30 3b 33 37 6d 20 5b 64 62 20 65 62
]....You remove    5d ff f9 0d 0a 59 6f 75 20 72 65 6d 6f 76 65 20


Here you can see the packet ended in the middle of a line beginning with "You remove"

The next packet begins:
1 slippery elm,    31 20 73 6c 69 70 70 65 72 79 20 65 6c 6d 2c 20
bringing the tot   62 72 69 6e 67 69 6e 67 20 74 68 65 20 74 6f 74
al in the cache    61 6c 20 69 6e 20 74 68 65 20 63 61 63 68 65 20
to 110....[32mH:   74 6f 20 31 31 30 2e 0d 0a 1b 5b 33 32 6d 48 3a
2886.[37m.[32m M   32 38 38 36 1b 5b 33 37 6d 1b 5b 33 32 6d 20 4d


And continues on from there. So the line that was broken up by the packets was "You remove 1 slippery elm, bringing the total in the cache to 110."

This is how that line displayed in the output to the screen:
You remove 
1 slippery elm, bringing the total in the cache to 110.


It should appear as:
You remove 1 slippery elm, bringing the total in the cache to 110.


I'm pretty sure that the plugin is causing this because the problem goes away when I uninstall it. Is there any way to stop it from adding that line break?

Please let me know if you need some more information.
Amended on Sat 12 Mar 2005 04:37 PM by Bobble
Russia #34
Instead of appending newlines to prompts, on IRE games you could use a temporary patch (until version 3.66 comes out). The following plugin replaces the GO AHEAD codes (\ff\f9) which appear at the end of the packet with newlines (\0d\0a) and suppresses the extra newlines at the beginning of the next packet if GA was already replaced, removing the need for additional triggers to suppress extra empty lines, which result from duplicate newlines being produced. It's in Python since I didn't want to deal with Replace anymore, but it shouldn't be too hard to port to something else. The GA pattern is supposed to only match if it follows the "-" character (the last char in an Achaea prompt) so it would need to be replaced by something that's appropriate in your case:


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Sunday, March 13, 2005, 4:11 PM -->
<!-- MuClient version 3.65 -->

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

<muclient>
<plugin
   name="PromptCatcher_Achaea"
   author="Keldar"
   id="8f85913ad96bd5bc255e434a"
   language="Python"
   purpose="Capturing prompts"
   date_written="2005-03-13 16:10:15"
   requires="3.65"
   version="1.0"
   >

</plugin>
<script>
<![CDATA[
import re
pat1 = re.compile(u"\-\u044f\u0449$")
pat2 = re.compile("^\x0d\x0a")
terminated = False

#from time import clock

def OnPluginPacketReceived(packet):
	global terminated, pat1,pat2
	#start = clock()
	m1 = pat1.match(packet[len(packet)-3:])
	m2 = pat2.match(packet[:2])
	if m1:
		terminated = True
		packet = packet[:len(packet)-2] + "\x0d\x0a"
	if m2:
		if terminated:
			packet = packet[2:]
			terminated = False
	#timing = clock() - start
	#world.AppendToNotepad("test", repr(packet) + "\r\n")
	#world.Note (timing)
	return packet


]]>
</script>

</muclient>
Canada #35
Hey Ked!

I got python scripting up and running, so I gave this plugin a whirl. It's not putting any new lines in at all, which makes me think I haven't altered the plugin to properly catch the last character of a prompt line in Aetolia.

Prompts in Aetolia look like this:
H:3038 M:3579 E:15200 W:17420 B:100% [db eb]

They always end with the "]" character. With this in mind, I altered one line of the plugin as such:
pat1 = re.compile(u"\]\u044f\u0449$")

The "\-" has been replaced by "\]" now. But it doesn't seem to match this as the end of the prompt and no new lines are being added. Have I made this alteration correctly or is there something else that must be done?

As always, any help is appreciated.

Amended on Tue 15 Mar 2005 04:13 PM by Bobble
Russia #36
This one replaces any and all GA codes it finds in a packet, still supressing extra newlines. You'll also need to replace the "-" char with your "]". The previous one only replaced the GA found at the very end of the packet, meaning that all other prompts were left untouched.


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Sunday, March 13, 2005, 4:11 PM -->
<!-- MuClient version 3.65 -->

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

<muclient>
<plugin
   name="PromptCatcher_Achaea"
   author="Keldar"
   id="8f85913ad96bd5bc255e434a"
   language="Python"
   purpose="Capturing prompts"
   date_written="2005-03-13 16:10:15"
   requires="3.65"
   version="1.0"
   >

</plugin>
<script>
<![CDATA[
import re
pat1 = re.compile(u"(\-\u044f\u0449)($)?")
pat2 = re.compile("^\x0d\x0a")
terminated = False

def repl(mo):
    global terminated
    if mo.groups()[1] == "":
        terminated = True
    return "-\x0d\x0a"
        
def OnPluginPacketReceived(packet):
    global terminated, pat1,pat2
    if terminated:
        packet = pat2.sub("",packet)
        terminated = False
    packet = pat1.sub(repl, packet)
    return packet


]]>
</script>

</muclient>
Canada #37
Hi Ked!

Thanks for all your help, but I'm still not having any luck with this plugin. It's not adding any new line breaks. I wish I could give you more instructive feed back, but I don't know python or how to read packets all that well.

Here are the changes I made to the plugin:
pat1 = re.compile(u"(\]\u044f\u0449)($)?")
and
return "]\x0d\x0a"

Here's a sample of some output I got when I spammed getting several different herbs from my cache:
H:3260 M:3579 E:15200 W:17420 B:100% [d eb]You remove 1 prickly ash bark, bringing the total in the cache to 101.
H:3260 M:3579 E:15200 W:17420 B:100% [d eb]You remove 1 goldenseal root, bringing the total in the cache to 111.
H:3260 M:3579 E:15200 W:17420 B:100% [d eb]You remove 1 kelp, bringing the total in the cache to 106.
H:3260 M:3579 E:15200 W:17420 B:100% [d eb]You remove 1 lobelia seed, bringing the total in the cache to 98.
H:3260 M:3579 E:15200 W:17420 B:100% [d eb]You remove 1 ginseng root, bringing the total in the cache to 134.
H:3260 M:3579 E:15200 W:17420 B:100% [d eb]You remove 1 bellwort flower, bringing the total in the cache to 135.
H:3260 M:3579 E:15200 W:17420 B:100% [d eb]You remove 1 slippery elm, bringing the total in the cache to 112.
H:3260 M:3579 E:15200 W:17420 B:100% [d eb]You remove 1 bloodroot leaf, bringing the total in the cache to 74.
H:3260 M:3579 E:15200 W:17420 B:100% [d eb]You remove 1 valerian, bringing the total in the cache to 17.
H:3260 M:3579 E:15200 W:17420 B:100% [d eb]You remove 1 skullcap, bringing the total in the cache to 118.
H:3260 M:3579 E:15200 W:17420 B:100% [d eb]You remove 1 irid moss, bringing the total in the cache to 71.
H:3260 M:3579 E:15200 W:17420 B:100% [d eb]You remove 1 hawthorn berry, bringing the total in the cache to 83.
H:3260 M:3579 E:15200 W:17420 B:100% [d eb]You remove 1 bayberry bark, bringing the total in the cache to 27.
H:3260 M:3579 E:15200 W:17420 B:100% [d eb]You remove 1 sileris, bringing the total in the cache to 13.
H:3260 M:3579 E:15200 W:17420 B:100% [d eb]You remove 1 black cohosh, bringing the total in the cache to 115.
H:3260 M:3579 E:15200 W:17420 B:100% [d eb]You remove 1 kola nut, bringing the total in the cache to 94.
H:3260 M:3579 E:15200 W:17420 B:100% [d eb]You remove 1 echinacea, bringing the total in the cache to 27.

As you can see, the newlines aren't being added at all. Is there any more information I could give you that might help solve this problem?
Amended on Tue 15 Mar 2005 11:04 PM by Bobble
Russia #38
Strange, it works for me on Achaea, although it still has the same problem as Lusternia's server-side prompt newlines - extra empty lines every once in a while. About the only thing that comes to my mind is that you somehow managed to get the non-Unicode version of Python, or maybe pywin32. Replace the OnPluginPacketReceived function with the following one and post the output it gives:


def OnPluginPacketReceived(packet):
    global terminated, pat1,pat2
    world.AppendToNotepad("test", repr(packet))
    if terminated:
        packet = pat2.sub("",packet)
        terminated = False
    packet = pat1.sub(repl, packet)
    return packet

Canada #39
The output to the screen looked like this:
You remove 1 kelp, bringing the total in the cache to 104.
H:3260 M:3479 E:10672 W:17420 B:100% [db eb]You remove 1 irid moss, bringing the total in the cache to 69.

The output to the notepad was:
u'You remove 1 kelp, bringing the total in the cache to 104.\r\n\x1b[32mH:3260\x1b[37m\x1b[32m M:3479\x1b[37m\x1b[1;33m E:10672\x1b[0;37m\x1b[32m W:17420\x1b[37m\x1b[1;31m B:100%\x1b[0;37m [db eb]\xff\xf9'u'You remove 1 irid moss, bringing the total in the cache to 69.\r\n\x1b[32mH:3260\x1b[37m\x1b[32m M:3479\x1b[37m\x1b[1;33m E:10672\x1b[0;37m\x1b[32m W:17420\x1b[37m\x1b[1;31m B:100%\x1b[0;37m [db eb]\xff\xf9'
Amended on Wed 16 Mar 2005 12:42 AM by Bobble
Russia #40
Once again - very strange. Either your Python is screwed up, or mine is :) The problem is that the GA regexp is set to match on the Unicode escape of "\u044f\u0449", which is what I get, but in your case it seems that the GA code is the normal "\xff\xf9". So to fix it, simply replace the pattern for pat1 with: "(\-\xff\xf9)($|\x0d\x0a)?". The extra option in the second group, seems to capture most of the extra lines, and won't hurt in any case.
Russia #41
And try to optionally include/exclude the 'u' before the pattern string, to see what works.
Canada #42
Hey Ked!

Seems to work like a charm! Thanks for all your help, it's much appreciated.
#43
Hiya, umm, I'm sort of having a similar problem with MUSH, and Achaea and after having pretty much experienced all of the above! I was wondering if I could get some help with these scripts, me having to pick up what I can from examples etc. :)

Basically, I used the updated script by Nick, and got the extra spaces, the weird newlines on things that aren't prompts, so I went back to the first one that was put up.

I'm also using that "Deletes the empty spaces trigger" using "^$", which is a little inconvenient but works, expecially since I've never heard of Python before, or could figure out which bits to change into VBscript (which is what I'm using).

Well, now theres a slight problem that the prompt isn't being picked up, on -every- prompt that comes, basically whenever a few lines are sent rapidly to the world consecutively... possibly its not the fact they're being sent, but that information is coming back too fast...

Its frustrating, especially when important triggers are set for those lines and they aren't recognised... I can't quite seem to figure out how to make either:

1 The prompt be recognised regardless of whats in front or behind (perhaps if the plugin isn't detecting it for some reason).
or 2 Make a trigger, that will send the real command back through the system, since what I've been doing mostly, is putting a trigger that captures stuff that might be tagged onto a prompt and reoutputting it, minus prompt stuff. This doesn't trigger anything though.

Wow, hope that was easy to understand, I'm running 3.65 so any help would be greatly appreciated! Thanks.
USA #44
Release 3.66 sometime soon please... I'm begging you here Nick ;) ?
Australia Forum Administrator #45
Version 3.66 now released. :)
USA #46
You're my hero Nick! Sort of.
#47
Ked, when I try to put your plugin in I get a bunch of errors:

Traceback (innermost last):
File "<Script Block >", line 4, in ?
terminated = False
NameError: False

Line in error:
terminated = False

Line 21: Error parsing script (problem in this file)

I don't really know what the problem is since I can't read Python. Could anyone help me?

EDIT: Its the second script you posted by the way.

EDIT: I got it fixed, just had to restart the computer to get python to reload. Then I had to change the pat1 expression to another one listed here.
Amended on Sat 21 May 2005 04:53 AM by Nexes
#48
I am new to this mushclient but i'm playing achaea and this newline trick is vital.
An enhancement to the gagging trigger would be to use the GetLineCount function. In Vbscript, my blank line gagging trigger is linked to this sub.

Sub GagBlankLine (name, line, wildcards)

dim Prompt
Prompt = World.GetVariable ("PromptLine")

If World.GetLineCount > Prompt + 1 Then
World.Note " "
End If

End Sub


I assume that there is a sub processing the prompt, the trick is to use GetLineCount to get the unique line number of the prompt and to put it in a Variable with World.SetVariable.

Now just link the gagging trigger to a simple sub which will compare the line number of the gag trigger to the line number of the last prompt. Now if the difference is greater than one, it would mean that this "new line" has not been "forced" and this "new line" is coming from the mud which could easily be re_created with a world.send " ".