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.
 Entire forum ➜ SMAUG ➜ SMAUG coding ➜ Samson's color code and escape characters

Samson's color code and escape characters

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


Pages: 1 2  

Posted by Dace K   Canada  (169 posts)  Bio
Date Tue 14 Feb 2006 07:41 PM (UTC)

Amended on Tue 14 Feb 2006 08:05 PM (UTC) by Dace K

Message
I posted something about this last year, and never got a response. Problem seemed to fix itself for awhile, then returned. (Either that, or players just stopped reporting it for awhile).

After installing AFKMud's color code, for some reason at occasional intervals, players' prompts will contain strange information instead of color codes always at the same point in the prompt, such as

dle.36mEnergy
WLD

"The pertinent string in the code is:

strcpy(buf, "&w<&GHealth&W: %h &CEnergy: %m&w &RAmmo&W: &w%A&w>");

Code for case 'h' is
if (percent >= 60)
sprintf (pbuf, "\x1b[1;32m%d%%", percent);
else if (percent >= 40 && percent < 60)
sprintf (pbuf, "\x1b[1;33m%d%%", percent);
else if (percent >= 20 && percent < 40)
sprintf (pbuf, "\x1b[1;34m%d%%", percent);
else
sprintf (pbuf, "\x1b[1;31m%d%%", percent);

'm' is almost identical.

Code for cyan is
#define ANSI_CYAN "\033[0;36m"

Any ideas why this is happening?

Note: After further testing, I've verified the following:

- The errors occur regardless of using 'x1b' in place of '033', and vice versa.

- The errors still occur if &C is used in place of the ansi code.

- The errors occur on the first variable call in the prompt, regardless of which var it is.

ASJ Games - .Dimension 2, Resident Evil, and snippets - oh my!
http://asj.mudmagic.com

Drop by the area archives and find something for your mud. http://areaarchives.servegame.com
Top

Posted by Zeno   USA  (2,871 posts)  Bio
Date Reply #1 on Tue 14 Feb 2006 08:45 PM (UTC)
Message
Has this happened on different MUD clients? I'm using the color code in FUSS and have no problems.

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

Posted by Dace K   Canada  (169 posts)  Bio
Date Reply #2 on Wed 15 Feb 2006 12:08 AM (UTC)
Message
Gmud, Zmud, and Mushclient, according to my players.

This error, oddly, dissapears when the prompt is set to call a variable first that does not have a color code in it.

However, if the first var contains a color code, it causes an error, regardless of whether it's a default or player-set prompt.

ASJ Games - .Dimension 2, Resident Evil, and snippets - oh my!
http://asj.mudmagic.com

Drop by the area archives and find something for your mud. http://areaarchives.servegame.com
Top

Posted by Zeno   USA  (2,871 posts)  Bio
Date Reply #3 on Wed 15 Feb 2006 01:49 AM (UTC)
Message
Your best bet is to post on the AFKMUD site.
http://www.afkmud.com

If you already did a while ago, bump the topic.

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

Posted by Samson   USA  (683 posts)  Bio
Date Reply #4 on Wed 15 Feb 2006 02:31 AM (UTC)
Message
Probably asking for trouble, but could you post the entire content of your display_prompt function? What little you've given us so far isn't enough to go on except to identify that your prompt code is not stock Smaug.
Top

Posted by Dace K   Canada  (169 posts)  Bio
Date Reply #5 on Wed 15 Feb 2006 06:11 AM (UTC)

Amended on Wed 15 Feb 2006 07:42 AM (UTC) by Dace K

Message
Not all that much has been changed from stock, aside from the deletion of a few cases, and cases 'h', 'm', and 'A'. The error code ALWAYS happens either before, in place of, or after the first time %h or %m is called. There is never an error elsewhere in the string, or if %A is called first.


