Notes: ** lines are my comments, >> lines are code lines, that are present
	purely for reference. (so you can figure out where the code goes)
	Numbers are references to readme file.


**  The code for main.c
** -----------------------------------------------------------------------
** 1)

#ifdef KEEP_LINKDEAD
static void cleanup_link(void);
#endif


** -----------------------------------------------------------------------
** 2)


#ifdef KEEP_LINKDEAD

/*
**  Cleanup and close the file descriptor of a linkdead player, without 
**  actually kicking them out of the game.  -Ithor
*/
static void cleanup_link(void)
{
  INP_HANDLER *i, *j;
  char b[256];
  int fd;
  int me = real_mynum;

  send_msg(ploc(me), 0, pvis(me), LVL_MAX, me, NOBODY,
	   "%s turns into a stone statue.\n", pname(me), psex(me)?"her":"his");
  
  if (pfighting(mynum) >= 0) 
  {
    int plx;
    
    if (cur_player->aliased) 
    {
      send_msg(DEST_ALL, MODE_QUIET|MODE_COLOR,
	       max(pvis(me), LVL_WIZARD),
	       LVL_MAX, mynum, me,
	       "[%s (aliased to %s) has lost link in %s&+Y (%s)]\n"
	       "&+Y[%s (str %d) was fighting %s (str %d)]\n",
	       pname(me), pname(mynum), sdesc(ploc(mynum)),
	       xshowname(b,ploc(mynum)),
	       pname(mynum), pstr(mynum),
	       pname(pfighting(mynum)),
	       pstr(pfighting(mynum)));
      mudlog("LINK: %s (aliased to %s) (str %d) has lost their link"
	     "\n\twhile fighting %s (str %d)",
	     pname(me), pname(mynum), pstr(mynum),
	     pname(pfighting(mynum)), pstr(pfighting(mynum)));
    } 
    else 
    {
      send_msg(DEST_ALL, MODE_QUIET|MODE_COLOR,
	       max(pvis(mynum), LVL_WIZARD),
	       LVL_MAX, mynum, NOBODY,
	       "[%s has lost link in %s&+Y (%s)]\n"
	       "&+Y[%s (str %d) was fighting %s (str %d)]\n",
	       pname(mynum), sdesc(ploc(mynum)),
	       xshowname(b,ploc(mynum)),
	       pname(mynum), pstr(mynum),
	       pname(pfighting(mynum)),
	       pstr(pfighting(mynum)));                             
      mudlog("LINK: %s (str %d) has lost their link"
	     "\n\twhile fighting %s (str %d)",
	     pname(mynum), pstr(mynum), 
	     pname(pfighting(mynum)), pstr(pfighting(mynum)));
    }
    for (plx = 0; plx < numchars; plx++) 
    {
      if (pfighting(plx) == mynum) 
      {
	setpfighting(plx, -1);
	set_hate(plx, mynum);
      }
    }
    setpfighting(mynum, -1);
  } 
  else 
  {
    if (cur_player->aliased) 
    {
      send_msg(DEST_ALL, MODE_QUIET|MODE_COLOR, 
	       max(pvis(me), LVL_WIZARD), 
	       LVL_MAX, me, NOBODY,
	       "[%s (aliased to %s) has lost link in %s&+Y (%s)]\n",
	       pname(me), pname(mynum), sdesc(ploc(mynum)),
	       xshowname(b,ploc(mynum)));
      mudlog("LINK: %s (aliased to %s) has lost their link",
	     pname(me), pname(mynum));
    } 
    else 
    {
      send_msg(DEST_ALL, MODE_QUIET|MODE_COLOR,
	       max(pvis(mynum), LVL_WIZARD), 
	       LVL_MAX, mynum, NOBODY,
	       "[%s has lost link in %s&+Y (%s)]\n",
	       pname(mynum), sdesc(ploc(mynum)),
	       xshowname(b,ploc(mynum)));
      mudlog("LINK: %s has lost their link", pname(mynum));
    }
  }

  fd = cur_player->fil_des;
  bflush();

#ifdef KEEP_LINKDEAD
  /* Reset idle time if we idle link dead people out at special time */
  if (KEEP_LINKDEAD > 0)
    cur_player->lastcommand_time = time(0);
#endif

  /*  Free all the input handlers */
  i = cur_player->inp_handler;
  while (i != NULL) 
  {
    j = i;
    i = i->next;
    free(j);
  }
  cur_player->inp_handler = NULL;
  cur_player->linkdead = true;

  if((cur_player->fil_des!=-1) && cur_player->fil_des) 
  {
    if(FD_ISSET(fd,&buffer_fds))          /* Erkk! Hopefully the fix      */
      inp_buf_c--;                        /* for the processor eating bug */
    FD_CLR(fd,&sockets_fds);
    FD_CLR(fd,&buffer_fds);
    close(fd);
  }
  cur_player->fil_des = -1;
  
  if (cur_player->stream) 
  {
    fclose(cur_player->stream);
    cur_player->stream = NULL;
  }
}

#endif  /* KEEP_LINKDEAD */


