Пример #1
0
void name_generator( string & argument )
{
   int start_counter = 0, middle_counter = 0, end_counter = 0;
   char start_string[100][10], middle_string[100][10], end_string[100][10];
   char tempstring[151], name[300];
   struct timeval starttime;
   time_t t;
   FILE *infile;

   tempstring[0] = '\0';

   if( !( infile = fopen( NAMEGEN_FILE, "r" ) ) )
   {
      log_string( "Can't find NAMEGEN file." );
      return;
   }

   fgets( tempstring, 150, infile );
   tempstring[strlen( tempstring ) - 1] = '\0';
   while( str_cmp( tempstring, "[start]" ) != 0 )
   {
      fgets( tempstring, 150, infile );
      tempstring[strlen( tempstring ) - 1] = '\0'; /* remove linefeed */
   }

   while( str_cmp( tempstring, "[middle]" ) != 0 )
   {
      fgets( tempstring, 150, infile );
      tempstring[strlen( tempstring ) - 1] = '\0'; /* remove linefeed */
      if( tempstring[0] != '/' )
         mudstrlcpy( start_string[start_counter++], tempstring, 100 );
   }
   while( str_cmp( tempstring, "[end]" ) != 0 )
   {
      fgets( tempstring, 150, infile );
      tempstring[strlen( tempstring ) - 1] = '\0'; /* remove linefeed */
      if( tempstring[0] != '/' )
         mudstrlcpy( middle_string[middle_counter++], tempstring, 100 );
   }
   while( str_cmp( tempstring, "[finish]" ) != 0 )
   {
      fgets( tempstring, 150, infile );
      tempstring[strlen( tempstring ) - 1] = '\0'; /* remove linefeed */
      if( tempstring[0] != '/' )
         mudstrlcpy( end_string[end_counter++], tempstring, 100 );
   }
   FCLOSE( infile );
   gettimeofday( &starttime, nullptr );
   srand( ( unsigned )time( &t ) + starttime.tv_usec );
   --start_counter;
   --middle_counter;
   --end_counter;

   mudstrlcpy( name, start_string[rand(  ) % start_counter], 300 );  /* get a start */
   mudstrlcat( name, middle_string[rand(  ) % middle_counter], 300 );   /* get a middle */
   mudstrlcat( name, end_string[rand(  ) % end_counter], 300 );   /* get an ending */
   argument.append( name );
}
Пример #2
0
/*
 * Quixadhal - This takes a string and converts any and all color tokens
 * in it to the desired output tokens, using the provided character's
 * preferences.
 */
char *colorize( const char *txt, DESCRIPTOR_DATA * d )
{
   static char result[MAX_STRING_LENGTH];

   *result = '\0';

   if( txt && *txt && d )
   {
      const char *colstr;
      const char *prevstr = txt;
      char colbuf[20];
      int ln;

      while( ( colstr = strpbrk( prevstr, "&^}hH" ) ) != NULL )
      {
         register int reslen = 0;

         if( colstr > prevstr )
         {
            if( ( MAX_STRING_LENGTH - ( reslen = strlen( result ) ) ) <= ( colstr - prevstr ) )
            {
               bug( "%s: OVERFLOW in internal MAX_STRING_LENGTH buffer!", __PRETTY_FUNCTION__ );
               break;
            }
            strncat( result, prevstr, ( colstr - prevstr ) );  /* Leave this one alone! BAD THINGS(TM) will happen if you don't! */
            result[reslen + ( colstr - prevstr )] = '\0';   /* strncat will NOT NULL terminate this! */
         }

         if( colstr[0] == 'h' || colstr[0] == 'H' )
            if( colstr[1] == 't' || colstr[1] == 'T' )
               if( colstr[2] == 't' || colstr[2] == 'T' )
                  if( colstr[3] == 'p' || colstr[3] == 'P' )
                  {
                     char http[MAX_INPUT_LENGTH];

                     one_argument( colstr, http );
                     mudstrlcat( result, http, sizeof( result ) );
                     ln = strlen( http );
                     prevstr = colstr + ln;
                     continue;
                  }

         ln = colorcode( colstr, colbuf, d, 20, NULL );
         if( ln > 0 )
         {
            mudstrlcat( result, colbuf, MAX_STRING_LENGTH );
            prevstr = colstr + ln;
         }
         else
            prevstr = colstr + 1;
      }
      if( *prevstr )
         mudstrlcat( result, prevstr, MAX_STRING_LENGTH );
   }
   return result;
}
Пример #3
0
/*
 * Quixadhal - This takes a string and converts any and all color tokens
 * in it to the desired output tokens, using the provided character's
 * preferences.
 */
