示例#1
0
文件: chess.cpp 项目: xorith/AFKMud
void free_game( game_board_data * board )
{
    if( !board )
        return;

#ifdef IMC
    if( board->type == TYPE_IMC )
    {
        deleteptr( board->imc_player );
        imc_send_chess( !board->player1.empty(  )? board->player1 : nullptr, board->player2, "stop" );
        board->player2.clear(  );
    }
#endif

    if( !board->player1.empty(  ) )
    {
        if( char_data * ch = supermob->get_char_world( board->player1 ) ) // Added for bugfix - Findecano 23/11/07
        {
            ch->printf( "Your chess game has been stopped at %d total moves.\r\n", board->turn );
            ch->pcdata->game_board = nullptr;
        }
    }

    if( !board->player2.empty(  ) )
    {
        if( char_data * ch = supermob->get_char_world( board->player2 ) ) // Added for bugfix - Findecano 23/11/07
        {
            ch->printf( "Your chess game has been stopped at %d total moves.\r\n", board->turn );
            ch->pcdata->game_board = nullptr;
        }
    }
    deleteptr( board );
}
示例#2
0
/*
 * Clean out the extracted object queue
 */
void clean_obj_queue( void )
{
   extracted_obj_data *ood;

   for( ood = extracted_obj_queue; ood; ood = extracted_obj_queue )
   {
      extracted_obj_queue = ood->next;

      objlist.remove( ood->obj );
      deleteptr( ood->obj );
      deleteptr( ood );
      --cur_qobjs;
   }
}
示例#3
0
/*
 * Load a realm file
 */
bool load_realm_file( const char *realmfile )
{
   char filename[256];
   realm_data *realm;
   FILE *fp;
   bool found;

   realm = new realm_data;

   clean_realm( realm );  /* Default settings so we don't get wierd ass stuff */

   found = false;
   snprintf( filename, 256, "%s%s", REALM_DIR, realmfile );

   if( ( fp = fopen( filename, "r" ) ) != nullptr )
   {
      found = true;
      for( ;; )
      {
         char letter;
         char *word;

         letter = fread_letter( fp );
         if( letter == '*' )
         {
            fread_to_eol( fp );
            continue;
         }

         if( letter != '#' )
         {
            bug( "%s: # not found.", __func__ );
            break;
         }

         word = fread_word( fp );
         if( !str_cmp( word, "REALM" ) )
            fread_realm( realm, fp );
         else if( !str_cmp( word, "ROSTER" ) )
            fread_realm_memberlist( realm, fp );
         else if( !str_cmp( word, "END" ) )
            break;
         else
         {
            bug( "%s: bad section: %s.", __func__, word );
            break;
         }
      }
      FCLOSE( fp );
   }

   if( found )
      realmlist.push_back( realm );
   else
      deleteptr( realm );

   return found;
}
示例#4
0
/*
 * clean out the extracted character queue
 */
void clean_char_queue( void )
{
   extracted_char_data *ccd;

   for( ccd = extracted_char_queue; ccd; ccd = extracted_char_queue )
   {
      extracted_char_queue = ccd->next;
      if( ccd->extract )
      {
         charlist.remove( ccd->ch );
         if( !ccd->ch->isnpc(  ) )
            pclist.remove( ccd->ch );
         deleteptr( ccd->ch );
      }
      deleteptr( ccd );
      --cur_qchars;
   }
}
示例#5
0
void free_realms( void )
{
   list < realm_data * >::iterator rl;

   for( rl = realmlist.begin(  ); rl != realmlist.end(  ); )
   {
      realm_data *realm = *rl;
      ++rl;

      deleteptr( realm );
   }
}
示例#6
0
void free_all_auths( void )
{
   list < auth_data * >::iterator au;

   for( au = authlist.begin(  ); au != authlist.end(  ); )
   {
      auth_data *auth = *au;
      ++au;

      deleteptr( auth );
   }
}
示例#7
0
void remove_from_auth( const string & name )
{
   auth_data *old_name;

   if( !( old_name = get_auth_name( name ) ) )  /* Its not old */
      return;
   else
   {
      deleteptr( old_name );
      save_auth_list(  );
   }
}
示例#8
0
void free_ships( void )
{
   list < ship_data * >::iterator sh;

   for( sh = shiplist.begin(  ); sh != shiplist.end(  ); )
   {
      ship_data *ship = *sh;
      ++sh;

      deleteptr( ship );
   }
}
示例#9
0
void free_mudchannels( void )
{
   list < mud_channel * >::iterator chan;

   for( chan = chanlist.begin(  ); chan != chanlist.end(  ); )
   {
      mud_channel *channel = *chan;
      ++chan;

      deleteptr( channel );
   }
}
示例#10
0
/* NeoCode 0.08 Revamp of this! I now base it off of descriptor_data.
 * It will pull needed data from the descriptor. If there's no character
 * than it will use default information. -- X
 */
