Login
User Name:

Password:



Register
Forgot your password?
LOP Building Guide v1.0
Author: Hanaisse
Submitted by: Hanaisse
Reset Guide
Author: Hanaisse
Submitted by: Hanaisse
LOP 1.38r2
Author: Remcon
Submitted by: Remcon
LOP 1.37
Author: Remcon
Submitted by: Remcon
LOP 1.36
Author: Remcon
Submitted by: Remcon
Yahoo! Slurp, Quixadhal, Baiduspider

Members: 1
Guests: 4
Stats
Files
Topics
Posts
Members
Newest Member
369
3,185
15,632
526
Craty####
» SmaugMuds.org » Codebases » SmaugFUSS » AFKMUD board snippet
Forum Rules | Mark all | Recent Posts

AFKMUD board snippet
< Newer Topic :: Older Topic >

Pages:<< prev 1 next >>
Post is unread #1 Jun 16, 2009, 9:46 pm
Go to the bottom of the page Go to the top of the page
Metsuro
Apprentice
GroupMembers
Posts68
JoinedSep 2, 2006

Ok so I'm attempting to add this to 1.9 just had a decent to talk with David over at the mush forums about consts and the conversions so I think I'm doing ok now, I've gotten it pretty much compiling clean so far expect this one error.

boards.c: In function âvoid do_note_remove(CHAR_DATA*, const char*)â:
boards.c:2203: error: assignment of read-only location

So here is the function itself. However I am not sure how you'd correct this to make it work correctly?

Code:
void do_note_remove( CHAR_DATA * ch, const char *argument )
{
   BOARD_DATA *board;
   NOTE_DATA *pnote;
   char arg[MIL];
   short n_num = 0, r_num = 0, i = 0;
   char s1[16], s2[16], s3[16];

   snprintf( s1, 16, "%s", color_str( AT_BOARD, ch ) );
   snprintf( s2, 16, "%s", color_str( AT_BOARD2, ch ) );
   snprintf( s3, 16, "%s", color_str( AT_BOARD3, ch ) );

   if( !( board = find_board( ch ) ) )
   {
      if( !argument || argument[0] == '\0' )
      {
         ch_printf( ch, "%sRemoves a note from the board.\r\n%sSyntax: %serase %s<%sboard%s> <%snote#%s>.[%sreply#%s]&D\r\n",
                    s1, s3, s1, s3, s2, s3, s2, s3, s2, s3 );
         return;
      }

      argument = one_argument( argument, arg );
      if( !( board = get_board( ch, arg ) ) )
      {
         ch_printf( ch, "%sNo board found!&D\r\n", s1 );
         return;
      }
   }
   else
      ch_printf( ch, "%sUsing current board in room: %s%s&D\r\n", s1, s2, board->name );

   if( !IS_BOARD_FLAG( board, BOARD_PRIVATE ) && !can_remove( ch, board ) )
   {
      send_to_char( "You are unable to remove the notes on this board.\r\n", ch );
      return;
   }

   if( !argument || argument[0] == '\0' )
   {
      send_to_char( "Remove which note?\r\n", ch );
      return;
   }

   while( 1 )
   {
      if( argument[i] == '.' )
      {
         r_num = atoi( argument + i + 1 );
         argument[i] = '\0';  <-- this being line 2203.
         n_num = atoi( argument );
         break;
      }
      if( argument[i] == '\0' )
      {
         n_num = atoi( argument );
         r_num = -1;
         break;
      }
      i++;
   }

   n_num = atoi( argument );

   if( n_num == 0 )
   {
      send_to_char( "Remove which note?\r\n", ch );
      return;
   }

   if( r_num == 0 )
   {
      send_to_char( "Remove which reply?\r\n", ch );
      return;
   }

   i = 1;
   for( pnote = board->first_note; pnote; pnote = pnote->next )
   {
      if( IS_BOARD_FLAG( board, BOARD_PRIVATE ) && !is_note_to( ch, pnote ) && !can_remove( ch, board ) )
         continue;
      if( i == n_num )
         break;
      i++;
   }

   if( !pnote )
   {
      send_to_char( "Note not found!\r\n", ch );
      return;
   }

   if( is_name( "all", pnote->to_list ) && !can_remove( ch, board ) )
   {
      send_to_char( "You can not remove that note.\r\n", ch );
      return;
   }

   if( r_num > 0 )
   {
      NOTE_DATA *reply;

      i = 1;
      for( reply = pnote->first_reply; reply; reply = reply->next )
         if( i == r_num )
            break;
         else
            i++;

      if( !reply )
      {
         send_to_char( "Reply not found!\r\n", ch );
         return;
      }

      ch_printf( ch, "%sYou remove the reply from %s%s%s, titled '%s%s%s' from the %s%s%s board.&D\r\n",
                 s1, s2, reply->sender ? reply->sender : "--Error--", s1,
                 s2, reply->subject ? reply->subject : "--Error--", s1, s2, board->name, s1 );
      note_remove( board, reply );
      act( AT_GREY, "$n removes a reply from the board.", ch, NULL, NULL, TO_ROOM );
      return;
   }

   ch_printf( ch, "%sYou remove the note from %s%s%s, titled '%s%s%s' from the %s%s%s board.&D\r\n",
              s1, s2, pnote->sender ? pnote->sender : "--Error--", s1,
              s2, pnote->subject ? pnote->subject : "--Error--", s1, s2, board->name, s1 );
   note_remove( board, pnote );
   act( AT_GREY, "$n removes a note from the board.", ch, NULL, NULL, TO_ROOM );
   return;
}
       