const char *colorize( const string & txt, descriptor_data * d )
{
   static char result[MSL];

   *result = '\0';

   if( !txt.empty(  ) && d )
   {
      const char *colstr;
      const char *prevstr = txt.c_str(  );
      char colbuf[20];
      int ln;

      while( ( colstr = strpbrk( prevstr, "&{}hH" ) ) != nullptr )
      {
         register int reslen = 0;

         if( colstr > prevstr )
         {
            if( ( MSL - ( reslen = strlen( result ) ) ) <= ( colstr - prevstr ) )
            {
               bug( "%s: OVERFLOW in internal MSL buffer!", __PRETTY_FUNCTION__ );
               break;
            }
            strncat( result, prevstr, ( colstr - prevstr ) );  /* Leave this one alone! BAD THINGS(TM) will happen if you don't! */
            result[reslen + ( colstr - prevstr )] = '\0';   /* strncat will NOT nullptr terminate this! */
         }
         ln = colorcode( colstr, colbuf, d, 20, nullptr );

         if( colstr[0] == 'h' || colstr[0] == 'H' )
            if( colstr[1] == 't' || colstr[1] == 'T' )
               if( colstr[2] == 't' || colstr[2] == 'T' )
                  if( colstr[3] == 'p' || colstr[3] == 'P' )
                  {
                     char http[MIL];

                     one_argument( colstr, http );
                     mudstrlcat( result, http, sizeof( result ) );
                     ln = strlen( http );
                     prevstr = colstr + ln;
                     continue;
                  }

         if( ln > 0 )
         {
            mudstrlcat( result, colbuf, MSL );
            prevstr = colstr + ln;
         }
         else
            prevstr = colstr + 1;
      }
      if( *prevstr )
         mudstrlcat( result, prevstr, MSL );
   }
   return result;
}
Пример #4
0
/* xcatf a formated string */
void safe_strcatf( const char *file, const char *function, int line, int size, char *prev, char *next, ... )
{
   char buf[MAS];
   va_list args;

   va_start( args, next );
   vsnprintf( buf, MAS, next, args );
   va_end( args );

   /*
    * Max Alloc Size is allot!
    */
   if( size > MAS )
   {
      char egbug[MSL];
      log_string( LOG_BUG, "xcatf size greater then MAS!!!!\n\r" );
      log_string( LOG_BUG, "ERROR: System Memory Corrupted by Overflow, through xcatf.\n\r" );
      log_string( LOG_BUG, "Memcheck: xcatf:File %s, Function %s, Line %d.\n\r", file, function, line );
      xprintf( egbug, "Memcheck: System memory corrupted by overflow through xcatf: File: %s Function: %s Line: %d", file,
               function, line );
      wiznet( egbug, NULL, NULL, WIZ_MEMCHECK, 0, 0 );
      return;
   }

   if( ( unsigned )size < strlen( buf ) + 1 )
   {
      char egbug[MSL];
      log_string( LOG_BUG, "XCATF error: fmt %s.\n\r", next );
      log_string( LOG_BUG, "ERROR: System Memory Corrupted by Overflow, through xcatf.\n\r" );
      log_string( LOG_BUG, "Memcheck: xcatf: File %s, Function %s, Line %d.\n\r", file, function, line );
      /*
       * Yes, this is a potential loop bug if infact the xcatf does collapse in on itself..
       */
      xprintf( egbug, "Memcheck: System memory corrupted by overflow through xcatf: File: %s Function: %s Line: %d", file,
               function, line );
      wiznet( egbug, NULL, NULL, WIZ_MEMCHECK, 0, 0 );
      return;
   }

   mudstrlcat( prev, buf, size );

   /*
    * Just double checking.
    */
   if( strlen( prev ) > ( unsigned )size - 1 )
   {
      char egbug[MSL];
      log_string( LOG_BUG, "XCATF error: fmt %s.\n\r", next );
      log_string( LOG_BUG, "ERROR: System Memory Corrupted by Overflow, through xcatf.\n\r" );
      log_string( LOG_BUG, "Memcheck: Xcatf: File %s, Function %s, Line %d.\n\r", file, function, line );
      /*
       * Yes, this is a potential loop bug if infact the xcatf does collapse in on itself..
       */
      xprintf( egbug, "Memcheck: System memory corrupted by overflow through xcatf: File: %s Function: %s Line: %d", file,
               function, line );
      wiznet( egbug, NULL, NULL, WIZ_MEMCHECK, 0, 0 );
   }
}
Пример #5
0
char *print_big_board( game_board_data * board )
{
    static char retbuf[MSL * 2];
    char buf[MSL], buf2[MSL];
    char s1[16], s2[16];
    int x, y;

    snprintf( s1, 16, "&Y&W" );
    snprintf( s2, 16, "&z&z" );

    snprintf( retbuf, MSL * 2, WHITE_FOREGROUND "\r\n&g     1      2      3      4      5      6      7      8\r\n" );

    for( x = 0; x < 8; ++x )
    {
        mudstrlcat( retbuf, "  ", MSL * 2 );
        for( y = 0; y < 8; ++y )
        {
            snprintf( buf, MSL, "%s%s",
                      x % 2 == 0 ? ( y % 2 == 0 ? BLACK_BACKGROUND : WHITE_BACKGROUND ) :
                      ( y % 2 == 0 ? WHITE_BACKGROUND : BLACK_BACKGROUND ), big_pieces[board->board[x][y]][0] );
            snprintf( buf2, MSL, buf, IS_WHITE( board->board[x][y] ) ? s1 : s2 );
            strcat( retbuf, buf2 );
        }
        mudstrlcat( retbuf, BLACK_BACKGROUND "\r\n", MSL * 2 );

        snprintf( buf, MSL, WHITE_FOREGROUND "&g%c ", 'A' + x );
        mudstrlcat( retbuf, buf, MSL * 2 );
        for( y = 0; y < 8; ++y )
        {
            snprintf( buf, MSL, "%s%s",
                      x % 2 == 0 ? ( y % 2 == 0 ? BLACK_BACKGROUND : WHITE_BACKGROUND ) :
                      ( y % 2 == 0 ? WHITE_BACKGROUND : BLACK_BACKGROUND ), big_pieces[board->board[x][y]][1] );
            snprintf( buf2, MSL, buf, IS_WHITE( board->board[x][y] ) ? s1 : s2 );
            mudstrlcat( retbuf, buf2, MSL * 2 );
        }
        mudstrlcat( retbuf, BLACK_BACKGROUND "\r\n", MSL * 2 );
    }

    return retbuf;
}
Пример #6
0
void wiznet_printf( CHAR_DATA * ch, OBJ_DATA * obj, long flag, long flag_skip, int min_level, char *format, ... )
{
   va_list ap;
   char buf[MSL], buf2[MSL], Newtime[30];
   char *strtime = ( char * )ctime( &current_time );
   DESCRIPTOR_DATA *d;
   int pos = 0, i = 1;

   do
   {
      if( i > 11 )
         buf[pos++] = *strtime;
   }
   while( *strtime++ && i++ && pos < 8 );
   buf[pos] = '\0';
   mudstrlcpy( Newtime, buf, 30 );
   xprintf( buf, "[WiZNET] %s: ", Newtime );

   va_start( ap, format );

   if( !descriptor_list )
      return;

   for( d = descriptor_list; d != NULL; d = d->next )
   {
      char immnetbuffer[MSL];

      if( !d->character )
         continue;

      if( d->connected == CON_PLAYING && IS_IMMORTAL( d->character ) && IS_SET( d->character->wiznet, WIZ_ON )
          && ( !flag || IS_SET( d->character->wiznet, flag ) ) && ( !flag_skip
                                                                    || !IS_SET( d->character->wiznet, flag_skip ) )
          && get_trust( d->character ) >= min_level && d->character != ch )
      {
         vsnprintf( buf2, sizeof( buf2 ), format, ap );
         mudstrlcat( buf, buf2, MSL );
         xprintf( immnetbuffer, "%s", buf );
         act( immnetbuffer, d->character, obj, ch, TO_CHAR );
      }
   }

   va_end( ap );
   return;
}
Пример #7
0
/* changed for new auth */
void auth_update( void )
{
   list < auth_data * >::iterator auth;
   char buf[MIL], lbuf[MSL];
   int level;
   bool found_imm = false; /* Is at least 1 immortal on? */
   bool found_hit = false; /* was at least one found? */

   if( ( level = check_command_level( "authorize", MAX_LEVEL ) ) == -1 )
      level = LEVEL_IMMORTAL;

   mudstrlcpy( lbuf, "--- Characters awaiting approval ---\r\n", MSL );
   for( auth = authlist.begin(  ); auth != authlist.end(  ); ++auth )
   {
      auth_data *au = *auth;

      if( au->state < AUTH_CHANGE_NAME )
      {
         found_hit = true;
         snprintf( buf, MIL, "Name: %s      Status: %s\r\n", au->name.c_str(  ), ( au->state == AUTH_ONLINE ) ? "Online" : "Offline" );
         mudstrlcat( lbuf, buf, MSL );
      }
   }

   if( found_hit )
   {
      list < descriptor_data * >::iterator ds;

      for( ds = dlist.begin(  ); ds != dlist.end(  ); ++ds )
      {
         descriptor_data *d = *ds;

         if( d->connected == CON_PLAYING && d->character && d->character->is_immortal(  ) && d->character->level >= level )
            found_imm = true;
      }
      if( found_imm )
         log_string_plus( LOG_AUTH, level, lbuf );
   }
}
Пример #8
0
/* Display the map to the player */
void show_map( CHAR_DATA * ch, char *text )
{
	char buf[MAX_STRING_LENGTH * 2];
	int x, y, pos;
	char *p;
	bool alldesc = FALSE;	/* Has desc been fully displayed? */

	if ( !text )
		alldesc = TRUE;

	pos = 0;
	p = text;
	buf[0] = '\0';

	/*
	 * Show exits 
	 */
	if ( xIS_SET( ch->act, PLR_AUTOEXIT ) )
		snprintf( buf, MAX_STRING_LENGTH * 2, "%s%s", color_str( AT_EXITS, ch ), get_exits( ch ) );
	else
		mudstrlcpy( buf, "", MAX_STRING_LENGTH * 2 );

	/*
	 * Top of map frame 
	 */
	mudstrlcat( buf, "&z+-----------+&w ", MAX_STRING_LENGTH * 2 );
	if ( !alldesc )
	{
		pos = get_line( p, 63 );
		if ( pos > 0 )
		{
			mudstrlcat( buf, color_str( AT_RMDESC, ch ), MAX_STRING_LENGTH * 2 );
			strncat( buf, p, pos );
			p += pos;
		}
		else
		{
			mudstrlcat( buf, color_str( AT_RMDESC, ch ), MAX_STRING_LENGTH * 2 );
			mudstrlcat( buf, p, MAX_STRING_LENGTH * 2 );
			alldesc = TRUE;
		}
	}
	mudstrlcat( buf, "\r\n", MAX_STRING_LENGTH * 2 );

	/*
	 * Write out the main map area with text 
	 */
	for ( y = 0; y <= MAPY; ++y )
	{
		mudstrlcat( buf, "&z|&D", MAX_STRING_LENGTH * 2 );

		for ( x = 0; x <= MAPX; ++x )
		{
			switch ( dmap[x][y].tegn )
			{
				case '-':
				case '|':
				case '\\':
				case '/':
					snprintf( buf + strlen( buf ), ( MAX_STRING_LENGTH * 2 ) - strlen( buf ), "&O%c&d", dmap[x][y].tegn );
					break;

				case '@':	// Character is standing here
					snprintf( buf + strlen( buf ), ( MAX_STRING_LENGTH * 2 ) - strlen( buf ), "&R%c&d", dmap[x][y].tegn );
					break;

				case 'O':	// Indoors
					snprintf( buf + strlen( buf ), ( MAX_STRING_LENGTH * 2 ) - strlen( buf ), "&w%c&d", dmap[x][y].tegn );
					break;

				case '=':
					snprintf( buf + strlen( buf ), ( MAX_STRING_LENGTH * 2 ) - strlen( buf ), "&B%c&d", dmap[x][y].tegn );
					break;

				case '~':
					snprintf( buf + strlen( buf ), ( MAX_STRING_LENGTH * 2 ) - strlen( buf ), "&C%c&d", dmap[x][y].tegn );
					break;

				case '+':
					snprintf( buf + strlen( buf ), ( MAX_STRING_LENGTH * 2 ) - strlen( buf ), "&Y%c&d", dmap[x][y].tegn );
					break;

				case '*':
					snprintf( buf + strlen( buf ), ( MAX_STRING_LENGTH * 2 ) - strlen( buf ), "&g%c&d", dmap[x][y].tegn );
					break;

				case 'X':
					snprintf( buf + strlen( buf ), ( MAX_STRING_LENGTH * 2 ) - strlen( buf ), "&R%c&d", dmap[x][y].tegn );
					break;

				case ':':
					snprintf( buf + strlen( buf ), ( MAX_STRING_LENGTH * 2 ) - strlen( buf ), "&Y%c&d", dmap[x][y].tegn );
					break;

				default:	// Empty space
					snprintf( buf + strlen( buf ), ( MAX_STRING_LENGTH * 2 ) - strlen( buf ), "%c", dmap[x][y].tegn );
					break;
			}
		}
		mudstrlcat( buf, "&z|&D ", MAX_STRING_LENGTH * 2 );

		/*
		 * Add the text, if necessary 
		 */
		if ( !alldesc )
		{
			pos = get_line( p, 63 );
			char col[10], c[2];

			strcpy( c, whatColor( text, p ) );
			if ( c[0] == '\0' )
				mudstrlcpy( col, color_str( AT_RMDESC, ch ), 10 );
			else
				snprintf( col, 10, "%s", c );

			if ( pos > 0 )
			{
				mudstrlcat( buf, col, MAX_STRING_LENGTH * 2 );
				strncat( buf, p, pos );
				p += pos;
			}
			else
			{
				mudstrlcat( buf, col, MAX_STRING_LENGTH * 2 );
				mudstrlcat( buf, p, MAX_STRING_LENGTH * 2 );
				alldesc = TRUE;
			}
		}
		mudstrlcat( buf, "\r\n", MAX_STRING_LENGTH * 2 );
	}

	/*
	 * Finish off map area 
	 */
	mudstrlcat( buf, "&z+-----------+&D ", MAX_STRING_LENGTH * 2 );
	if ( !alldesc )
	{
		char col[10], c[2];

		pos = get_line( p, 63 );

		strcpy( c, whatColor( text, p ) );
		if ( c[0] == '\0' )
			mudstrlcpy( col, color_str( AT_RMDESC, ch ), 10 );
		else
			snprintf( col, 10, "%s", c );

		if ( pos > 0 )
		{
			mudstrlcat( buf, col, MAX_STRING_LENGTH * 2 );
			strncat( buf, p, pos );
			p += pos;
			mudstrlcat( buf, "\r\n", MAX_STRING_LENGTH * 2 );
		}
		else
		{
			mudstrlcat( buf, col, MAX_STRING_LENGTH * 2 );
			mudstrlcat( buf, p, MAX_STRING_LENGTH * 2 );
			alldesc = TRUE;
		}
	}

	/*
	 * Deal with any leftover text 
	 */
	if ( !alldesc )
	{
		char col[10], c[2];

		do
		{
			/*
			 * Note the number - no map to detract from width 
			 */
			pos = get_line( p, 78 );

			strcpy( c, whatColor( text, p ) );
			if ( c[0] == '\0' )
				mudstrlcpy( col, color_str( AT_RMDESC, ch ), 10 );
			else
				snprintf( col, 10, "%s", c );

			if ( pos > 0 )
			{
				mudstrlcat( buf, col, MAX_STRING_LENGTH * 2 );
				strncat( buf, p, pos );
				p += pos;
				mudstrlcat( buf, "\r\n", MAX_STRING_LENGTH * 2 );
			}
			else
			{
				mudstrlcat( buf, col, MAX_STRING_LENGTH * 2 );
				mudstrlcat( buf, p, MAX_STRING_LENGTH * 2 );
				alldesc = TRUE;
			}
		}
		while ( !alldesc );
	}
	mudstrlcat( buf, "&D\r\n", MAX_STRING_LENGTH * 2 );
	send_to_char( buf, ch );
}
Пример #9
0
char *get_exits( CHAR_DATA * ch )
{
	static char buf[MAX_STRING_LENGTH];
	EXIT_DATA *pexit;
	bool found = FALSE;

	buf[0] = '\0';

	if ( !check_blind( ch ) )
		return buf;

	set_char_color( AT_EXITS, ch );

	mudstrlcpy( buf, "[Exits:", MAX_STRING_LENGTH );

	for ( pexit = ch->in_room->first_exit; pexit; pexit = pexit->next )
	{
		if ( IS_IMMORTAL( ch ) )
			/*
			 * Immortals see all exits, even secret ones 
			 */
		{
			if ( pexit->to_room )
			{
				found = TRUE;
				mudstrlcat( buf, " ", MAX_STRING_LENGTH );

				mudstrlcat( buf, capitalize( dir_name[pexit->vdir] ), MAX_STRING_LENGTH );

				/*
				 * New code added to display closed, or otherwise invisible exits to immortals 
				 * Installed by Samson 1-25-98 
				 */
				if ( IS_SET( pexit->exit_info, EX_CLOSED ) )
					mudstrlcat( buf, "->(Closed)", MAX_STRING_LENGTH );
				if ( IS_SET( pexit->exit_info, EX_DIG ) )
					mudstrlcat( buf, "->(Dig)", MAX_STRING_LENGTH );
				if ( IS_SET( pexit->exit_info, EX_WINDOW ) )
					mudstrlcat( buf, "->(Window)", MAX_STRING_LENGTH );
				if ( IS_SET( pexit->exit_info, EX_HIDDEN ) )
					mudstrlcat( buf, "->(Hidden)", MAX_STRING_LENGTH );
				if ( xIS_SET( pexit->to_room->room_flags, ROOM_DEATH ) )
					mudstrlcat( buf, "->(Deathtrap)", MAX_STRING_LENGTH );
			}
		}
		else
		{
			if ( pexit->to_room
				&& !IS_SET( pexit->exit_info, EX_SECRET ) && ( !IS_SET( pexit->exit_info, EX_WINDOW ) || IS_SET( pexit->exit_info, EX_ISDOOR ) ) && !IS_SET( pexit->exit_info, EX_HIDDEN ) )
			{
				found = TRUE;
				mudstrlcat( buf, " ", MAX_STRING_LENGTH );

				mudstrlcat( buf, capitalize( dir_name[pexit->vdir] ), MAX_STRING_LENGTH );

				if ( IS_SET( pexit->exit_info, EX_CLOSED ) )
					mudstrlcat( buf, "->(Closed)", MAX_STRING_LENGTH );
				if ( IS_AFFECTED( ch, AFF_DETECTTRAPS ) && xIS_SET( pexit->to_room->room_flags, ROOM_DEATH ) )
					mudstrlcat( buf, "->(Deathtrap)", MAX_STRING_LENGTH );
			}
		}
	}

	if ( !found )
		mudstrlcat( buf, " none]", MAX_STRING_LENGTH );
	else
		mudstrlcat( buf, "]", MAX_STRING_LENGTH );
	mudstrlcat( buf, "\r\n", MAX_STRING_LENGTH );
	return buf;
}
Пример #10
0
void do_mpmset( CHAR_DATA * ch, const char *argument )
{
	char arg1[MAX_INPUT_LENGTH];
	char arg2[MAX_INPUT_LENGTH];
	char arg3[MAX_INPUT_LENGTH];
	char buf[MAX_STRING_LENGTH];
	char log_buf[MAX_STRING_LENGTH];
	char outbuf[MAX_STRING_LENGTH];
	CHAR_DATA *victim;
	int value, v2;
	int minattr, maxattr;

	/*
	 * A desc means switched.. too many loopholes if we allow that.. 
	 */
	if ( !IS_NPC( ch ) || IS_AFFECTED( ch, AFF_CHARM ) || ch->desc )
	{
		send_to_char( "Huh?\r\n", ch );
		return;
	}

	smash_tilde( argument );

	argument = one_argument( argument, arg1 );
	argument = one_argument( argument, arg2 );
	mudstrlcpy( arg3, argument, MAX_INPUT_LENGTH );

	if ( !*arg1 )
	{
		progbug( "MpMset: no args", ch );
		return;
	}

	if ( ( victim = get_char_room( ch, arg1 ) ) == NULL )
	{
		progbug( "MpMset: no victim", ch );
		return;
	}

	if ( IS_IMMORTAL( victim ) )
	{
		send_to_char( "You can't do that!\r\n", ch );
		return;
	}

	if ( IS_NPC( victim ) && xIS_SET( victim->act, ACT_PROTOTYPE ) )
	{
		progbug( "MpMset: victim is proto", ch );
		return;
	}

	if ( IS_NPC( victim ) )
	{
		minattr = 1;
		maxattr = 25;
	}
	else
	{
		minattr = 3;
		maxattr = 18;
	}

	value = is_number( arg3 ) ? atoi( arg3 ) : -1;
	if ( atoi( arg3 ) < -1 && value == -1 )
		value = atoi( arg3 );

	if ( !str_cmp( arg2, "str" ) )
	{
		if ( value < minattr || value > maxattr )
		{
			progbug( "MpMset: Invalid str", ch );
			return;
		}
		victim->perm_str = value;
		return;
	}

	if ( !str_cmp( arg2, "int" ) )
	{
		if ( value < minattr || value > maxattr )
		{
			progbug( "MpMset: Invalid int", ch );
			return;
		}
		victim->perm_int = value;
		return;
	}

	if ( !str_cmp( arg2, "wis" ) )
	{
		if ( value < minattr || value > maxattr )
		{
			progbug( "MpMset: Invalid wis", ch );
			return;
		}
		victim->perm_wis = value;
		return;
	}

	if ( !str_cmp( arg2, "dex" ) )
	{
		if ( value < minattr || value > maxattr )
		{
			progbug( "MpMset: Invalid dex", ch );
			return;
		}
		victim->perm_dex = value;
		return;
	}

	if ( !str_cmp( arg2, "con" ) )
	{
		if ( value < minattr || value > maxattr )
		{
			progbug( "MpMset: Invalid con", ch );
			return;
		}
		victim->perm_con = value;
		return;
	}

	if ( !str_cmp( arg2, "cha" ) )
	{
		if ( value < minattr || value > maxattr )
		{
			progbug( "MpMset: Invalid cha", ch );
			return;
		}
		victim->perm_cha = value;
		return;
	}

	if ( !str_cmp( arg2, "lck" ) )
	{
		if ( value < minattr || value > maxattr )
		{
			progbug( "MpMset: Invalid lck", ch );
			return;
		}
		victim->perm_lck = value;
		return;
	}

	if ( !str_cmp( arg2, "sav1" ) )
	{
		if ( value < -30 || value > 30 )
		{
			progbug( "MpMset: Invalid sav1", ch );
			return;
		}
		victim->saving_poison_death = value;
		return;
	}

	if ( !str_cmp( arg2, "sav2" ) )
	{
		if ( value < -30 || value > 30 )
		{
			progbug( "MpMset: Invalid sav2", ch );
			return;
		}
		victim->saving_wand = value;
		return;
	}

	if ( !str_cmp( arg2, "sav3" ) )
	{
		if ( value < -30 || value > 30 )
		{
			progbug( "MpMset: Invalid sav3", ch );
			return;
		}
		victim->saving_para_petri = value;
		return;
	}

	if ( !str_cmp( arg2, "sav4" ) )
	{
		if ( value < -30 || value > 30 )
		{
			progbug( "MpMset: Invalid sav4", ch );
			return;
		}
		victim->saving_breath = value;
		return;
	}

	if ( !str_cmp( arg2, "sav5" ) )
	{
		if ( value < -30 || value > 30 )
		{
			progbug( "MpMset: Invalid sav5", ch );
			return;
		}
		victim->saving_spell_staff = value;
		return;
	}

	if ( !str_cmp( arg2, "sex" ) )
	{
		if ( value < 0 || value > 2 )
		{
			progbug( "MpMset: Invalid sex", ch );
			return;
		}
		victim->sex = value;
		return;
	}

	if ( !str_cmp( arg2, "class" ) )
	{
		if ( IS_NPC( victim ) )	/* Broken by Haus... fixed by Thoric */
		{
			if ( value >= MAX_NPC_CLASS || value < 0 )
			{
				progbug( "MpMset: Invalid npc class", ch );
				return;
			}
			victim->Class = value;
			return;
		}
		progbug( "MpMset: can't set pc class", ch );
	}

	if ( !str_cmp( arg2, "race" ) )
	{
		value = get_npc_race( arg3 );
		if ( value < 0 )
			value = atoi( arg3 );
		if ( !IS_NPC( victim ) )
		{
			progbug( "MpMset: can't set pc race", ch );
			return;
		}
		if ( value < 0 || value >= MAX_NPC_RACE )
		{
			progbug( "MpMset: Invalid npc race", ch );
			return;
		}
		victim->race = value;
		return;
	}

	if ( !str_cmp( arg2, "armor" ) )
	{
		if ( value < -300 || value > 300 )
		{
			send_to_char( "AC range is -300 to 300.\r\n", ch );
			return;
		}
		victim->armor = value;
		return;
	}

	if ( !str_cmp( arg2, "level" ) )
	{
		if ( !IS_NPC( victim ) )
		{
			progbug( "MpMset: can't set pc level", ch );
			return;
		}

		if ( value < 0 || value > LEVEL_AVATAR + 5 )
		{
			progbug( "MpMset: Invalid npc level", ch );
			return;
		}
		victim->level = value;
		return;
	}

	if ( !str_cmp( arg2, "numattacks" ) )
	{
		if ( !IS_NPC( victim ) )
		{
			progbug( "MpMset: can't set pc numattacks", ch );
			return;
		}

		if ( value < 0 || value > 20 )
		{
			progbug( "MpMset: Invalid npc numattacks", ch );
			return;
		}
		victim->numattacks = value;
		return;
	}

	if ( !str_cmp( arg2, "gold" ) )
	{
		victim->gold = value;
		return;
	}

	if ( !str_cmp( arg2, "hitroll" ) )
	{
		victim->hitroll = URANGE( 0, value, 85 );
		return;
	}

	if ( !str_cmp( arg2, "damroll" ) )
	{
		victim->damroll = URANGE( 0, value, 65 );
		return;
	}

	if ( !str_cmp( arg2, "hp" ) )
	{
		if ( value < 1 || value > 32700 )
		{
			progbug( "MpMset: Invalid hp", ch );
			return;
		}
		victim->max_hit = value;
		return;
	}

	if ( !str_cmp( arg2, "mana" ) )
	{
		if ( value < 0 || value > 30000 )
		{
			progbug( "MpMset: Invalid mana", ch );
			return;
		}
		victim->max_mana = value;
		return;
	}

	if ( !str_cmp( arg2, "move" ) )
	{
		if ( value < 0 || value > 30000 )
		{
			progbug( "MpMset: Invalid move", ch );
			return;
		}
		victim->max_move = value;
		return;
	}

	if ( !str_cmp( arg2, "practice" ) )
	{
		if ( value < 0 || value > 100 )
		{
			progbug( "MpMset: Invalid practice", ch );
			return;
		}
		victim->practice = value;
		return;
	}

	if ( !str_cmp( arg2, "align" ) )
	{
		if ( value < -1000 || value > 1000 )
		{
			progbug( "MpMset: Invalid align", ch );
			return;
		}
		victim->alignment = value;
		return;
	}

/* non-functional for now -- Blod
    if ( !str_cmp( arg2, "quest" ) )
    {
	if ( IS_NPC(victim) )
	{
	    progbug("MpMset: can't set npc quest", ch);
	    return;
	}

	if ( value < 0 || value > 500 )
	{
	    progbug("MpMset: Invalid pc quest", ch);
	    return;
	}

	victim->pcdata->quest = value;
	return;
    }
*/

	if ( !str_cmp( arg2, "questplus" ) )
	{
		if ( IS_NPC( victim ) )
		{
			progbug( "MpMset: can't set npc qp", ch );
			return;
		}

		if ( value < 0 || value > 5000 )
		{
			progbug( "MpMset: Invalid pc qp", ch );
			return;
		}
		snprintf( log_buf, MAX_STRING_LENGTH, "%s raising glory of %s by %d ...", ch->name, victim->name, value );
		log_string( log_buf );
		victim->pcdata->quest_curr += value;
		victim->pcdata->quest_accum += value;
		return;
	}

	if ( !str_cmp( arg2, "favor" ) )
	{
		if ( IS_NPC( victim ) )
		{
			progbug( "MpMset: can't set npc favor", ch );
			return;
		}

		if ( value < -2500 || value > 2500 )
		{
			progbug( "MpMset: Invalid pc favor", ch );
			return;
		}

		victim->pcdata->favor = value;
		return;
	}

	if ( !str_cmp( arg2, "mentalstate" ) )
	{
		if ( value < -100 || value > 100 )
		{
			progbug( "MpMset: Invalid mentalstate", ch );
			return;
		}
		victim->mental_state = value;
		return;
	}

	if ( !str_cmp( arg2, "emotion" ) )
	{
		if ( value < -100 || value > 100 )
		{
			progbug( "MpMset: Invalid emotion", ch );
			return;
		}
		victim->emotional_state = value;
		return;
	}

	if ( !str_cmp( arg2, "thirst" ) )
	{
		if ( IS_NPC( victim ) )
		{
			progbug( "MpMset: can't set npc thirst", ch );
			return;
		}

		if ( value < 0 || value > 100 )
		{
			progbug( "MpMset: Invalid pc thirst", ch );
			return;
		}

		victim->pcdata->condition[COND_THIRST] = value;
		return;
	}

	if ( !str_cmp( arg2, "drunk" ) )
	{
		if ( IS_NPC( victim ) )
		{
			progbug( "MpMset: can't set npc drunk", ch );
			return;
		}

		if ( value < 0 || value > 100 )
		{
			progbug( "MpMset: Invalid pc drunk", ch );
			return;
		}

		victim->pcdata->condition[COND_DRUNK] = value;
		return;
	}

	if ( !str_cmp( arg2, "full" ) )
	{
		if ( IS_NPC( victim ) )
		{
			progbug( "MpMset: can't set npc full", ch );
			return;
		}

		if ( value < 0 || value > 100 )
		{
			progbug( "MpMset: Invalid pc full", ch );
			return;
		}

		victim->pcdata->condition[COND_FULL] = value;
		return;
	}

	if ( !str_cmp( arg2, "blood" ) )
	{
		if ( IS_NPC( victim ) )
		{
			progbug( "MpMset: can't set npc blood", ch );
			return;
		}

		if ( value < 0 || value > MAX_LEVEL + 10 )
		{
			progbug( "MpMset: Invalid pc blood", ch );
			return;
		}

		victim->pcdata->condition[COND_BLOODTHIRST] = value;
		return;
	}

	if ( !str_cmp( arg2, "name" ) )
	{
		if ( !IS_NPC( victim ) )
		{
			progbug( "MpMset: can't set pc name", ch );
			return;
		}

		STRFREE( victim->name );
		victim->name = STRALLOC( arg3 );
		return;
	}

	if ( !str_cmp( arg2, "deity" ) )
	{
		DEITY_DATA *deity;

		if ( IS_NPC( victim ) )
		{
			progbug( "MpMset: can't set npc deity", ch );
			return;
		}

		if ( arg3[0] == '\0' )
		{
			STRFREE( victim->pcdata->deity_name );
			victim->pcdata->deity_name = STRALLOC( "" );
			victim->pcdata->deity = NULL;
			return;
		}

		deity = get_deity( arg3 );
		if ( !deity )
		{
			progbug( "MpMset: Invalid deity", ch );
			return;
		}
		STRFREE( victim->pcdata->deity_name );
		victim->pcdata->deity_name = QUICKLINK( deity->name );
		victim->pcdata->deity = deity;
		return;
	}

	if ( !str_cmp( arg2, "short" ) )
	{
		STRFREE( victim->short_descr );
		victim->short_descr = STRALLOC( arg3 );
		return;
	}

	if ( !str_cmp( arg2, "long" ) )
	{
		STRFREE( victim->long_descr );
		mudstrlcpy( buf, arg3, MAX_STRING_LENGTH );
		mudstrlcat( buf, "\r\n", MAX_STRING_LENGTH );
		victim->long_descr = STRALLOC( buf );
		return;
	}

	if ( !str_cmp( arg2, "title" ) )
	{
		if ( IS_NPC( victim ) )
		{
			progbug( "MpMset: can't set npc title", ch );
			return;
		}

		set_title( victim, arg3 );
		return;
	}

	if ( !str_cmp( arg2, "spec" ) )
	{
		if ( !IS_NPC( victim ) )
		{
			progbug( "MpMset: can't set pc spec", ch );
			return;
		}

		if ( !str_cmp( arg3, "none" ) )
		{
			victim->spec_fun = NULL;
			return;
		}

		if ( ( victim->spec_fun = spec_lookup( arg3 ) ) == 0 )
		{
			progbug( "MpMset: Invalid spec", ch );
			return;
		}
		return;
	}

	if ( !str_cmp( arg2, "flags" ) )
	{
		if ( !IS_NPC( victim ) )
		{
			progbug( "MpMset: can't set pc flags", ch );
			return;
		}

		if ( !argument || argument[0] == '\0' )
		{
			progbug( "MpMset: no flags", ch );
			return;
		}
		while ( argument[0] != '\0' )
		{
			argument = one_argument( argument, arg3 );
			value = get_actflag( arg3 );
			if ( value < 0 || value >= MAX_BITS )
				progbug( "MpMset: Invalid flag", ch );
			else
			{
				if ( value == ACT_PROTOTYPE )
					progbug( "MpMset: can't set prototype flag", ch );
				else if ( value == ACT_IS_NPC )
					progbug( "MpMset: can't remove npc flag", ch );
				else
					xTOGGLE_BIT( victim->act, value );
			}
		}
		return;
	}

	if ( !str_cmp( arg2, "affected" ) )
	{
		if ( !IS_NPC( victim ) )
		{
			progbug( "MpMset: can't modify pc affected", ch );
			return;
		}

		if ( !argument || argument[0] == '\0' )
		{
			progbug( "MpMset: no affected", ch );
			return;
		}
		while ( argument[0] != '\0' )
		{
			argument = one_argument( argument, arg3 );
			value = get_aflag( arg3 );
			if ( value < 0 || value >= MAX_BITS )
				progbug( "MpMset: Invalid affected", ch );
			else
				xTOGGLE_BIT( victim->affected_by, value );
		}
		return;
	}

	/*
	 * save some more finger-leather for setting RIS stuff
	 * Why there's can_modify checks here AND in the called function, Ill
	 * never know, so I removed them.. -- Alty
	 */
	if ( !str_cmp( arg2, "r" ) )
	{
		snprintf( outbuf, MAX_STRING_LENGTH, "%s resistant %s", arg1, arg3 );
		do_mpmset( ch, outbuf );
		return;
	}
	if ( !str_cmp( arg2, "i" ) )
	{
		snprintf( outbuf, MAX_STRING_LENGTH, "%s immune %s", arg1, arg3 );
		do_mpmset( ch, outbuf );
		return;
	}
	if ( !str_cmp( arg2, "s" ) )
	{
		snprintf( outbuf, MAX_STRING_LENGTH, "%s susceptible %s", arg1, arg3 );
		do_mpmset( ch, outbuf );
		return;
	}
	if ( !str_cmp( arg2, "ri" ) )
	{
		snprintf( outbuf, MAX_STRING_LENGTH, "%s resistant %s", arg1, arg3 );
		do_mpmset( ch, outbuf );
		snprintf( outbuf, MAX_STRING_LENGTH, "%s immune %s", arg1, arg3 );
		do_mpmset( ch, outbuf );
		return;
	}

	if ( !str_cmp( arg2, "rs" ) )
	{
		snprintf( outbuf, MAX_STRING_LENGTH, "%s resistant %s", arg1, arg3 );
		do_mpmset( ch, outbuf );
		snprintf( outbuf, MAX_STRING_LENGTH, "%s susceptible %s", arg1, arg3 );
		do_mpmset( ch, outbuf );
		return;
	}
	if ( !str_cmp( arg2, "is" ) )
	{
		snprintf( outbuf, MAX_STRING_LENGTH, "%s immune %s", arg1, arg3 );
		do_mpmset( ch, outbuf );
		snprintf( outbuf, MAX_STRING_LENGTH, "%s susceptible %s", arg1, arg3 );
		do_mpmset( ch, outbuf );
		return;
	}
	if ( !str_cmp( arg2, "ris" ) )
	{
		snprintf( outbuf, MAX_STRING_LENGTH, "%s resistant %s", arg1, arg3 );
		do_mpmset( ch, outbuf );
		snprintf( outbuf, MAX_STRING_LENGTH, "%s immune %s", arg1, arg3 );
		do_mpmset( ch, outbuf );
		snprintf( outbuf, MAX_STRING_LENGTH, "%s susceptible %s", arg1, arg3 );
		do_mpmset( ch, outbuf );
		return;
	}

	if ( !str_cmp( arg2, "resistant" ) )
	{
		if ( !IS_NPC( victim ) )
		{
			progbug( "MpMset: can't set pc resistant", ch );
			return;
		}
		if ( !argument || argument[0] == '\0' )
		{
			progbug( "MpMset: no resistant", ch );
			return;
		}
		while ( argument[0] != '\0' )
		{
			argument = one_argument( argument, arg3 );
			value = get_risflag( arg3 );
			if ( value < 0 || value > 31 )
				progbug( "MpMset: Invalid resistant", ch );
			else
				TOGGLE_BIT( victim->resistant, 1 << value );
		}
		return;
	}

	if ( !str_cmp( arg2, "immune" ) )
	{
		if ( !IS_NPC( victim ) )
		{
			progbug( "MpMset: can't set pc immune", ch );
			return;
		}
		if ( !argument || argument[0] == '\0' )
		{
			progbug( "MpMset: no immune", ch );
			return;
		}
		while ( argument[0] != '\0' )
		{
			argument = one_argument( argument, arg3 );
			value = get_risflag( arg3 );
			if ( value < 0 || value > 31 )
				progbug( "MpMset: Invalid immune", ch );
			else
				TOGGLE_BIT( victim->immune, 1 << value );
		}
		return;
	}

	if ( !str_cmp( arg2, "susceptible" ) )
	{
		if ( !IS_NPC( victim ) )
		{
			progbug( "MpMset: can't set pc susceptible", ch );
			return;
		}
		if ( !argument || argument[0] == '\0' )
		{
			progbug( "MpMset: no susceptible", ch );
			return;
		}
		while ( argument[0] != '\0' )
		{
			argument = one_argument( argument, arg3 );
			value = get_risflag( arg3 );
			if ( value < 0 || value > 31 )
				progbug( "MpMset: Invalid susceptible", ch );
			else
				TOGGLE_BIT( victim->susceptible, 1 << value );
		}
		return;
	}

	if ( !str_cmp( arg2, "part" ) )
	{
		if ( !IS_NPC( victim ) )
		{
			progbug( "MpMset: can't set pc part", ch );
			return;
		}
		if ( !argument || argument[0] == '\0' )
		{
			progbug( "MpMset: no part", ch );
			return;
		}
		while ( argument[0] != '\0' )
		{
			argument = one_argument( argument, arg3 );
			value = get_partflag( arg3 );
			if ( value < 0 || value > 31 )
				progbug( "MpMset: Invalid part", ch );
			else
				TOGGLE_BIT( victim->xflags, 1 << value );
		}
		return;
	}

	if ( !str_cmp( arg2, "attack" ) )
	{
		if ( !IS_NPC( victim ) )
		{
			progbug( "MpMset: can't set pc attack", ch );
			return;
		}
		if ( !argument || argument[0] == '\0' )
		{
			progbug( "MpMset: no attack", ch );
			return;
		}
		while ( argument[0] != '\0' )
		{
			argument = one_argument( argument, arg3 );
			value = get_attackflag( arg3 );
			if ( value < 0 )
				progbug( "MpMset: Invalid attack", ch );
			else
				xTOGGLE_BIT( victim->attacks, value );
		}
		return;
	}

	if ( !str_cmp( arg2, "defense" ) )
	{
		if ( !IS_NPC( victim ) )
		{
			progbug( "MpMset: can't set pc defense", ch );
			return;
		}
		if ( !argument || argument[0] == '\0' )
		{
			progbug( "MpMset: no defense", ch );
			return;
		}
		while ( argument[0] != '\0' )
		{
			argument = one_argument( argument, arg3 );
			value = get_defenseflag( arg3 );
			if ( value < 0 || value >= MAX_BITS )
				progbug( "MpMset: Invalid defense", ch );
			else
				xTOGGLE_BIT( victim->defenses, value );
		}
		return;
	}

	if ( !str_cmp( arg2, "pos" ) )
	{
		if ( !IS_NPC( victim ) )
		{
			progbug( "MpMset: can't set pc pos", ch );
			return;
		}
		if ( value < 0 || value > POS_STANDING )
		{
			progbug( "MpMset: Invalid pos", ch );
			return;
		}
		victim->position = value;
		return;
	}

	if ( !str_cmp( arg2, "defpos" ) )
	{
		if ( !IS_NPC( victim ) )
		{
			progbug( "MpMset: can't set pc defpos", ch );
			return;
		}
		if ( value < 0 || value > POS_STANDING )
		{
			progbug( "MpMset: Invalid defpos", ch );
			return;
		}
		victim->defposition = value;
		return;
	}

	if ( !str_cmp( arg2, "speaks" ) )
	{
		if ( !argument || argument[0] == '\0' )
		{
			progbug( "MpMset: no speaks", ch );
			return;
		}
		while ( argument[0] != '\0' )
		{
			argument = one_argument( argument, arg3 );
			value = get_langflag( arg3 );
			v2 = get_langnum( arg3 );
			if ( value == LANG_UNKNOWN )
				progbug( "MpMset: Invalid speaks", ch );
			else if ( !IS_NPC( victim ) )
			{
				if ( !( value &= VALID_LANGS ) )
				{
					progbug( "MpMset: Invalid player language", ch );
					continue;
				}
				if ( v2 == -1 )
					ch_printf( ch, "Unknown language: %s\r\n", arg3 );
				else
					TOGGLE_BIT( victim->speaks, 1 << v2 );
			}
			else
			{
				if ( v2 == -1 )
					ch_printf( ch, "Unknown language: %s\r\n", arg3 );
				else
					TOGGLE_BIT( victim->speaks, 1 << v2 );
			}
		}
		if ( !IS_NPC( victim ) )
		{
			REMOVE_BIT( victim->speaks, race_table[victim->race]->language );
			if ( !knows_language( victim, victim->speaking, victim ) )
				victim->speaking = race_table[victim->race]->language;
		}
		return;
	}

	if ( !str_cmp( arg2, "speaking" ) )
	{
		if ( !IS_NPC( victim ) )
		{
			progbug( "MpMset: can't set pc speaking", ch );
			return;
		}
		if ( !argument || argument[0] == '\0' )
		{
			progbug( "MpMset: no speaking", ch );
			return;
		}
		while ( argument[0] != '\0' )
		{
			argument = one_argument( argument, arg3 );
			value = get_langflag( arg3 );
			if ( value == LANG_UNKNOWN )
				progbug( "MpMset: Invalid speaking", ch );
			else
			{
				v2 = get_langnum( arg3 );
				if ( v2 == -1 )
					ch_printf( ch, "Unknown language: %s\r\n", arg3 );
				else
					TOGGLE_BIT( victim->speaks, 1 << v2 );
			}
		}
		return;
	}

	progbug( "MpMset: Invalid field", ch );
	return;
}
Пример #11
0
/*
 * Quixadhal - I rewrote this from scratch.  It now returns the number of
 * characters in the SOURCE string that should be skipped, it always fills
 * the DESTINATION string with a valid translation (even if that is itself,
 * or an empty string), and the default for ANSI is FALSE, since mobs and
 * logfiles shouldn't need colour.
 *
 * NOTE:  dstlen is the length of your pre-allocated buffer that you passed
 * in.  It must be at least 3 bytes, but should be long enough to hold the
 * longest translation sequence (probably around 16-32).
 *
 * NOTE:  vislen is the "visible" length of the translation token.  This is
 * used by color_strlen to properly figure the visual length of a string.
 * If you need the number of bytes (such as for output buffering), use the
 * normal strlen function.
 */
