replace all NUL characters

Post Reply
Bronte
Posts: 7
Joined: Sat Aug 27, 2011 6:29 pm

replace all NUL characters

Post by Bronte »

The MUD I play on (WoTMUD) outputs NUL characters which messes many things up. If I save a plain text log, I can use Notepad++ to replace all instances of \0 (backslash zero) with a space or nothing. What I'd like to do is create a trigger to replace those instances on the fly. What I can't figure out how to do is use selectstring to capture an "escaped" character, like \0. Here's what I'm trying which doesn't work:

pattern: \n (pearl regex)

script:
selectString("\0",1)
replace(" ")

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: replace all NUL characters

Post by Heiko »

Special characters can only be matched with perl regex triggers. To select the character and replace it you can simply use selectCaptureGroup(). I've posted a script to replace all bell characters with a sound somewhere.

Bronte
Posts: 7
Joined: Sat Aug 27, 2011 6:29 pm

Re: replace all NUL characters

Post by Bronte »

That sounds great, Heiko. I tried searching for your script, but couldn't find anything. Any clues on where I can search for it?

Bronte
Posts: 7
Joined: Sat Aug 27, 2011 6:29 pm

Re: replace all NUL characters

Post by Bronte »

Continuing my quest to be able to post logs of exciting MUD action to forums. To recap the challenge. If I log via text, my sent commands are not included. If I log to html, I get all the output and the sent commands, but the logging stops in unpredictable ways. If I copy and paste from the screen buffer, the NUL characters (\0, chr(0), etc.) sent in the output of my MUD truncate the copy and paste results. I believe that's an issue with the Windows clipboard because it happens when I try to copy and paste from Notepad ++ as well. Here's an example of what some text log output looks like using Notepadd ++

* R HP:Scratched MV:Full > They aren't here. LF
*Feru* has arrived from the east, riding a wild stallion. LF
LF
* R HP:Scratched MV:Full > LF
You try to blast *Feru*, but he parries successfully. LF
LF
* R HP:Scratched MV:Full - Feru: Healthy > LF
You do the best you can! LF
LF
* R HP:Scratched MV:Full - Feru: Healthy > LF
NUL LF
NUL You try to blast *Feru*, but he deflects the blow. LF
[bash ] LF
LF
NUL NUL-NUL=LF
NUL+NUL*LF
NUL NUL*NUL+LF
NUL=NUL-LF
NUL LF
You dodge a bash from *Feru* who loses his balance and falls! LF
LF
NUL-NUL=LF
Your bash at *Feru* sends him sprawling! LF
LF
* R HP:Scratched MV:Full - Feru: Scratched > LF

So as you can see, there are many NUL characters that cause me issues. So what I'd like to do is simply have Mudlet replace all instances of the NUL character with a space to prevent them from ever appearing in the screen output or the logs. Based on Heiko's recommendation, I tried exploring the use of selectCaptureGroup(), but I'm not making any progress. I believe it's because I can't match the NUL character. Here's all the triggers I've tried without success:

pattern: ^\0$ (perl regex)
pattern: \0 (perl regex)
pattern: \00 (perl regex)
pattern: \x00 (perl regex)
pattern: \000 (perl regex)

script:
echo("Found NUL")

None of those work, but the same script works fine when trying to capture the newline character. These all work fine:

\n
^\n$
\x0A
^\x0A$
\012
^\012$

In addition to the newline matches above, the following special character matches all work fine too
\a (bell)
\v (vertical tab?)
\\ (backslash)

But I just can't match the NUL character. Before I even get into trying to replace it, does anyone have suggestions here on how to match for it?

One idea I thought of was to just process each line of output, and write a function to parse each character of each line and replace the output via echo() with only the acceptable characters (basically anything other than NUL)

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: replace all NUL characters

Post by Heiko »

I'll need to check this out myself. How can I produce NULL characters in your MUD and what is the address of your MUD?

Bronte
Posts: 7
Joined: Sat Aug 27, 2011 6:29 pm

Re: replace all NUL characters

Post by Bronte »

The MUD is WoTMUD

wotmud.org:2222
207.234.147.46:2222

There's actually a NUL in the output during logon, immediately after you enter and existing name, and just before it prompts for the passphrase:

The Wheel Of Time MUD
Mark IV

Updated and Maintained by
Flash, Ingtar, Mournblade, & Zun

Based on the novels by Robert Jordan
and published by Tor Books

Running since Summer 1993
Original Code - CircleMUD
[DikuMUD I Original Source]

Original game idea, concept, and design:
Katja Nyboa, Tom Madsen, Hans Henrik Staerfeldt
Michael Seifert, and Sebastian Hammer

LF
By what name do you wish to be known? LF
Bronte
NUL Passphrase: LF

If you want to do some more extensive testing, I've sent you a PM with a character and passphrase, or you can just create a new character. If you then type "search universe", you'll see something like this:

o HP:Healthy MV:Fresh >
search universe
-=
+*

*+=
-
-=
+

**
+=-
-
=+
*
You didn't find such a thing here.

o HP:Healthy MV:Full >


That should generate all kinds of NULs mixed in with the plus, minus, asterisk, and equal characters. I can see those NULs when I open the text log in Notepad++ with View/Show Symbol/Show all characters turned on.

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: replace all NUL characters

Post by Heiko »

I'm working on a solution.

Bronte
Posts: 7
Joined: Sat Aug 27, 2011 6:29 pm

Re: replace all NUL characters

Post by Bronte »

Thanks for looking into this, Heiko. Much appreciated.

Post Reply