Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ MUSHclient ➜ General ➜ scroll back while displaying recent text

scroll back while displaying recent text

Posting of new messages is disabled at present.

Refresh page


Pages: 1  2 3  

Posted by LupusFatalis   (154 posts)  Bio
Date Reply #15 on Mon 20 Apr 2009 06:07 AM (UTC)
Message
ok so it seems as if the following works on the majority

function OnPluginPacketReceived (s)
  return (string.gsub (s, "\n> ", "\n"))
end -- function OnPluginPacketReceived

however, it does not work on all of them, for the rest the following works, but I can't seem to get the rest to work due to the "[" it throws an error... I used an \ before the bracket but it still says expecting "]" or some such...

function OnPluginPacketReceived (s)
  return (string.gsub (s, "0m> ", ""))
end -- function OnPluginPacketReceived


How can I combine this to catch both cases with a newline on each?
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #16 on Tue 21 Apr 2009 03:43 AM (UTC)

Amended on Tue 21 Apr 2009 03:45 AM (UTC) by Nick Gammon

Message
Quote:

0d 0a 1b 5b 30 6d 3e 20


You have: \r \n \027 [ 0 m >

In Lua regular expressions, you have to escape a square bracket with a % rather than a backslash.

Quote:

How can I combine this to catch both cases with a newline on each?


Something like this:


function OnPluginPacketReceived (s)
  s = string.gsub (s, "\r\n\027%[0m> ", "")
  return (string.gsub (s, "\r\n> ", ""))
end -- function OnPluginPacketReceived


The first string.gsub deals with the lines with the ANSI sequence in it, the second then fixes up the others.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by LupusFatalis   (154 posts)  Bio
Date Reply #17 on Tue 21 Apr 2009 04:43 AM (UTC)

Amended on Tue 21 Apr 2009 04:48 AM (UTC) by LupusFatalis

Message
function OnPluginPacketReceived (s)
  s = string.gsub (s, "\r\n\027%[0m> ", "\n\027%[0m")
  return (string.gsub (s, "\r\n> ", "\n"))
end -- function OnPluginPacketReceived

So, I had to add back in the \n, because I'm removing a new line without it in there. Also, in the first portion, I added the color code back in, as it was changing the colors, etc... similarly it also needed a new line. Now, the only time I see the > is when I send a carriage return. In which case I see a blank line and then a line with only the "> " on it.

Sent  packet: 65 (2 bytes) at Tuesday, April 21, 2009, 12:30:45 AM

..                 0d 0a

Incoming packet: 82 (2 bytes) at Tuesday, April 21, 2009, 12:30:45 AM

>                  3e 20


I tried adding in your omit blank lines plugin as well, to get of half the spam in that instance, but it doesn't seem to be the issue.
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #18 on Tue 21 Apr 2009 06:40 AM (UTC)
Message
What you said makes sense. :) I probably stripped away too many newlines.

You could always fix the problem with the packet with just 3e 20 in it by adding a line:


if s == "> " then
  return ""
end -- if only a prompt



- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by LupusFatalis   (154 posts)  Bio
Date Reply #19 on Thu 23 Apr 2009 04:57 AM (UTC)
Message
works so far, it seems to be gone from everything but when I first log, which is no big deal. Thanks again Nick!
Top

Posted by LupusFatalis   (154 posts)  Bio
Date Reply #20 on Fri 24 Apr 2009 05:28 AM (UTC)

Amended on Sat 25 Apr 2009 04:18 AM (UTC) by Nick Gammon

Message
Looks like I spoke too soon Nick, I have to get this one as well...

Incoming packet: 4152 (999 bytes) at Friday, April 24, 2009, 1:21:59 AM


