AFK oddity, help anyone?

Posted by Gatewaysysop2 on Sun 06 Jul 2003 10:11 PM — 2 posts, 12,298 views.

USA #0
I have this AFK code, found in some distrubtion of Smaug1.4aR4 I think(?) but it has a bug. For some reason, when you are already AFK and you type "afk" it will say

"you are no longer flagged as being away"
"you are now away"

Clearly this isn't right. As with all other activity, typing in "afk" should simply drop you back out of being afk and leave it at that, no drop you out and throw you right back into it. Here's the code that's giving me trouble.



void do_afk( CHAR_DATA *ch, char *argument )
{
    if ( IS_NPC(ch) )
        return;

    if xIS_SET(ch->act, PLR_AFK)
    {
        xREMOVE_BIT(ch->act, PLR_AFK);
        if( ch->pcdata->afkmsg )
        {
            STRFREE( ch->pcdata->afkmsg );
            ch->pcdata->afkmsg = NULL;
        }
        send_to_char( "You are no longer away.\n\r", ch );
        act(AT_GREY,"$n is no longer away.", ch, NULL, NULL, TO_CANSEE);
    }
    else
    {
        if( strlen( argument ) > 50 )
        {
            send_to_char( "Message is too long. Try to keep under 50 characters.\n\r", ch );
            return;
        }
        
        xSET_BIT(ch->act, PLR_AFK);
         
        if( argument[0] != '\0')
        {
            char buf[MAX_INPUT_LENGTH];
        
            sprintf( buf, " (%s) ", argument );
            ch->pcdata->afkmsg = STRALLOC( buf );
            ch_printf( ch, "You are now away: (%s)\n\r", argument );
            act(AT_GREY,"$n is now away: ($t).", ch, argument, NULL, TO_CANSEE);
        }
        else
        {
            send_to_char( "You are now away.\n\r", ch );
            act(AT_GREY,"$n is now away.", ch, NULL, NULL, TO_CANSEE);
        }
        return;
    }
}



Any ideas on why this isn't working quite right? I've stuck in a return; in a few places trying to fix this, but to no avail. Help is appreciated.

USA #1
Found the fix for this, was looking in the wrong place (newbie, go figure).

Leave the do_afk code as is, go into interp.c and find this:



        /*
         * Turn off afk bit when any command performed. - Ntanel
         */
        if( xIS_SET ( ch->act, PLR_AFK ) && !IS_NPC( ch ))
        {
            xREMOVE_BIT( ch->act, PLR_AFK );
            if( ch->pcdata->afkmsg )
            {
                STRFREE( ch->pcdata->afkmsg );
                ch->pcdata->afkmsg = NULL;
            }
            act( AT_GREY, "$n is no longer away.", ch, NULL, NULL, TO_CANSEE );
            send_to_char("You are no longer flagged as being away.\r\n", ch);
        }
    }



Just change the "&& !IS_NPC( ch ))" to read: "&& (str_cmp(command, "AFK")) && !IS_NPC( ch )) "