Post is unread #2 Jun 17, 2009, 8:50 am
Go to the bottom of the page Go to the top of the page


Kayle
Nibelungen
GroupAdministrators
Posts885
JoinedMar 21, 2006
WWW

You'll need to use a temporary buffer to make the modifications. So up at the top of the function add a char *tmp; then do something like this:

Code:
   while( 1 )
   {
      tmp = str_dup( argument );
      if( tmp[i] == '.' )
      {
         r_num = atoi( tmp + i + 1 );
         tmp[i] = '\0';
         n_num = atoi( tmp );
         break;
      }
      if( tmp[i] == '\0' )
      {
         n_num = atoi( tmp );
         r_num = -1;
         break;
      }
      i++;
   }
   DISPOSE( tmp );
.........................
Owner/Coder                                                                    Coder
Malevolent Whispers                                                        Star Wars: The Sith Wars
{Development Phase - Not accepting players}                {Open Alpha - Players welcome, but with frequent changes to core systems.}
IMC2 Contact: Kayle@MW                                                IMC2 Contact: Kayle@SWTSW
       
Post is unread #3 Jun 17, 2009, 9:16 am
Go to the bottom of the page Go to the top of the page


David Haley
Sorcerer
GroupMembers
Posts830
JoinedJan 29, 2007
WWW

Probably want the str_dup to be outside the loop though. :tongue: .........................
David Haley
Head Coder, Legends of the Darkstone
BabbleMUD Project
http://david.the-haleys.org
       
Post is unread #4 Jun 17, 2009, 9:32 am
Go to the bottom of the page Go to the top of the page


Kayle
Nibelungen
GroupAdministrators
Posts885
JoinedMar 21, 2006
WWW

David's right, it should look like this:

Code:
   tmp = str_dup( argument );
   while( 1 )
   {
      if( tmp[i] == '.' )
      {
         r_num = atoi( tmp + i + 1 );
         tmp[i] = '\0';
         n_num = atoi( tmp );
         break;
      }
      if( tmp[i] == '\0' )
      {
         n_num = atoi( tmp );
         r_num = -1;
         break;
      }
      i++;
   }
   DISPOSE( tmp );
.........................
Owner/Coder                                                                    Coder
Malevolent Whispers                                                        Star Wars: The Sith Wars
{Development Phase - Not accepting players}                {Open Alpha - Players welcome, but with frequent changes to core systems.}
IMC2 Contact: Kayle@MW                                                IMC2 Contact: Kayle@SWTSW
       
Post is unread #5 Jun 17, 2009, 6:23 pm
Go to the bottom of the page Go to the top of the page
Metsuro
Apprentice
GroupMembers
Posts68
JoinedSep 2, 2006

Ok thanks fellas, got it in and working fine I believe. Notice I couldn't do an all message unless just hitting enter for the default value is that normal? or something I did wrong.
       