int colorcode( const char *src, char *dst, DESCRIPTOR_DATA * d, int dstlen, int *vislen )
{
   CHAR_DATA *ch = NULL;
   bool ansi = FALSE;
   const char *sympos = NULL;

   /*
    * No descriptor, assume ANSI conversion can't be done. 
    */
   if( !d )
      ansi = FALSE;
   /*
    * But, if we have one, check for a PC and set accordingly. If no PC, assume ANSI can be done. For color logins. 
    */
   else
   {
      ch = d->original ? d->original : d->character;

      if( ch )
         ansi = ( !IS_NPC( ch ) && xIS_SET( ch->act, PLR_ANSI ) );
      else
         ansi = TRUE;
   }

   if( !dst )
      return 0;   /* HEY, I said at least 3 BYTES! */

   dst[0] = '\0'; /* Initialize the the default NOTHING */

   /*
    * Move along, nothing to see here 
    */
   if( !src || !*src )
      return 0;

   switch ( *src )
   {
      case '&':  /* NORMAL, Foreground colour */
         switch ( src[1] )
         {
            case '&':  /* Escaped self, return one of us */
               dst[0] = src[0];
               dst[1] = '\0';
               if( vislen )
                  *vislen = 1;
               return 2;

            case 'Z':  /* Random Ansi Foreground */
               if( ansi )
                  mudstrlcpy( dst, random_ansi( 1 ), dstlen );
               break;

            case '[':  /* Symbolic color name */
               if( ( sympos = strchr( src + 2, ']' ) ) )
               {
                  register int subcnt = 0;
                  unsigned int sublen = 0;

                  sublen = sympos - src - 2;
                  for( subcnt = 0; subcnt < MAX_COLORS; subcnt++ )
                  {
                     if( !strncmp( src + 2, pc_displays[subcnt], sublen ) )
                     {
                        if( strlen( pc_displays[subcnt] ) == sublen )
                        {
                           /*
                            * These can only be used with a logged in char 
                            */
                           if( ansi && ch )
                              mudstrlcpy( dst, color_str( subcnt, ch ), dstlen );
                           if( vislen )
                              *vislen = 0;
                           return sublen + 3;
                        }
                     }
                  }
               }  /* found matching ] */

               /*
                * Unknown symbolic name, return just the sequence  
                */
               dst[0] = src[0];
               dst[1] = src[1];
               dst[2] = '\0';
               if( vislen )
                  *vislen = 2;
               return 2;

            case 'i':  /* Italic text */
            case 'I':
               if( ansi )
                  mudstrlcpy( dst, ANSI_ITALIC, dstlen );
               break;

            case 'v':  /* Reverse colors */
            case 'V':
               if( ansi )
                  mudstrlcpy( dst, ANSI_REVERSE, dstlen );
               break;

            case 'u':  /* Underline */
            case 'U':
               if( ansi )
                  mudstrlcpy( dst, ANSI_UNDERLINE, dstlen );
               break;

            case 's':  /* Strikeover */
            case 'S':
               if( ansi )
                  mudstrlcpy( dst, ANSI_STRIKEOUT, dstlen );
               break;

            case 'd':  /* Player's client default color */
               if( ansi )
                  mudstrlcpy( dst, ANSI_RESET, dstlen );
               break;

            case 'D':  /* Reset to custom color for whatever is being displayed */
               if( ansi )
               {
                  /*
                   * Yes, this reset here is quite necessary to cancel out other things 
                   */
                  mudstrlcpy( dst, ANSI_RESET, dstlen );
                  if( ch && ch->desc )
                     mudstrlcat( dst, color_str( ch->desc->pagecolor, ch ), dstlen );
               }
               break;

            case 'x':  /* Black */
               if( ansi )
                  mudstrlcpy( dst, ANSI_BLACK, dstlen );
               break;

            case 'O':  /* Orange/Brown */
               if( ansi )
                  mudstrlcpy( dst, ANSI_ORANGE, dstlen );
               break;

            case 'c':  /* Cyan */
               if( ansi )
                  mudstrlcpy( dst, ANSI_CYAN, dstlen );
               break;

            case 'z':  /* Dark Grey */
               if( ansi )
                  mudstrlcpy( dst, ANSI_DGREY, dstlen );
               break;

            case 'g':  /* Dark Green */
               if( ansi )
                  mudstrlcpy( dst, ANSI_DGREEN, dstlen );
               break;

            case 'G':  /* Light Green */
               if( ansi )
                  mudstrlcpy( dst, ANSI_GREEN, dstlen );
               break;

            case 'P':  /* Pink/Light Purple */
               if( ansi )
                  mudstrlcpy( dst, ANSI_PINK, dstlen );
               break;

            case 'r':  /* Dark Red */
               if( ansi )
                  mudstrlcpy( dst, ANSI_DRED, dstlen );
               break;

            case 'b':  /* Dark Blue */
               if( ansi )
                  mudstrlcpy( dst, ANSI_DBLUE, dstlen );
               break;

            case 'w':  /* Grey */
               if( ansi )
                  mudstrlcpy( dst, ANSI_GREY, dstlen );
               break;

            case 'Y':  /* Yellow */
               if( ansi )
                  mudstrlcpy( dst, ANSI_YELLOW, dstlen );
               break;

            case 'C':  /* Light Blue */
               if( ansi )
                  mudstrlcpy( dst, ANSI_LBLUE, dstlen );
               break;

            case 'p':  /* Purple */
               if( ansi )
                  mudstrlcpy( dst, ANSI_PURPLE, dstlen );
               break;

            case 'R':  /* Red */
               if( ansi )
                  mudstrlcpy( dst, ANSI_RED, dstlen );
               break;

            case 'B':  /* Blue */
               if( ansi )
                  mudstrlcpy( dst, ANSI_BLUE, dstlen );
               break;

            case 'W':  /* White */
               if( ansi )
                  mudstrlcpy( dst, ANSI_WHITE, dstlen );
               break;

            default:   /* Unknown sequence, return all the chars */
               dst[0] = src[0];
               dst[1] = src[1];
               dst[2] = '\0';
               if( vislen )
                  *vislen = 2;
               return 2;
         }
         break;

      case '^':  /* BACKGROUND colour */
         switch ( src[1] )
         {
            case '^':  /* Escaped self, return one of us */
               dst[0] = src[0];
               dst[1] = '\0';
               if( vislen )
                  *vislen = 1;
               return 2;

            case 'Z':  /* Random Ansi Background */
               if( ansi )
                  mudstrlcpy( dst, random_ansi( 3 ), dstlen );
               break;

            case 'x':  /* Black */
               if( ansi )
                  mudstrlcpy( dst, BACK_BLACK, dstlen );
               break;

            case 'r':  /* Dark Red */
               if( ansi )
                  mudstrlcpy( dst, BACK_DRED, dstlen );
               break;

            case 'g':  /* Dark Green */
               if( ansi )
                  mudstrlcpy( dst, BACK_DGREEN, dstlen );
               break;

            case 'O':  /* Orange/Brown */
               if( ansi )
                  mudstrlcpy( dst, BACK_ORANGE, dstlen );
               break;

            case 'b':  /* Dark Blue */
               if( ansi )
                  mudstrlcpy( dst, BACK_DBLUE, dstlen );
               break;

            case 'p':  /* Purple */
               if( ansi )
                  mudstrlcpy( dst, BACK_PURPLE, dstlen );
               break;

            case 'c':  /* Cyan */
               if( ansi )
                  mudstrlcpy( dst, BACK_CYAN, dstlen );
               break;

            case 'w':  /* Grey */
               if( ansi )
                  mudstrlcpy( dst, BACK_GREY, dstlen );
               break;

            case 'z':  /* Dark Grey */
               if( ansi )
                  mudstrlcpy( dst, BACK_DGREY, dstlen );
               break;

            case 'R':  /* Red */
               if( ansi )
                  mudstrlcpy( dst, BACK_RED, dstlen );
               break;

            case 'G':  /* Green */
               if( ansi )
                  mudstrlcpy( dst, BACK_GREEN, dstlen );
               break;

            case 'Y':  /* Yellow */
               if( ansi )
                  mudstrlcpy( dst, BACK_YELLOW, dstlen );
               break;

            case 'B':  /* Blue */
               if( ansi )
                  mudstrlcpy( dst, BACK_BLUE, dstlen );
               break;

            case 'P':  /* Pink */
               if( ansi )
                  mudstrlcpy( dst, BACK_PINK, dstlen );
               break;

            case 'C':  /* Light Blue */
               if( ansi )
                  mudstrlcpy( dst, BACK_LBLUE, dstlen );
               break;

            case 'W':  /* White */
               if( ansi )
                  mudstrlcpy( dst, BACK_WHITE, dstlen );
               break;

            default:   /* Unknown sequence, return all the chars */
               dst[0] = src[0];
               dst[1] = src[1];
               dst[2] = '\0';
               if( vislen )
                  *vislen = 2;
               return 2;
         }
         break;

      case '}':  /* BLINK Foreground colour */
         switch ( src[1] )
         {
            case '}':  /* Escaped self, return one of us */
               dst[0] = src[0];
               dst[1] = '\0';
               if( vislen )
                  *vislen = 1;
               return 2;

            case 'Z':  /* Random Ansi Blink */
               if( ansi )
                  mudstrlcpy( dst, random_ansi( 2 ), dstlen );
               break;

            case 'x':  /* Black */
               if( ansi )
                  mudstrlcpy( dst, BLINK_BLACK, dstlen );
               break;

            case 'O':  /* Orange/Brown */
               if( ansi )
                  mudstrlcpy( dst, BLINK_ORANGE, dstlen );
               break;

            case 'c':  /* Cyan */
               if( ansi )
                  mudstrlcpy( dst, BLINK_CYAN, dstlen );
               break;

            case 'z':  /* Dark Grey */
               if( ansi )
                  mudstrlcpy( dst, BLINK_DGREY, dstlen );
               break;

            case 'g':  /* Dark Green */
               if( ansi )
                  mudstrlcpy( dst, BLINK_DGREEN, dstlen );
               break;

            case 'G':  /* Light Green */
               if( ansi )
                  mudstrlcpy( dst, BLINK_GREEN, dstlen );
               break;

            case 'P':  /* Pink/Light Purple */
               if( ansi )
                  mudstrlcpy( dst, BLINK_PINK, dstlen );
               break;

            case 'r':  /* Dark Red */
               if( ansi )
                  mudstrlcpy( dst, BLINK_DRED, dstlen );
               break;

            case 'b':  /* Dark Blue */
               if( ansi )
                  mudstrlcpy( dst, BLINK_DBLUE, dstlen );
               break;

            case 'w':  /* Grey */
               if( ansi )
                  mudstrlcpy( dst, BLINK_GREY, dstlen );
               break;

            case 'Y':  /* Yellow */
               if( ansi )
                  mudstrlcpy( dst, BLINK_YELLOW, dstlen );
               break;

            case 'C':  /* Light Blue */
               if( ansi )
                  mudstrlcpy( dst, BLINK_LBLUE, dstlen );
               break;

            case 'p':  /* Purple */
               if( ansi )
                  mudstrlcpy( dst, BLINK_PURPLE, dstlen );
               break;

            case 'R':  /* Red */
               if( ansi )
                  mudstrlcpy( dst, BLINK_RED, dstlen );
               break;

            case 'B':  /* Blue */
               if( ansi )
                  mudstrlcpy( dst, BLINK_BLUE, dstlen );
               break;

            case 'W':  /* White */
               if( ansi )
                  mudstrlcpy( dst, BLINK_WHITE, dstlen );
               break;

            default:   /* Unknown sequence, return all the chars */
               dst[0] = src[0];
               dst[1] = src[1];
               dst[2] = '\0';
               if( vislen )
                  *vislen = 2;
               return 2;
         }
         break;

      default:   /* Just a normal character */
         dst[0] = *src;
         dst[1] = '\0';
         if( vislen )
            *vislen = 1;
         return 1;
   }
   if( vislen )
      *vislen = 0;
   return 2;
}
Пример #12
0
char *sec_to_hms( time_t loctime, char *tstr )
{
   time_t t_rem;
   int sc, mn, hr, dy, wk;
   int sflg = 0;
   char buff[MSL];

   if( loctime < 1 )
   {
      mudstrlcat( tstr, "no time at all", MSL );
      return ( tstr );
   }

   sc = loctime % DUR_SCMN;
   t_rem = loctime - sc;

   if( t_rem > 0 )
   {
      t_rem /= DUR_SCMN;
      mn = t_rem % DUR_MNHR;
      t_rem -= mn;

      if( t_rem > 0 )
      {
         t_rem /= DUR_MNHR;
         hr = t_rem % DUR_HRDY;
         t_rem -= hr;

         if( t_rem > 0 )
         {
            t_rem /= DUR_HRDY;
            dy = t_rem % DUR_DYWK;
            t_rem -= dy;

            if( t_rem > 0 )
            {
               wk = t_rem / DUR_DYWK;

               if( wk )
               {
                  sflg = 1;
                  snprintf( buff, MSL, "%d week%c", wk, DUR_ADDS( wk ) );
                  mudstrlcat( tstr, buff, MSL );
               }
            }
            if( dy )
            {
               if( sflg == 1 )
                  mudstrlcat( tstr, " ", MSL );
               sflg = 1;
               snprintf( buff, MSL, "%d day%c", dy, DUR_ADDS( dy ) );
               mudstrlcat( tstr, buff, MSL );
            }
         }
         if( hr )
         {
            if( sflg == 1 )
               mudstrlcat( tstr, " ", MSL );
            sflg = 1;
            snprintf( buff, MSL, "%d hour%c", hr, DUR_ADDS( hr ) );
            mudstrlcat( tstr, buff, MSL );
         }
      }
      if( mn )
      {
         if( sflg == 1 )
            mudstrlcat( tstr, " ", MSL );
         sflg = 1;
         snprintf( buff, MSL, "%d minute%c", mn, DUR_ADDS( mn ) );
         mudstrlcat( tstr, buff, MSL );
      }
   }
   if( sc )
   {
      if( sflg == 1 )
         mudstrlcat( tstr, " ", MSL );
      snprintf( buff, MSL, "%d second%c", sc, DUR_ADDS( sc ) );
      mudstrlcat( tstr, buff, MSL );
   }
   return ( tstr );
}
Пример #13
0
/* Duplicate of to_channel from act_comm.c modified for dynamic channels */
void send_tochannel( char_data * ch, mud_channel * channel, string & argument )
{
   int speaking = -1;

   for( int lang = 0; lang < LANG_UNKNOWN; ++lang )
   {
      if( ch->speaking == lang )
      {
         speaking = lang;
         break;
      }
   }

   if( ch->isnpc(  ) && channel->type == CHAN_GUILD )
   {
      ch->print( "Mobs can't be in clans/guilds.\r\n" );
      return;
   }

   if( ch->has_pcflag( PCFLAG_SILENCE ) )
   {
      ch->printf( "You can't %s.\r\n", channel->name.c_str(  ) );
      return;
   }

   if( ch->has_aflag( AFF_SILENCE ) )
   {
      ch->print( "You are unable to utter a sound!\r\n" );
      return;
   }

   if( !ch->IS_PKILL(  ) && channel->type == CHAN_PK )
   {
      if( !ch->is_immortal(  ) )
      {
         ch->print( "Peacefuls have no need to use PK channels.\r\n" );
         return;
      }
   }

   if( ch->in_room->flags.test( ROOM_SILENCE ) || ch->in_room->flags.test( ROOM_NOYELL ) || ch->in_room->area->flags.test( AFLAG_SILENCE ) )
   {
      ch->print( "The room absorbs your words!\r\n" );
      return;
   }

   if( ch->isnpc(  ) && ch->has_aflag( AFF_CHARM ) )
   {
      if( ch->master )
         ch->master->print( "I don't think so...\r\n" );
      return;
   }

   if( argument.empty(  ) )
   {
      if( !channel->flags.test( CHAN_KEEPHISTORY ) )
      {
         ch->printf( "%s what?\r\n", capitalize( channel->name ).c_str(  ) );
         return;
      }

      show_channel_history( ch, channel );
      return;
   }

   // Adaptation of Smaug 1.8b feature. Stop whitespace abuse now!
   strip_spaces( argument );

   string arg, word;
   char_data *victim = nullptr;
   social_type *social = nullptr;
   string socbuf_char, socbuf_vict, socbuf_other;

   arg = argument;
   arg = one_argument( arg, word );

   if( word[0] == '@' && ( social = find_social( word.substr( 1, word.length(  ) ) ) ) != nullptr )
   {
      if( !arg.empty(  ) )
      {
         string name;

         one_argument( arg, name );

         if( ( victim = ch->get_char_world( name ) ) )
            arg = one_argument( arg, name );

         if( !victim )
         {
            socbuf_char = social->char_no_arg;
            socbuf_vict = social->others_no_arg;
            socbuf_other = social->others_no_arg;
            if( socbuf_char.empty(  ) && socbuf_other.empty(  ) )
               social = nullptr;
         }
         else if( victim == ch )
         {
            socbuf_char = social->char_auto;
            socbuf_vict = social->others_auto;
            socbuf_other = social->others_auto;
            if( socbuf_char.empty(  ) && socbuf_other.empty(  ) )
               social = nullptr;
         }
         else
         {
            socbuf_char = social->char_found;
            socbuf_vict = social->vict_found;
            socbuf_other = social->others_found;
            if( socbuf_char.empty(  ) && socbuf_other.empty(  ) && socbuf_vict.empty(  ) )
               social = nullptr;
         }
      }
      else
      {
         socbuf_char = social->char_no_arg;
         socbuf_vict = social->others_no_arg;
         socbuf_other = social->others_no_arg;
         if( socbuf_char.empty(  ) && socbuf_other.empty(  ) )
            social = nullptr;
      }
   }

   bool emote = false;
   if( word[0] == ',' )
   {
      emote = true;
      argument = argument.substr( 1, argument.length(  ) );
   }

   if( social )
   {
      act_printf( AT_PLAIN, ch, argument.c_str(  ), victim, TO_CHAR, "&W[&[%s]%s&W] &[%s]%s",
                  channel->colorname.c_str(  ), capitalize( channel->name ).c_str(  ), channel->colorname.c_str(  ), socbuf_char.c_str(  ) );
   }
   else if( emote )
   {
      ch->printf( "&W[&[%s]%s&W] &[%s]%s %s\r\n",
                  channel->colorname.c_str(  ), capitalize( channel->name ).c_str(  ), channel->colorname.c_str(  ), ch->name, argument.c_str(  ) );
   }
   else
   {
      if( ch->has_pcflag( PCFLAG_WIZINVIS ) )
         ch->printf( "&[%s](%d) You %s '%s'\r\n", channel->colorname.c_str(  ), ( !ch->isnpc(  ) ? ch->pcdata->wizinvis : ch->mobinvis ), channel->name.c_str(  ), argument.c_str(  ) );
      else
         ch->printf( "&[%s]You %s '%s'\r\n", channel->colorname.c_str(  ), channel->name.c_str(  ), argument.c_str(  ) );
   }

   if( ch->in_room->flags.test( ROOM_LOGSPEECH ) )
      append_to_file( LOG_FILE, "%s: %s (%s)", ch->isnpc(  )? ch->short_descr : ch->name, argument.c_str(  ), channel->name.c_str(  ) );

   /*
    * Channel history. Records the last MAX_CHANHISTORY messages to channels which keep historys 
    */
   if( channel->flags.test( CHAN_KEEPHISTORY ) )
      update_channel_history( ch, channel, argument, emote );

   list < char_data * >::iterator ich;
   for( ich = pclist.begin(  ); ich != pclist.end(  ); ++ich )
   {
      char_data *vch = *ich;

      /*
       * Hackish solution to stop that damned "someone chat" bug - Matarael 17.3.2002 
       */
      bool mapped = false;
      int origmap = -1, origx = -1, origy = -1;

      if( vch == ch || !vch->desc )
         continue;

      if( vch->desc->connected == CON_PLAYING && hasname( vch->pcdata->chan_listen, channel->name ) )
      {
         string sbuf = argument;
         char lbuf[MIL + 4];  /* invis level string + buf */

         if( vch->level < channel->level )
            continue;

         if( vch->in_room->flags.test( ROOM_SILENCE ) || vch->in_room->area->flags.test( AFLAG_SILENCE ) )
            continue;

         if( channel->type == CHAN_ROOM )
         {
            if( vch->in_room != ch->in_room )
               continue;

            /*
             * Check to see if a player on a map is at the same coords as the recipient
             */
            if( !is_same_char_map( ch, vch ) )
               continue;
         }

         if( channel->type == CHAN_ZONE && ( vch->in_room->area != ch->in_room->area || vch->in_room->flags.test( ROOM_NOYELL ) ) )
            continue;

         if( channel->type == CHAN_PK && !vch->IS_PKILL(  ) && !vch->is_immortal(  ) )
            continue;

         if( channel->type == CHAN_GUILD )
         {
            if( vch->isnpc(  ) )
               continue;
            if( vch->pcdata->clan != ch->pcdata->clan )
               continue;
         }

         int position = vch->position;
         vch->position = POS_STANDING;

         if( ch->has_pcflag( PCFLAG_WIZINVIS ) && vch->can_see( ch, false ) && vch->is_immortal(  ) )
            snprintf( lbuf, MIL + 4, "&[%s](%d) ", channel->colorname.c_str(  ), ( !ch->isnpc(  ) ) ? ch->pcdata->wizinvis : ch->mobinvis );
         else
            lbuf[0] = '\0';

         if( speaking != -1 && ( !ch->isnpc(  ) || ch->speaking ) )
         {
            int speakswell = UMIN( knows_language( vch, ch->speaking, ch ), knows_language( ch, ch->speaking, vch ) );

            if( speakswell < 85 )
               sbuf = translate( speakswell, argument, lang_names[speaking] );
         }

         /*
          * Check to see if target is ignoring the sender 
          */
         if( is_ignoring( vch, ch ) )
         {
            /*
             * If the sender is an imm then they cannot be ignored 
             */
            if( !ch->is_immortal(  ) || vch->level > ch->level )
            {
               /*
                * Off to oblivion! 
                */
               continue;
            }
         }

         MOBtrigger = false;

         /*
          * Hackish solution to stop that damned "someone chat" bug - Matarael 17.3.2002 
          */
         if( ch->has_pcflag( PCFLAG_ONMAP ) )
         {
            mapped = true;
            origx = ch->mx;
            origy = ch->my;
            origmap = ch->wmap;
         }

         if( ch->isnpc(  ) && ch->has_actflag( ACT_ONMAP ) )
         {
            mapped = true;
            origx = ch->mx;
            origy = ch->my;
            origmap = ch->wmap;
         }
         fix_maps( vch, ch );

         char buf[MSL];
         if( !social && !emote )
         {
            snprintf( buf, MSL, "&[%s]$n %ss '$t&[%s]'", channel->colorname.c_str(  ), channel->name.c_str(  ), channel->colorname.c_str(  ) );
            mudstrlcat( lbuf, buf, MIL + 4 );
            act( AT_PLAIN, lbuf, ch, sbuf.c_str(  ), vch, TO_VICT );
         }

         if( emote )
         {
            snprintf( buf, MSL, "&W[&[%s]%s&W] &[%s]$n $t", channel->colorname.c_str(  ), capitalize( channel->name ).c_str(  ), channel->colorname.c_str(  ) );
            mudstrlcat( lbuf, buf, MIL + 4 );
            act( AT_PLAIN, lbuf, ch, sbuf.c_str(  ), vch, TO_VICT );
         }

         if( social )
         {
            if( vch == victim )
            {
               act_printf( AT_PLAIN, ch, nullptr, vch, TO_VICT, "&W[&[%s]%s&W] &[%s]%s",
                           channel->colorname.c_str(  ), capitalize( channel->name ).c_str(  ), channel->colorname.c_str(  ), socbuf_vict.c_str(  ) );
            }
            else
            {
               act_printf( AT_PLAIN, ch, vch, victim, TO_THIRD, "&W[&[%s]%s&W] &[%s]%s", channel->colorname.c_str(  ),
                           capitalize( channel->name ).c_str(  ), channel->colorname.c_str(  ), socbuf_other.c_str(  ) );
            }
         }

         vch->position = position;
         /*
          * Hackish solution to stop that damned "someone chat" bug - Matarael 17.3.2002 
          */
         if( mapped )
         {
            ch->wmap = origmap;
            ch->mx = origx;
            ch->my = origy;
            if( ch->isnpc(  ) )
               ch->set_actflag( ACT_ONMAP );
            else
               ch->set_pcflag( PCFLAG_ONMAP );
         }
         else
         {
            if( ch->isnpc(  ) )
               ch->unset_actflag( ACT_ONMAP );
            else
               ch->unset_pcflag( PCFLAG_ONMAP );
            ch->wmap = -1;
            ch->mx = -1;
            ch->my = -1;
         }
      }
   }
}