.[1mGymnasium.[0   1b 5b 31 6d 47 79 6d 6e 61 73 69 75 6d 1b 5b 30
m..This is the t   6d 0d 0a 54 68 69 73 20 69 73 20 74 68 65 20 74
raining hall whe   72 61 69 6e 69 6e 67 20 68 61 6c 6c 20 77 68 65
re the members o   72 65 20 74 68 65 20 6d 65 6d 62 65 72 73 20 6f
f the Palace Gua   66 20 74 68 65 20 50 61 6c 61 63 65 20 47 75 61
rd work out and    72 64 20 77 6f 72 6b 20 6f 75 74 20 61 6e 64 20
hone their skill   68 6f 6e 65 20 74 68 65 69 72 20 73 6b 69 6c 6c
s.   One entire    73 2e 20 20 20 4f 6e 65 20 65 6e 74 69 72 65 20
wall is covered    77 61 6c 6c 20 69 73 20 63 6f 76 65 72 65 64 20
by a wooden rack   62 79 20 61 20 77 6f 6f 64 65 6e 20 72 61 63 6b
 to hold weapons   20 74 6f 20 68 6f 6c 64 20 77 65 61 70 6f 6e 73
 and shields and   20 61 6e 64 20 73 68 69 65 6c 64 73 20 61 6e 64
 a target stands   20 61 20 74 61 72 67 65 74 20 73 74 61 6e 64 73
 near the opposi   20 6e 65 61 72 20 74 68 65 20 6f 70 70 6f 73 69
te wall.  Near t   74 65 20 77 61 6c 6c 2e 20 20 4e 65 61 72 20 74
he rack is a sma   68 65 20 72 61 63 6b 20 69 73 20 61 20 73 6d 61
ll bronze gong h   6c 6c 20 62 72 6f 6e 7a 65 20 67 6f 6e 67 20 68
angs on the wall   61 6e 67 73 20 6f 6e 20 74 68 65 20 77 61 6c 6c
.  Several ropes   2e 20 20 53 65 76 65 72 61 6c 20 72 6f 70 65 73
 hang from the r   20 68 61 6e 67 20 66 72 6f 6d 20 74 68 65 20 72
afters and the b   61 66 74 65 72 73 20 61 6e 64 20 74 68 65 20 62
ack wall appears   61 63 6b 20 77 61 6c 6c 20 61 70 70 65 61 72 73
 to be rough, wi   20 74 6f 20 62 65 20 72 6f 75 67 68 2c 20 77 69
th many protrusi   74 68 20 6d 61 6e 79 20 70 72 6f 74 72 75 73 69
ons.  In the bac   6f 6e 73 2e 20 20 49 6e 20 74 68 65 20 62 61 63
k corner, a poli   6b 20 63 6f 72 6e 65 72 2c 20 61 20 70 6f 6c 69
shed brass pole    73 68 65 64 20 62 72 61 73 73 20 70 6f 6c 65 20
reaches from the   72 65 61 63 68 65 73 20 66 72 6f 6d 20 74 68 65
 floor to the ce   20 66 6c 6f 6f 72 20 74 6f 20 74 68 65 20 63 65
iling.  The area   69 6c 69 6e 67 2e 20 20 54 68 65 20 61 72 65 61
 is .[37m.[1mglo   20 69 73 20 1b 5b 33 37 6d 1b 5b 31 6d 67 6c 6f
wing.[0m .[30m.[   77 69 6e 67 1b 5b 30 6d 20 1b 5b 33 30 6d 1b 5b
1mfaintly.[0m.     31 6d 66 61 69 6e 74 6c 79 1b 5b 30 6d 2e 20 20
It is blindingly   49 74 20 69 73 20 62 6c 69 6e 64 69 6e 67 6c 79
 bright here....   20 62 72 69 67 68 74 20 68 65 72 65 2e 0d 0a 1b
[1;37mThere is o   5b 31 3b 33 37 6d 54 68 65 72 65 20 69 73 20 6f
ne obvious exit.   6e 65 20 6f 62 76 69 6f 75 73 20 65 78 69 74 1b
[0m: .[0;36mwest   5b 30 6d 3a 20 1b 5b 30 3b 33 36 6d 77 65 73 74
.[0m...a wooden    1b 5b 30 6d 2e 0d 0a 61 20 77 6f 6f 64 65 6e 20
wagon (hitched t   77 61 67 6f 6e 20 28 68 69 74 63 68 65 64 20 74
o Dour), an open   6f 20 44 6f 75 72 29 2c 20 61 6e 20 6f 70 65 6e
 cedar cask of w   20 63 65 64 61 72 20 63 61 73 6b 20 6f 66 20 77
ater, and a stor   61 74 65 72 2c 20 61 6e 64 20 61 20 73 74 6f 72
age bin...Drab t   61 67 65 20 62 69 6e 2e 0d 0a 44 72 61 62 20 74
he black palfrey   68 65 20 62 6c 61 63 6b 20 70 61 6c 66 72 65 79
...Dour the blac   2e 0d 0a 44 6f 75 72 20 74 68 65 20 62 6c 61 63
k destrier (pull   6b 20 64 65 73 74 72 69 65 72 20 28 70 75 6c 6c
ing a wooden wag   69 6e 67 20 61 20 77 6f 6f 64 65 6e 20 77 61 67
on)...a sparring   6f 6e 29 2e 0d 0a 61 20 73 70 61 72 72 69 6e 67
 golem (attackin   20 67 6f 6c 65 6d 20 28 61 74 74 61 63 6b 69 6e
g Fey)...a sparr   67 20 46 65 79 29 2e 0d 0a 61 20 73 70 61 72 72
ing golem (attac   69 6e 67 20 67 6f 6c 65 6d 20 28 61 74 74 61 63
king Fey)...Fey    6b 69 6e 67 20 46 65 79 29 2e 0d 0a 46 65 79 20
the spyder (atta   74 68 65 20 73 70 79 64 65 72 20 28 61 74 74 61
cking Golem)...D   63 6b 69 6e 67 20 47 6f 6c 65 6d 29 2e 0d 0a 44
ismal the rowan    69 73 6d 61 6c 20 74 68 65 20 72 6f 77 61 6e 20
(blurry)...Junyl   28 62 6c 75 72 72 79 29 2e 0d 0a 4a 75 6e 79 6c
 the catfolk (ly   20 74 68 65 20 63 61 74 66 6f 6c 6b 20 28 6c 79
ing on the floor   69 6e 67 20 6f 6e 20 74 68 65 20 66 6c 6f 6f 72
)...Captain Nazi   29 2e 0d 0a 43 61 70 74 61 69 6e 20 4e 61 7a 69
r the cadet mast   72 20 74 68 65 20 63 61 64 65 74 20 6d 61 73 74
er...a target du   65 72 2e 0d 0a 61 20 74 61 72 67 65 74 20 64 75
mmy...>            6d 6d 79 2e 0d 0a 3e


think you can give me a hand?

right now I am using...


function OnPluginPacketReceived (s)
  s = string.gsub (s, "\r\n\027%[0m> ", "\n\027%[0m")
  s = string.gsub (s, "\r\n> ", "\n")
  
  if s == "> " then 
    return ""
  else
    return (s)
  end

end -- function OnPluginPacketReceived
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #21 on Sat 25 Apr 2009 04:20 AM (UTC)
Message
You mean the very last one? Looks like it is at the end of the packet (999 bytes) and probably the MUD has broken the output up at the 999 byte mark. It is hard to catch those without batching up packets.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by LupusFatalis   (154 posts)  Bio
Date Reply #22 on Sat 25 Apr 2009 06:54 AM (UTC)
Message
hmm... I guess its a no-go then. No biggy, I'll try to look at it later when I understand more about these packets and such. Thanks again though.
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #23 on Sat 25 Apr 2009 07:02 AM (UTC)
Message
This thread has an example of concatenating packets until you get a whole line:

http://mushclient.com/forum/?id=7430

What you can do in OnPluginPacketReceived is concatenate packets first (storing a partial line in the plugin), and then extract out whole lines. These can then be reliably checked for prompts.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by LupusFatalis   (154 posts)  Bio
Date Reply #24 on Sat 25 Apr 2009 07:52 PM (UTC)
Message
Ok, now I'm unfamiliar with LUA, so bear with me... Here is what I have after looking at that page...
partial = ""

function OnPluginPacketReceived (s)

	partial = partial .. string.gsub (s, "\r", "")
	t = {}

	partial = string.gsub (partial, "(.-)\n", 
		function (line) 
		table.insert (t, line) 
		return ""
		end)

	partial = string.gsub (partial, "\r\n\027%[0m> ", "\n\027%[0m")
	partial = string.gsub (partial, "\r\n> ", "\n")
	
	if partial == "> " then 
		partial = ""
	end

	if table.getn (t) > 0 then
		table.insert (t, "")
	end

	return table.concat (t, "\n")

end


Now, I hope I'm doing this correctly... The triggering on regular expressions didn't work to get rid of the "> ". So its not currently in the plugin.
Top

Posted by LupusFatalis   (154 posts)  Bio
Date Reply #25 on Sat 25 Apr 2009 07:53 PM (UTC)
Message
There are several places where it goes awry:
1)
Incoming packet: 2 (614 bytes) at Saturday, April 25, 2009, 3:41:56 PM

            _..    20 20 20 20 20 20 20 20 20 20 20 20 5f 0d 0a 20
          | |..    20 20 20 20 20 20 20 20 20 20 7c 20 7c 0d 0a 20
   _ _ _ _|:|___   20 20 20 5f 20 5f 20 5f 20 5f 7c 3a 7c 5f 5f 5f
________________   5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f
________________   5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f
___..  O(_|_|_|_   5f 5f 5f 0d 0a 20 20 4f 28 5f 7c 5f 7c 5f 7c 5f
|:|_____________   7c 3a 7c 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f
________________   5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f
_________>..       5f 5f 5f 5f 5f 5f 5f 5f 5f 3e 0d 0a 20 20 20 20
       |:|..       20 20 20 20 20 20 20 7c 3a 7c 0d 0a 20 20 20 20
       |_|   The   20 20 20 20 20 20 20 7c 5f 7c 20 20 20 54 68 65
 Creators of Dar   20 43 72 65 61 74 6f 72 73 20 6f 66 20 44 61 72
tMUD ....          74 4d 55 44 20 0d 0a 0d 0a 20 20 20 20 20 20 20
                   20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
Welcome You To .   57 65 6c 63 6f 6d 65 20 59 6f 75 20 54 6f 20 0d
...                0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20
               T   20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 54
he Lands of Ferd   68 65 20 4c 61 6e 64 73 20 6f 66 20 46 65 72 64
archi!..           61 72 63 68 69 21 0d 0a 20 20 20 20 20 20 20 20
                   20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
                   20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
  _..     The or   20 20 5f 0d 0a 20 20 20 20 20 54 68 65 20 6f 72
iginal and still   69 67 69 6e 61 6c 20 61 6e 64 20 73 74 69 6c 6c
 the best!    |    20 74 68 65 20 62 65 73 74 21 20 20 20 20 7c 20
| -Since-..   __   7c 20 2d 53 69 6e 63 65 2d 0d 0a 20 20 20 5f 5f
________________   5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f
________________   5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f
____|:|_ _ _ _ .   5f 5f 5f 5f 7c 3a 7c 5f 20 5f 20 5f 20 5f 20 0d
.  <____________   0a 20 20 3c 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f
________________   5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f
__________|:|_|_   5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 7c 3a 7c 5f 7c 5f
|_|_)O ..          7c 5f 7c 5f 29 4f 20 0d 0a 20 20 20 20 20 20 20
                   20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
                   20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
  |:| ..           20 20 7c 3a 7c 20 0d 0a 20 20 20 20 20 20 20 20
  [Version 1.3.1   20 20 5b 56 65 72 73 69 6f 6e 20 31 2e 33 2e 31
-3.2.1]            2d 33 2e 32 2e 31 5d 20 20 20 20 20 20 20 20 20
 |_| 1 9 9 1....   20 7c 5f 7c 20 31 20 39 20 39 20 31 0d 0a 0d 0a
Name:              4e 61 6d 65 3a 20

Incoming packet: 3 (13 bytes) at Saturday, April 25, 2009, 3:41:59 PM

Password: ÿû.      50 61 73 73 77 6f 72 64 3a 20 ff fb 01


It doesn't actually display the query "Name:" and "Password:" until after I have already typed them in...
Top

Posted by LupusFatalis   (154 posts)  Bio
Date Reply #26 on Sat 25 Apr 2009 07:55 PM (UTC)
Message
2)
Incoming packet: 5 (5 bytes) at Saturday, April 25, 2009, 3:42:01 PM

ÿü.>               ff fc 03 3e 20

Incoming packet: 6 (47 bytes) at Saturday, April 25, 2009, 3:42:02 PM

.[32mYou're brig   1b 5b 33 32 6d 59 6f 75 27 72 65 20 62 72 69 67
ht-eyed and bush   68 74 2d 65 79 65 64 20 61 6e 64 20 62 75 73 68
y-tailed..[0m..    79 2d 74 61 69 6c 65 64 2e 1b 5b 30 6d 0d 0a


This actually displays as follows:
> You're bright-eyed and bushy-tailed.
Top

Posted by LupusFatalis   (154 posts)  Bio
Date Reply #27 on Sat 25 Apr 2009 07:57 PM (UTC)
Message
3)
Incoming packet: 8 (999 bytes) at Saturday, April 25, 2009, 3:42:08 PM

.[36m       Name   1b 5b 33 36 6d 20 20 20 20 20 20 20 4e 61 6d 65
                   20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
     Idle          20 20 20 20 20 49 64 6c 65 20 20 20 20 20 20 20
    Name           20 20 20 20 4e 61 6d 65 20 20 20 20 20 20 20 20
             Idl   20 20 20 20 20 20 20 20 20 20 20 20 20 49 64 6c
e.[0m..       .[   65 1b 5b 30 6d 0d 0a 20 20 20 20 20 20 20 1b 5b
1;31ma determine   31 3b 33 31 6d 61 20 64 65 74 65 72 6d 69 6e 65
d ranger.[0m       64 20 72 61 6e 67 65 72 1b 5b 30 6d 20 20 20 20
  1m 46s           20 20 31 6d 20 34 36 73 20 20 20 20 20 20 20 20
 .[0;36ma furry    20 1b 5b 30 3b 33 36 6d 61 20 66 75 72 72 79 20
herbalist.[0m      68 65 72 62 61 6c 69 73 74 1b 5b 30 6d 20 20 20
     2s      ..    20 20 20 20 20 32 73 20 20 20 20 20 20 0d 0a 20
      a hapless    20 20 20 20 20 20 61 20 68 61 70 6c 65 73 73 20
adventurer     1   61 64 76 65 6e 74 75 72 65 72 20 20 20 20 20 31
2s            .[   32 73 20 20 20 20 20 20 20 20 20 20 20 20 1b 5b
1;36ma helpful c   31 3b 33 36 6d 61 20 68 65 6c 70 66 75 6c 20 63
rafter.[0m         72 61 66 74 65 72 1b 5b 30 6d 20 20 20 20 20 20
  14s     ..       20 20 31 34 73 20 20 20 20 20 0d 0a 20 20 20 20
   .[1;36ma hung   20 20 20 1b 5b 31 3b 33 36 6d 61 20 68 75 6e 67
ry houri.[0m       72 79 20 68 6f 75 72 69 1b 5b 30 6d 20 20 20 20
       20s         20 20 20 20 20 20 20 32 30 73 20 20 20 20 20 20
      .[1;37ma p   20 20 20 20 20 20 1b 5b 31 3b 33 37 6d 61 20 70
atient wanderer.   61 74 69 65 6e 74 20 77 61 6e 64 65 72 65 72 1b
[0m       16s      5b 30 6d 20 20 20 20 20 20 20 31 36 73 20 20 20
  ..       .[1;3   20 20 0d 0a 20 20 20 20 20 20 20 1b 5b 31 3b 33
3ma peerless cat   33 6d 61 20 70 65 65 72 6c 65 73 73 20 63 61 74
folk.[0m       4   66 6f 6c 6b 1b 5b 30 6d 20 20 20 20 20 20 20 34
s             .[   73 20 20 20 20 20 20 20 20 20 20 20 20 20 1b 5b
1;37ma sparkly e   31 3b 33 37 6d 61 20 73 70 61 72 6b 6c 79 20 65
lfess.[0m          6c 66 65 73 73 1b 5b 30 6d 20 20 20 20 20 20 20
  4s      ..       20 20 34 73 20 20 20 20 20 20 0d 0a 20 20 20 20
   Abraxas the r   20 20 20 41 62 72 61 78 61 73 20 74 68 65 20 72
owan        14s    6f 77 61 6e 20 20 20 20 20 20 20 20 31 34 73 20
           Avar    20 20 20 20 20 20 20 20 20 20 20 41 76 61 72 20
the gnome          74 68 65 20 67 6e 6f 6d 65 20 20 20 20 20 20 20
    2s      ..     20 20 20 20 32 73 20 20 20 20 20 20 0d 0a 20 20
     Azoron the    20 20 20 20 20 41 7a 6f 72 6f 6e 20 74 68 65 20
rowan         10   72 6f 77 61 6e 20 20 20 20 20 20 20 20 20 31 30
s            Cat   73 20 20 20 20 20 20 20 20 20 20 20 20 43 61 74
era the braman     65 72 61 20 74 68 65 20 62 72 61 6d 61 6e 20 20
      34s     ..   20 20 20 20 20 20 33 34 73 20 20 20 20 20 0d 0a
       Daelin th   20 20 20 20 20 20 20 44 61 65 6c 69 6e 20 74 68
e human            65 20 68 75 6d 61 6e 20 20 20 20 20 20 20 20 20
56s            D   35 36 73 20 20 20 20 20 20 20 20 20 20 20 20 44
omik the human     6f 6d 69 6b 20 74 68 65 20 68 75 6d 61 6e 20 20
        20s        20 20 20 20 20 20 20 20 32 30 73 20 20 20 20 20
..       Fisher    0d 0a 20 20 20 20 20 20 20 46 69 73 68 65 72 20
the human          74 68 65 20 68 75 6d 61 6e 20 20 20 20 20 20 20
  38s       .[32   20 20 33 38 73 20 20 20 20 20 20 20 1b 5b 33 32
m[.[0m.[31mB.[0m   6d 5b 1b 5b 30 6d 1b 5b 33 31 6d 42 1b 5b 30 6d
.[37mH.[0m.[32m]   1b 5b 33 37 6d 48 1b 5b 30 6d 1b 5b 33 32 6d 5d
.[0m Kuktuchik t   1b 5b 30 6d 20 4b 75 6b 74 75 63 68 69 6b 20 74
he spyder          68 65 20 73 70 79 64 65 72 20 20 20 20 20 20 20
      ..  .[32m[   20 20 20 20 20 20 0d 0a 20 20 1b 5b 33 32 6d 5b
.[0m.[31mB.[0m.[   1b 5b 30 6d 1b 5b 33 31 6d 42 1b 5b 30 6d 1b 5b
37mH.[0m.[32m].[   33 37 6d 48 1b 5b 30 6d 1b 5b 33 32 6d 5d 1b 5b
0m Napala the el   30 6d 20 4e 61 70 61 6c 61 20 74 68 65 20 65 6c
f           3m 5   66 20 20 20 20 20 20 20 20 20 20 20 33 6d 20 35
2s         Wodeu   32 73 20 20 20 20 20 20 20 20 20 57 6f 64 65 75
m the human        6d 20 74 68 65 20 68 75 6d 61 6e 20 20 20 20 20
    2s      ...[   20 20 20 20 32 73 20 20 20 20 20 20 0d 0a 1b 5b
36m  We extrapol   33 36 6d 20 20 57 65 20 65 78 74 72 61 70 6f 6c
ate tha            61 74 65 20 74 68 61

Incoming packet: 9 (25 bytes) at Saturday, April 25, 2009, 3:42:08 PM

t there are 23 p   74 20 74 68 65 72 65 20 61 72 65 20 32 33 20 70
layers on          6c 61 79 65 72 73 20 6f 6e

Incoming packet: 10 (226 bytes) at Saturday, April 25, 2009, 3:42:08 PM

.  Only 18 retur   2e 20 20 4f 6e 6c 79 20 31 38 20 72 65 74 75 72
ned their census   6e 65 64 20 74 68 65 69 72 20 63 65 6e 73 75 73
 forms...  Most    20 66 6f 72 6d 73 2e 0d 0a 20 20 4d 6f 73 74 20
people seem to b   70 65 6f 70 6c 65 20 73 65 65 6d 20 74 6f 20 62
e in Tirachi rig   65 20 69 6e 20 54 69 72 61 63 68 69 20 72 69 67
ht now...  Estim   68 74 20 6e 6f 77 2e 0d 0a 20 20 45 73 74 69 6d
ated active char   61 74 65 64 20 61 63 74 69 76 65 20 63 68 61 72
acters: 190 this   61 63 74 65 72 73 3a 20 31 39 30 20 74 68 69 73
 month, 70 today   20 6d 6f 6e 74 68 2c 20 37 30 20 74 6f 64 61 79
...  Ferdarchi w   2e 0d 0a 20 20 46 65 72 64 61 72 63 68 69 20 77
as last renewed    61 73 20 6c 61 73 74 20 72 65 6e 65 77 65 64 20
12 days 4 hours    31 32 20 64 61 79 73 20 34 20 68 6f 75 72 73 20
13 minutes 20 se   31 33 20 6d 69 6e 75 74 65 73 20 32 30 20 73 65
conds ago....[0m   63 6f 6e 64 73 20 61 67 6f 2e 0d 0a 1b 5b 30 6d
>                  3e 20

Sent  packet: 6 (3 bytes) at Saturday, April 25, 2009, 3:42:10 PM

l..                6c 0d 0a

Incoming packet: 11 (24 bytes) at Saturday, April 25, 2009, 3:42:10 PM

It is pitch blac   49 74 20 69 73 20 70 69 74 63 68 20 62 6c 61 63
k.  ..>            6b 2e 20 20 0d 0a 3e 20


This actually displays as...
[The Who List, etc...]
> It is pitch black.

Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #28 on Sun 26 Apr 2009 09:26 PM (UTC)

Amended on Sun 26 Apr 2009 09:27 PM (UTC) by Nick Gammon

Message
Quote:

partial = string.gsub (partial, "(.-)\n",
function (line)
table.insert (t, line)
return ""
end)

partial = string.gsub (partial, "\r\n\027%[0m> ", "\n\027%[0m")
partial = string.gsub (partial, "\r\n> ", "\n")


No, once you have done the string.gsub, all the lines except the last partial one will be in the table "t", not in the string "partial", so doing a string.gsub on that won't achieve anything.

So now you have a table of lines, so you do your matches on that, eg.


partial = ""

function OnPluginPacketReceived (s)

  -- get rid of carriage-returns
  
  partial = partial .. string.gsub (s, "\r", "")
  local t = {}

  -- turn finished lines into table t
  
  partial = string.gsub (partial, "(.-)\n", 
    function (line) 
    table.insert (t, line) 
    return ""
    end)

  -- get rid of prompts  (in a regexp, ^ indicates the start of a line)
  
  for i, line in ipairs (t) do
    t [i] = string.gsub (line, "^\027%[0m> ", "\027%[0m")
    t [i] = string.gsub (line, "^> ", "")
  end -- for
  
  -- reassemble completed packet with line-based corrections
  
  local fixed_packet = ""
  
  -- drop completely empty lines
  for i, line in ipairs (t) do
    if line ~= "" then
      fixed_packet = fixed_packet .. line .. "\n"
    end -- if
  end -- for
  
  return fixed_packet

end -- OnPluginPacketReceived


(Disclaimer: I didn't test or compile the above code).

Quote:

It doesn't actually display the query "Name:" and "Password:" until after I have already typed them in...


That is exactly what you expect to happen if you batch up lines until you get a newline character. You probably need to do nothing with the incoming packets until some flag is set to indicate you have finished the login sequence.

Or, use the "auto-login" function in MUSHclient which sends down the username and password as soon as you connect, so they will be supplied even if you don't see the question.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #29 on Sun 26 Apr 2009 09:40 PM (UTC)

Amended on Sun 26 Apr 2009 09:43 PM (UTC) by Nick Gammon

Message
More simply, you might fix up the prompts as you build the table, like this:


partial = ""

function OnPluginPacketReceived (s)

  local t = {}  -- table of reassembled lines

  -- get rid of carriage-returns, add new packet to existing partial one
  
  partial = partial .. string.gsub (s, "\r", "")

  -- turn finished lines into table t
  
  partial = string.gsub (partial, "(.-)\n", 
    function (line) 
      
      -- remove prompt as we add to the table
      
      line = string.gsub (line, "^\027%[0m> ", "\027[0m", 1)
      line = string.gsub (line, "^> ", "", 1)
         
      if line ~= "" then
        table.insert (t, line) 
      end -- if not empty
      
      return ""
    end) -- function
  
  if #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 -- OnPluginPacketReceived


- Nick Gammon

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


89,767 views.

This is page 2, subject is 3 pages long:  [Previous page]  1  2 3  [Next page]

Posting of new messages is disabled at present.

Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.