Post is unread #6 Jun 26, 2009, 5:41 pm
Go to the bottom of the page Go to the top of the page
Andril
Magician
GroupMembers
Posts103
JoinedJun 9, 2009

Try this in the board_parse function in boards.c as the first item under SUB_BOARD_TO in the switch statement.

Code:
		if( !argument || argument[0] == '\0' || argument[0] == ' ' || !str_cmp( argument, "all" ) )
		{
			if( IS_BOARD_FLAG( ch->pcdata->board, BOARD_PRIVATE ) && !IS_IMMORTAL( ch ) )
			{
				send_to_char( "You must specify a recipient.", ch );
				return;
			}
			STRFREE( ch->pnote->to_list );
			if( ch->pnote->parent )
			ch->pnote->to_list = STRALLOC( ch->pnote->parent->sender );
			else
			ch->pnote->to_list = STRALLOC( "All" );

			ch_printf( ch, "No recipient specified. Defaulting to '%s'\r\n", ch->pnote->to_list );
		}


And remove that else if ( !str_cmp( argument, "all" ) ) if check and it should work just fine. Assuming of course it's supposed to be set up so players can't send a message to All on a private board...
       
Post is unread #7 Jun 26, 2009, 6:10 pm   Last edited Jun 26, 2009, 6:11 pm by Metsuro
Go to the bottom of the page Go to the top of the page
Metsuro
Apprentice
GroupMembers
Posts68
JoinedSep 2, 2006

Samson actually helped me get this corrected with the help Kayle and Retnur, and has been noted but thank you for the help anyway!
       
Post is unread #8 Jun 26, 2009, 7:33 pm
Go to the bottom of the page Go to the top of the page


Kayle
Nibelungen
GroupAdministrators
Posts885
JoinedMar 21, 2006
WWW

That's not right at all.

No where in there do you actually take anything they specify and set it to the to_list. .........................
Owner/Coder                                                                    Coder
Malevolent Whispers                                                        Star Wars: The Sith Wars
{Development Phase - Not accepting players}                {Open Alpha - Players welcome, but with frequent changes to core systems.}
IMC2 Contact: Kayle@MW                                                IMC2 Contact: Kayle@SWTSW
       
Post is unread #9 Jun 26, 2009, 7:49 pm
Go to the bottom of the page Go to the top of the page


Samson
Scaly but Handsome
GroupAdministrators
Posts3,347
JoinedJan 1, 2002
WWW

Then speak now and provide a proper fix, because otherwise once I've got this thing playing nice with const correctness it's getting updated. :) .........................
PDNS-Admin | Top MUD Sites | Arthmoor MUD Hosting Services | The Truth About Medievia: A Saga of Code Theft.

"The past was erased, the erasure was forgotten, the lie became truth." -- George Orwell, 1984
       
Post is unread #10 Jun 26, 2009, 8:01 pm
Go to the bottom of the page Go to the top of the page
Metsuro
Apprentice
GroupMembers
Posts68
JoinedSep 2, 2006

Want me to give you my hacked attempt at correcting the const Samson? mine compiles in 1.9 just fine but I dont know if im perfectly got it updated?
       
Post is unread #11 Jun 26, 2009, 8:03 pm
Go to the bottom of the page Go to the top of the page


Kayle
Nibelungen
GroupAdministrators
Posts885
JoinedMar 21, 2006
WWW

