Smaug web who, colored?

Posted by Zeno on Sat 15 Oct 2005 01:50 AM — 4 posts, 19,729 views.

USA #0
I've noticed quite a few MUD websites have a web who that is colored. While I have a web who, it is not colored. I am using the Wolfpaw snippet, and I was wondering if anyone could explain how I could have colors on web who?

I realize I'd probably have to go through a strip and replace Smaug tokens with HTML codes, but I'm not good with that kind of string changes.

I noticed in the Wolfpaw snippet:
/* Rip out the Smaug Color Sequences --GW */
/* Hey -- I didnt sayit was perfect.. a hack at most*/
Amended on Sat 15 Oct 2005 02:02 AM by Zeno
Canada #1
This is actually the functions that I use, can't remember where I got it from, but mine was originally the Wolfpaw server as well, though at this points it's much different.
int web_colour(char type, char *string)
{
        char code[50];  /* Either this is MSL, or all the things below are 50, i chose this, faster */
        char     *p = '\0';

        switch (type)
        {
        default:
                break;
        case '&':
                mudstrlcpy(code, "&", 50);
                break;
        case 'x':
                mudstrlcpy(code, "</font><font color=#000000>", 50);
                break;
        case 'b':
                mudstrlcpy(code, "</font><font color=#00007F>", 50);
                break;
        case 'c':
                mudstrlcpy(code, "</font><font color=#007F7F>", 50);
                break;
        case 'g':
                mudstrlcpy(code, "</font><font color=#007F00>", 50);
                break;
        case 'r':
                mudstrlcpy(code, "</font><font color=#7F0000>", 50);
                break;
        case 'w':
                mudstrlcpy(code, "</font><font color=#BFBFBF>", 50);
                break;
        case 'y':
                mudstrlcpy(code, "</font><font color=#FFFF00>", 50);
                break;
        case 'Y':
                mudstrlcpy(code, "</font><font color=#FFFF00>", 50);
                break;
        case 'B':
                mudstrlcpy(code, "</font><font color=#0000FF>", 50);
                break;
        case 'C':
                mudstrlcpy(code, "</font><font color=#00FFFF>", 50);
                break;
        case 'G':
                mudstrlcpy(code, "</font><font color=#00FF00>", 50);
                break;
        case 'R':
                mudstrlcpy(code, "</font><font color=#FF0000>", 50);
                break;
        case 'W':
                mudstrlcpy(code, "</font><font color=#FFFFFF>", 50);
                break;
        case 'z':
                mudstrlcpy(code, "</font><font color=#7F7F7F>", 50);
                break;
        case 'o':
                mudstrlcpy(code, "</font><font color=#FFFF00>", 50);
                break;
        case 'O':
                mudstrlcpy(code, "</font><font color=#7F7F00>", 50);
                break;
        case 'p':
                mudstrlcpy(code, "</font><font color=#7F007F>", 50);
                break;
        case 'P':
                mudstrlcpy(code, "</font><font color=#FF00FF>", 50);
                break;

        case '/':
                mudstrlcpy(code, "<br>", 50);
                break;
        case '{':
                snprintf(code, 50, "%c", '{');
                break;
        case '-':
                snprintf(code, 50, "%c", '~');
                break;
        }
        p = code;
        while (*p != '\0')
        {
                *string = *p++;
                *++string = '\0';
        }
        return (strlen(code));
}

void web_colourconv(char *buffer, const char *txt)
{
        const char *point;
        int skip = 0;

        if (txt == NULL || buffer == NULL)
        {
                bug("Null txt or buffer", 0);
                return;
        }
        for (point = txt; *point; point++)
        {
                if (*point == '&')
                {
                        point++;
                        skip = web_colour(*point, buffer);
                        while (skip-- > 0)
                                ++buffer;
                        continue;
                }
                *buffer = *point;
                *++buffer = '\0';
        }
        *buffer = '\0';
        return;
}

int send_buf(int fd, char *buf, int filter)
{
        char string[MSL * 10];

        if (filter == 1)
        {
                send(fd, "<CODE>", 6, 0);
                buf = smash_color(buf);
                buf = text2html(buf);
                send(fd, "</CODE>", 7, 0);
        }
        if (filter == 2)
        {
                web_colourconv(string, buf);
                return send(fd, string, strlen(string), 0);
        }
        return send(fd, buf, strlen(buf), 0);
}
USA #2
Thanks, but now I have some issues. In this function:
int send_buf(int fd, char* buf, bool filter )
{
/*
   if ( filter )
   {
        send(fd, "<CODE>", 6, 0);
        buf = text2html(buf);
        send(fd, "</CODE>", 7, 0);
   }
*/
        return send(fd, buf, strlen(buf), 0);
}

I had to comment that bit out or else the code would not work because of the text2html. But now, the color works but the formatting (like the spaces etc) is lost as well as the font. Any ideas? This is what I have:
        web_colourconv( col_buf, buf );
      send_buf(wdesc->fd, col_buf, TRUE);
      send_buf(wdesc->fd,"<BR>",FALSE);  /*Equiv to /n/r --GW */


[EDIT] I fixed the font. All that's left to fix is this tab issue. This is on the MUD:
Owner          Zeno McDohl, the council is inducting  [Head of Newbie Council]

Owner Zeno McDohl, the council is inducting  [Head of Newbie Council] 

The above is on the web who. It used to work without the color. Any idea how to fix this?

[EDIT 2] Fixed. There was a <BR> in there, so I removed that and stuck in <PRE>
Amended on Sat 15 Oct 2005 05:05 PM by Zeno
USA #3
Of course if you wanted to get fancier about it you can use some CSS styling and then go with a white-space:pre and hope that works. Not all browsers will understand it though as far as I know. <pre> text tends to look uglier than the CSSified versions.