void display_prompt( DESCRIPTOR_DATA *d )
{
  CHAR_DATA *ch = d->character;
  CHAR_DATA *och = (d->original ? d->original : d->character);
  CHAR_DATA *victim;
  OBJ_DATA *obj;
  bool ansi = (!IS_NPC(och) && xIS_SET(och->act, PLR_ANSI));
  const char *prompt;
  /*const char *helpstart = "<Type HELP START>";*/
  char buf[MAX_STRING_LENGTH];
  char *pbuf = buf;
  int pstat, percent;

  if ( !ch )
  {
    bug( "display_prompt: NULL ch" );
    return;
  }

/*  if ( !IS_NPC(ch) && !IS_SET(ch->pcdata->flags, PCFLAG_HELPSTART ) )
	prompt = helpstart;*/
  else if ( !IS_NPC(ch) && ch->substate != SUB_NONE && ch->pcdata->subprompt
  &&   ch->pcdata->subprompt[0] != '\0' )
    prompt = ch->pcdata->subprompt;
  else if (IS_NPC (ch) || (!ch->fighting && (!ch->pcdata->prompt || !*ch->pcdata->prompt) ) )
    prompt = default_prompt (ch);
  else if ( ch->fighting )
  {
        if ( !ch->pcdata->fprompt || !*ch->pcdata->fprompt )
                prompt = default_fprompt ( ch );
        else
                prompt = ch->pcdata->fprompt;
  }
  else
    prompt = ch->pcdata->prompt;
  if ( ansi )
  {
    strcpy( pbuf, ANSI_RESET );
    d->prevcolor = 0x08;
    pbuf += 4;
  }
  /* Clear out old color stuff */
  for ( ; *prompt; prompt++ )
  {
    /*
     * '%' = prompt commands
     * Note: foreground changes will revert background to 0 (black)
     */
    if( *prompt != '%' )
    {
      *(pbuf++) = *prompt;
      continue;
    }
    ++prompt;
    if ( !*prompt )
      break;
    if ( *prompt == *(prompt-1) )
    {
      *(pbuf++) = *prompt;
      continue;
    }
    switch(*(prompt-1))
    {
    default:
      bug( "Display_prompt: bad command char '%c'.", *(prompt-1) );
      break;
    case '%':
      *pbuf = '\0';
      pstat = 0x80000000;
      switch(*prompt)
      {
      case '%':
	*pbuf++ = '%';
	*pbuf = '\0';
	break;
      case 'A':
      if ( (obj = get_eq_char( ch, WEAR_WIELD )) && obj->item_type == ITEM_FIREWEAPON)
	sprintf(pbuf, "%d",obj->value[2]);
	else
	strcpy(pbuf, "N/A");
        break;
      case 'h':
      if (ch->max_hit > 0)
      percent =  (100 * ch->hit ) / ch->max_hit;
      else
      percent = -1;
      if (percent >= 60)
      sprintf (pbuf, "\033[1;32m%d%%", percent);
      else if (percent >= 40 && percent < 60)
      sprintf (pbuf, "\033[1;33m%d%%", percent);
      else if (percent >= 20 && percent < 40)
      sprintf (pbuf, "\033[1;34m%d%%", percent);
      else
      sprintf (pbuf, "\033[1;31m%d%%", percent);
	break;
      case 'm':
      if (ch->max_mana > 0)
      percent =  (100 * ch->mana ) / ch->max_mana;
      else
      percent = -1;
      if (percent >= 60)
      sprintf (pbuf, "\033[1;32m%d%%", percent);
      else if (percent >= 40 && percent < 60)
      sprintf (pbuf, "\033[1;33m%d%%", percent);
      else if (percent >= 20 && percent < 40)
      sprintf (pbuf, "\033[1;34m%d%%", percent);
      else
      sprintf (pbuf, "\033[1;31m%d%%", percent);
	break;
        case 'N': /* Tank */
	  if ( !IS_IMMORTAL(ch) ) break;
          if ( !ch->fighting || ( victim = ch->fighting->who ) == NULL )
            strcpy( pbuf, "N/A" );
          else if(!victim->fighting||(victim=victim->fighting->who)==NULL)
            strcpy( pbuf, "N/A" );
          else {
            if ( ch == victim )
                    strcpy ( pbuf, "You" );
            else if ( IS_NPC(victim) )
                    strcpy ( pbuf, victim->short_descr );
            else
                    strcpy ( pbuf, victim->name );
                pbuf[0] = UPPER( pbuf[0] );
          }
          break;
        case 'n':
	  if ( !IS_IMMORTAL(ch) ) break;
          if (!ch->fighting || (victim = ch->fighting->who) == NULL )
            strcpy( pbuf, "N/A" );
          else {
            if ( ch == victim )
                    strcpy ( pbuf, "You" );
            else if ( IS_NPC(victim) )
                    strcpy ( pbuf, victim->short_descr );
            else
                    strcpy ( pbuf, victim->name );
            pbuf[0] = UPPER( pbuf[0] );
          }
          break;
      case 'T':
        if      ( time_info.hour <  5 ) strcpy( pbuf, "night" );
        else if ( time_info.hour <  6 ) strcpy( pbuf, "dawn" );
        else if ( time_info.hour < 19 ) strcpy( pbuf, "day" );
        else if ( time_info.hour < 21 ) strcpy( pbuf, "dusk" );
        else                            strcpy( pbuf, "night" );
        break;

ASJ Games - .Dimension 2, Resident Evil, and snippets - oh my!
http://asj.mudmagic.com

Drop by the area archives and find something for your mud. http://areaarchives.servegame.com
Top

Posted by Dace K   Canada  (169 posts)  Bio
Date Reply #6 on Wed 15 Feb 2006 06:11 AM (UTC)

Amended on Wed 15 Feb 2006 07:42 AM (UTC) by Dace K

Message

      case 'u':
	pstat = num_descriptors;
	break;
      case 'U':
	pstat = sysdata.maxplayers;
	break;
      case 'v':
	pstat = ch->move;
	break;
      case 'V':
	pstat = ch->max_move;
	break;
      case 'g':
	pstat = ch->gold;
	break;
      case 'r':
	if ( IS_IMMORTAL(och) )
	  pstat = ch->in_room->vnum;
	break;
      case 'F':
	if ( IS_IMMORTAL( och ) )
	  sprintf( pbuf, "%s", flag_string( ch->in_room->room_flags, r_flags) );
	break;
      case 'R':
	if ( xIS_SET(och->act, PLR_ROOMVNUM) )
	  sprintf(pbuf, "<#%d> ", ch->in_room->vnum);
	break;
      case 'o':         /* display name of object on auction */
        if ( auction->item )
           strcpy( pbuf, auction->item->name );
        break;
/*      case 'S':
        if      ( ch->style == STYLE_BERSERK )    strcpy( pbuf, "B" );
        else if ( ch->style == STYLE_AGGRESSIVE ) strcpy( pbuf, "A" );
        else if ( ch->style == STYLE_DEFENSIVE )  strcpy( pbuf, "D" );
        else if ( ch->style == STYLE_EVASIVE )    strcpy( pbuf, "E" );
        else                                      strcpy( pbuf, "S" );
	break;*/
      case 'i':
	if ( (!IS_NPC(ch) && xIS_SET(ch->act, PLR_WIZINVIS)) ||
	      (IS_NPC(ch) && xIS_SET(ch->act, ACT_MOBINVIS)) )
	  sprintf(pbuf, "(Invis %d) ", (IS_NPC(ch) ? ch->mobinvis : ch->pcdata->wizinvis));
	else if ( IS_AFFECTED(ch, AFF_INVISIBLE) )
	  sprintf(pbuf, "(Invis) " );
	break;
      case 'I':
	pstat = (IS_NPC(ch) ? (xIS_SET(ch->act, ACT_MOBINVIS) ? ch->mobinvis : 0)
	     : (xIS_SET(ch->act, PLR_WIZINVIS) ? ch->pcdata->wizinvis : 0));
	break;
      }
      if ( pstat != 0x80000000 )
	sprintf(pbuf, "%d", pstat);
      pbuf += strlen(pbuf);
      break;
    }
  }
  *pbuf = '\0';
  send_to_char( buf, ch );
  return;
}

