Пример #1
0
/*
 * Find an obj in a list.
 */
obj_data *get_obj_list( char_data * ch, const string & argument, list < obj_data * >source )
{
   string arg;
   list < obj_data * >::iterator iobj;

   int number = number_argument( argument, arg );
   int count = 0;
   for( iobj = source.begin(  ); iobj != source.end(  ); ++iobj )
   {
      obj_data *obj = *iobj;

      if( ch->can_see_obj( obj, false ) && hasname( obj->name, arg ) )
         if( ( count += obj->count ) >= number )
            return obj;
   }

   /*
    * If we didn't find an exact match, run through the list of objects
    * again looking for prefix matching, ie swo == sword.
    * Added by Narn, Sept/96
    */
   count = 0;
   for( iobj = source.begin(  ); iobj != source.end(  ); ++iobj )
   {
      obj_data *obj = *iobj;

      if( ch->can_see_obj( obj, false ) && nifty_is_name_prefix( arg, obj->name ) )
         if( ( count += obj->count ) >= number )
            return obj;
   }
   return NULL;
}
Пример #2
0
void to_channel( const string & argument, const string & xchannel, int level )
{
   mud_channel *channel;

   if( dlist.empty(  ) || argument.empty(  ) )
      return;

   if( !( channel = find_channel( xchannel ) ) )
      return;

   if( channel->type != CHAN_LOG )
      return;

   if( channel->flags.test( CHAN_KEEPHISTORY ) )
      update_channel_history( nullptr, channel, argument, false );

   list < descriptor_data * >::iterator ds;
   for( ds = dlist.begin(  ); ds != dlist.end(  ); ++ds )
   {
      descriptor_data *d = *ds;
      char_data *vch = d->original ? d->original : d->character;

      if( !vch )
         continue;

      if( d->original )
         continue;

      /*
       * This could be coming in higher than the normal level, so check first 
       */
      if( vch->level < level )
         continue;

      if( d->connected == CON_PLAYING && vch->level >= channel->level && hasname( vch->pcdata->chan_listen, channel->name ) )
      {
         char buf[MSL];

         snprintf( buf, MSL, "%s: %s\r\n", capitalize( channel->name ).c_str(  ), argument.c_str(  ) );
         vch->set_color( AT_LOG );
         vch->print( buf );
      }
   }
}
Пример #3
0
bool local_channel_hook( char_data * ch, const string & command, string & argument )
{
   mud_channel *channel;

   if( !ch )
      return false;

   if( !( channel = find_channel( command ) ) )
      return false;

   if( ch->level < channel->level )
      return false;

   /*
    * Logs are meant to be seen, not talked on, but if they keep history, they are viewable.
    */
   if( channel->type == CHAN_LOG )
   {
      if( channel->flags.test( CHAN_KEEPHISTORY ) )
         show_channel_history( ch, channel );
      return true;
   }

   if( !ch->isnpc(  ) && !hasname( ch->pcdata->chan_listen, channel->name ) && !channel->flags.test( CHAN_ALWAYSON ) )
   {
      ch->printf( "&RYou are not listening to the &G%s &Rchannel.\r\n", channel->name.c_str(  ) );
      return true;
   }

#if !defined(__CYGWIN__)
#ifdef MULTIPORT
   if( channel->flags.test( CHAN_INTERPORT ) )
      mud_message( ch, channel, argument );
#endif
#endif
   send_tochannel( ch, channel, argument );
   return true;
}
Пример #4
0
/*
 * Parse a name for acceptability.
 */
bool check_parse_name( const string & name, bool newchar )
{
   /*
    * Names checking should really only be done on new characters, otherwise
    * we could end up with people who can't access their characters. Would
    * have also provided for that new area havoc mentioned below, while still
    * disallowing current area mobnames. I personally think that if we can
    * have more than one mob with the same keyword, then may as well have
    * players too though, so I don't mind that removal.  -- Alty
    */

   /*
    * Length restrictions.
    */
   if( name.length(  ) < 3 || name.length(  ) > 12 )
      return false;

   /*
    * Alphanumerics only.
    * Lock out IllIll twits.
    *
    {
    char *pc;
    bool fIll;
    
    fIll = true;
    for( pc = name; *pc != '\0'; ++pc )
    {
    if( !isalpha( *pc ) )
    return false;
    if( LOWER( *pc ) != 'i' && LOWER( *pc ) != 'l' )
    fIll = false;
    }
    
    if( fIll )
    return false;
    } */

   // Alphanumeric checks
   string::const_iterator ptr = name.begin(  );
   while( ptr != name.end(  ) )
   {
      if( !isalpha( *ptr ) )
         return false;
      ++ptr;
   }

   /*
    * Mob names illegal for newbies now - Samson 7-24-00 
    */
   list < char_data * >::iterator ich;
   for( ich = charlist.begin(  ); ich != charlist.end(  ); ++ich )
   {
      char_data *vch = *ich;

      if( vch->isnpc(  ) )
      {
         if( hasname( vch->name, name ) && newchar )
            return false;
      }
   }

   /*
    * This grep idea was borrowed from SunderMud.
    * * Reserved names list was getting much too large to load into memory.
    * * Placed last so as to avoid problems from any of the previous conditions causing a problem in shell.
    */
   char buf[MSL];
   snprintf( buf, MSL, "grep -i -x %s ../system/reserved.lst > /dev/null", name.c_str(  ) );

   if( system( buf ) == 0 && newchar )
   {
      buf[0] = '\0';
      return false;
   }

   /*
    * Check for inverse naming as well 
    */
   string invname = invert_string( name );
   snprintf( buf, MSL, "grep -i -x %s ../system/reserved.lst > /dev/null", invname.c_str(  ) );

   if( system( buf ) == 0 && newchar )
   {
      buf[0] = '\0';
      return false;
   }
   return true;
}
Пример #5
0
/* Duplicate of to_channel from act_comm.c modified for dynamic channels */
void send_tochannel( char_data * ch, mud_channel * channel, string & argument )
{
   int speaking = -1;

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

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

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

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

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

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

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

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

      show_channel_history( ch, channel );
      return;
   }

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

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

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

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

         one_argument( arg, name );

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

         MOBtrigger = false;

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

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

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

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

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

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