Code:
      case SUB_BOARD_TO:
         if( !argument || argument[0] == '\0' )
         {
            if( ch->getPcData( )->board->flags.test( BOARD_PRIVATE ) && !ch->isImmortal( ) )
            {
               ch->printf( "%sYou must specify a recipient:&D   ", s1 );
               return;
            }
            STRFREE( ch->getPnote( )->to_list );
            if( ch->getPnote( )->parent )
               ch->getPnote( )->to_list = STRALLOC( ch->getPnote( )->parent->sender );
            else
               ch->getPnote( )->to_list = STRALLOC( "All" );

            ch->printf( "%sNo recipient specified. Defaulting to '%s%s%s'&D\r\n",
                       s1, s2, ch->getPnote( )->to_list, s1 );
         }
         else if( !str_cmp( argument, "all" ) )
         {
            if( !ch->isImmortal( ) && ch->getPcData( )->board->flags.test( BOARD_PRIVATE ) )
            {
               ch->printf( "%sYou can not send a message to '%sAll%s' on this board!\r\nYou must specify a recipient:&D   ",
                       s1, s2, s1 );
               return;
            }
            STRFREE( ch->getPnote( )->to_list );
            ch->getPnote( )->to_list = STRALLOC( "All" );
         }
         else
         {
            struct stat fst;
            char buf[MSL];

            snprintf( buf, MSL, "%s%c/%s", PLAYER_DIR, tolower( argument[0] ), capitalize( argument ) );
            if( stat( buf, &fst ) == -1 || !check_parse_name( capitalize( argument ), false ) )
            {
               ch->printf( "%sNo such player named '%s%s%s'.\r\nTo whom is this note addressed?   &D",
                          s1, s2, argument, s1 );
               return;
            }
            STRFREE( ch->getPnote( )->to_list );
            ch->getPnote( )->to_list = STRALLOC( argument );
         }

         ch->printf( "%sTo: %s%-15s %sFrom: %s%s&D\r\n", s1, s2, ch->getPnote( )->to_list,
                    s1, s2, ch->getPnote( )->sender );
         if( ch->getPnote( )->subject )
         {
            ch->printf( "%sSubject: %s%s&D\r\n", s1, s2, ch->getPnote( )->subject );
            ch->setSubState( SUB_BOARD_TEXT );
            ch->printf( "%sPlease enter the text for your message:&D\r\n", s1 );
            if( !ch->getPnote( )->text )
               ch->getPnote( )->text = str_dup( "" );
            ch->StartEditing( ch->getPnote( )->text );
            return;
         }
         ch->setSubState( SUB_BOARD_SUBJECT );
         ch->printf( "%sPlease enter a subject for this note:&D   ", s1 );
         return;


If you need it translated to stock I can do that. .........................
Owner/Coder                                                                    Coder
Malevolent Whispers                                                        Star Wars: The Sith Wars
{Development Phase - Not accepting players}                {Open Alpha - Players welcome, but with frequent changes to core systems.}
IMC2 Contact: Kayle@MW                                                IMC2 Contact: Kayle@SWTSW
       
Post is unread #12 Jun 26, 2009, 8:50 pm   Last edited Jun 26, 2009, 8:54 pm by Andril
Go to the bottom of the page Go to the top of the page
Andril
Magician
GroupMembers
Posts103
JoinedJun 9, 2009

Kayle said:
That's not right at all.

No where in there do you actually take anything they specify and set it to the to_list.


How you figure? If argument is not equal to one of those checks in the if check for that block, which includes a check for "all", it just bypasses it and then starts hunting for player names further down in the else. The "ch->pnote->to_list = STRALLOC( "All" );" is where to_list is getting set, and that's only happening if, when asked who the note is for, the player is hitting enter without typing anything, or just a space or is specifying "all".

