Register forum user name 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.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ SMAUG ➜ SMAUG coding ➜ Smaug web who, colored?

Smaug web who, colored?

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Zeno   USA  (2,871 posts)  Bio
Date Sat 15 Oct 2005 01:50 AM (UTC)

Amended on Sat 15 Oct 2005 02:02 AM (UTC) by Zeno

Message
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*/

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
Top

Posted by Greven   Canada  (835 posts)  Bio
Date Reply #1 on Sat 15 Oct 2005 06:39 AM (UTC)
Message
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);
}

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
Top

Posted by Zeno   USA  (2,871 posts)  Bio
Date Reply #2 on Sat 15 Oct 2005 04:45 PM (UTC)

Amended on Sat 15 Oct 2005 05:05 PM (UTC) by Zeno

Message
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>

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
Top

Posted by Samson   USA  (683 posts)  Bio
Date Reply #3 on Mon 24 Oct 2005 02:47 AM (UTC)
Message
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.
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.


15,496 views.

It is now over 60 days since the last post. This thread is closed.     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.