void update_connhistory( descriptor_data * d, int type )
{
   list < conn_data * >::iterator conn;
   conn_data *con;
   char_data *vch;
   struct tm *local;
   time_t t;
   char when[MIL];

   if( !d )
   {
      bug( "%s: NULL descriptor!", __FUNCTION__ );
      return;
   }

   vch = d->original ? d->original : d->character;
   if( !vch )
      return;

   if( vch->isnpc(  ) )
      return;

   /*
    * Count current histories, if more than the defined MAX, then remove the first one. -- X 
    */
   if( connlist.size(  ) >= MAX_CONNHISTORY )
   {
      con = *connlist.begin(  );
      connlist.erase( connlist.begin(  ) );
      deleteptr( con );
   }

   /*
    * Build our time string... 
    */
   t = time( NULL );
   local = localtime( &t );

   /*
    * Create our entry and fill the fields! 
    */
   con = new conn_data;
   con->user = vch->name ? vch->name : "NoName";
   snprintf( when, MIL, "%-2.2d/%-2.2d %-2.2d:%-2.2d", local->tm_mon + 1, local->tm_mday, local->tm_hour, local->tm_min );
   con->when = when;
   con->host = !d->host.empty(  )? d->host : "unknown";
   con->type = type;
   con->level = vch->level;
   con->invis_lvl = vch->has_pcflag( PCFLAG_WIZINVIS ) ? vch->pcdata->wizinvis : 0;
   connlist.push_back( con );
   save_connhistory(  );
}
示例#11
0
void purge_channel_history( mud_channel *channel )
{
   list < chan_history * >::iterator ihist;

   for( ihist = channel->history.begin(  ); ihist != channel->history.end(  ); )
   {
      chan_history *entry = *ihist;
      ++ihist;

      deleteptr( entry );
   }
   channel->history.clear();
}
示例#12
0
/* For use during realm removal and memory cleanup */
void remove_all_realm_rosters( realm_data * realm )
{
   list < realm_roster_data * >::iterator member;

   for( member = realm->memberlist.begin(  ); member != realm->memberlist.end(  ); )
   {
      realm_roster_data *roster = *member;
      ++member;

      realm->memberlist.remove( roster );
      deleteptr( roster );
   }
}
示例#13
0
/* This could possibly be useless, as the code that handles updating the file
 * already does most of this. Why not be extra-safe though? */
