Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ SMAUG ➜ Lua ➜ deleting pfiles

deleting pfiles

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Orik   USA  (182 posts)  Bio
Date Wed 13 Feb 2008 11:06 PM (UTC)
Message
Hello,

when a player deletes, the lua file is not deleted. What do I need to do in order to delete the associated lua file?
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Thu 14 Feb 2008 12:47 AM (UTC)
Message
Well, in the player directories is the additional .lua file, for example:


Admin Admin.lua


In the do_destroy function in act_wiz.c you would add a bit of code to delete (or, probably, rename) that as well.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Orik   USA  (182 posts)  Bio
Date Reply #2 on Thu 14 Feb 2008 01:21 AM (UTC)
Message

void do_destroy( CHAR_DATA * ch, char *argument )
{
   CHAR_DATA *victim;
   char buf[MAX_STRING_LENGTH];
   char buf2[MAX_STRING_LENGTH];
   char arg[MAX_INPUT_LENGTH];
   char *name;
   struct stat fst;

   set_char_color( AT_RED, ch );

   one_argument( argument, arg );
   if( arg[0] == '\0' )
   {
      send_to_char( "Destroy what player file?\r\n", ch );
      return;
   }

   /*
    * Set the file points.
    */
   name = capitalize( arg );
   snprintf( buf, MAX_STRING_LENGTH, "%s%c/%s", PLAYER_DIR, tolower( arg[0] ), name );
   snprintf( buf2, MAX_STRING_LENGTH, "%s%c/%s", BACKUP_DIR, tolower( arg[0] ), name );

   /*
    * This check makes sure the name is valid and that the file is there, else there
    * is no need to go on. -Orion
    */
   if( !check_parse_name( name, TRUE ) || lstat( buf, &fst ) == -1 )
   {
      ch_printf( ch, "No player exists by the name %s.\r\n", name );
      return;
   }

   for( victim = first_char; victim; victim = victim->next )
      if( !IS_NPC( victim ) && !str_cmp( victim->name, arg ) )
        break;

   if( !victim )
   {
      DESCRIPTOR_DATA *d;

      /*
       * Make sure they aren't halfway logged in.
       */
      for( d = first_descriptor; d; d = d->next )
         if( ( victim = d->character ) && !IS_NPC( victim ) && !str_cmp( victim->name, arg ) )
            break;
      if( d )
         close_socket( d, TRUE );
   }
   else
   {
      int x, y;

      quitting_char = victim;
      save_char_obj( victim );
      saving_char = NULL;
      extract_char( victim, TRUE );
      for( x = 0; x < MAX_WEAR; x++ )
         for( y = 0; y < MAX_LAYERS; y++ )
            save_equipment[x][y] = NULL;
   }

   
  if( !rename( buf, buf2 ) )
   {
      AREA_DATA *pArea;

      set_char_color( AT_RED, ch );
      ch_printf( ch, "Player %s destroyed.  Pfile saved in backup directory.\r\n", name );
      snprintf( buf, MAX_STRING_LENGTH, "%s%s", GOD_DIR, name );
      if( !remove( buf ) )
         send_to_char( "Player's immortal data destroyed.\r\n", ch );
      else if( errno != ENOENT )
      {
         ch_printf( ch, "Unknown error #%d - %s (immortal data). Report to www.smaugfuss.org\r\n", errno,
                    strerror( errno ) );
         snprintf( buf2, MAX_STRING_LENGTH, "%s destroying %s", ch->name, buf );
         perror( buf2 );
      }

      snprintf( buf2, MAX_STRING_LENGTH, "%s.are", name );
      for( pArea = first_build; pArea; pArea = pArea->next )
         if( !str_cmp( pArea->filename, buf2 ) )
         {
            snprintf( buf, MAX_STRING_LENGTH, "%s%s", BUILD_DIR, buf2 );
            if( IS_SET( pArea->status, AREA_LOADED ) )
               fold_area( pArea, buf, FALSE );
            close_area( pArea );
            snprintf( buf2, MAX_STRING_LENGTH, "%s.bak", buf );
            set_char_color( AT_RED, ch ); /* Log message changes colors */
            if( !rename( buf, buf2 ) )
               send_to_char( "Player's area data destroyed.  Area saved as backup.\r\n", ch );
            else if( errno != ENOENT )
            {
               ch_printf( ch, "Unknown error #%d - %s (area data). Report to www.smaugfuss.org\r\n", errno,
                          strerror( errno ) );
               snprintf( buf2, MAX_STRING_LENGTH, "%s destroying %s", ch->name, buf );
               perror( buf2 );
            }
            break;
         }
   }
   else if( errno == ENOENT )
   {
      set_char_color( AT_PLAIN, ch );
      send_to_char( "Player does not exist.\r\n", ch );
   }
   else
   {
      set_char_color( AT_WHITE, ch );
      ch_printf( ch, "Unknown error #%d - %s. Report to www.smaugfuss.org\r\n", errno, strerror( errno ) );
      snprintf( buf, MAX_STRING_LENGTH, "%s destroying %s", ch->name, arg );
      perror( buf );
   }
   return;
}