** -----------------------------------------------------------------------
** 3)

>>for(fd=0; fd<width; fd++) {
>>  if (FD_ISSET(fd,&e_fds)) {
>>    
>>    int plx = find_pl_index(fd);
>>    
>>    if(plx<0) {
>>      return;
>>    }
>>  
>>    setup_globals(plx);
>>    
>>    if(cur_player->stream==NULL) {
>>      continue;
>>    }
	  
#ifdef KEEP_LINKDEAD
	    if(is_on(plx)) 
	    {
	      cleanup_link();
	      errno = 0;
	    } 
	    else 
	    {
	      crapup(NULL,CRAP_SAVE|CRAP_UNALIAS|CRAP_RETURN|CRAP_LINKLOSS);
	      errno = 0;                   /* Loose link */
	      quit_player();
	    }
#else
	    crapup(NULL,CRAP_SAVE|CRAP_UNALIAS|CRAP_RETURN|CRAP_LINKLOSS);
	    errno = 0;                   /* Loose link */
	    quit_player();
	    
#endif /* KEEP_LINKDEAD */
	    

** ------------------------------------------------------------------------
** 4)


>>  if(!cur_player->inp_buffer_end)
>>  {
>>    if ((x = recv(fd,cur_player->inp_buffer,MAX_COM_LEN, NULL)) <= 0)
>>    {
>>      if (errno == ECONNRESET ||     /* Connection reset by peer */
>>	  errno == EHOSTUNREACH ||   /* No route to host */
>>	  errno == ETIMEDOUT ||      /* Connection timed out */
>>	  errno == ENETUNREACH ||    /* Network is unreachable */
>>	  errno == ENETRESET ||      /* Network dropped connection on reset */
>>	  errno == ENETDOWN ||       /* Network is down */
>>	  !x)                        /* Link sends empty packets */
>>      {
>>
#ifdef KEEP_LINKDEAD
	if(is_on(real_mynum)) 
	{
	  cleanup_link();
	  errno = 0;
	} 
	else 
	{
	  crapup(NULL,CRAP_SAVE|CRAP_UNALIAS|CRAP_RETURN|CRAP_LINKLOSS);
	  errno = 0;                   /* Loose link */
	  quit_player();
	}
#else
	crapup(NULL,CRAP_SAVE|CRAP_UNALIAS|CRAP_RETURN|CRAP_LINKLOSS);
	errno = 0;                   /* Loose link */
	quit_player();

#endif /* KEEP_LINKDEAD */

>>	return;

** ------------------------------------------------------------
**  timing.c
**  The code for idling link dead players out..Goes in on_timer() 
**  Note that the else if() might need to be made an if ()
** 5)

#ifdef KEEP_LINKDEAD
	else if ((cur_player->linkdead == true)
	         && ((time(0) - cur_player->lastcommand_time)>KEEP_LINKDEAD) 
		 && (KEEP_LINKDEAD > 0))
	  {
	    /* There is little point in telling them they idled out */
	    /* since they are linkdead.                             */
	    send_msg(ploc(mynum), 0, pvis(mynum), LVL_MAX, mynum, NOBODY,
		     "The stone statue of %s disappears before your eyes.\n", pname(mynum));
	    send_msg(DEST_ALL, MODE_QUIET|MODE_COLOR,
		     max(pvis(mynum), LVL_WIZARD), LVL_MAX,
		     mynum, NOBODY,
		     "[%s was link dead and has idled out from %s&+Y (%s)]\n",
		     pname(mynum), sdesc(ploc(mynum)), 
		     xshowname(b, ploc(mynum)));
	    mudlog("LINK: Kicking linkdead player %s out.", pname(mynum));
	    players[mynum].linkdead = false;
	    quit_player();
	    crapup("You have timed out!", SAVE_ME|CRAP_NOMSG);
	  }

#endif /* KEEP_LINKDEAD */



**--------------------------------------------------------------------------
** 6)

#ifdef KEEP_LINKDEAD  /* Do not attack link dead players. (Ithor)          */
    if (players[plx].linkdead == true)
      continue;
#endif /* KEEP_LINKDEAD */



**--------------------------------------------------------------------------
** 7)
**  add this in list_people() just after the code that adds 'sitting' to
**  what you see of a player when you look.

#ifdef KEEP_LINKDEAD
	if (players[i].linkdead == true)
	  {
	    bprintf(" (Brain Dead)");
	  }
#endif /* KEEP_LINKDEAD */



**--------------------------------------------------------------------------
** 8) regenerate()


>>  for(i = 0; i < max_players; ++i)
>>  {
>>    if (is_in_game(i) 
>>	&& (pfighting(i) < 0) 
#ifdef KEEP_LINKDEAD  /* Don't heal link dead chars -Ithor */
	&& (players[i].linkdead == false)
#endif
>>	&& (pstr(i) < maxstrength(i)))
>>      {



** -----------------------------------------------------------------------
** 9) Just add the prototype to top of mud.c

#ifdef KEEP_LINKDEAD
static void reconnect_player(void);
#endif


** -----------------------------------------------------------------------
** 10) find_free_player_slot().  We replace the current forloop
**  with this #ifdef version