int check_conn_entry( conn_data * conn )
{
   if( !conn )
      return CHK_CONN_REMOVED;

   if( conn->user.empty(  ) || conn->host.empty(  ) || conn->when.empty(  ) )
   {
      deleteptr( conn );
      bug( "%s: Removed bugged conn entry!", __FUNCTION__ );
      return CHK_CONN_REMOVED;
   }
   return CHK_CONN_OK;
}
示例#14
0
void recv_text_handler( string & str )
{
   mud_channel *channel = nullptr;
   char_data *ch = nullptr;
   string arg1, arg2, arg3, arg4, arg5, chname;
   int ilevel = -1, clevel = -1;
   bool isnpc, isinvis;

   str = one_argument( str, arg1 );
   str = one_argument( str, arg2 );
   str = one_argument( str, arg3 );
   str = one_argument( str, arg4 );
   str = one_argument( str, arg5 );
   str = one_argument( str, chname );
   ilevel = atoi( arg2.c_str(  ) );
   clevel = atoi( arg3.c_str(  ) );
   isnpc = atoi( arg4.c_str(  ) );
   isinvis = atoi( arg5.c_str(  ) );

   if( !( channel = find_channel( arg1 ) ) )
   {
      bug( "%s: channel %s doesn't exist!", __func__, arg1.c_str(  ) );
      return;
   }

   /*
    * Massive punt here 
    */
   ch = new char_data;

   if( !isnpc )
   {
      ch->name = STRALLOC( capitalize( chname.c_str(  ) ) );
      ch->pcdata = new pc_data;
      ch->pcdata->wizinvis = ilevel;
      if( isinvis )
         ch->set_pcflag( PCFLAG_WIZINVIS );
   }
   else
   {
      ch->set_actflag( ACT_IS_NPC );
      ch->short_descr = STRALLOC( capitalize( chname.c_str(  ) ) );
      ch->mobinvis = ilevel;
   }
   ch->level = clevel;
   ch->to_room( get_room_index( ROOM_VNUM_LIMBO ) );
   send_tochannel( ch, channel, str );

   ch->from_room(  );
   deleteptr( ch );
}
示例#15
0
void clear_auth_list( void )
{
   list < auth_data * >::iterator auth;

   for( auth = authlist.begin(  ); auth != authlist.end(  ); )
   {
      auth_data *nauth = *auth;
      ++auth;

      if( !exists_player( nauth->name ) )
         deleteptr( nauth );
   }
   save_auth_list(  );
}
示例#16
0
/* Frees all the histories from memory.
 * If Arg == 1, then it also deletes the conn.hist file
 */
void free_connhistory( int arg )
{
   list < conn_data * >::iterator iconn;

   for( iconn = connlist.begin(  ); iconn != connlist.end(  ); )
   {
      conn_data *con = *iconn;
      ++iconn;

      deleteptr( con );
   }

   if( arg == 1 )
      unlink( CH_FILE );
}
示例#17
0
void remove_realm_roster( realm_data * realm, const string & name )
{
   list < realm_roster_data * >::iterator mem;

   for( mem = realm->memberlist.begin(  ); mem != realm->memberlist.end(  ); ++mem )
   {
      realm_roster_data *member = *mem;

      if( !str_cmp( name, member->name ) )
      {
         realm->memberlist.remove( member );
         deleteptr( member );
         return;
      }
   }
}
示例#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
/* Channel history. Records the last MAX_CHANHISTORY messages to channels which keep historys */
void update_channel_history( char_data * ch, mud_channel * channel, const string & argument, bool emote )
{
   int type = 0;
   const string newarg = add_percent( argument );

   chan_history *entry = new chan_history;

   if( !ch )
      entry->name = "System";
   else if( ch->isnpc() )
      entry->name = ch->short_descr;
   else
      entry->name = ch->name;

   strdup_printf( &entry->format, "   &R[%%s] &G%%s%s %s\r\n", emote ? "" : ":", newarg.c_str(  ) );

   entry->timestamp = current_time;

   if( ch && ch->has_aflag( AFF_INVISIBLE ) )
      type = 1;
   if( ch && ch->has_pcflag( PCFLAG_WIZINVIS ) )
   {
      type = 2;
      entry->invis = ch->pcdata->wizinvis;
   }
   entry->level = type;

   channel->history.push_back( entry );

   if( channel->history.size() > MAX_CHANHISTORY )
   {
      chan_history *oldentry = channel->history.front();

      channel->history.pop_front();
      deleteptr( oldentry );
   }
}
示例#20
0
void clean_auth_list( void )
{
   list < auth_data * >::iterator auth;

   for( auth = authlist.begin(  ); auth != authlist.end(  ); )
   {
      auth_data *nauth = *auth;
      ++auth;

      if( !exists_player( nauth->name ) )
         deleteptr( nauth );
      else
      {
         time_t tdiff = 0;
         time_t curr_time = time( 0 );
         struct stat fst;
         char file[256];
         int MAX_AUTH_WAIT = 7;

         snprintf( file, 256, "%s%c/%s", PLAYER_DIR, LOWER( nauth->name[0] ), capitalize( nauth->name ).c_str(  ) );

         if( stat( file, &fst ) != -1 )
            tdiff = ( curr_time - fst.st_mtime ) / 86400;
         else
            bug( "%s: File %s does not exist!", __func__, file );

         if( tdiff > MAX_AUTH_WAIT )
         {
            if( unlink( file ) == -1 )
               perror( "Unlink: do_auth: \"clean\"" );
            else
               log_printf( "%s deleted for inactivity: %ld days", file, tdiff );
         }
      }
   }
}
示例#21
0
void free_env( environment_data * env )
{
   envlist.remove( env );
   deleteptr( env );
}
示例#22
0
/*
 * Clean all memory on exit to help find leaks
 * Yeah I know, one big ugly function -Druid
 * Added to AFKMud by Samson on 5-8-03.
 */