char *default_prompt( CHAR_DATA *ch )
{
  static char buf[60];

  strcpy(buf, "&w<&GHealth&W: %h &CEnergy: %m&w  &RAmmo&W: &w%A&w>");
  if ( IS_NPC(ch) || IS_IMMORTAL(ch) )
    strcat(buf, "%i%R");
  return buf;
}

ASJ Games - .Dimension 2, Resident Evil, and snippets - oh my!
http://asj.mudmagic.com

Drop by the area archives and find something for your mud. http://areaarchives.servegame.com
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #7 on Wed 15 Feb 2006 06:52 AM (UTC)
Message
Crikey, but you should use the code tag. :-)

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #8 on Wed 15 Feb 2006 07:37 PM (UTC)

Amended on Wed 15 Feb 2006 07:38 PM (UTC) by Nick Gammon

Message
There is something rather strange about this prompt code. First it checks that it has a '%' symbol, and then later on backs up and re-checks again. I refer to these lines:


switch(*(prompt-1))
    {
    default:
      bug( "Display_prompt: bad command char '%c'.", *(prompt-1) );
      break;
    case '%':


This is done after it already knows that *(prompt-1) is a %.

Anyway, you are having a problem with %h and %m, both of which put ANSI codes into the prompt string. This is then passed to the colour code, which re-evaluates the string and puts more ANSI codes in it. It might be safer to put in the colour code (like &C) rather than the ANSI codes, although you say you have done that.

You haven't posted the colour code, but is it possible that it is treating the % symbol differently? After all, the %m is echoing the mana as a percent (eg. 40%) and that % might be causing the colour code to react badly. I can't say for sure without seeing the colour code.

- Nick Gammon

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

Posted by Dace K   Canada  (169 posts)  Bio
Date Reply #9 on Thu 16 Feb 2006 06:41 AM (UTC)

Amended on Thu 16 Feb 2006 10:15 PM (UTC) by Dace K

Message
The color code is an almost completely unmodified copy of Samson's code included in SmaugFUSS. Contains no references to % that I can see.

You're right about the extra case '%'.
It's quite weird - its only purpose seems to add a *pbuf = '\0'.

What does the line

pstat = 0x80000000;

do?

Note: I think you're on the right track about the % affecting the code badly. It only happens on the first value called with %% in the string.

Note 2: Out of curiosity, I removed the int percent check from the prompt value. It seems to have decreased the frequency of the prompt errors, but it still occurs...

ASJ Games - .Dimension 2, Resident Evil, and snippets - oh my!
http://asj.mudmagic.com

Drop by the area archives and find something for your mud. http://areaarchives.servegame.com
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #10 on Fri 17 Feb 2006 03:25 AM (UTC)
Message
Quote:

What does the line

pstat = 0x80000000;

do?


It sets pstat to some value unlikely to occur in normal numbers. Then later on if it is changed to a "real" number, like:


pstat = ch->move;


... it does this:


sprintf(pbuf, "%d", pstat);


Effectively, simple numbers are simply output to the prompt line.

- Nick Gammon

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

Posted by Dace K   Canada  (169 posts)  Bio
Date Reply #11 on Fri 17 Feb 2006 05:23 AM (UTC)

Amended on Fri 17 Feb 2006 08:54 AM (UTC) by Dace K

Message
Ah, Thanks.
I just got some information from a couple players.
The color bug most often occurs in the prompt, but a couple have received them outside prompt, where there is no % sign, even at the start of a line.

ch_printf( ch, "&gYou %s run along a treadmill at %d mph.\n\r", buf2, number_fuzzy(get_curr_con(ch) + 2));

became

 jeou shakily run along a treadmill at 7 mph.

Perhaps it's not liking \033 calling ANSI instead of \x1b?

I am incredibly confused at this point. I ran a compare of my color.c and .h with the distro copy from AFKmud's homepage, and could find no significant differences. I suppose tomorrow I'll give replacing the files a try, but I doubt it will help.

ASJ Games - .Dimension 2, Resident Evil, and snippets - oh my!
http://asj.mudmagic.com

Drop by the area archives and find something for your mud. http://areaarchives.servegame.com
Top

Posted by Dace K   Canada  (169 posts)  Bio
Date Reply #12 on Sat 18 Feb 2006 07:56 PM (UTC)
Message
Valgrind returned no memory leaks, even after the color bug had cropped up a few times. Will try replacing the color code with something stock.

ASJ Games - .Dimension 2, Resident Evil, and snippets - oh my!
http://asj.mudmagic.com

Drop by the area archives and find something for your mud. http://areaarchives.servegame.com
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #13 on Sat 18 Feb 2006 10:33 PM (UTC)
Message
That first unprintable character is your \1B so that is working OK.

What you have there is:


\1B [0;N je


There is no "m" so the client is not displaying it as a colour sequence. Why there is no "m" is the mystery.

- Nick Gammon

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

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #14 on Sun 19 Feb 2006 01:12 AM (UTC)
Message
Also, how did "you" get turned into "jeou"?

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
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.


57,037 views.

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

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.