#ifdef KEEP_LINKDEAD
  for (i = 0; ((i < v) &&
       ((players[i].inp_handler != NULL)||(players[i].linkdead == true)));)
#else
  for (i = 0; ((i < v) && (players[i].inp_handler != NULL));)
#endif


** -----------------------------------------------------------------------
** 11) Add this also to find_free_player_slot()

#ifdef KEEP_LINKDEAD
    p->linkdead    = false;
#endif



** -----------------------------------------------------------------------
** 12) Add this code to get_passwd1() after the code listed below.

>>  else
>>  {
>>    if (strcmp(cur_player->passwd,b) == 0)
>>    {
>>      /*        IAC WON'T ECHO (turn on local echo again) */
>>      cur_player->no_echo = false;
>>      if ( (plx = fpbns(pname(mynum))) >= 0)
>>      {
>>	bprintf( "\n\nThere was already someone named %s in the game.\n",
>>		pname(mynum));
>>	if (plx >= max_players)
>>	{
>>	  bprintf( "You can't use %s as a name.\n", pname(mynum));
>>	  quit_player();
>>	  /* calls loseme() for the lost pseudoconnection broadcast there */
>>	  loseme(0);
>>	}
#ifdef KEEP_LINKDEAD
	else if (players[plx].linkdead == true)
	{
	  reconnect_player();
	}
#endif /* KEEP_LINKDEAD */
>>	else
>>	{
>>	  kick_out_yn(NULL);



** -----------------------------------------------------------------------
** 13) The function reconnect_player

#ifdef KEEP_LINKDEAD

/*
**  reconnect a link dead player to their old player slot. -Ithor
*/
static void reconnect_player(void)
{
  int 	plx;
  int 	fd;
  FILE	*fp;
  PLAYER_REC *p;
  struct sockaddr_in sin;
  char host[MAXHOSTNAMELEN];

  bprintf("%s was link dead.\nWelcome back %s.\n\n",
	  psex(mynum)?"She":"He", pname(mynum));
  if ((plx = fpbns(pname(mynum))) < 0) {
    do_motd(NULL);
    return;
  }

  bflush();

  p = players + plx;
  fd = p->fil_des;
  p->fil_des = cur_player->fil_des;
  cur_player->fil_des = fd;
  sin = p->sin;
  p->sin = cur_player->sin;
  cur_player->sin = sin;
  fp = p->stream;
  p->stream = cur_player->stream;
  cur_player->stream = fp;
  fd = p->sin_len;
  p->sin_len = cur_player->sin_len;
  cur_player->sin_len = fd;
  strcpy(host, p->hostname);
  strcpy(p->hostname, cur_player->hostname);
  strcpy(cur_player->hostname, host);
  p->inp_buffer_p= p->inp_buffer;
  p->inp_buffer_end = NULL;
  p->sock_buffer_p= p->sock_buffer;
  p->linkdead = false;

  send_msg(ploc(plx), 0, pvis(plx), LVL_MAX, mynum, plx,
	   "The stone statue of %s suddenly comes back to life.\n",
	   pname(plx));
  
  send_msg(DEST_ALL, MODE_QUIET|MODE_COLOR, max(pvis(plx), LVL_WIZARD),
	   LVL_MAX, mynum, plx,
	   "[%s has reconnected]\n", pname(plx));
  mudlog("LINK: %s has reconnected.", pname(real_mynum));
  quit_player();
  fd = real_mynum;
  setup_globals(plx);
  trapch(ploc(mynum));
  push_input_handler(get_command);
  get_command(NULL);
  setup_globals(fd);
  return;
}

#endif /* KEEP_LINKDEAD */



** ---------------------------------------------------------------------
** Add this to the PLAYER_REC declared in mudtypes.h or playertype.h

#ifdef KEEP_LINKDEAD
  bool   	     linkdead;    /* Flag to record if a player is linkdead */
#endif



** ---------------------------------------------------------------------
** Add this to commands.c, tellcom()

#ifdef KEEP_LINKDEAD
  if ((b < max_players) && (b >= 0) && (players[b].linkdead == true)) 
  {
    bprintf("%s appears to be brain dead and unavailable for conversation"
	    " at the moment!!\n", pname(b));
    return;
  }
#endif /* KEEP_LINKDEAD */



** ---------------------------------------------------------------------

** userinfo.c (mobile.c) Add this to whocom
**

>>    if (plev(mynum) >= LVL_WIZARD && ststflg(i, SFL_NOCHAT))
>>      bprintf(" &+r<NoChat>&*");
>>    
#ifdef KEEP_LINKDEAD  /* Keep linkdead players in game. Ithor */
    if (players[i].linkdead == true) 
    {
      bprintf(" &+m<BrainDead>&*");
    } 
    else
#endif /* KEEP_LINKDEAD */
>>    if (ststflg(i,SFL_BUSY))
>>      bprintf(" &+r<Busy>&*");
>>    if (ststflg(i,SFL_AWAY))
>>      bprintf(" &+r<Away>&*");