void cleanup_memory( void )
{
   int hash;

#ifdef IMC
   fprintf( stdout, "%s", "IMC2 Data.\n" );
   free_imcdata( true );
   imc_delete_info(  );
#endif

   fprintf( stdout, "%s", "Quote List.\n" );
   free_quotes(  );

   fprintf( stdout, "%s", "Random Environment Data.\n" );
   free_envs(  );

   fprintf( stdout, "%s", "Auction Sale Data.\n" );
   free_sales(  );

   fprintf( stdout, "%s", "Project Data.\n" );
   free_projects(  );

   fprintf( stdout, "%s", "Ban Data.\n" );
   free_bans(  );

   fprintf( stdout, "%s", "Auth List.\n" );
   free_all_auths(  );

   fprintf( stdout, "%s", "Morph Data.\n" );
   free_morphs(  );

   fprintf( stdout, "%s", "Rune Data.\n" );
   free_runedata(  );

   fprintf( stdout, "%s", "Connection History Data.\n" );
   free_connhistory( 0 );

   fprintf( stdout, "%s", "Slay Table.\n" );
   free_slays(  );

   fprintf( stdout, "%s", "Holidays.\n" );
   free_holidays(  );

   fprintf( stdout, "%s", "Specfun List.\n" );
   free_specfuns(  );

   fprintf( stdout, "%s", "Wizinfo Data.\n" );
   clear_wizinfo(  );

   fprintf( stdout, "%s", "Skyship landings.\n" );
   free_landings(  );

   fprintf( stdout, "%s", "Ships.\n" );
   free_ships(  );

   fprintf( stdout, "%s", "Overland Landmarks.\n" );
   free_landmarks(  );

   fprintf( stdout, "%s", "Overland Exits.\n" );
   free_mapexits(  );

   fprintf( stdout, "%s", "Mixtures and Liquids.\n" );
   free_liquiddata(  );

   fprintf( stdout, "%s", "DNS Cache data.\n" );
   free_dns_list(  );

   fprintf( stdout, "%s", "Local Channels.\n" );
   free_mudchannels(  );

   // Helps
   fprintf( stdout, "%s", "Helps.\n" );
   free_helps(  );

   // Commands 
   fprintf( stdout, "%s", "Commands.\n" );
   free_commands(  );

#ifdef MULTIPORT
   // Shell Commands 
   fprintf( stdout, "%s", "Shell Commands.\n" );
   free_shellcommands(  );
#endif

   // Socials 
   fprintf( stdout, "%s", "Socials.\n" );
   free_socials(  );

   // Languages 
   fprintf( stdout, "%s", "Languages.\n" );
   free_tongues(  );

   // Boards 
   fprintf( stdout, "%s", "Boards.\n" );
   free_boards(  );

   // Events 
   fprintf( stdout, "%s", "Events.\n" );
   free_all_events(  );

   // Find and eliminate all running chess games
   fprintf( stdout, "%s", "Ending chess games.\n" );
   free_all_chess_games(  );

   // Whack supermob 
   fprintf( stdout, "%s", "Whacking supermob.\n" );
   if( supermob )
   {
      supermob->from_room(  );
      charlist.remove( supermob );
      deleteptr( supermob );
   }

   // Free Characters 
   fprintf( stdout, "%s", "Characters.\n" );
   extract_all_chars(  );

   // Free Objects 
   fprintf( stdout, "%s", "Objects.\n" );
   extract_all_objs(  );

   // Descriptors 
   fprintf( stdout, "%s", "Descriptors.\n" );
   free_all_descs(  );

   // Deities 
   fprintf( stdout, "%s", "Deities.\n" );
   free_deities(  );

   // Clans 
   fprintf( stdout, "%s", "Clans.\n" );
   free_clans(  );

   // Races 
   fprintf( stdout, "%s", "Races.\n" );
   free_all_races(  );

   // Classes 
   fprintf( stdout, "%s", "Classes.\n" );
   free_all_classes(  );

   // Teleport lists 
   fprintf( stdout, "%s", "Teleport Data.\n" );
   free_teleports(  );

   // Areas - this includes killing off the hash tables and such 
   fprintf( stdout, "%s", "Area Data Tables.\n" );
   close_all_areas(  );

   // Get rid of auction pointer MUST BE AFTER OBJECTS DESTROYED 
   fprintf( stdout, "%s", "Auction.\n" );
   deleteptr( auction );

   // Title table 
   fprintf( stdout, "%s", "Title table.\n" );
   free_all_titles(  );

   // Skills 
   fprintf( stdout, "%s", "Skills and Herbs.\n" );
   free_skills(  );

   // Prog Act lists 
   fprintf( stdout, "%s", "Mudprog act lists.\n" );
   free_prog_actlists(  );

   // Questbit data
   fprintf( stdout, "%s", "Abit/Qbit Data.\n" );
   free_questbits(  );

   free_mssp_info();

   fprintf( stdout, "%s", "Checking string hash for leftovers.\n" );
   {
      for( hash = 0; hash < 1024; ++hash )
         hash_dump( hash );
   }

#if !defined(__CYGWIN__) && defined(SQL)
   fprintf( stdout, "%s", "Closing database connection.\n" );
   close_db(  );
#endif

   // Last but not least, close the libdl and dispose of sysdata - Samson 
   fprintf( stdout, "%s", "System data.\n" );
   dlclose( sysdata->dlHandle );
   deleteptr( sysdata );
   fprintf( stdout, "%s", "Memory cleanup complete, exiting.\n" );
}
示例#23
0
文件: rare.cpp 项目: smaugmuds/xsmaug
/*
 * Bring up the pfile for rare item adjustments
 */