Not seeing where it exactly deletes the pfile.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #3 on Thu 14 Feb 2008 01:30 AM (UTC)
Message

 if( !rename( buf, buf2 ) )


It is renaming it from PLAYER_DIR to BACKUP_DIR (see the snprintf further up), so there is still a copy in case you do it by mistake.

So you could probably repeat the operation with the player name with .lua at the end of it.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Orik   USA  (182 posts)  Bio
Date Reply #4 on Thu 14 Feb 2008 01:36 AM (UTC)
Message
so:


snprintf( buf3, MAX_STRING_LENGTH, "%s%c/%s.lua", PLAYER_DIR, tolower( arg[0] ), name );


then:

if( !rename( buf3, buf2 ) )
   {
      AREA_DATA *pArea;

      set_char_color( AT_RED, ch );
      ch_printf( ch, "Player %s.lua destroyed.  Lua Pfile saved in backup directory.\r\n", name );
      snprintf( buf, MAX_STRING_LENGTH, "%s%s", GOD_DIR, name );
      if( !remove( buf3 ) )
         send_to_char( "Player's immortal data destroyed.\r\n", ch );
      else if( errno != ENOENT )
      {
         ch_printf( ch, "Unknown error #%d - %s (immortal data). Report to www.smaugfuss.org\r\n", errno,
                    strerror( errno ) );
         snprintf( buf2, MAX_STRING_LENGTH, "%s destroying %s.lua", ch->name, buf3 );
         perror( buf2 );
      }

      snprintf( buf2, MAX_STRING_LENGTH, "%s.are", name );
      for( pArea = first_build; pArea; pArea = pArea->next )
         if( !str_cmp( pArea->filename, buf2 ) )
         {
            snprintf( buf, MAX_STRING_LENGTH, "%s%s", BUILD_DIR, buf2 );
            if( IS_SET( pArea->status, AREA_LOADED ) )
               fold_area( pArea, buf3, FALSE );
            close_area( pArea );
            snprintf( buf2, MAX_STRING_LENGTH, "%s.bak", buf );
            set_char_color( AT_RED, ch ); /* Log message changes colors */
            if( !rename( buf, buf2 ) )
               send_to_char( "Player's area data destroyed.  Area saved as backup.\r\n", ch );
            else if( errno != ENOENT )
            {
               ch_printf( ch, "Unknown error #%d - %s (area data). Report to www.smaugfuss.org\r\n", errno,
                          strerror( errno ) );
               snprintf( buf2, MAX_STRING_LENGTH, "%s destroying %s", ch->name, buf3 );
               perror( buf2 );
            }
            break;
         }
   }
   else if( errno == ENOENT )
   {
      set_char_color( AT_PLAIN, ch );
      send_to_char( "Player does not exist.\r\n", ch );
   }
   else
   {
      set_char_color( AT_WHITE, ch );
      ch_printf( ch, "Unknown error #%d - %s. Report to www.smaugfuss.org\r\n", errno, strerror( errno ) );
      snprintf( buf3, MAX_STRING_LENGTH, "%s destroying %s", ch->name, arg );
      perror( buf );
   }


Would that work?
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #5 on Thu 14 Feb 2008 01:57 AM (UTC)
Message
Well not exactly, that would rename the .lua file but leave the original player file there. You need to do 2 renames.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Orik   USA  (182 posts)  Bio
Date Reply #6 on Thu 14 Feb 2008 06:10 AM (UTC)
Message
Well, that's what I meant. I'd have the first rename with the first buf, then have a second rename with the third buf. I could probably take out the imm stuff and area stuff as well to make it smaller.
Top

Posted by Orik   USA  (182 posts)  Bio
Date Reply #7 on Thu 14 Feb 2008 08:51 PM (UTC)
Message
This is what I came up with. Feel free to use it. It deletes the lua file in the player_dir and places it in the backup_dir.


