예제 #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
const char *get_hint( int level )
{
   HINT_DATA *hintData;
   static char buf[MAX_STRING_LENGTH];
   int count, which;

   count = 0;
   if( level < 0 )
   {
      snprintf( buf, MAX_STRING_LENGTH, "HintLevel error, Level was %d", level );
      return buf;
   }
   else
   {
      hintData = first_hint;
      for( hintData = first_hint; hintData; hintData = hintData->next )
      {
         if( level >= hintData->low && level <= hintData->high )
            ++count;
      }
      if( count > 1 )
      {
         which = number_range( 1, count );
         count = 0;
         for( hintData = first_hint; hintData; hintData = hintData->next )
         {
            if( level >= hintData->low && level <= hintData->high )
               ++count;
            if( count == which )
            {
               mudstrlcpy( buf, hintData->text, MAX_STRING_LENGTH );
               return buf;
            }
         }
      }
      else if( count == 1 )
      {
         for( hintData = first_hint; hintData; hintData = hintData->next )
         {
            if( level >= hintData->low && level <= hintData->high )
            {
               mudstrlcpy( buf, hintData->text, MAX_STRING_LENGTH );
               return buf;
            }
         }
      }
      else
         return " ";
   }
   return " ";
}
예제 #3
0
파일: player.c 프로젝트: m241dan/swrproject
void do_prompt( CHAR_DATA * ch, const char *argument )
{
   char arg[MAX_INPUT_LENGTH];

   if( IS_NPC( ch ) )
   {
      send_to_char( "NPC's can't change their prompt..\r\n", ch );
      return;
   }
   argument = smash_tilde_static( argument );
   one_argument( argument, arg );
   if( !*arg )
   {
      send_to_char( "Set prompt to what? (try help prompt)\r\n", ch );
      return;
   }
   if( ch->pcdata->prompt )
      STRFREE( ch->pcdata->prompt );

   char prompt[128];
   mudstrlcpy(prompt, argument, 128);

   /*
    * Can add a list of pre-set prompts here if wanted.. perhaps
    * 'prompt 1' brings up a different, pre-set prompt 
    */
   if( !str_cmp( arg, "default" ) )
      ch->pcdata->prompt = STRALLOC( "" );
   else
      ch->pcdata->prompt = STRALLOC( prompt );
   send_to_char( "Ok.\r\n", ch );
   return;
}
예제 #4
0
파일: player.c 프로젝트: Igdra/smaugfuss
void do_title( CHAR_DATA* ch, const char* argument)
{
   if( IS_NPC( ch ) )
      return;

   set_char_color( AT_SCORE, ch );
   if( ch->level < 5 )
   {
      send_to_char( "Sorry... you must be at least level 5 to set your title...\r\n", ch );
      return;
   }
   if( IS_SET( ch->pcdata->flags, PCFLAG_NOTITLE ) )
   {
      set_char_color( AT_IMMORT, ch );
      send_to_char( "The Gods prohibit you from changing your title.\r\n", ch );
      return;
   }

   if( argument[0] == '\0' )
   {
      send_to_char( "Change your title to what?\r\n", ch );
      return;
   }

   char title[50];
   mudstrlcpy(title, argument, 50);

   smash_tilde( title );
   set_title( ch, title );
   send_to_char( "Ok.\r\n", ch );
}
예제 #5
0
/* Ever so slightly modified version of "friendly_ctime" provided by Aurora.
 * Merged with the Timezone snippet by Ryan Jennings (Markanth) [email protected]
 */