void adjust_pfile( const string & name )
{
   char_data *ch;
   char fname[256];
   struct stat fst;

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

      if( !str_cmp( name, temp->name ) )
      {
         log_printf( "Skipping rare item adjustments for %s, player is online.", temp->name );
         if( temp->is_immortal(  ) )   /* Get the rare items off the immortals */
         {
            list < obj_data * >::iterator iobj;

            log_printf( "Immortal: Removing rare items from %s.", temp->name );
            for( iobj = temp->carrying.begin(  ); iobj != temp->carrying.end(  ); )
            {
               obj_data *tobj = *iobj;
               ++iobj;

               rare_purge( temp, tobj );
            }
         }
         return;
      }
   }

   room_index *temproom, *original;
   if( !( temproom = get_room_index( ROOM_VNUM_RAREUPDATE ) ) )
   {
      bug( "%s: Error in rare item adjustment, temporary loading room is missing!", __FUNCTION__ );
      return;
   }

   snprintf( fname, 256, "%s%c/%s", PLAYER_DIR, tolower( name[0] ), capitalize( name ).c_str(  ) );

   if( stat( fname, &fst ) != -1 )
   {
      descriptor_data *d = new descriptor_data;
      d->init(  );
      d->connected = CON_PLOADED;

      load_char_obj( d, name, false, false );
      charlist.push_back( d->character );
      pclist.push_back( d->character );
      original = d->character->in_room;
      if( !d->character->to_room( temproom ) )
         log_printf( "char_to_room: %s:%s, line %d.", __FILE__, __FUNCTION__, __LINE__ );
      ch = d->character;   /* Hopefully this will work, if not, we're SOL */
      d->character->desc = NULL;
      d->character = NULL;
      deleteptr( d );

      log_printf( "Updating rare items for %s", ch->name );

      ++ch->pcdata->daysidle;
      expire_items( ch );

      ch->from_room(  );
      if( !ch->to_room( original ) )
         log_printf( "char_to_room: %s:%s, line %d.", __FILE__, __FUNCTION__, __LINE__ );

      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;

      /*
       * After extract_char the ch is no longer valid!
       */
      ch->extract( true );
      for( int x = 0; x < MAX_WEAR; ++x )
         for( int y = 0; y < MAX_LAYERS; ++y )
            save_equipment[x][y] = NULL;

      log_printf( "Rare items for %s updated sucessfully.", name.c_str(  ) );
   }
}