Granted, it's still saying that it's defaulting to "All", so something like the following would probably be a little better:
Code:
if( !argument || argument[0] == '\0' || argument[0] == ' ' || !str_cmp( argument, "all" ) )
{
	if( IS_BOARD_FLAG( ch->pcdata->board, BOARD_PRIVATE ) && !IS_IMMORTAL( ch ) )
	{
		send_to_char( "You must specify a recipient.", ch );
		return;
	}
	STRFREE( ch->pnote->to_list );
	if( ch->pnote->parent )
	ch->pnote->to_list = STRALLOC( ch->pnote->parent->sender );
	else
	ch->pnote->to_list = STRALLOC( "All" );

        if ( str_cmp( argument, "all" ) )  ---- slight change here
	      ch_printf( ch, "No recipient specified. Defaulting to '%s'\r\n", ch->pnote->to_list );
        else
              send_to_char( "Recipient set to 'All', ch );
}


There's no need for that extra else if ( !str_cmp( argument, "all" ) ) below that first one because it's being checked for there anyways, and if the board has the BOARD_PRIVATE flag set, it's not going to let you do it if you're not an imm anyways.
       
Post is unread #13 Jun 26, 2009, 10:40 pm
Go to the bottom of the page Go to the top of the page


Samson
Scaly but Handsome
GroupAdministrators
Posts3,347
JoinedJan 1, 2002
WWW

Andril, that updated block makes perfect sense to me and I went ahead and incorporated it. The snippet update is in the files section now. Anyone who tried to put it in before should go back over it again just to be safe.

One spot in the save.c instructions also got missed, so watch for that as well. .........................
PDNS-Admin | Top MUD Sites | Arthmoor MUD Hosting Services | The Truth About Medievia: A Saga of Code Theft.

"The past was erased, the erasure was forgotten, the lie became truth." -- George Orwell, 1984
       
Post is unread #14 Jun 26, 2009, 11:09 pm   Last edited Jun 26, 2009, 11:22 pm by Metsuro
Go to the bottom of the page Go to the top of the page
Metsuro
Apprentice
GroupMembers
Posts68
JoinedSep 2, 2006

Fun stuff, I'll be trying to go over mine tomorrow and get the new stuff put in. I'll bug you if I find more odd stuff Samson *tongue*

Edit: - Sorry to be a pain Samson... in your snippet notes you forgot to include the DECLARE_DO_FUN( do_board_moderate ); in the list, hopefully people would just get the hint but... you never know!
       
Post is unread #15 Jun 27, 2009, 11:36 am
Go to the bottom of the page Go to the top of the page


Kayle
Nibelungen
GroupAdministrators
Posts885
JoinedMar 21, 2006
WWW

Sorry, that block just looks clunky as all hell, and that's one of the things I dislike about how Smaug and it's ilk are written. .........................
Owner/Coder                                                                    Coder
Malevolent Whispers                                                        Star Wars: The Sith Wars
{Development Phase - Not accepting players}                {Open Alpha - Players welcome, but with frequent changes to core systems.}
IMC2 Contact: Kayle@MW                                                IMC2 Contact: Kayle@SWTSW
       
Post is unread #16 Jun 28, 2009, 1:14 pm
Go to the bottom of the page Go to the top of the page


Conner
Sorcerer
GroupMembers
Posts821
JoinedMay 8, 2005
WWW ICQ AIM Yahoo MSN GT

Just for my own clarification here, what about it is "clunky" other than that he didn't indent the lines following the if and else right after the STRFREE? .........................
                                              -=Conner=-

Administrator/Coder                                                          Primary SysOp
Land of Legends                                                                The Castle's Dungeon BBS
http://tcdbbs.zapto.org/mud/nwlightninglol1.jpg                            http://tcdbbs.zapto.org/catapult1.gif
telnet://tcdbbs.zapto.org:4000                                          telnet://tcdbbs.zapto.org:23
       
Post is unread #17 Jun 28, 2009, 2:01 pm
Go to the bottom of the page Go to the top of the page


Kayle
Nibelungen
GroupAdministrators
Posts885
JoinedMar 21, 2006
WWW

The flow seems off. It doesn't really seem to make sense to me.

There's two separate types of logic being addressed in that one block, and it just seems wrong. Yes, it may compile, and it may work, but it still doesn't feel right.
.........................
Owner/Coder                                                                    Coder
Malevolent Whispers                                                        Star Wars: The Sith Wars
{Development Phase - Not accepting players}                {Open Alpha - Players welcome, but with frequent changes to core systems.}
IMC2 Contact: Kayle@MW                                                IMC2 Contact: Kayle@SWTSW
       
Post is unread #18 Jun 28, 2009, 4:17 pm
Go to the bottom of the page Go to the top of the page


Conner
Sorcerer
GroupMembers
Posts821
JoinedMay 8, 2005
WWW ICQ AIM Yahoo MSN GT

Oh, ok, I was just wondering. I've had on formal training in C or C++ so I wouldn't be surprised at all if most of the stuff I've coded would seem that way to you, but I do try to learn as I go so even little things like this help. :) .........................
                                              -=Conner=-

Administrator/Coder                                                          Primary SysOp
Land of Legends                                                                The Castle's Dungeon BBS
http://tcdbbs.zapto.org/mud/nwlightninglol1.jpg                            http://tcdbbs.zapto.org/catapult1.gif
telnet://tcdbbs.zapto.org:4000                                          telnet://tcdbbs.zapto.org:23
       
Pages:<< prev 1 next >>