I think another issue you're going to have with iterating through
char_list like this is you're going to lose track of the next pointer if a
char_data node is extracted from the list while you're in the midst of
iterating.  This extraction will happen with mob deaths, player logouts,
etc.
     Try using:

for ( ch_check = char_list; ch_check != NULL; ch_check = ch_check_next )
{
     ch_check_next = ch_next->next;

<snippet resumes>

     Hope this helps.

- Strife Daemonkin

----- Original Message -----
From: "Anarchangel" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Thursday, November 14, 2002 12:01 PM
Subject: Multiplay check question


> Hey everyone,
>
> I'd appreciate any input and constructive criticism on the
> following.  Hopefully it's something simple that I'm overlooking.
>
> I recently put together a simple check for a multiplaying character.  It
> doesn't do anything except write to wiznet.  It seems to be working fine,
> but today I noticed the mud I'm working on crashed in the
> function.  Here's the GDB info:
>
> #0  0x8079fcc in check_multiplay (ch=0x40bd38e0) at comm.c:4388
> 4388            if ( (!IS_NPC(ch_check) && !IS_NPC(ch))
> (gdb) bt
> #0  0x8079fcc in check_multiplay (ch=0x40bd38e0) at comm.c:4388
> #1  0x80777f3 in nanny (d=0x40a3334c, argument=0x40a33774 "") at
> comm.c:3064
> #2  0x80740f0 in game_loop_unix (control=4) at comm.c:1183
> #3  0x80734fb in main (argc=4, argv=0xbffffdd4) at comm.c:497
> #4  0x4005ecbe in __libc_start_main () from /lib/libc.so.6
>
> #0  0x8079fcc in check_multiplay (ch=0x40bd38e0) at comm.c:4388
> 4388            if ( (!IS_NPC(ch_check) && !IS_NPC(ch))
> (gdb) info local
> ch = (CHAR_DATA *) 0x40bd38e0
> ch_check = (CHAR_DATA *) 0x40ba01d4
>
> I went ahead and printed ch and ch_check and they're both PC's, as I
> thought.  I can't think of why it would have crashed, as there have been
> at least a hundred logins and logouts since I made this live.
>
> I call it in the nanny, right when it tells the room that someone entered
> the game.
>
>         check_multiplay( ch );
>
> Here's the function:
> host is IP address and host2 is resolved domain.
>
> void check_multiplay( CHAR_DATA *ch )
> {
>     CHAR_DATA *ch_check;
>
>     if(!ch)
>     {
>         log_string( "ch is null in multiplay check." );
>         return;
>     }
>
>     /* Don't want to give away immortals */
>     if(IS_IMMORTAL(ch))
>         return;
>
>     for ( ch_check = char_list; ch_check != NULL; ch_check =
ch_check->next )
>     {
>         if ( (!IS_NPC(ch_check) && !IS_NPC(ch)) <-- Offending line
>         && !str_cmp( ch->desc->host2, ch_check->desc->host2)
>         && ch != ch_check )
>         {
>             char buf[MSL];
>
>     /* Don't want to give away immortals */
>             if(IS_IMMORTAL(ch_check))
>                 return;
>
>     /* Just in case */
>             if(ch->name)
>                 sprintf(buf, "%s may be multiplaying.", ch->name);
>             else
>             {
>                 log_string( "ch->name is null in multiplay check." );
>                 return;
>             }
>
>             wiznet( "$N may be multiplaying.", ch, NULL,
WIZ_ON,0,get_trust(ch));
>             log_string( buf );
>
>             return;
>         }
>     }
>
>     return;
>
> }
>
>
> --
> ROM mailing list
> [email protected]
> http://www.rom.org/cgi-bin/mailman/listinfo/rom
>
>



Reply via email to