Re: [CODE] A newbie implementor wonders about AFK...

From: George (greerga@DRAGON.HAM.MUOHIO.EDU)
Date: 07/29/97


On Tue, 29 Jul 1997, Tony Robbins wrote:

>When a player goes AFK it's fine, when they come back it's fine, but if
>they go AFK again, BUG!!!  MUD crash.  I'm not great with coding, I'm
>just trying to get something going that my friends and I and others can
>enjoy.

Remember people, you can't free() a string constant. (Not directed at you
in particular as you didn't write the code)

>void set_afk(struct char_data * ch, char *afk_message)
>{
>
>if (strlen(afk_message) > POOF_LENGTH)
>        afk_message[POOF_LENGTH] = '\0';
>
>        if (GET_AFK(ch) != NULL)
>                free(GET_AFK(ch));
>
>        GET_AFK(ch) = str_dup(afk_message);
>}

Ok, here we check if the person has a previous afk message, if they do free
it so we can make a new one, but ...

>ACMD(do_afk)
>{
[snip]
>        if (!*argument)
>        {
>           result = PRF_TOG_CHK(ch, PRF_AFK);
>           GET_AFK(ch) = "I am AFK!";
>        }
[snip]

...right above, we assign the message as a string constant if they didn't
type anything else.  To reproduce problem, "afk;afk;afk".  To fix problem,
just change it to 'GET_AFK(ch) = str_dup("I am AFK!");'

 --
greerga@muohio.edu me@null.net | Genius may have its limitations, but stupidity
http://www.muohio.edu/~greerga | is not thus handicapped. -- Elbert Hubbard


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/08/00 PST