char *c_time( time_t curtime, int tz )
{
   static const char *day[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
   static const char *month[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
   static char strtime[128];
   struct tm *ptime;
   char tzonename[50];

   if( curtime <= 0 )
      curtime = current_time;

   if( tz > -1 && tz < MAX_TZONE )
   {
      mudstrlcpy( tzonename, tzone_table[tz].zone, 50 );
#if defined(__CYGWIN__)
      curtime += ( time_t ) timezone;
#elif defined(__FreeBSD__) || defined(__OpenBSD__)
      /*
       * Hopefully this works 
       */
      ptime = localtime( &curtime );
      curtime += ptime->tm_gmtoff;
#else
      curtime += timezone; /* timezone external variable in time.h holds the 
                            * difference in seconds to GMT. */
#endif
      curtime += ( 60 * 60 * tzone_table[tz].gmt_offset );  /* Add the offset hours */
   }
   ptime = localtime( &curtime );
   if( tz < 0 || tz >= MAX_TZONE )
#if defined(__CYGWIN__)
      mudstrlcpy( tzonename, tzname[ptime->tm_isdst], 50 );
#else
      mudstrlcpy( tzonename, ptime->tm_zone, 50 );
#endif

   snprintf( strtime, 128, "%3s %3s %d, %d %d:%02d:%02d %cM %s",
             day[ptime->tm_wday], month[ptime->tm_mon], ptime->tm_mday, ptime->tm_year + 1900,
             ptime->tm_hour == 0 ? 12 : ptime->tm_hour > 12 ? ptime->tm_hour - 12 : ptime->tm_hour,
             ptime->tm_min, ptime->tm_sec, ptime->tm_hour < 12 ? 'A' : 'P', tzonename );
   return strtime;
}
예제 #6
0
파일: player.c 프로젝트: Igdra/smaugfuss
void set_title( CHAR_DATA * ch, const char *title )
{
   char buf[MAX_STRING_LENGTH];

   if( IS_NPC( ch ) )
   {
      bug( "%s: NPC.", __FUNCTION__ );
      return;
   }

   if( isalpha( title[0] ) || isdigit( title[0] ) )
   {
      buf[0] = ' ';
      mudstrlcpy( buf + 1, title, MAX_STRING_LENGTH - 1 );
   }
   else
      mudstrlcpy( buf, title, MAX_STRING_LENGTH );

   STRFREE( ch->pcdata->title );
   ch->pcdata->title = STRALLOC( buf );
}
예제 #7
0
/* Added by Tarl 5 Dec 02 to allow picking names from a file. Used for the namegen
   code in reset.c */
void pick_name( string & argument, const char *filename )
{
   FILE *infile;
   struct timeval starttime;
   char names[200][20];
   char name[200], tempstring[151];
   int counter = 0;
   time_t t;

   tempstring[0] = '\0';

   infile = fopen( filename, "r" );
   if( infile == nullptr )
   {
      log_printf( "Can't find %s", filename );
      return;
   }

   fgets( tempstring, 150, infile );
   tempstring[strlen( tempstring ) - 1] = '\0';
   while( str_cmp( tempstring, "[start]" ) != 0 )
   {
      fgets( tempstring, 100, infile );
      tempstring[strlen( tempstring ) - 1] = '\0'; /* remove linefeed */
   }
   while( str_cmp( tempstring, "[finish]" ) != 0 )
   {
      fgets( tempstring, 100, infile );
      tempstring[strlen( tempstring ) - 1] = '\0';
      if( tempstring[0] != '/' )
         mudstrlcpy( names[counter++], tempstring, 200 );
   }
   FCLOSE( infile );
   gettimeofday( &starttime, nullptr );
   srand( ( unsigned )time( &t ) + starttime.tv_usec );
   --counter;

   mudstrlcpy( name, names[rand(  ) % counter], 200 );
   argument.append( name );
}
예제 #8
0
/* timeZone is not shown as it's a bit .. long.. but it is respected -- Xorith */
char *mini_c_time( time_t curtime, int tz )
{
   static char strtime[128];
   struct tm *ptime;
   char tzonename[50];

   if( curtime <= 0 )
      curtime = current_time;

   if( tz > -1 && tz < MAX_TZONE )
   {
      mudstrlcpy( tzonename, tzone_table[tz].zone, 50 );
#if defined(__CYGWIN__)
      curtime += ( time_t ) timezone;
#elif defined(__FreeBSD__) || defined(__OpenBSD__)
      /*
       * Hopefully this works 
       */
      ptime = localtime( &curtime );
      curtime += ptime->tm_gmtoff;
#else
      curtime += timezone; /* timezone external variable in time.h holds the
                            * difference in seconds to GMT. */
#endif
      curtime += ( 60 * 60 * tzone_table[tz].gmt_offset );  /* Add the offset hours */
   }
   ptime = localtime( &curtime );
   if( tz < 0 || tz >= MAX_TZONE )
#if defined(__CYGWIN__)
      mudstrlcpy( tzonename, tzname[ptime->tm_isdst], 50 );
#else
      mudstrlcpy( tzonename, ptime->tm_zone, 50 );
#endif

   snprintf( strtime, 128, "%02d/%02d/%02d %02d:%02d%c", ptime->tm_mon + 1, ptime->tm_mday, ptime->tm_year - 100,
             ptime->tm_hour == 0 ? 12 : ptime->tm_hour > 12 ? ptime->tm_hour - 12 : ptime->tm_hour, ptime->tm_min,
             ptime->tm_hour < 12 ? 'A' : 'P' );
   return strtime;
}
예제 #9
0
/* Reformat room descriptions to exclude undesirable characters */
void reformat_desc( char *desc )
{
	/*
	 * Index variables to keep track of array/pointer elements 
	 */
	unsigned int i = 0;
	int j = 0;
	char buf[MAX_STRING_LENGTH], *p;

	buf[0] = '\0';

	if ( !desc )
		return;

	/*
	 * Replace all "\n" and "\r" with spaces 
	 */
	for ( i = 0; i <= strlen( desc ); ++i )
	{
		if ( ( desc[i] == '\r' ) || ( desc[i] == '\n' ) )
			desc[i] = ' ';
	}

	/*
	 * Remove multiple spaces 
	 */
	for ( p = desc; *p != '\0'; ++p )
	{
		buf[j] = *p;
		++j;

		/*
		 * Two or more consecutive spaces? 
		 */
		if ( ( *p == ' ' ) && ( *( p + 1 ) == ' ' ) )
		{
			do
			{
				++p;
			}
			while ( *( p + 1 ) == ' ' );
		}
	}

	buf[j] = '\0';

	/*
	 * Copy to desc 
	 */
	mudstrlcpy( desc, buf, MAX_STRING_LENGTH );
}
예제 #10
0
/*Originaly, i heard on gamedev that someone was looking for a way to stop xprintf
 *from overflowing, ofcourse, people fail to think of functions like strlcpy, which
 *is essentaily a safe xprintf, atleast as it has been described to me.  I however
 *chose to write my own system.  This allows me to capture the function, and line
 *of the overflowing string in question.  Thus allowing me to essentaily find out
 *where the mud overflows, and stop it from happening.  Great little tool.
 *All i ask is that you leave this header in place.  -- Darien of Sandstorm:Mages Sanctuary
 */
void safe_printf( const char *file, const char *function, int line, int size, char *str, char *fmt, ... )
{
   char buf[MAS];
   va_list args;
   va_start( args, fmt );
   vsprintf( buf, fmt, args );
   va_end( args );

   /*
    * Max Alloc Size is allot!
    */
   if( size > MAS )
   {
      log_string( LOG_BUG, "xprintf size greater then MAS!!!!\n\r" );
      log_string( LOG_BUG, "Warning: Overflow has been caught by xprintf.\n\r" );
      log_string( LOG_BUG, "Memcheck: xprintf:File %s, Function %s, Line %d.\n\r", file, function, line );
      wiznet_printf( NULL, NULL, WIZ_MEMCHECK, 0, 0, "Memcheck: System memory corrupted by overflow through xprintf: File: %s Function: %s Line: %d", file, function, line  );
      return;
   }

   if( ( unsigned )size < strlen( buf ) + 1 )
   {
      log_string( LOG_BUG, "XPRINTF error: fmt %s.\n\r", fmt );
      log_string( LOG_BUG, "Warning: Overflow has been caught by xprintf.\n\r" );
      log_string( LOG_BUG, "Memcheck: xprintf: File %s, Function %s, Line %d.\n\r", file, function, line );
      wiznet_printf( NULL, NULL, WIZ_MEMCHECK, 0, 0, "Memcheck: System memory corrupted by overflow through xprintf: File: %s Function: %s Line: %d", file, function, line  );
   }
   else
   {
      mudstrlcpy( str, buf, size );

      /*
       * Just double checking.
       */
      if( strlen( str ) > ( unsigned )size - 1 )
      {
         char egbug[MSL];
         log_string( LOG_BUG, "XPRINTF error: fmt %s.\n\r", fmt );
         log_string( LOG_BUG, "Warning: Overflow has been caught by xprintf.\n\r" );
         log_string( LOG_BUG, "Memcheck: Xprintf: File %s, Function %s, Line %d.\n\r", file, function, line );

         /*
          * Yes, this is a potential loop bug if infact the xprintf does collapse in on itself..
          */
         xprintf( egbug, "Memcheck: System memory corrupted by overflow through xprintf: File: %s Function: %s Line: %d",
                  file, function, line );
         wiznet( egbug, NULL, NULL, WIZ_MEMCHECK, 0, 0 );
      }
   }
}
예제 #11
0
void load_modules(  )
{
   DIR *dp;
   struct dirent *dentry;
   char directory_name[100];

   return;  // castrated for now.

   mudstrlcpy( directory_name, "../src/modules/so", 100 );
   dp = opendir( directory_name );
   dentry = readdir( dp );
   while( dentry )
   {
      /*
       * Added by Tarl 3 Dec 02 because we are now using CVS 
       */
      if( !str_cmp( dentry->d_name, "CVS" ) )
      {
         dentry = readdir( dp );
         continue;
      }
      if( dentry->d_name[0] != '.' )
      {
         string filename = dentry->d_name;
         string name;
         string::size_type ps;
         char path[100];

         if( ( ps = filename.find( '.' ) ) == string::npos )
            name = filename;
         else
            name = filename.substr( 0, ps );

         snprintf( path, 100, "%s/%s", directory_name, name.c_str(  ) );
         module[name] = dlopen( path, RTLD_NOW );
         if( !module[name] )
         {
            log_string( dlerror(  ) );
            continue;
         }
      }
      dentry = readdir( dp );
   }
   closedir( dp );

   init_modules(  );
}
예제 #12
0
/* Clear, generate and display the map */
void draw_room_map( CHAR_DATA * ch, const char *desc )
{
	int x, y;
	static char buf[MAX_STRING_LENGTH];

	mudstrlcpy( buf, desc, MAX_STRING_LENGTH );
	/*
	 * Remove undesirable characters 
	 */
	reformat_desc( buf );

	/*
	 * Clear map 
	 */
	for ( y = 0; y <= MAPY; ++y )
	{
		for ( x = 0; x <= MAPX; ++x )
		{
			clear_coord( x, y );
		}
	}

	/*
	 * Start with players pos at centre of map 
	 */
	x = MAPX / 2;
	y = MAPY / 2;

	dmap[x][y].vnum = ch->in_room->vnum;
	dmap[x][y].depth = 0;

	/*
	 * Generate the map 
	 */
	map_exits( ch, ch->in_room, x, y, 0 );

	/*
	 * Current position should be a "X" 
	 */
	dmap[x][y].tegn = '@';
	dmap[x][y].sector = -1;

	/*
	 * Send the map 
	 */
	show_map( ch, buf );
}
예제 #13
0
char *resolve_address( int address )
{
   static char addr_str[256];
   struct hostent *from;
   int addr;

   if( ( from = gethostbyaddr( ( char * )&address, sizeof( address ), AF_INET ) ) != NULL )
   {
      mudstrlcpy( addr_str, strcmp( from->h_name, "localhost" ) ? from->h_name : "local-host", 256 );
   }
   else
   {
      addr = ntohl( address );
      snprintf( addr_str, 256, "%d.%d.%d.%d", ( addr >> 24 ) & 0xFF, ( addr >> 16 ) & 0xFF, ( addr >> 8 ) & 0xFF, ( addr ) & 0xFF );
   }
   return addr_str;
}
예제 #14
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;
}
예제 #15
0
파일: player.c 프로젝트: Igdra/smaugfuss
void do_homepage( CHAR_DATA* ch, const char* argument)
{
   char buf[MAX_STRING_LENGTH];

   if( IS_NPC( ch ) )
      return;

   if( ch->level < 5 )
   {
      send_to_char( "Sorry... you must be at least level 5 to do that.\r\n", ch );
      return;
   }

   if( argument[0] == '\0' )
   {
      if( !ch->pcdata->homepage )
         ch->pcdata->homepage = str_dup( "" );
      ch_printf( ch, "Your homepage is: %s\r\n", show_tilde( ch->pcdata->homepage ) );
      return;
   }

   if( !str_cmp( argument, "clear" ) )
   {
      if( ch->pcdata->homepage )
         DISPOSE( ch->pcdata->homepage );
      ch->pcdata->homepage = str_dup( "" );
      send_to_char( "Homepage cleared.\r\n", ch );
      return;
   }

   if( strstr( argument, "://" ) )
      mudstrlcpy( buf, argument, MAX_STRING_LENGTH );
   else
      snprintf( buf, MAX_STRING_LENGTH, "http://%s", argument );
   if( strlen( buf ) > 70 )
      buf[70] = '\0';

   hide_tilde( buf );
   if( ch->pcdata->homepage )
      DISPOSE( ch->pcdata->homepage );
   ch->pcdata->homepage = str_dup( buf );
   send_to_char( "Homepage set.\r\n", ch );
}
예제 #16
0
void do_prompt( CHAR_DATA * ch, const char *argument )
{
	char arg[MAX_INPUT_LENGTH];

	set_char_color( AT_GREY, ch );

	if ( IS_NPC( ch ) )
	{
		send_to_char( "NPC's can't change their prompt..\r\n", ch );
		return;
	}
	smash_tilde( argument );
	one_argument( argument, arg );
	if ( !*arg || !str_cmp( arg, "display" ) )
	{
		send_to_char( "Your current prompt string:\r\n", ch );
		set_char_color( AT_WHITE, ch );
		ch_printf( ch, "%s\r\n", !str_cmp( ch->pcdata->prompt, "" ) ? "(default prompt)" : ch->pcdata->prompt );
		set_char_color( AT_GREY, ch );
		send_to_char( "Type 'help prompt' for information on changing your prompt.\r\n", ch );
		return;
	}
	send_to_char( "Replacing old prompt of:\r\n", ch );
	set_char_color( AT_WHITE, ch );
	ch_printf( ch, "%s\r\n", !str_cmp( ch->pcdata->prompt, "" ) ? "(default prompt)" : ch->pcdata->prompt );
	if ( ch->pcdata->prompt )
		STRFREE( ch->pcdata->prompt );

	char prompt[128];

	mudstrlcpy( prompt, argument, 128 );

	/*
	 * Can add a list of pre-set prompts here if wanted.. perhaps
	 * 'prompt 1' brings up a different, pre-set prompt 
	 */
	if ( !str_cmp( arg, "default" ) )
		ch->pcdata->prompt = STRALLOC( "" );
	else
		ch->pcdata->prompt = STRALLOC( prompt );
	return;
}
예제 #17
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 );
   }
}
예제 #18
0
void delete_realm( char_data * ch, realm_data * realm )
{
   list < char_data * >::iterator ich;
   char filename[256];
   string realmname = realm->name;

   mudstrlcpy( filename, realm->filename.c_str(  ), 256 );

   for( ich = pclist.begin(  ); ich != pclist.end(  ); ++ich )
   {
      char_data *vch = *ich;

      if( !vch->pcdata->realm )
         continue;

      if( vch->pcdata->realm == realm )
      {
         vch->pcdata->realm_name.clear(  );
         vch->pcdata->realm = nullptr;
         vch->printf( "The realm known as &W%s&D has been destroyed by the gods!\r\n", realm->name.c_str(  ) );
      }
   }

   realmlist.remove( realm );
   deleteptr( realm );

   if( !ch )
   {
      if( !remove( filename ) )
         log_printf( "Realm data for %s destroyed - no members left.", realmname.c_str(  ) );
      return;
   }

   if( !remove( filename ) )
   {
      ch->printf( "&RRealm data for %s has been destroyed.\r\n", realmname.c_str(  ) );
      log_printf( "Realm data for %s has been destroyed by %s.", realmname.c_str(  ), ch->name );
   }
}
예제 #19
0
void do_chess( CHAR_DATA * ch, const char *argument )
{
	char arg[MAX_INPUT_LENGTH];

	argument = one_argument( argument, arg );

	if ( IS_NPC( ch ) )
	{
		send_to_char( "NPC's can't be in chess games.\r\n", ch );
		return;
	}

	if ( !str_cmp( arg, "begin" ) )
	{
		GAME_BOARD_DATA *board;

		if ( ch->pcdata->game_board )
		{
			send_to_char( "You are already in a chess match.\r\n", ch );
			return;
		}

		CREATE( board, GAME_BOARD_DATA, 1 );
		init_board( board );
		ch->pcdata->game_board = board;
		ch->pcdata->game_board->player1 = QUICKLINK( ch->name );
		send_to_char( "You have started a game of chess.\r\n", ch );
		return;
	}

	if ( !str_cmp( arg, "join" ) )
	{
		GAME_BOARD_DATA *board = NULL;
		CHAR_DATA *vch;
		char arg2[MAX_INPUT_LENGTH];

		if ( ch->pcdata->game_board )
		{
			send_to_char( "You are already in a game of chess.\r\n", ch );
			return;
		}

		argument = one_argument( argument, arg2 );
		if ( arg2[0] == '\0' )
		{
			send_to_char( "Join whom in a chess match?\r\n", ch );
			return;
		}

#ifdef IMC
		if ( strstr( arg2, "@" ) )
		{
			if ( !str_cmp( imc_mudof( arg2 ), this_imcmud->localname ) )
			{
				send_to_char( "You cannot join IMC chess on the local mud!\r\n", ch );
				return;
			}

			if ( !str_cmp( imc_mudof( arg2 ), "*" ) )
			{
				send_to_char( "* is not a valid mud name.\r\n", ch );
				return;
			}

			if ( !str_cmp( imc_nameof( arg2 ), "*" ) )
			{
				send_to_char( "* is not a valid player name.\r\n", ch );
				return;
			}

			send_to_char( "Attempting to initiate IMC chess game...\r\n", ch );

			CREATE( board, GAME_BOARD_DATA, 1 );
			init_board( board );
			board->type = TYPE_IMC;
			board->player1 = QUICKLINK( ch->name );
			board->player2 = STRALLOC( arg2 );
			board->turn = -1;
			ch->pcdata->game_board = board;
			imc_send_chess( ch->name, arg2, "start" );
			return;
		}
#endif

		if ( !( vch = get_char_world( ch, arg2 ) ) )
		{
			send_to_char( "Cannot find that player.\r\n", ch );
			return;
		}

		if ( IS_NPC( vch ) )
		{
			send_to_char( "That player is an NPC, and cannot play games.\r\n", ch );
			return;
		}

		board = vch->pcdata->game_board;
		if ( !board )
		{
			send_to_char( "That player is not playing a game.\r\n", ch );
			return;
		}

		if ( board->player2 )
		{
			send_to_char( "That game already has two players.\r\n", ch );
			return;
		}

		board->player2 = QUICKLINK( ch->name );
		ch->pcdata->game_board = board;
		send_to_char( "You have joined a game of chess.\r\n", ch );

		vch = get_char_world( ch, board->player1 );
		ch_printf( vch, "%s has joined your game.\r\n", ch->name );
		return;
	}

	if ( !ch->pcdata->game_board )
	{
		send_to_char( "Usage: chess <begin|cease|status|board|move|join>\r\n", ch );
		return;
	}

	if ( !str_cmp( arg, "cease" ) )
	{
		free_game( ch->pcdata->game_board );
		return;
	}

	if ( !str_cmp( arg, "status" ) )
	{
		GAME_BOARD_DATA *board = ch->pcdata->game_board;

		if ( !board->player1 )
			send_to_char( "There is no black player.\r\n", ch );
		else if ( !str_cmp( board->player1, ch->name ) )
			send_to_char( "You are black.\r\n", ch );
		else
			ch_printf( ch, "%s is black.\r\n", board->player1 );

		if ( king_in_checkmate( board, BLACK_KING ) )
			send_to_char( "The black king is in checkmate!\r\n", ch );
		else if ( king_in_check( board, BLACK_KING ) )
			send_to_char( "The black king is in check.\r\n", ch );

		if ( !board->player2 )
			send_to_char( "There is no white player.\r\n", ch );
		else if ( !str_cmp( board->player2, ch->name ) )
			send_to_char( "You are white.\r\n", ch );
		else
			ch_printf( ch, "%s is white.\r\n", board->player2 );

		if ( king_in_checkmate( board, WHITE_KING ) )
			send_to_char( "The white king is in checkmate!\r\n", ch );
		else if ( king_in_check( board, WHITE_KING ) )
			send_to_char( "The white king is in check.\r\n", ch );

		if ( !board->player2 || !board->player1 )
			return;

		ch_printf( ch, "%d turns.\r\n", board->turn );
		if ( board->turn % 2 == 1 && !str_cmp( board->player1, ch->name ) )
		{
			ch_printf( ch, "It is %s's turn.\r\n", board->player2 );
			return;
		}
		else if ( board->turn % 2 == 0 && !str_cmp( board->player2, ch->name ) )
		{
			ch_printf( ch, "It is %s's turn.\r\n", board->player1 );
			return;
		}
		else
		{
			send_to_char( "It is your turn.\r\n", ch );
			return;
		}
		return;
	}

	if ( !str_prefix( arg, "board" ) )
	{
		send_to_char( print_big_board( ch, ch->pcdata->game_board ), ch );
		return;
	}

	if ( !str_prefix( arg, "move" ) )
	{
		CHAR_DATA *opp;
		char opp_name[MAX_INPUT_LENGTH];
		char a, b;
		int x, y, dx, dy, ret;

		if ( !ch->pcdata->game_board->player1 || !ch->pcdata->game_board->player2 )
		{
			send_to_char( "There is only 1 player.\r\n", ch );
			return;
		}

		if ( ch->pcdata->game_board->turn < 0 )
		{
			send_to_char( "The game hasn't started yet.\r\n", ch );
			return;
		}

		if ( king_in_checkmate( ch->pcdata->game_board, BLACK_KING ) )
		{
			send_to_char( "The black king has been checkmated, the game is over.\r\n", ch );
			return;
		}

		if ( king_in_checkmate( ch->pcdata->game_board, WHITE_KING ) )
		{
			send_to_char( "The white king has been checkmated, the game is over.\r\n", ch );
			return;
		}

		if ( !*argument )
		{
			send_to_char( "Usage: chess move [piece to move] [where to move]\r\n", ch );
			return;
		}

		if ( ch->pcdata->game_board->turn % 2 == 1 && !str_cmp( ch->pcdata->game_board->player1, ch->name ) )
		{
			send_to_char( "It is not your turn.\r\n", ch );
			return;
		}

		if ( ch->pcdata->game_board->turn % 2 == 0 && !str_cmp( ch->pcdata->game_board->player2, ch->name ) )
		{
			send_to_char( "It is not your turn.\r\n", ch );
			return;
		}

		if ( sscanf( argument, "%c%d %c%d", &a, &y, &b, &dy ) != 4 )
		{
			send_to_char( "Usage: chess move [dest] [source]\r\n", ch );
			return;
		}

		if ( a < 'a' || a > 'h' || b < 'a' || b > 'h' || y < 1 || y > 8 || dy < 1 || dy > 8 )
		{
			send_to_char( "Invalid move, use a-h, 1-8.\r\n", ch );
			return;
		}

		x = a - 'a';
		dx = b - 'a';
		--y;
		--dy;

		ret = is_valid_move( ch, ch->pcdata->game_board, x, y, dx, dy );
		if ( ret == MOVE_OK || ret == MOVE_TAKEN )
		{
			GAME_BOARD_DATA *board;
			int piece, destpiece;

			board = ch->pcdata->game_board;
			piece = board->board[x][y];
			destpiece = board->board[dx][dy];
			board->board[dx][dy] = piece;
			board->board[x][y] = NO_PIECE;

			if ( king_in_check( board, IS_WHITE( board->board[dx][dy] ) ? WHITE_KING : BLACK_KING ) && ( board->board[dx][dy] != WHITE_KING && board->board[dx][dy] != BLACK_KING ) )
			{
				board->board[dx][dy] = destpiece;
				board->board[x][y] = piece;
				ret = MOVE_INCHECK;
			}
			else
			{
				++board->turn;
#ifdef IMC
				if ( ch->pcdata->game_board->type == TYPE_IMC )
				{
					snprintf( arg, LGST, "move %d%d %d%d", x, y, dx, dy );
					imc_send_chess( ch->pcdata->game_board->player1, ch->pcdata->game_board->player2, arg );
				}
#endif
			}
		}

		if ( !str_cmp( ch->name, ch->pcdata->game_board->player1 ) )
		{
			opp = get_char_world( ch, ch->pcdata->game_board->player2 );
			if ( !opp )
				mudstrlcpy( opp_name, ch->pcdata->game_board->player2, MAX_INPUT_LENGTH );
		}
		else
		{
			opp = get_char_world( ch, ch->pcdata->game_board->player1 );
			if ( !opp )
				mudstrlcpy( opp_name, ch->pcdata->game_board->player1, MAX_INPUT_LENGTH );
		}

#ifdef IMC
#    define SEND_TO_OPP(arg,opp) \
      if( opp ) \
      { \
         if( ch->pcdata->game_board->type == TYPE_LOCAL ) \
            ch_printf( (opp), "%s\r\n", (arg) ); \
      } \
      else \
      { \
         if( ch->pcdata->game_board->type == TYPE_IMC ) \
            imc_send_tell( ch->name, opp_name, (arg), 1 ); \
      }
#else
#    define SEND_TO_OPP(arg,opp) \
      if( opp ) \
      { \
         if( ch->pcdata->game_board->type == TYPE_LOCAL ) \
            ch_printf( (opp), "%s\r\n", (arg) ); \
      }
#endif

		switch ( ret )
		{
			case MOVE_OK:
				send_to_char( "Ok.\r\n", ch );
				snprintf( arg, MAX_INPUT_LENGTH, "%s has moved.\r\n", ch->name );
				SEND_TO_OPP( arg, opp );
				break;

			case MOVE_INVALID:
				send_to_char( "Invalid move.\r\n", ch );
				break;

			case MOVE_BLOCKED:
				send_to_char( "You are blocked in that direction.\r\n", ch );
				break;

			case MOVE_TAKEN:
				send_to_char( "You take the enemy's piece.\r\n", ch );
				snprintf( arg, MAX_INPUT_LENGTH, "%s has taken one of your pieces!", ch->name );
				SEND_TO_OPP( arg, opp );
				break;

			case MOVE_CHECKMATE:
				send_to_char( "That move would result in a checkmate.\r\n", ch );
				snprintf( arg, MAX_INPUT_LENGTH, "%s has attempted a move that would result in checkmate.", ch->name );
				SEND_TO_OPP( arg, opp );
				break;

			case MOVE_OFFBOARD:
				send_to_char( "That move would be off the board.\r\n", ch );
				break;

			case MOVE_SAMECOLOR:
				send_to_char( "Your own piece blocks the way.\r\n", ch );
				break;

			case MOVE_CHECK:
				send_to_char( "That move would result in a check.\r\n", ch );
				snprintf( arg, MAX_INPUT_LENGTH, "%s has made a move that would result in a check.", ch->name );
				SEND_TO_OPP( arg, opp );
				break;

			case MOVE_WRONGCOLOR:
				send_to_char( "That is not your piece.\r\n", ch );
				break;

			case MOVE_INCHECK:
				send_to_char( "You are in check, you must save your king.\r\n", ch );
				break;

			default:
				bug( "%s: Unknown return value", __FUNCTION__ );
				break;
		}
#undef SEND_TO_OPP
		return;
	}
	send_to_char( "Usage: chess <begin|cease|status|board|move|join>\r\n", ch );
}
예제 #20
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;
}
예제 #21
0
void found_prey( CHAR_DATA * ch, CHAR_DATA * victim )
{
    char buf[MAX_STRING_LENGTH];
    char victname[MAX_STRING_LENGTH];

    if( victim == NULL )
    {
        bug( "%s", "Found_prey: null victim" );
        return;
    }

    if( victim->in_room == NULL )
    {
        bug( "%s", "Found_prey: null victim->in_room" );
        return;
    }

    mudstrlcpy( victname, IS_NPC( victim ) ? victim->short_descr : victim->name, MAX_STRING_LENGTH );

    if( !can_see( ch, victim ) )
    {
        if( number_percent(  ) < 90 )
            return;
        switch ( number_bits( 2 ) )
        {
        case 0:
            snprintf( buf, MAX_STRING_LENGTH, "Don't make me find you, %s!", victname );
            do_say( ch, buf );
            break;
        case 1:
            act( AT_ACTION, "$n sniffs around the room for $N.", ch, NULL, victim, TO_NOTVICT );
            act( AT_ACTION, "You sniff around the room for $N.", ch, NULL, victim, TO_CHAR );
            act( AT_ACTION, "$n sniffs around the room for you.", ch, NULL, victim, TO_VICT );
            do_say( ch, "I can smell your blood!" );
            break;
        case 2:
            snprintf( buf, MAX_STRING_LENGTH, "I'm going to tear %s apart!", victname );
            do_yell( ch, buf );
            break;
        case 3:
            do_say( ch, "Just wait until I find you..." );
            break;
        }
        return;
    }

    if( xIS_SET( ch->in_room->room_flags, ROOM_SAFE ) )
    {
        if( number_percent(  ) < 90 )
            return;
        switch ( number_bits( 2 ) )
        {
        case 0:
            do_say( ch, "C'mon out, you coward!" );
            snprintf( buf, MAX_STRING_LENGTH, "%s is a bloody coward!", victname );
            do_yell( ch, buf );
            break;
        case 1:
            snprintf( buf, MAX_STRING_LENGTH, "Let's take this outside, %s", victname );
            do_say( ch, buf );
            break;
        case 2:
            snprintf( buf, MAX_STRING_LENGTH, "%s is a yellow-bellied wimp!", victname );
            do_yell( ch, buf );
            break;
        case 3:
            act( AT_ACTION, "$n takes a few swipes at $N.", ch, NULL, victim, TO_NOTVICT );
            act( AT_ACTION, "You try to take a few swipes $N.", ch, NULL, victim, TO_CHAR );
            act( AT_ACTION, "$n takes a few swipes at you.", ch, NULL, victim, TO_VICT );
            break;
        }
        return;
    }

    switch ( number_bits( 2 ) )
    {
    case 0:
        snprintf( buf, MAX_STRING_LENGTH, "Your blood is mine, %s!", victname );
        do_yell( ch, buf );
        break;
    case 1:
        snprintf( buf, MAX_STRING_LENGTH, "Alas, we meet again, %s!", victname );
        do_say( ch, buf );
        break;
    case 2:
        snprintf( buf, MAX_STRING_LENGTH, "What do you want on your tombstone, %s?", victname );
        do_say( ch, buf );
        break;
    case 3:
        act( AT_ACTION, "$n lunges at $N from out of nowhere!", ch, NULL, victim, TO_NOTVICT );
        act( AT_ACTION, "You lunge at $N catching $M off guard!", ch, NULL, victim, TO_CHAR );
        act( AT_ACTION, "$n lunges at you from out of nowhere!", ch, NULL, victim, TO_VICT );
    }
    stop_hunting( ch );
    set_fighting( ch, victim );
    multi_hit( ch, victim, TYPE_UNDEFINED );
    return;
}
예제 #22
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 );
}
예제 #23
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;
}
예제 #24
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;
}
예제 #25
0
void do_mposet( 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];
	OBJ_DATA *obj;
	char outbuf[MAX_STRING_LENGTH];
	int value, tmp;

	/*
	 * 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( "MpOset: no args", ch );
		return;
	}

	if ( ( obj = get_obj_here( ch, arg1 ) ) == NULL )
	{
		progbug( "MpOset: no object", ch );
		return;
	}

	if ( IS_OBJ_STAT( obj, ITEM_PROTOTYPE ) )
	{
		progbug( "MpOset: can't set prototype items", ch );
		return;
	}
	separate_obj( obj );
	value = atoi( arg3 );

	if ( !str_cmp( arg2, "value0" ) || !str_cmp( arg2, "v0" ) )
	{
		obj->value[0] = value;
		return;
	}

	if ( !str_cmp( arg2, "value1" ) || !str_cmp( arg2, "v1" ) )
	{
		obj->value[1] = value;
		return;
	}

	if ( !str_cmp( arg2, "value2" ) || !str_cmp( arg2, "v2" ) )
	{
		obj->value[2] = value;
		return;
	}

	if ( !str_cmp( arg2, "value3" ) || !str_cmp( arg2, "v3" ) )
	{
		obj->value[3] = value;
		return;
	}

	if ( !str_cmp( arg2, "value4" ) || !str_cmp( arg2, "v4" ) )
	{
		obj->value[4] = value;
		return;
	}

	if ( !str_cmp( arg2, "value5" ) || !str_cmp( arg2, "v5" ) )
	{
		obj->value[5] = value;
		return;
	}

	if ( !str_cmp( arg2, "type" ) )
	{
		if ( !argument || argument[0] == '\0' )
		{
			progbug( "MpOset: no type", ch );
			return;
		}
		value = get_otype( argument );
		if ( value < 1 )
		{
			progbug( "MpOset: Invalid type", ch );
			return;
		}
		obj->item_type = ( short ) value;
		return;
	}

	if ( !str_cmp( arg2, "flags" ) )
	{
		if ( !argument || argument[0] == '\0' )
		{
			progbug( "MpOset: no flags", ch );
			return;
		}
		while ( argument[0] != '\0' )
		{
			argument = one_argument( argument, arg3 );
			value = get_oflag( arg3 );
			if ( value < 0 || value >= MAX_BITS )
				progbug( "MpOset: Invalid flag", ch );
			else
			{
				if ( value == ITEM_PROTOTYPE )
					progbug( "MpOset: can't set prototype flag", ch );
				else
					xTOGGLE_BIT( obj->extra_flags, value );
			}
		}
		return;
	}

	if ( !str_cmp( arg2, "wear" ) )
	{
		if ( !argument || argument[0] == '\0' )
		{
			progbug( "MpOset: no wear", ch );
			return;
		}
		while ( argument[0] != '\0' )
		{
			argument = one_argument( argument, arg3 );
			value = get_wflag( arg3 );
			if ( value < 0 || value > 31 )
				progbug( "MpOset: Invalid wear", ch );
			else
				TOGGLE_BIT( obj->wear_flags, 1 << value );
		}
		return;
	}

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

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

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

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

	if ( !str_cmp( arg2, "name" ) )
	{
		STRFREE( obj->name );
		obj->name = STRALLOC( arg3 );
		return;
	}

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

		if ( obj == supermob_obj )
		{
			STRFREE( supermob->short_descr );
			supermob->short_descr = QUICKLINK( obj->short_descr );
		}

		/*
		 * Feature added by Narn, Apr/96 
		 * * If the item is not proto, add the word 'rename' to the keywords
		 * * if it is not already there.
		 */
		if ( str_infix( "mprename", obj->name ) )
		{
			snprintf( buf, MAX_STRING_LENGTH, "%s %s", obj->name, "mprename" );
			STRFREE( obj->name );
			obj->name = STRALLOC( buf );
		}
		return;
	}

	if ( !str_cmp( arg2, "long" ) )
	{
		STRFREE( obj->description );
		mudstrlcpy( buf, arg3, MAX_STRING_LENGTH );
		obj->description = STRALLOC( buf );
		return;
	}

	if ( !str_cmp( arg2, "actiondesc" ) )
	{
		if ( strstr( arg3, "%n" ) || strstr( arg3, "%d" ) || strstr( arg3, "%l" ) )
		{
			progbug( "MpOset: Illegal actiondesc", ch );
			return;
		}
		STRFREE( obj->action_desc );
		obj->action_desc = STRALLOC( arg3 );
		return;
	}

	if ( !str_cmp( arg2, "affect" ) )
	{
		AFFECT_DATA *paf;
		short loc;
		int bitv;

		argument = one_argument( argument, arg2 );
		if ( arg2[0] == '\0' || !argument || argument[0] == 0 )
		{
			progbug( "MpOset: Bad affect syntax", ch );
			send_to_char( "Usage: oset <object> affect <field> <value>\r\n", ch );
			return;
		}
		loc = get_atype( arg2 );
		if ( loc < 1 )
		{
			progbug( "MpOset: Invalid affect field", ch );
			return;
		}
		if ( loc >= APPLY_AFFECT && loc < APPLY_WEAPONSPELL )
		{
			bitv = 0;
			while ( argument[0] != '\0' )
			{
				argument = one_argument( argument, arg3 );
				if ( loc == APPLY_AFFECT )
					value = get_aflag( arg3 );
				else
					value = get_risflag( arg3 );
				if ( value < 0 || value > 31 )
					progbug( "MpOset: bad affect flag", ch );
				else
					SET_BIT( bitv, 1 << value );
			}
			if ( !bitv )
				return;
			value = bitv;
		}
		else
		{
			argument = one_argument( argument, arg3 );
			value = atoi( arg3 );
		}
		CREATE( paf, AFFECT_DATA, 1 );
		paf->type = -1;
		paf->duration = -1;
		paf->location = loc;
		paf->modifier = value;
		xCLEAR_BITS( paf->bitvector );
		paf->next = NULL;
		LINK( paf, obj->first_affect, obj->last_affect, next, prev );
		++top_affect;
		return;
	}

	if ( !str_cmp( arg2, "rmaffect" ) )
	{
		AFFECT_DATA *paf;
		short loc, count;

		if ( !argument || argument[0] == '\0' )
		{
			progbug( "MpOset: no rmaffect", ch );
			return;
		}
		loc = atoi( argument );
		if ( loc < 1 )
		{
			progbug( "MpOset: Invalid rmaffect", ch );
			return;
		}

		count = 0;

		for ( paf = obj->first_affect; paf; paf = paf->next )
		{
			if ( ++count == loc )
			{
				UNLINK( paf, obj->first_affect, obj->last_affect, next, prev );
				DISPOSE( paf );
				send_to_char( "Removed.\r\n", ch );
				--top_affect;
				return;
			}
		}
		progbug( "MpOset: rmaffect not found", ch );
		return;
	}

	/*
	 * save some finger-leather
	 */
	if ( !str_cmp( arg2, "ris" ) )
	{
		snprintf( outbuf, MAX_STRING_LENGTH, "%s affect resistant %s", arg1, arg3 );
		do_mposet( ch, outbuf );
		snprintf( outbuf, MAX_STRING_LENGTH, "%s affect immune %s", arg1, arg3 );
		do_mposet( ch, outbuf );
		snprintf( outbuf, MAX_STRING_LENGTH, "%s affect susceptible %s", arg1, arg3 );
		do_mposet( ch, outbuf );
		return;
	}

	if ( !str_cmp( arg2, "r" ) )
	{
		snprintf( outbuf, MAX_STRING_LENGTH, "%s affect resistant %s", arg1, arg3 );
		do_mposet( ch, outbuf );
		return;
	}

	if ( !str_cmp( arg2, "i" ) )
	{
		snprintf( outbuf, MAX_STRING_LENGTH, "%s affect immune %s", arg1, arg3 );
		do_mposet( ch, outbuf );
		return;
	}
	if ( !str_cmp( arg2, "s" ) )
	{
		snprintf( outbuf, MAX_STRING_LENGTH, "%s affect susceptible %s", arg1, arg3 );
		do_mposet( ch, outbuf );
		return;
	}

	if ( !str_cmp( arg2, "ri" ) )
	{
		snprintf( outbuf, MAX_STRING_LENGTH, "%s affect resistant %s", arg1, arg3 );
		do_mposet( ch, outbuf );
		snprintf( outbuf, MAX_STRING_LENGTH, "%s affect immune %s", arg1, arg3 );
		do_mposet( ch, outbuf );
		return;
	}

	if ( !str_cmp( arg2, "rs" ) )
	{
		snprintf( outbuf, MAX_STRING_LENGTH, "%s affect resistant %s", arg1, arg3 );
		do_mposet( ch, outbuf );
		snprintf( outbuf, MAX_STRING_LENGTH, "%s affect susceptible %s", arg1, arg3 );
		do_mposet( ch, outbuf );
		return;
	}

	if ( !str_cmp( arg2, "is" ) )
	{
		snprintf( outbuf, MAX_STRING_LENGTH, "%s affect immune %s", arg1, arg3 );
		do_mposet( ch, outbuf );
		snprintf( outbuf, MAX_STRING_LENGTH, "%s affect susceptible %s", arg1, arg3 );
		do_mposet( ch, outbuf );
		return;
	}

	/*
	 * Make it easier to set special object values by name than number
	 *                  -Thoric
	 */
	tmp = -1;
	switch ( obj->item_type )
	{
		case ITEM_WEAPON:
			if ( !str_cmp( arg2, "weapontype" ) )
			{
				unsigned int x;

				value = -1;
				for ( x = 0; x < sizeof( attack_table ) / sizeof( attack_table[0] ); x++ )
					if ( !str_cmp( arg3, attack_table[x] ) )
						value = x;
				if ( value < 0 )
				{
					progbug( "MpOset: Invalid weapon type", ch );
					return;
				}
				tmp = 3;
				break;
			}
			if ( !str_cmp( arg2, "condition" ) )
				tmp = 0;
			break;
		case ITEM_ARMOR:
			if ( !str_cmp( arg2, "condition" ) )
				tmp = 3;
			if ( !str_cmp( arg2, "ac" ) )
				tmp = 1;
			break;
		case ITEM_SALVE:
			if ( !str_cmp( arg2, "slevel" ) )
				tmp = 0;
			if ( !str_cmp( arg2, "maxdoses" ) )
				tmp = 1;
			if ( !str_cmp( arg2, "doses" ) )
				tmp = 2;
			if ( !str_cmp( arg2, "delay" ) )
				tmp = 3;
			if ( !str_cmp( arg2, "spell1" ) )
				tmp = 4;
			if ( !str_cmp( arg2, "spell2" ) )
				tmp = 5;
			if ( tmp >= 4 && tmp <= 5 )
				value = skill_lookup( arg3 );
			break;
		case ITEM_SCROLL:
		case ITEM_POTION:
		case ITEM_PILL:
			if ( !str_cmp( arg2, "slevel" ) )
				tmp = 0;
			if ( !str_cmp( arg2, "spell1" ) )
				tmp = 1;
			if ( !str_cmp( arg2, "spell2" ) )
				tmp = 2;
			if ( !str_cmp( arg2, "spell3" ) )
				tmp = 3;
			if ( tmp >= 1 && tmp <= 3 )
				value = skill_lookup( arg3 );
			break;
		case ITEM_STAFF:
		case ITEM_WAND:
			if ( !str_cmp( arg2, "slevel" ) )
				tmp = 0;
			if ( !str_cmp( arg2, "spell" ) )
			{
				tmp = 3;
				value = skill_lookup( arg3 );
			}
			if ( !str_cmp( arg2, "maxcharges" ) )
				tmp = 1;
			if ( !str_cmp( arg2, "charges" ) )
				tmp = 2;
			break;
		case ITEM_CONTAINER:
			if ( !str_cmp( arg2, "capacity" ) )
				tmp = 0;
			if ( !str_cmp( arg2, "cflags" ) )
				tmp = 1;
			if ( !str_cmp( arg2, "key" ) )
				tmp = 2;
			break;
		case ITEM_SWITCH:
		case ITEM_LEVER:
		case ITEM_PULLCHAIN:
		case ITEM_BUTTON:
			if ( !str_cmp( arg2, "tflags" ) )
			{
				tmp = 0;
				value = get_trigflag( arg3 );
			}
			break;
	}
	if ( tmp >= 0 && tmp <= 3 )
	{
		obj->value[tmp] = value;
		return;
	}

	progbug( "MpOset: Invalid field", ch );
	return;
}
예제 #26
0
파일: interp.c 프로젝트: m241dan/W4M-Repo
/*
 * The main entry point for executing commands.
 * Can be recursively called from 'at', 'order', 'force'.
 */
