Example #1
0
void char_leaving( char_data * ch, int howleft )
{
   auth_data *old_auth = NULL;

   /*
    * new auth 
    */
   old_auth = get_auth_name( ch->name );
   if( old_auth != NULL )
      if( old_auth->state == AUTH_ONLINE )
         old_auth->state = AUTH_OFFLINE;  /* Logging off */

   ch->pcdata->camp = howleft;

   if( howleft == 0 )   /* Rented at an inn */
   {
      switch ( ch->in_room->area->continent )
      {
         case ACON_ONE:
            ch->pcdata->one = ch->in_room->vnum;
            break;
         default:
            break;
      }
   }

   /*
    * Get 'em dismounted until we finish mount saving -- Blodkai, 4/97 
    */
   if( ch->position == POS_MOUNTED )
      interpret( ch, "dismount" );

   if( ch->morph )
      interpret( ch, "revert" );

   if( ch->desc )
   {
      if( ch->timer > 24 )
         update_connhistory( ch->desc, CONNTYPE_IDLE );
      else
         update_connhistory( ch->desc, CONNTYPE_QUIT );
   }

   list < obj_data * >::iterator iobj;
   for( iobj = ch->carrying.begin(  ); iobj != ch->carrying.end(  ); )
   {
      obj_data *obj = *iobj;
      ++iobj;

      inventory_scan( ch, obj );
   }
   quotes( ch );
   quitting_char = ch;
   ch->save(  );

   if( sysdata->save_pets )
   {
      list < char_data * >::iterator pet;

      for( pet = ch->pets.begin(  ); pet != ch->pets.end(  ); )
      {
         char_data *cpet = *pet;
         ++pet;

         cpet->extract( true );
      }
   }

   /*
    * Synch clandata up only when clan member quits now. --Shaddai 
    */
   if( ch->pcdata->clan )
      save_clan( ch->pcdata->clan );

   saving_char = NULL;
   ch->extract( true );

   for( int x = 0; x < MAX_WEAR; ++x )
      for( int y = 0; y < MAX_LAYERS; ++y )
         save_equipment[x][y] = NULL;
}
Example #2
0
void process_input( void )
{
   string cmdline;
   list < descriptor_data * >::iterator ds;

   /*
    * Kick out descriptors with raised exceptions
    * or have been idle, then check for input.
    */
   for( ds = dlist.begin(  ); ds != dlist.end(  ); )
   {
      descriptor_data *d = *ds;
      ++ds;

#ifdef MULTIPORT
      // Shell code - checks for forked descriptors 
      if( d->connected == CON_FORKED )
      {
         int status;
         if( !d->process )
            d->connected = CON_PLAYING;

         if( ( waitpid( d->process, &status, WNOHANG ) ) == -1 )
         {
            d->connected = CON_PLAYING;
            d->process = 0;
         }
         else if( status > 0 )
         {
            char_data *ch = d->original ? d->original : d->character;
            d->connected = CON_PLAYING;
            d->process = 0;

            if( ch )
               ch->printf( "Process exited with status code %d.\r\n", status );
         }
         if( d->connected == CON_FORKED )
            continue;
      }
#endif

      // True if do_disconnect is called. Hasta la vista baby!
      if( d->disconnect )
      {
            d->outbuf.clear(  );
            close_socket( d, true );
            continue;
      }

      ++d->idle;  /* make it so a descriptor can idle out */
      if( FD_ISSET( d->descriptor, &exc_set ) )
      {
         FD_CLR( d->descriptor, &in_set );
         FD_CLR( d->descriptor, &out_set );
         if( d->character && d->connected >= CON_PLAYING )
            d->character->save(  );
         d->outbuf.clear(  );
         close_socket( d, true );
         continue;
      }
      else if( ( !d->character && d->idle > 360 )  /* 2 mins */
               || ( d->connected != CON_PLAYING && d->idle > 2400 )  /* 10 mins */
               || ( ( d->idle > 14400 ) && ( d->character->level < LEVEL_IMMORTAL ) )  /* 1hr */
               || ( ( d->idle > 32000 ) && ( d->character->level >= LEVEL_IMMORTAL ) ) )
         // imms idle off after 32000 to prevent rollover crashes 
      {
         if( d->character && d->character->level >= LEVEL_IMMORTAL )
            d->idle = 0;
         else
         {
            d->write( "Idle timeout... disconnecting.\r\n" );
            update_connhistory( d, CONNTYPE_IDLE );
            d->outbuf.clear(  );
            close_socket( d, true );
         }
         continue;
      }
      else
      {
         d->fcommand = false;

         if( FD_ISSET( d->descriptor, &in_set ) )
         {
            d->idle = 0;
            if( d->character )
               d->character->timer = 0;
            if( !d->read(  ) )
            {
               FD_CLR( d->descriptor, &out_set );
               if( d->character && d->connected >= CON_PLAYING )
                  d->character->save(  );
               d->outbuf.clear(  );
               update_connhistory( d, CONNTYPE_LINKDEAD );
               close_socket( d, false );
               continue;
            }
         }

#if !defined(WIN32)
         // Check for input from the dns 
         if( ( d->connected == CON_PLAYING || d->character != NULL ) && d->ifd != -1 && FD_ISSET( d->ifd, &in_set ) )
            d->process_dns(  );
#endif

         if( d->character && d->character->wait > 0 )
         {
            --d->character->wait;
            continue;
         }

         d->read_from_buffer(  );

         if( !d->incomm.empty(  ) )
         {
            d->fcommand = true;
            if( d->character && !d->character->has_aflag( AFF_SPAMGUARD ) )
               d->character->stop_idling(  );

            cmdline = d->incomm;
            d->incomm.clear(  );

            if( !d->pagebuf.empty(  ) )
               d->set_pager_input( cmdline );
            else
               switch ( d->connected )
               {
                  default:
                     d->nanny( cmdline );
                     break;

                  case CON_PLAYING:
                     if( d->original )
                        d->original->pcdata->cmd_recurse = 0;
                     else
                        d->character->pcdata->cmd_recurse = 0;
                     interpret( d->character, cmdline );
                     break;

                  case CON_EDITING:
                     d->character->edit_buffer( cmdline );
                     break;
               }
         }
      }
   }
}