void do_destroy( CHAR_DATA * ch, char *argument )
{
   CHAR_DATA *victim;
   char buf[MAX_STRING_LENGTH];
   char buf2[MAX_STRING_LENGTH];
   
   /* Deleting Lua Files and placing them in backup Dir - Rao 2/14/08*/
   char buf3[MAX_STRING_LENGTH];
   char buf4[MAX_STRING_LENGTH];
   /******************************************************************/

   char arg[MAX_INPUT_LENGTH];
   char *name;
   struct stat fst;

   set_char_color( AT_RED, ch );

   one_argument( argument, arg );
   if( arg[0] == '\0' )
   {
      send_to_char( "Destroy what player file?\r\n", ch );
      return;
   }

   /*
    * Set the file points.
    */
   name = capitalize( arg );
   snprintf( buf, MAX_STRING_LENGTH, "%s%c/%s", PLAYER_DIR, tolower( arg[0] ), name );
   snprintf( buf2, MAX_STRING_LENGTH, "%s%c/%s", BACKUP_DIR, tolower( arg[0] ), name );

   /* Deleting Lua Files and placing them in backup Dir - Rao 2/14/08*/
   snprintf( buf3, MAX_STRING_LENGTH, "%s%c/%s.lua", PLAYER_DIR, tolower( arg[0] ), name );
   snprintf( buf4, MAX_STRING_LENGTH, "%s%c/%s.lua", BACKUP_DIR, tolower( arg[0] ), name );
   /******************************************************************/

   /*
    * This check makes sure the name is valid and that the file is there, else there
    * is no need to go on. -Orion
    */
   if( !check_parse_name( name, TRUE ) || lstat( buf, &fst ) == -1 )
   {
      ch_printf( ch, "No player exists by the name %s.\r\n", name );
      return;
   }

   for( victim = first_char; victim; victim = victim->next )
      if( !IS_NPC( victim ) && !str_cmp( victim->name, arg ) )
         break;

   if( !victim )
   {
      DESCRIPTOR_DATA *d;

      /*
       * Make sure they aren't halfway logged in. 
       */
      for( d = first_descriptor; d; d = d->next )
         if( ( victim = d->character ) && !IS_NPC( victim ) && !str_cmp( victim->name, arg ) )
            break;
      if( d )
         close_socket( d, TRUE );
   }
   else
   {
      int x, y;

      quitting_char = victim;
      save_char_obj( victim );
      saving_char = NULL;
      extract_char( victim, TRUE );
      for( x = 0; x < MAX_WEAR; x++ )
         for( y = 0; y < MAX_LAYERS; y++ )
            save_equipment[x][y] = NULL;
   }

   if( !rename( buf, buf2 ) )
   {
      AREA_DATA *pArea;

      set_char_color( AT_RED, ch );
      ch_printf( ch, "Player %s destroyed.  Pfile saved in backup directory.\r\n", name );
      snprintf( buf, MAX_STRING_LENGTH, "%s%s", GOD_DIR, name );
      if( !remove( buf ) )
         send_to_char( "Player's immortal data destroyed.\r\n", ch );
      else if( errno != ENOENT )
      {
         ch_printf( ch, "Unknown error #%d - %s (immortal data). Report to www.legendsofold.com\r\n", errno,
                    strerror( errno ) );
         snprintf( buf2, MAX_STRING_LENGTH, "%s destroying %s", ch->name, buf );
         perror( buf2 );
      }

      snprintf( buf2, MAX_STRING_LENGTH, "%s.are", name );
      for( pArea = first_build; pArea; pArea = pArea->next )
         if( !str_cmp( pArea->filename, buf2 ) )
         {
            snprintf( buf, MAX_STRING_LENGTH, "%s%s", BUILD_DIR, buf2 );
            if( IS_SET( pArea->status, AREA_LOADED ) )
               fold_area( pArea, buf, FALSE );
            close_area( pArea );
            snprintf( buf2, MAX_STRING_LENGTH, "%s.bak", buf );
            set_char_color( AT_RED, ch ); /* Log message changes colors */
            if( !rename( buf, buf2 ) )
               send_to_char( "Player's area data destroyed.  Area saved as backup.\r\n", ch );
            else if( errno != ENOENT )
            {
               ch_printf( ch, "Unknown error #%d - %s (area data). Report to www.legendsofold.com\r\n", errno,
                          strerror( errno ) );
               snprintf( buf2, MAX_STRING_LENGTH, "%s destroying %s", ch->name, buf );
               perror( buf2 );
            }
            break;
         }
   }
   else if( errno == ENOENT )
   {
      set_char_color( AT_PLAIN, ch );
      send_to_char( "Player does not exist.\r\n", ch );
   }
   else
   {
      set_char_color( AT_WHITE, ch );
      ch_printf( ch, "Unknown error #%d - %s. Report to www.legendsofold.com\r\n", errno, strerror( errno ) );
      snprintf( buf, MAX_STRING_LENGTH, "%s destroying %s", ch->name, arg );
      perror( buf );
   }

   /* Deleting Lua Files and placing them in backup Dir - Rao 2/14/08*/
   if( !rename( buf3, buf4 ) )
   {

      set_char_color( AT_RED, ch );
      ch_printf( ch, "LUA: Player %s Lua file destroyed.  Lua Pfile saved in backup directory.\r\n", name );
   }
   else if( errno == ENOENT )
   {
      set_char_color( AT_PLAIN, ch );
      send_to_char( "LUA: Player does not exist.\r\n", ch );
   }
   else
   {
      set_char_color( AT_WHITE, ch );
      ch_printf( ch, "LUA: Unknown error #%d - %s. Report to www.legendsofold.com\r\n", errno, strerror( errno ) );
      snprintf( buf3, MAX_STRING_LENGTH, "LUA: %s destroying %s", ch->name, arg );
      perror( buf3 );
   }
   /******************************************************************/

   return;
}

Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


21,481 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.