void interpret( CHAR_DATA * ch, char *argument )
{
   char command[MAX_INPUT_LENGTH];
   char logline[MAX_INPUT_LENGTH];
   char logname[MAX_INPUT_LENGTH];
   char log_buf[MAX_STRING_LENGTH];
   char *origarg = argument;
   char *buf;
   TIMER *timer = NULL;
   CMDTYPE *cmd = NULL;
   int trust;
   int loglvl;
   bool found;
   struct timeval time_used;
   long tmptime;

   if( !ch )
   {
      bug( "%s: null ch!", __FUNCTION__ );
      return;
   }

   if( !ch->in_room )
   {
      bug( "%s: null in_room!", __FUNCTION__ );
      return;
   }

   found = FALSE;
   if( ch->substate == SUB_REPEATCMD )
   {
      DO_FUN *fun;

      if( ( fun = ch->last_cmd ) == NULL )
      {
         ch->substate = SUB_NONE;
         bug( "%s: SUB_REPEATCMD with NULL last_cmd", __FUNCTION__ );
         return;
      }
      else
      {
         int x;

         /*
          * yes... we lose out on the hashing speediness here...
          * but the only REPEATCMDS are wizcommands (currently)
          */
         for( x = 0; x < 126; x++ )
         {
            for( cmd = command_hash[x]; cmd; cmd = cmd->next )
               if( cmd->do_fun == fun )
               {
                  found = TRUE;
                  break;
               }
            if( found )
               break;
         }
         if( !found )
         {
            cmd = NULL;
            bug( "%s: SUB_REPEATCMD: last_cmd invalid", __FUNCTION__ );
            return;
         }
         snprintf( logline, MAX_INPUT_LENGTH, "(%s) %s", cmd->name, argument );
      }
   }

   if( !cmd )
   {
      /*
       * Changed the order of these ifchecks to prevent crashing. 
       */
      if( !argument || !strcmp( argument, "" ) )
      {
         bug( "%s: null argument!", __FUNCTION__ );
         return;
      }

      /*
       * Strip leading spaces.
       */
      while( isspace( *argument ) )
         argument++;
      if( argument[0] == '\0' )
         return;

      /*
       * xREMOVE_BIT( ch->affected_by, AFF_HIDE ); 
       */

      /*
       * Implement freeze command.
       */
      if( !IS_NPC( ch ) && xIS_SET( ch->act, PLR_FREEZE ) )
      {
         send_to_char( "You're totally frozen!\r\n", ch );
         return;
      }

      /*
       * Grab the command word.
       * Special parsing so ' can be a command,
       *   also no spaces needed after punctuation.
       */
      mudstrlcpy( logline, argument, MAX_INPUT_LENGTH );
      if( !isalpha( argument[0] ) && !isdigit( argument[0] ) )
      {
         command[0] = argument[0];
         command[1] = '\0';
         argument++;
         while( isspace( *argument ) )
            argument++;
      }
      else
         argument = one_argument( argument, command );

      /*
       * Look for command in command table.
       * Check for council powers and/or bestowments
       */
      trust = get_trust( ch );
      for( cmd = command_hash[LOWER( command[0] ) % 126]; cmd; cmd = cmd->next )
         if( !str_prefix( command, cmd->name )
             && ( cmd->level <= trust
                  || ( !IS_NPC( ch ) && ch->pcdata->council
                       && is_name( cmd->name, ch->pcdata->council->powers )
                       && cmd->level <= ( trust + MAX_CPD ) )
                  || ( !IS_NPC( ch ) && ch->pcdata->bestowments && ch->pcdata->bestowments[0] != '\0'
                       && is_name( cmd->name, ch->pcdata->bestowments ) && cmd->level <= ( trust + sysdata.bestow_dif ) ) ) )
         {
            found = TRUE;
            break;
         }

      /*
       * Turn off afk bit when any command performed.
       */
      if( !IS_NPC( ch ) && xIS_SET( ch->act, PLR_AFK ) && ( str_cmp( command, "AFK" ) ) )
      {
         xREMOVE_BIT( ch->act, PLR_AFK );
         act( AT_GREY, "$n is no longer afk.", ch, NULL, NULL, TO_CANSEE );
      }
   }

   /*
    * Log and snoop.
    */
   snprintf( lastplayercmd, ( MAX_INPUT_LENGTH * 2 ), "%s used %s", ch->name, logline );

   if( found && cmd->log == LOG_NEVER )
      mudstrlcpy( logline, "XXXXXXXX XXXXXXXX XXXXXXXX", MAX_INPUT_LENGTH );

   loglvl = found ? cmd->log : LOG_NORMAL;

   /*
    * Write input line to watch files if applicable
    */
   if( !IS_NPC( ch ) && ch->desc && valid_watch( logline ) )
   {
      if( found && IS_SET( cmd->flags, CMD_WATCH ) )
         write_watch_files( ch, cmd, logline );
      else if( IS_SET( ch->pcdata->flags, PCFLAG_WATCH ) )
         write_watch_files( ch, NULL, logline );
   }

   if( ( !IS_NPC( ch ) && xIS_SET( ch->act, PLR_LOG ) )
       || fLogAll || loglvl == LOG_BUILD || loglvl == LOG_HIGH || loglvl == LOG_ALWAYS )
   {
      /*
       * Added by Narn to show who is switched into a mob that executes
       * a logged command.  Check for descriptor in case force is used. 
       */
      if( ch->desc && ch->desc->original )
         snprintf( log_buf, MAX_STRING_LENGTH, "Log %s (%s): %s", ch->name, ch->desc->original->name, logline );
      else
         snprintf( log_buf, MAX_STRING_LENGTH, "Log %s: %s", ch->name, logline );

      /*
       * Make it so a 'log all' will send most output to the log
       * file only, and not spam the log channel to death   -Thoric
       */
      if( fLogAll && loglvl == LOG_NORMAL && ( IS_NPC( ch ) || !xIS_SET( ch->act, PLR_LOG ) ) )
         loglvl = LOG_ALL;

      log_string_plus( log_buf, loglvl, get_trust( ch ) );
   }

   if( ch->desc && ch->desc->snoop_by )
   {
      snprintf( logname, MAX_INPUT_LENGTH, "%s", ch->name );
      write_to_buffer( ch->desc->snoop_by, logname, 0 );
      write_to_buffer( ch->desc->snoop_by, "% ", 2 );
      write_to_buffer( ch->desc->snoop_by, logline, 0 );
      write_to_buffer( ch->desc->snoop_by, "\r\n", 2 );
   }

   /*
    * check for a timer delayed command (search, dig, detrap, etc) 
    */
   if( ( timer = get_timerptr( ch, TIMER_DO_FUN ) ) != NULL )
   {
      int tempsub;

      tempsub = ch->substate;
      ch->substate = SUB_TIMER_DO_ABORT;
      ( timer->do_fun ) ( ch, "" );
      if( char_died( ch ) )
         return;
      if( ch->substate != SUB_TIMER_CANT_ABORT )
      {
         ch->substate = tempsub;
         extract_timer( ch, timer );
      }
      else
      {
         ch->substate = tempsub;
         return;
      }
   }

   /*
    * Look for command in skill and socials table.
    */
   if( !found )
   {
      if( !check_skill( ch, command, argument ) && !check_ability( ch, command, argument )   // Racial Abilities Support - Kayle 7-8-07
          && !rprog_command_trigger( ch, origarg )
          && !mprog_command_trigger( ch, origarg )
          && !oprog_command_trigger( ch, origarg )
          && !check_social( ch, command, argument ) && !news_cmd_hook( ch, command, argument )
#ifdef IMC
          && !imc_command_hook( ch, command, argument )
#endif
          )
      {
         EXIT_DATA *pexit;

         /*
          * check for an auto-matic exit command 
          */
         if( ( pexit = find_door( ch, command, TRUE ) ) != NULL && IS_SET( pexit->exit_info, EX_xAUTO ) )
         {
            if( IS_SET( pexit->exit_info, EX_CLOSED )
                && ( !IS_AFFECTED( ch, AFF_PASS_DOOR ) || IS_SET( pexit->exit_info, EX_NOPASSDOOR ) ) )
            {
               if( !IS_SET( pexit->exit_info, EX_SECRET ) )
                  act( AT_PLAIN, "The $d is closed.", ch, NULL, pexit->keyword, TO_CHAR );
               else
                  send_to_char( "You cannot do that here.\r\n", ch );
               return;
            }
            if( check_pos( ch, POS_STANDING ) )
               move_char( ch, pexit, 0 );
            return;
         }
         send_to_char( "Huh?\r\n", ch );
      }
      return;
   }

   /*
    * Character not in position for command?
    */
   if( !check_pos( ch, cmd->position ) )
      return;

   /*
    * Berserk check for flee.. maybe add drunk to this?.. but too much
    * hardcoding is annoying.. -- Altrag
    * This wasn't catching wimpy --- Blod
    * if ( !str_cmp(cmd->name, "flee") &&
    * IS_AFFECTED(ch, AFF_BERSERK) )
    * {
    * send_to_char( "You aren't thinking very clearly..\r\n", ch);
    * return;
    * } 
    */

   /*
    * So we can check commands for things like Posses and Polymorph
    * *  But still keep the online editing ability.  -- Shaddai
    * *  Send back the message to print out, so we have the option
    * *  this function might be usefull elsewhere.  Also using the
    * *  send_to_char_color so we can colorize the strings if need be. --Shaddai
    */

   buf = check_cmd_flags( ch, cmd );

   if( buf[0] != '\0' )
   {
      send_to_char_color( buf, ch );
      return;
   }

   /*
    * Nuisance stuff -- Shaddai
    */

   if( !IS_NPC( ch ) && ch->pcdata->nuisance && ch->pcdata->nuisance->flags > 9
       && number_percent(  ) < ( ( ch->pcdata->nuisance->flags - 9 ) * 10 * ch->pcdata->nuisance->power ) )
   {
      send_to_char( "You can't seem to do that just now.\r\n", ch );
      return;
   }

   /*
    * Dispatch the command.
    */
   ch->prev_cmd = ch->last_cmd;  /* haus, for automapping */
   ch->last_cmd = cmd->do_fun;
   start_timer( &time_used );
   ( *cmd->do_fun ) ( ch, argument );
   end_timer( &time_used );
   /*
    * Update the record of how many times this command has been used (haus)
    */
   update_userec( &time_used, &cmd->userec );
   tmptime = UMIN( time_used.tv_sec, 19 ) * 1000000 + time_used.tv_usec;

   /*
    * laggy command notice: command took longer than 1.5 seconds 
    */
   if( tmptime > 1500000 )
   {
      log_printf_plus( LOG_NORMAL, get_trust( ch ), "[*****] LAG: %s: %s %s (R:%d S:%ld.%06ld)", ch->name,
                       cmd->name, ( cmd->log == LOG_NEVER ? "XXX" : argument ),
                       ch->in_room ? ch->in_room->vnum : 0, time_used.tv_sec, time_used.tv_usec );
      cmd->lag_count++; /* count the lag flags */
   }

   tail_chain(  );
}
예제 #27
0
int main( int argc, char **argv )
#endif
{
   struct timeval now_time;
   int temp = -1, temp2 = -1;
   bool fCopyOver = false;

#if !defined(WIN32)
   moron_check(  );  // Debatable weather or not this is true in WIN32 anyway :)
#endif

   DONT_UPPER = false;
   num_descriptors = 0;
   num_logins = 0;
   dlist.clear(  );
   mudstrlcpy( lastplayercmd, "No commands issued yet", MIL * 2 );

   // Init time.
   tzset(  );
   gettimeofday( &now_time, NULL );
   current_time = now_time.tv_sec;
   mudstrlcpy( str_boot_time, c_time( current_time, -1 ), MIL );  /* Records when the mud was last rebooted */

   new_pfile_time_t = current_time + 86400;
   mud_start_time = current_time;

   // Get the port number.
   mud_port = 9500;
   if( argc > 1 )
   {
      if( !is_number( argv[1] ) )
      {
         fprintf( stderr, "Usage: %s [port #]\n", argv[0] );
         exit( 1 );
      }
      else if( ( mud_port = atoi( argv[1] ) ) <= 1024 )
      {
         fprintf( stderr, "%s", "Port number must be above 1024.\n" );
         exit( 1 );
      }

      if( argv[2] && argv[2][0] )
      {
         fCopyOver = true;
         control = atoi( argv[3] );
#ifdef IMC
         temp2 = atoi( argv[4] );
#endif
      }
      else
         fCopyOver = false;
   }

#if defined(WIN32)
   {
      /*
       * Initialise Windows sockets library 
       */
      unsigned short wVersionRequested = MAKEWORD( 1, 1 );
      WSADATA wsadata;
      int err;

      /*
       * Need to include library: wsock32.lib for Windows Sockets 
       */
      err = WSAStartup( wVersionRequested, &wsadata );
      if( err )
      {
         fprintf( stderr, "Error %i on WSAStartup\n", err );
         exit( 1 );
      }

      /*
       * standard termination signals 
       */
      signal( SIGINT, bailout );
      signal( SIGTERM, bailout );
   }
#endif /* WIN32 */

   // Initialize all startup functions of the mud. 
   init_mud( fCopyOver, mud_port, temp, temp2 );

#if !defined(WIN32)
   /*
    * Set various signal traps, waiting until after completing all bootup operations
    * before doing so because crashes during bootup should not be intercepted. Samson 3-11-04
    */
   signal( SIGTERM, SigTerm );   /* Catch kill signals */
   signal( SIGPIPE, SIG_IGN );
   signal( SIGALRM, caught_alarm );
   signal( SIGUSR1, SigUser1 );  /* Catch user defined signals */
   signal( SIGUSR2, SigUser2 );
#endif
#ifdef MULTIPORT
   signal( SIGCHLD, SigChld );
#endif

   /*
    * If this setting is active, intercept SIGSEGV and keep the mud running.
    * Doing so sets a flag variable which if true will cause SegVio to abort()
    * If game_loop is restarted and makes it through once without crashing again,
    * then the flag is unset and SIGSEGV will continue to be intercepted. Samson 3-11-04
    */
   if( sysdata->crashhandler == true )
      set_chandler(  );

   log_string( "No people online yet. Suspending autonomous update handlers." );

   // Sick isn't it? The whole game being run inside of one little statement..... :P 
   game_loop(  );

   // Clean up the loose ends. 
   close_mud(  );

   // That's all, folks.
   log_string( "Normal termination of game." );
   log_string( "Cleaning up Memory.&d" );
   cleanup_memory(  );
   exit( 0 );
}