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;
}
|