Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
tintin++ ogg sound player script for linux
Author: Robert Smith
Submitted by: Vladaar
6Dragons ogg Soundpack
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.4
Author: Vladaar
Submitted by: Vladaar
LoP 1.46
Author: Remcon
Submitted by: Remcon
LOP 1.45
Author: Remcon
Submitted by: Remcon
Users Online
CommonCrawl, Yandex, Google

Members: 0
Guests: 6
Stats
Files
Topics
Posts
Members
Newest Member
481
3,735
19,370
618
Micheal64X
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » Bugfix Lists » AFKMud Bugfix List » AFKMud Bug Archive » [Bug] add_ban has several pro...
Forum Rules | Mark all | Recent Posts

[Bug] add_ban has several problems
< Newer Topic :: Older Topic > AFKMud 1.75

Pages:<< prev 1 next >>
Post is unread #1 Aug 14, 2005, 10:13 pm   Last edited Nov 13, 2005, 11:08 am by Samson
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,643
JoinedJan 1, 2002

Bug: add_ban has several problems
Discovered in: AFKMud 1.75
Danger: High - Crashes + Memory leaks
Found by: lazerous and Remcon
Fixed by: Remcon

---

ban.c

Locate the add_ban function and replace it with this:
void add_ban( CHAR_DATA * ch, char *arg1, char *arg2, int bantime )
{
   BAN_DATA *pban, *temp;
   struct tm *tms;
   char *name;
   int level;
   bool prefix = FALSE, suffix = FALSE, user_name = FALSE;
   char *temp_host = NULL, *temp_user = NULL;
   unsigned int x;

   /*
    * Should we check to see if they have dropped link sometime in between 
    * * writing the note and now?  Not sure but for right now we won't since
    * * do_ban checks for that.  Shaddai
    */

   switch ( ch->substate )
   {
      default:
         bug( "add_ban: illegal substate: %d", ch->substate );
         return;

      case SUB_RESTRICTED:
         send_to_char( "You cannot use this command from within another command.\n\r", ch );
         return;

      case SUB_NONE:
      {
         smash_tilde( arg1 ); /* Make sure the immortals don't put a ~ in it. */

         if( arg1[0] == '\0' || arg2[0] == '\0' )
            return;

         if( is_number( arg2 ) )
         {
            level = atoi( arg2 );
            if( level < 0 || level > LEVEL_SUPREME )
            {
               ch_printf( ch, "Level range is from 0 to %d.\n\r", LEVEL_SUPREME );
               return;
            }
         }
         else if( !str_cmp( arg2, "all" ) )
            level = LEVEL_SUPREME;
         else if( !str_cmp( arg2, "newbie" ) )
            level = 1;
         else if( !str_cmp( arg2, "mortal" ) )
            level = LEVEL_AVATAR;
         else if( !str_cmp( arg2, "warn" ) )
            level = BAN_WARN;
         else
         {
            bug( "Bad string for flag in add_ban: %s", arg2 );
            return;
         }

         for( x = 0; x < strlen( arg1 ); x++ )
         {
            if( arg1[x] == '@' )
            {
               user_name = TRUE;
               temp_host = str_dup( &arg1[x + 1] );
               arg1[x] = '\0';
               temp_user = str_dup( arg1 );
               break;
            }
         }
         if( !user_name )
            name = arg1;
         else
            name = temp_host;

         if( !name ) /* Double check to make sure name isnt null */
         {
            /* Free this stuff if its there */
            if( user_name )
            {
               DISPOSE( temp_host );
               DISPOSE( temp_user );
            }
            send_to_char( "Name was null.\n\r", ch );
            return;
         }

         if( name[0] == '*' )
         {
            prefix = TRUE;
            name++;
         }

         if( name[strlen( name ) - 1] == '*' )
         {
            suffix = TRUE;
            name[strlen( name ) - 1] = '\0';
         }

         for( temp = first_ban; temp; temp = temp->next )
         {
            if( !str_cmp( temp->name, name ) )
            {
               if( temp->level == level && ( prefix && temp->prefix )
                   && ( suffix && temp->suffix ) && ( !user_name || ( user_name && !str_cmp( temp->user, temp_user ) ) ) )
               {
                  /* Free this stuff if its there */
                  if( user_name )
                  {
                     DISPOSE( temp_host );
                     DISPOSE( temp_user );
                  }
                  send_to_char( "That entry already exists.\n\r", ch );
                  return;
               }
               else
               {
                  temp->suffix = suffix;
                  temp->prefix = prefix;
                  if( temp->level == BAN_WARN )
                     temp->warn = TRUE;
                  temp->level = level;
                  strdup_printf( &temp->ban_time, "%24.24s", c_time( current_time, -1 ) );
                  if( bantime > 0 )
                  {
                     temp->duration = bantime;
                     tms = localtime( &current_time );
                     tms->tm_mday += bantime;
                     temp->unban_date = mktime( tms );
                  }
                  else
                  {
                     temp->duration = -1;
                     temp->unban_date = -1;
                  }
                  DISPOSE( temp->ban_by );
                  if( user_name )
                  {
                     DISPOSE( temp_host );
                     DISPOSE( temp_user );
                  }
                  temp->ban_by = str_dup( ch->name );
                  send_to_char( "Updated entry.\n\r", ch );
                  save_banlist(  );
                  return;
               }
            }
         }
         CREATE( pban, BAN_DATA, 1 );
         pban->ban_by = str_dup( ch->name );
         pban->suffix = suffix;
         pban->prefix = prefix;
         pban->name = str_dup( name );
         pban->level = level;
         if( user_name )
         {
            pban->user = str_dup( temp_user );
            DISPOSE( temp_host );
            DISPOSE( temp_user );
         }
         LINK( pban, first_ban, last_ban, next, prev );
         strdup_printf( &pban->ban_time, "%24.24s", c_time( current_time, -1 ) );
         if( bantime > 0 )
         {
            pban->duration = bantime;
            tms = localtime( &current_time );
            tms->tm_mday += bantime;
            pban->unban_date = mktime( tms );
         }
         else
         {
            pban->duration = -1;
            pban->unban_date = -1;
         }
         if( pban->level == BAN_WARN )
            pban->warn = TRUE;
         ch->substate = SUB_BAN_DESC;
         ch->pcdata->dest_buf = pban;
         if( !pban->note )
            pban->note = str_dup( "" );
         start_editing( ch, pban->note );
         set_editor_desc( ch, "A ban description." );
         return;
      }

      case SUB_BAN_DESC:
         pban = ( BAN_DATA * ) ch->pcdata->dest_buf;
         if( !pban )
         {
            bug( "%s", "do_ban: sub_ban_desc: NULL ch->pcdata->dest_buf" );
            ch->substate = SUB_NONE;
            return;
         }
         DISPOSE( pban->note );
         pban->note = copy_buffer_nohash( ch );
         stop_editing( ch );
         ch->substate = ch->tempnum;
         save_banlist(  );
         if( pban->duration > 0 )
         {
            if( !pban->user )
               ch_printf( ch, "%s banned for %d days.\n\r", pban->name, pban->duration );
            else
               ch_printf( ch, "%s@%s banned for %d days.\n\r", pban->user, pban->name, pban->duration );
         }
         else
         {
            if( !pban->user )
               ch_printf( ch, "%s banned forever.\n\r", pban->name );
            else
               ch_printf( ch, "%s@%s banned forever.\n\r", pban->user, pban->name );
         }
         return;

      case SUB_EDIT_ABORT:
         ch->substate = SUB_NONE;
         send_to_char( "Aborting ban note.\n\r", ch );
         return;
   }
}


The add_ban function had multiple small problems that added up over time. From missing bits of code that result in a crash, to a pair of variables which are for some reason allocated but never disposes of, to the time not updating properly when a ban is modified. This replacement function should solve all of this.
       
Pages:<< prev 1 next >>